2011-04-05 47 views
1

我的GWT應用從http://localhost:8080/myapp運行正常。是否有可能以編程方式更改GWT RPC servlet路徑?

我需要在本質上是代理的東西后面託管gwt應用程序。在代理之後,url更改爲http://localhost:8080/foo/bar/00_00_00/myapp之類的內容。當出現GWT試圖Java對象序列,並將它們發送回客戶端RPC請求後發生

myAppServlet: ERROR: The module path requested, /foo/bar/00_00_00/myapp/MyApp/, is not in the same web application as this servlet, /myapp. Your module may not be properly configured or your client and server code maybe out of date.

的錯誤:當我嘗試代理之後訪問

GWT是拋出一個錯誤。

有什麼辦法通知GWT該應用程序在代理之後?

更新:

它似乎工作正常的第一個請求。但然後它失敗的所有其他請求??! 我發現錯誤來自RemoteServiceServlet.loadSerializationPolicy。不幸的是,我不能重寫,因爲它是靜態的。

也許有可能以編程方式設置servlet上下文路徑?

回答

1

我不知道,這是否會解決整個問題,因爲你說,它已經適用於你第一次撥打電話 - 但你可以嘗試當您在客戶端創建serviceAsync以下:

MyServiceAsync service = GWT.create(MyService.class); 
ServiceDefTarget serviceDefTarget = (ServiceDefTarget) service; 
serviceDefTarget.setServiceEntryPoint(
    "http://localhost:8080/foo/bar/00_00_00/myapp/MyApp/"); 
    /* ^^ Use your full servlet path here ^^ */ 

如果你想知道,爲什麼你必須明確地轉換這ServiceDefTarget - 這裏是從ServiceDefTarget的Javadoc中的解釋:

/** 
* An interface implemented by client-side RPC proxy objects. Cast the object 
* returned from {@link com.google.gwt.core.client.GWT#create(Class)} on a 
* {@link RemoteService} to this interface to initialize the target URL for the 
* remote service. 
*/ 

(我假設,你正在你的加載來自「http://localhost:8080」的html主頁,否則爲t他會因爲同源策略而失敗。)

我可以想象的另一個問題,可能與您的代理中的緩存有關 - 因此可能嘗試先關閉任何緩存,然後重新啓用它僅適用於資源與"*.cache.*"文件名(另見:Ideal HTTP cache control headers for different types of resources)。

+0

謝謝,這個我指出了正確的方向。我的web.xml爲我的服務定義了url映射爲/ myapp。但我終於意識到,你必須將servlet url映射到所有編譯gwt js東西的相同url。所以,我將servlet的url-mapping改爲/ MyApp/myapp。我的GWT模塊被命名爲MyApp。所以,現在這兩條路徑匹配,它的工作原理! – Upgradingdave 2011-04-05 19:45:29

相關問題