title: Cross-context request forwarding in tomcat results in java.lang.ClassCastException: org.glassfish.jersey.message.internal.TracingLogger
body: <p>I am trying to forward a request from one webapp (using Jersey 2.10) to another ("<code>myWebapp</code>") by using RequestDispatcher.forward(request, response). Both webapps reside in /tomcat/webapps. In the context.xml I set <code>&lt;Context crossContext="true"&gt;</code>.</p>
  
  <pre><code>@GET
  @Path("")
  public Response getTest(
          @Context ServletContext context,
          @Context HttpServletRequest request,
          @Context HttpServletResponse response)
          throws Exception {
  
          ServletContext fCtx = context.getContext("/myWebapp");
          System.out.println("ctx: "+context);
          System.out.println("forward-ctx: "+fCtx);
  
          RequestDispatcher dispatcher=fCtx.getRequestDispatcher("/test");
          System.out.println("rd: "+dispatcher);      
  
          System.out.println("request: "+request);
          System.out.println("response: "+response);
  
          dispatcher.forward(request, response); &lt;- throwing ClassCastException
  
  }
  </code></pre>
  
  <p>This shows the following output:</p>
  
  <pre><code>ctx: org.apache.catalina.core.ApplicationContextFacade@48a7c880
  forward-ctx: org.apache.catalina.core.ApplicationContextFacade@72d0abcb
  rd: org.apache.catalina.core.ApplicationDispatcher@7f5c70c3
  request: org.apache.catalina.connector.RequestFacade@3829f752
  response: org.apache.catalina.connector.ResponseFacade@4b2c454c
  </code></pre>
  
  <p>So everything should be set. But when I execute it, I get the following exception on forwarding:</p>
  
  <pre><code>java.lang.ClassCastException: org.glassfish.jersey.message.internal.TracingLogger$1 cannot be cast to org.glassfish.jersey.message.internal.TracingLogger
      at org.glassfish.jersey.message.internal.TracingLogger.getInstance(TracingLogger.java:144)
      at org.glassfish.jersey.server.internal.routing.UriRoutingContext.&lt;init&gt;(UriRoutingContext.java:115)
      at org.glassfish.jersey.server.ContainerRequest.&lt;init&gt;(ContainerRequest.java:179)
      at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:345)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:690)
      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:477)
      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
  </code></pre>
  
  <p>I am not sure, if this is not compatible with Jersey? I tried up to current version of Jersey 2.17. Is this maybe a Jersey thing which has nothing to do with the actual forwarding and how can I work around it...?</p>
  
  <p><strong>UPDATE:</strong>
  Interestingly, the same error is thrown no matter if the request method is GET or POST. Within another app, using exactly the same setup, the forwarding works. So I assume, its not a Jersey problem per se, but depending on my setup. Still can't figure out what it might be.</p>