2012-04-24 58 views
0

我試圖使用Dojo工具包似乎呼叫encountring一些的所有主題,這是與道場調用調用REST Web服務道場JAX-RS調用問題

dojo.xhrGet({ 
    url: 'http://localhost:9080/TestJMSWeb/jaxrs/categories/all', 
    handleAs: 'json', 
    timeout: 2000, 
    load: callback 
}); 
var callback = dojo.hitch(this, function(data) { 
    var massagedData = { 
    label: 'categorie', 
    identifier: 'id', 
    items: data 
    } 
    this.store = new dojo.data.ItemFileReadStore({data: massagedData}); 
    }); 

WebService的代碼是在這裏

@GET 
    @Path("/all") 
@Produces("application/json") 
public JSONArray getAllCategories() throws IOException { 
    final List<Categorie> allCategories = manager.getCategories(); 
    if (allCategories == null || allCategories.isEmpty()) 
     throw new WebApplicationException(ErrorUtil.jSONArrayResponse(Status.NO_CONTENT, "No category found")); 
    JSONArray jsonArray = jsonCustomerArray(allCategories); 
    return jsonArray; 

} 

當我打電話的web服務我得到一個錯誤信息

ResourceRegis I org.apache.wink.server.internal.registry.ResourceRegistry filterDispatchMethods The system cannot find any method in the ressources.CategorieRessouce class that supports OPTIONS. Verify that a method exists. 
[4/24/12 1:23:41:531 GMT] 0000002f SystemErr  R 0 TestJMSWeb INFO [WebContainer : 0] openjpa.Runtime - OpenJPA dynamically loaded a validation provider. 

似乎試圖調用ŧ當我使用.xhrGet函數時,他使用OPTIONS方法重新分配了什麼問題?

回答

0

這裏是描述問題的鏈接:http://engin.bzzzt.biz/2010/01/22/first-dojo-impression/

關於這傢伙的會談如何,如果它是一個跨域請求(我相信你的是,因爲端口),並且請求包含一些訪問控制 - * HTTP頭,比瀏覽器將請求作爲OPTIONS而不是GET發送。

Dojo在確定您正在進行跨域請求時添加Access-Control- *標頭。你可以嘗試去道場/ _base/xhr.js和註釋掉以下行(723至729)此修復自己:

// FIXME: is this appropriate for all content types? 
if(args.contentType !== false){ 
    xhr.setRequestHeader("Content-Type", args.contentType || _defaultContentType); 
} 
if(!args.headers || !("X-Requested-With" in args.headers)){ 
    xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); 
} 

我還沒有嘗試過這種修復又那麼請讓我知道如果有用!

+0

測試解決方案 之前,我有一個麻煩,我不能出於安全原因,數據
的XMLHttpRequest無法加載的http://本地主機:9080/TestJMSWeb/JAXRS /分類/所有。 Access-Control-Allow-Origin不允許源http:// localhost:8080。 – 2012-04-24 18:24:18

+0

所以你的數據在localhost:9080上,但你的dojo web應用程序在localhost:8080上?即使你看不到數據或訪問數據,這仍然不應該讓你在dojo/_base/xhr.js文件中註釋723-729行。還是你說你的網絡服務器需要Access-Control-Allow-Orgin頭文件? – MBillau 2012-04-24 20:30:34