2011-04-05 101 views
1

我的GWT应用从http://localhost:8080/myapp运行正常。是否有可能以编程方式更改GWT RPC servlet路径?

我需要在本质上是代理的东西后面托管gwt应用程序。在代理之后,url更改为http://localhost:8080/foo/bar/00_00_00/myapp之类的内容。当出现GWT试图Java对象序列,并将它们发送回客户端RPC请求后发生

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.

的错误:当我尝试代理之后访问

GWT是抛出一个错误。

有什么办法通知GWT该应用程序在代理之后?

更新:

它似乎工作正常的第一个请求。但然后它失败的所有其他请求??! 我发现错误来自RemoteServiceServlet.loadSerializationPolicy。不幸的是,我不能重写,因为它是静态的。

也许有可能以编程方式设置servlet上下文路径?

回答

1

我不知道,这是否会解决整个问题,因为你说,它已经适用于你第一次拨打电话 - 但你可以尝试当您在客户端创建serviceAsync以下:

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 ^^ */ 

如果你想知道,为什么你必须明确地转换这ServiceDefTarget - 这里是从ServiceDefTarget的Javadoc中的解释:

/** 
* 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. 
*/ 

(我假设,你正在你的加载来自“http://localhost:8080”的html主页,否则为t他会因为同源策略而失败。)

我可以想象的另一个问题,可能与您的代理中的缓存有关 - 因此可能尝试先关闭任何缓存,然后重新启用它仅适用于资源与"*.cache.*"文件名(另见:Ideal HTTP cache control headers for different types of resources)。

+0

谢谢,这个我指出了正确的方向。我的web.xml为我的服务定义了url映射为/ myapp。但我终于意识到,你必须将servlet url映射到所有编译gwt js东西的相同url。所以,我将servlet的url-mapping改为/ MyApp/myapp。我的GWT模块被命名为MyApp。所以,现在这两条路径匹配,它的工作原理! – Upgradingdave 2011-04-05 19:45:29

相关问题