GWT-如何在其他项目中对一个项目进行 RPC 调用(使用服务器端)?

GWT- How to make RPC call(use server side) of one project in some other project?

我们已经使用 java 在 GWT 上创建了我们的 Web 项目。完全工作正常。现在,我们正在努力制作移动网站版本,该版本也将在 gwt 上,并且肯定会有不同的 url(如 m.exam.com)。

ISSUE:-

We want to use the server side of our web project as server side of the mobile website. So that only front-end have to be changes. As gone through some tutorials got that its possible that gwt rpc call made from android app.

But we want that it should be possible in gwt to gwt RPC call.

For android app they use Syncproxy where they change the baseurl and use it to call the gwt server side methods. It will be for sure the reusability of the code.

ANDROID 示例:-

SyncProxy.setBaseURL("http://testing.enggheads.in/enggheads/");

        GreetingServiceAsync greetService = SyncProxy.create(GreetingService.class);

那么,GWT项目如何通过这种方法实现使用其他项目的服务器端方法呢?


编辑 新问题:无法解决导入 com.gdevelop

我已经浏览了更多 gwt 文档以了解跨域 rpc 调用,例如 gwt 到 android 应用程序。我得到了 syncproxy 0.5 jar 文件,它与 android 的完全相同。具有相同的功能。我在项目中导入jar文件,如下调用SyncProxy的功能

public void onModuleLoad() {

    SyncProxy.setBaseURL("http://www.enggheads.in/CrossModuleCode/");
      final GreetingServiceAsync greetService = SyncProxy.create(GreetingService.class);

    final Button sendButton = new Button("Send");
    final TextBox nameField = new TextBox();
    nameField.setText("GWT User");
    final Label errorLabel = new Label();

    // We can add style names to widgets
    sendButton.addStyleName("sendButton");

    // Add the nameField and sendButton to the RootPanel
    // Use RootPanel.get() to get the entire body element
    RootPanel.get("nameFieldContainer").add(nameField);
    RootPanel.get("sendButtonContainer").add(sendButton);
    RootPanel.get("errorLabelContainer").add(errorLabel);

}

现在在编译项目时出现以下错误。

编辑 2:-

尝试在您的子项目中设置服务入口点
((ServiceDefTarget) greetService).setServiceEntryPoint("http://testing.enggheads.in/enggheads/");

如果您的子项目部署在另一个域中,您可能需要一个 CORS 过滤器来允许跨站点请求

编辑:
如何设置一个简单的示例:

  1. 创建一个"New Web Application project..."和select"generate project sample code"并命名为"mobileapp"
  2. 创建另一个 "New Web Application project..." 和 select "generate project sample code" 并将其命名为 "webapp"
  3. Mobileapp.java的第一行复制这段代码onModuleLoad((ServiceDefTarget) greetingService).setServiceEntryPoint("http://127.0.0.1:8080/webapp/webapp/greet"); webapp/greet<url-pattern>/webapp/greet</url-pattern>来自你的web.xml . http://127.0.0.1:8080/webapp 是 URL 到您的 webapp
  4. 编译这两个应用程序并将它们部署在同一个 tomcat 实例上。如果您将它们部署在不同的 tomcats 上,您必须为您的 webapp 使用 CORS 过滤器并允许跨域请求。
  5. 在浏览器中打开 http://127.0.0.1:8080/mobileapp/,然后按 Send 按钮。它将使用您的 webapp
    的服务器方法 重要提示:这仅在两个 GreetingService 接口具有相同方法时才有效...因此请始终保持它们同步

在这里你可以下载两个项目,如上文所述,风险自负:googledrive link