简体   繁体   English

从其他网址启动应用程序时,GWT RPC失败

[英]GWT RPC fails when launching app from different urls

I'm using urls to navigate to different screens inside my GWT app. 我正在使用URL导航到我的GWT应用程序内的不同屏幕。 For example: 例如:

http://127.0.0.1/home
http://127.0.0.1/info/contact-us
http://127.0.0.1/app/index.html

I have a servlet that serves the html containing the required script element for GWT (my GWT module name is "app"): 我有一个Servlet,它为html包含GWT所需的脚本元素(我的GWT模块名称为“ app”):

<script type="text/javascript" language="javascript" src="/app/app.nocache.html">
</script>

This is working great with GWT 2.6.1. 与GWT 2.6.1一起使用时效果很好。 In the browser dev tools it's possible to see that RPC calls are made to my RemoteService at http://127.0.0.1/app/rpc 在浏览器开发工具中,可以在http://127.0.0.1/app/rpc上看到对我的RemoteService RPC调用

The problem is when I upgraded to GWT 2.8 , my app's RPC call endpoint is now different and wrong, depending on the URL used. 问题是,当我升级到GWT 2.8时 ,我的应用程序的RPC调用终结点现在有所不同并且是错误的,具体取决于所使用的URL。 For example: 例如:

http://127.0.0.1/home            -> http://127.0.0.1/rpc
http://127.0.0.1/info/contact-us -> http://127.0.0.1/info/rpc
http://127.0.0.1/app/index.html  -> http://127.0.0.1/app/rpc

For the above URLs the module is always correctly loaded and executed, however RPCs fail in the first two cases. 对于上述URL,模块始终正确加载和执行,但是在前两种情况下RPC失败。 only the last URL allows my app to make RPC calls. 只有最后一个URL允许我的应用进行RPC调用。

The RPC endpoint can be set by casting the client-side service proxy to ServiceDefTarget and using setServiceEntryPoint() . 可以通过将客户端服务代理转换为ServiceDefTarget并使用setServiceEntryPoint()来设置RPC端点。 As follows: 如下:

ourInstance = (MyRemoteServiceAsync)GWT.create(MyRemoteService.class);
ServiceDefTarget serviceDefTarget = (ServiceDefTarget) ourInstance;
serviceDefTarget.setServiceEntryPoint("/app/rpc");

However, the request payload still contains a reference to the incorrect module base. 但是,请求有效负载仍然包含对不正确的模块库的引用。 The http headers sent on the RPC request have incorrect values also: 在RPC请求上发送的http标头还具有不正确的值:

X-GWT-Module-Base:http://127.0.0.1/foo/bar/

Is there a way to force the client's RPC mechanism to use the correct RPC URL /app/rpc ? 有没有一种方法可以强制客户端的RPC机制使用正确的RPC URL /app/rpc Or perhaps a way to set the module-base correctly? 还是一种正确设置模块库的方法?

UPDATE 1 更新1

Seeing the same behaviour in GWT 2.7. 在GWT 2.7中看到了相同的行为。

Also, when deployed in a WAR the <module-hash>.cache.js file doesn't load because it is also requested relative to the url. 另外,在WAR中部署<module-hash>.cache.js文件时不会加载,因为它也是相对于URL的请求。 This is very bad because it means that the module code won't be cached, since this url is different every time. 这非常糟糕,因为这意味着模块代码不会被缓存,因为此URL每次都不同。 The fix needs to be made in the selector <module>.nocache.js . 需要在选择器<module>.nocache.js Is anyone actually using GWT with url linking in the real world? 有人在现实世界中实际使用带有URL链接的GWT吗?

By specifying a <meta> element in the <head> element of the html document, the bootstrap nocache.js selector javascript will choose the correct module baseUrl. 通过在html文档的<head>元素中指定一个<meta>元素,bootstrap nocache.js选择器javascript将选择正确的模块baseUrl。 The baseUrl must be a fully-specified absolute url, and end with a / . baseUrl必须是完全指定的绝对URL,并以/结尾。

For my example, the exact element was: 对于我的示例,确切的元素是:

<head>
   ...
   <meta name="gwt:property" content="baseUrl=http://127.0.0.1/app/" />
   ...
</head>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM