Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4904

Support for cross context request processing

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.3.34
    • 6.7.1
    • Dispatch Filter
    • None
    • Wildlfy 10.1.0
      Struts 2.3.34
      JDK 1.8.0_151

    Description

      When a request is forwarded from one context to another (both using struts2)

      ServletContext sContext = context.getContext("/context2");
      RequestDispatcher rd = sContext.getRequestDispatcher(resource);
      rd.forward(request, response);
      

      you get a ClassCastException. Both the projects has their own struts jars (in WEB-INF/lib folder).

      Caused by: java.lang.ClassCastException: org.apache.struts2.dispatcher.mapper.ActionMapping cannot be cast to org.apache.struts2.dispatcher.mapper.ActionMapping
          at org.apache.struts2.dispatcher.ng.PrepareOperations.findActionMapping(PrepareOperations.java:163)
          at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:92)
          at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
          at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
          at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
          at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
          at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
          at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:274)
          at io.undertow.servlet.handlers.ServletInitialHandler.dispatchToPath(ServletInitialHandler.java:209)
          at io.undertow.servlet.spec.RequestDispatcherImpl.forwardImpl(RequestDispatcherImpl.java:221)
          ... 128 more
      

      To make it work you have to have a filter (before struts2 filter) in the application that is receiving the request and have the below two lines.

      request.setAttribute("struts.actionMapping", new ActionMapping());
      request.setAttribute("struts.valueStack", null);
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            prasanth_struts Prasanth
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: