Search code examples
gwtgilead

Is it possible to programmatically change GWT RPC servlet path?


My GWT app works fine when run from http://localhost:8080/myapp.

I need to host the gwt app behind what is essentially a proxy. When behind the proxy, the url changes to something like http://localhost:8080/foo/bar/00_00_00/myapp.

Gwt is throwing an error when I try to access behind the proxy:

myAppServlet: ERROR: The module path requested, /foo/bar/00_00_00/myapp/MyApp/, is not in the same web application as this servlet, /myapp. Your module may not be properly configured or your client and server code maybe out of date.

The error appears to occur after rpc request when gwt tries to serialize java objects and send them back to client.

Is there any way to inform GWT that the app is behind a proxy?

Update:

It seems to work fine the first request. But then it fails for all other requests??!! I found the error is coming from RemoteServiceServlet.loadSerializationPolicy. Unfortunately, I can't override since it's static.

Maybe it's possible to set the servlet context path programmatically?


Solution

  • I'm not sure, if this will solve the entire problem, because you say, that it already works for the first time you make the call - but can you try the following when you create the serviceAsync on the client side:

    MyServiceAsync service = GWT.create(MyService.class);
    ServiceDefTarget serviceDefTarget = (ServiceDefTarget) service;
    serviceDefTarget.setServiceEntryPoint(
         "http://localhost:8080/foo/bar/00_00_00/myapp/MyApp/");
       /* ^^ Use your full servlet path here ^^ */
    

    If you wonder, why you'd have to cast this explicitly to ServiceDefTarget - here's an explanation from the Javadoc of ServiceDefTarget:

    /**
     * An interface implemented by client-side RPC proxy objects. Cast the object
     * returned from {@link com.google.gwt.core.client.GWT#create(Class)} on a
     * {@link RemoteService} to this interface to initialize the target URL for the
     * remote service.
     */
    

    (I assume, that you're loading your html host page from "http://localhost:8080", otherwise this would fail because of the Same Origin Policy.)

    Another problem I can imagine, may be related with caching in your proxy - so maybe try turning off any caching first, and then re-enable it only for resources with "*.cache.*" filenames (see also: Ideal HTTP cache control headers for different types of resources).