是否可以以编程方式更改GWT RPC servlet路径?

时间:2011-04-05 14:38:53

标签: gwt gilead

http://localhost:8080/myapp开始运行时,我的GWT应用程序正常运行。

我需要在基本上是代理的背后托管gwt app。在代理后面,网址会更改为http://localhost:8080/foo/bar/00_00_00/myapp

当我尝试在代理后面访问时,Gwt会抛出错误:

  

myAppServlet:错误:模块路径   要求,   / foo / bar / 00_00_00 / myapp / MyApp /,不是   在与此相同的Web应用程序中   servlet,/ myapp。你的模块可能没有   正确配置或您的客户端   和服务器代码可能已过期。

当gwt尝试序列化java对象并将它们发送回客户端时,在rpc请求之后出现错误。

有没有办法通知GWT应用程序是在代理服务器后面?

更新:

第一次请求似乎工作正常。但是它失败了所有其他请求?? !! 我发现错误来自RemoteServiceServlet.loadSerializationPolicy。不幸的是,我无法覆盖,因为它是静态的。

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

1 个答案:

答案 0 :(得分: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主页,否则由于同源政策而失败。)

我可以想象的另一个问题可能与您的代理中的缓存有关 - 所以可能先尝试关闭任何缓存,然后仅为具有"*.cache.*"文件名的资源重新启用它(另请参阅:{{3 }})。