We are using JBoss 5.1 with Guice 3.0 and need to forward from our Guice servlet to an external Servlet using the following technique:
@Inject HttpServletRequest request;
@Inject HttpServletResponse response;
@GET
@Produces("application/octet-stream")
@Path("/get/1234")
public void fwd() throws ServletException, IOException {
String newURL = "/ExternalServlet?action=1234";
RequestDispatcher dispatcher = request.getRequestDispatcher(newURL);
dispatcher.forward(request, response);
}
On several of our dev servers this forwards to the corrrect url (e.g. localhost/ourApp/ExternalServlet) but on our production staging server it is prepending /get/1234 so the url is forwarding to localhost/ourApp/get/1234/ExternalServlet. A redirect works.
Any idea why the forward is prepending the Guice servlet? Thanks.
I'm not sure of the exact cause of this, but you should be able to work around it using an HttpServletRequestWrapper. You can probably override what the getServletPath() or getContextPath() are returning to get your desired effect.
Another option is to try remote debugging your staging server and walking into the dispatcher code to see exactly where it is going wrong.