java - 在 GWT 中使用 RPC 时出现不兼容的远程服务异常

标签 java gwt gwt-rpc gwt2

我有一个具有 RPC 调用的 Web 应用程序项目。

一个 RPC 异步工作正常。但另一个给出了一个错误

    Mar 21, 2012 1:34:51 PM com.google.appengine.tools.development.ApiProxyLocalImpl log
SEVERE: javax.servlet.ServletContext log: ObjectStore: An      IncompatibleRemoteServiceException was thrown while processing this call.
com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException: This application is out of date, please click the refresh button on your browser. ( Blocked attempt to access interface 'com.client.RepositoryInterface', which is not implemented by 'com.server.ObjectStore'; this is either misconfiguration or a hack attempt )
at com.google.gwt.user.server.rpc.RPC.decodeRequest(RPC.java:252)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:206)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
<小时/>

正在运行的 RPC

 public interface ConnectionInterface extends RemoteService{

String connection(String[] authentication);

}

 public interface ConnectionInterfaceAsync {

void connection(String[] authentication, AsyncCallback<String> callback);

}

公共(public)类 ConnectionService 实现 ConnectionInterfaceAsync {

ConnectionInterfaceAsync service = (ConnectionInterfaceAsync)GWT.create(ConnectionInterface.class);

ServiceDefTarget endpoint = (ServiceDefTarget) service;

public ConnectionService() {

    endpoint.setServiceEntryPoint(GWT.getModuleBaseURL() + "rpc");
}

public void connectionCMIS(String[] authentication,
        AsyncCallback<String> callbackConnection) {

    service.connectionCMIS(authentication, callbackConnection);

}

//客户端调用

public class Login extends Composite  {
 private ConnectionService connectionService = new ConnectionService();
// more code
 public void onClick(ClickEvent event) {
      AsyncCallback<String> callbackConnection = new AsyncCallback<String>() {

            public void onSuccess(String result) {
                             // print Succuss
                          }
      }
      connectionService.connection(authentication, callbackConnection );
}
}

}

无法使用ink RPC

 public interface RepositoryInterface extends RemoteService {
public FolderCollection getRepositories();
 }

 public interface RepositoryInterfaceAsync {
void getRepositories(AsyncCallback<FolderCollection> repositoryCallback);
 }


  public class RepositoryService implements RepositoryInterfaceAsync{

RepositoryInterfaceAsync async = (RepositoryInterfaceAsync)GWT.create(RepositoryInterface.class);
ServiceDefTarget endpoint = (ServiceDefTarget) async;

public CmisRepositoryService() {
    endpoint.setServiceEntryPoint(GWT.getModuleBaseURL() + "repository");
}
public void getRepositories(
        AsyncCallback<FolderCollection> repositoryCallback) {

    async.getRepositories(repositoryCallback);
}
}

客户来电

 public class Workplace {
  private RepositoryService service = new RepositoryService();
  // some more code
  void doRepo(){
    AsyncCallback<FolderCollection> repositoryCallback = new AsyncCallback<FolderCollection>() {

        public void onSuccess(FolderCollection result) {
        }

        public void onFailure(Throwable caught) {
        }
    };

    service.getRepositories(repositoryCallback);
  }
 }

XML 代码

  <servlet>
  <servlet-name>ConnectionServlet</servlet-name>
   <servlet-class>com.server.ConnectionServiceImpl</servlet-class>
 </servlet>
<servlet>
 <servlet-name>ObjectStore</servlet-name>
<servlet-class>com.server.ObjectStore</servlet-class>

 <servlet-mapping>
 <servlet-name>ConnectionServlet</servlet-name>
 <url-pattern>/*</url-pattern>
  </servlet-mapping>
 <servlet-mapping>
 <servlet-name>ObjectStore</servlet-name>
 <url-pattern>/*</url-pattern>
 </servlet-mapping>

两个 RPC 的设计方式相似,但仍然给我一个错误。

如果有人能告诉我为什么会很有帮助

谢谢。

最佳答案

您的 URL 映射已关闭,您需要将 RPC RemoteServiceServlet 映射到更好的 url-pattern 。您将两个 servlet 映射到 /* 。当两个或多个映射到完全相同的 Servlet 时,无法保证执行哪个 Servlet url-pattern 。所以我的猜测是,每次执行不工作的服务时,调用都会映射到其他服务。

解决这个问题的一种方法是使用像这样的 web.xml

<servlet-mapping>
  <servlet-name>ConnectionServlet</servlet-name>
  <url-pattern>/ConnectionService.rpc</url-pattern>
 </servlet-mapping>
 <servlet-mapping>
   <servlet-name>ObjectStore</servlet-name>
   <url-pattern>/ObjectStoreService.rpc</url-pattern>
 </servlet-mapping>

当然,您还必须更改客户端服务以使用正确的 serviceEntryPoint ,所以

 endpoint.setServiceEntryPoint(GWT.getModuleBaseURL() + "rpc");

必须更改为类似的内容

 endpoint.setServiceEntryPoint(GWT.getHostPageBaseURL() + "ConnectionService.rpc");

获取正确的 servlet。

编辑:更改错误:

错误

 @ftr   `com.google.appengine.tools.development.ApiProxyLocalImpl log
SEVERE: javax.servlet.ServletContext log: ConnectionServlet: An IncompatibleRemoteServiceException was thrown while processing this call.
com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException: This application is out of date, please click the refresh button on your browser. ( Blocked attempt to access interface 'com.client.RepositoryInterface', which is not implemented by 'com.server.ConnectionServiceImpl'; this is either misconfiguration or a hack attempt )
at com.google.gwt.user.server.rpc.RPC.decodeRequest(RPC.java:252)
at  com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:206)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)

所以如果你仔细观察,错误是不同的:

Blocked attempt to access interface 'com.client.RepositoryInterface', which is not implemented by 'com.server.ConnectionServiceImplObjectStore'

而不是

Blocked attempt to access interface 'com.client.RepositoryInterface', which is not implemented by 'com.server.ObjectStore'

这说明你的配置还是错误的,你得把你的客户端指向RepositoryInterfaceAsyncRemoteServiceServlet实现 RepositoryInterface .

关于java - 在 GWT 中使用 RPC 时出现不兼容的远程服务异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9805262/

相关文章:

java - 无法从内存中检索 mp3 文件

java - Wildfly 无法部署应用程序(FileNotFoundException - 访问被拒绝)

spring - java.lang.NoSuchMethodError : org. slf4j.spi.LocationAwareLogger.log

java - 如何使用 GWT 实现进度条?

java - GWT-RPC 还是 RequestFactory 用于身份验证?

gwt - 如何确定为什么在GWT-RPC中触发onFailure?

java - 如何打破情况并重复程序直到用户选择退出

java - 在 Android 应用程序中显示从 PHP 捕获的 JSON 对象

java - Gwt编译错误: unable to find type

gwt - 如何在客户端缓存 RequestFactory 数据?