在GWT中使用RPC时不兼容的RemoteServiceException

时间:2012-03-21 13:08:21

标签: java gwt gwt-rpc gwt2

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

一个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);

}

公共类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 );
}
}

}

不是Workink 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都是以类似的模式设计的,但它仍然给我一个错误。

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

感谢。

2 个答案:

答案 0 :(得分:2)

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

解决这个问题的方法是使用像

这样的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)

因此,如果你仔细观察,错误是不同的:

  

阻止尝试访问'com.client.RepositoryInterface'接口,该接口未由'com.server.ConnectionServiceImplObjectStore'实现

而不是

  

阻止尝试访问“com.client.RepositoryInterface”接口,该接口未由'com.server.ObjectStore'实现

这意味着您的配置仍然存在错误,您必须将客户端RepositoryInterfaceAsync指向实施RemoteServiceServlet的{​​{1}}。

答案 1 :(得分:0)

可能是您的web容器上的gwt-servlet.jar版本配置错误。请检查您的开发gwt-servlet.jar版本和Web容器gwt-servlet.jar版本。 n供参考 Misconfiguration or hack attempt