GWT: Calling RPC Service inside another module

╄→尐↘猪︶ㄣ 提交于 2019-12-22 17:09:16

问题


I have a module B, which inherits module A. When I call RPC Services from A inside A, they work ok. But when I call the services from A in B, the RPC invocations always fail. Am I missing something?

Thanks in advance for any help.


回答1:


I've found the answer for my question here: http://blog.cloudglow.com/2010/03/making-gwt-rpc-endpoint-independent-of.html

The default GWT RPC service (Servlet) endpoint is @RemoteServiceRelativePath("some_name"), which resolves to /module_base/some_name at runtime on the client. The issue with this approach is that your RPC endpoint is now tied to GWT Module. While this may be fine for some cases, it was not for our situation. Hence this post.

We ended up creating a RPC services factory class that would create a static instance of the service endpoint and also seed it with the right endpoint; something like this:

public class ServicesFactory
{
public static final RPCServiceAsync RPCService = GWT.create(RPCService.class);

static
{
((ServiceDefTarget) RPCService).setServiceEntryPoint(GWT.getHostPageBaseURL() + RPCService.END_POINT);
}
}



回答2:


There is another way of solving it. Simply adding a new servlet mapping for each new method.

<servlet-mapping>
    <servlet-name>serverName</servlet-name>
    <url-pattern>/Module1</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>serverName</servlet-name>
    <url-pattern>/Module2</url-pattern>
</servlet-mapping>


来源:https://stackoverflow.com/questions/5284190/gwt-calling-rpc-service-inside-another-module

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!