Google app engine 使用GWTP Rest调度访问远程服务

Google app engine 使用GWTP Rest调度访问远程服务,google-app-engine,gwt,gwt-platform,Google App Engine,Gwt,Gwt Platform,我想为我的GWTP应用程序的UI和后端开发分离软件包。 当前,我的UI使用如下配置的Rest dispatch访问后端: bindConstant().annotatedWith(RestApplicationPath.class).to("/MyProject/api"); 我想使用LocalHostUI(使用eclipse插件运行GWT应用程序)访问远程服务。我将上述行更改为: bindConstant().annotatedWith(RestApplicationPath.class).

我想为我的GWTP应用程序的UI和后端开发分离软件包。 当前,我的UI使用如下配置的Rest dispatch访问后端:

bindConstant().annotatedWith(RestApplicationPath.class).to("/MyProject/api");
我想使用LocalHostUI(使用eclipse插件运行GWT应用程序)访问远程服务。我将上述行更改为:

bindConstant().annotatedWith(RestApplicationPath.class).to("http://my-app.appspot.com/MyProject/api");
使用此方法,调用成功到达服务器(我可以在appengine日志中看到),但UI始终返回状态代码0


以上设置有什么问题?要使用GWT ui访问远程服务,我还需要做其他事情吗?

如果您想要一个同时在localhost/App Engine上运行的解决方案,您需要使用以下内容:

import com.google.gwt.core.client.GWT;
import com.google.gwt.inject.client.AbstractGinModule;
import com.google.inject.Provides;
import com.gwtplatform.dispatch.rest.client.RestApplicationPath;
import com.gwtplatform.dispatch.rest.client.gin.RestDispatchAsyncModule;

public class ServiceModule extends AbstractGinModule {
    @Override
    protected void configure() {
        install(new RestDispatchAsyncModule.Builder().build());
    }

    @Provides
    @RestApplicationPath
    String getApplicationPath() {
        String baseUrl = GWT.getHostPageBaseURL();
        if (baseUrl.endsWith("/")) {
            baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
        }

        return baseUrl + "/MyProject/api";
    }
}
getApplicationPath
返回的字符串将绑定到
@RestApplicationPath
,并由GWTP的RestDispatch无缝使用


在您的情况下,字符串将解析为
http://localhost:8080/MyProject/api
“http://my-app.appspot.com/MyProject/api“
取决于本地运行的应用程序或在应用程序引擎上运行的应用程序。

我的应用程序(appengine和localhost)使用“bindConstant().annotatedWith(RestApplicationPath.class).to(“/MyProject/api”);”背景我想在桌面(本地主机)上运行UI,并访问在应用引擎机器上运行的服务。哦,我现在明白你们的意思了。服务器返回的状态码是什么?我知道您的GWT应用程序接收到状态0,但您的GAE应用程序响应的是实际的HTTP代码吗?例如,如果您的服务器响应为200 OK,而您的GWT应用程序将响应解释为代码0,则可能是另一个问题。问题是CORS未正确启用。有关详细信息,请参阅此线程: