Search code examples
javagwtgwt-rpcgwt2

IncompatibleRemoteServiceException while using RPC in GWT


I have web application Project having RPC call.

one RPC async is working fine. but Another gives a error

    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)

Working RPC

 public interface ConnectionInterface extends RemoteService{

String connection(String[] authentication);

}

 public interface ConnectionInterfaceAsync {

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

}

public class ConnectionService implements 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);

}

// client Call

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 );
}
}

}

Not 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);
}
}

client call

 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 Code

  <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>

Both RPC is designed in similar patter still it gives me an error.

If any one can tell me why will be of great Help

thanks.


Solution

  • Your URL-mapping is off, you need to map your RPC RemoteServiceServlets to a better url-pattern. You map both servlets to /*. There is no guarantee which Servlet is executed when two or more a mapped to the exact same url-pattern. So my guess is, everytime you execute your not working service, the call is mapped to the other service.

    A way to work this out would be to use a web.xml like

    <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>
    

    Of course you also have to change your client-side services to use the correct serviceEntryPoint , so

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

    would have to change to something like

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

    to get to the right servlet.

    EDIT: Error of change:

    ERROR

     @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)
    

    So if you look closely, the error is different:

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

    instead of

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

    This means your configuration is still wrong, you have to point your client-side RepositoryInterfaceAsync to a RemoteServiceServlet that implements RepositoryInterface.