2012-03-21 77 views
0

我有Web應用程序項目有RPC調用。在GWT中使用RPC時IncompatibleRemoteServiceException

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

您的URL映射已關閉,您需要將RPC RemoteServiceServlets映射到更好的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指向執行RepositoryInterfaceRemoteServiceServlet

+0

仍然我收到相同的錯誤。我正在更新您的代碼中的錯誤。 – GameBuilder 2012-03-21 13:42:27

+0

@GameBuilder你有另外一個實現'com.server.ObjectStore'的服務嗎?我只是意識到你對'RepositoryInterface'的請求實際上映射到了那個。我仍然認爲這是您的web.xml /服務入口點配置錯誤的情況。 – ftr 2012-03-21 13:53:31

+0

不,只有一個使用'com.server.ObjectStore'的服務。但其他服務使用'com.server.ConnectionServiceImpl'和'objectStore extends ConnectionServiceImpl' – GameBuilder 2012-03-21 14:01:33

0

這可能是您的web-container上的gwt-servlet.jar版本配置錯誤。請檢查您的開發gwt-servlet.jar版本和web容器gwt-servlet.jar版本。 n供參考 Misconfiguration or hack attempt