dojo jax-rs呼叫问题

时间:2012-04-24 00:36:39

标签: dojo jax-rs

我正在尝试使用dojo工具包调用REST Web服务,似乎调用遇到了一些问题,这是与dojo的调用

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

网络服务代码在这里

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

}

当我调用webservice时收到错误消息

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.

似乎是在尝试使用OPTIONS方法调用ressource而我正在使用.xhrGet函数有什么问题?

1 个答案:

答案 0 :(得分:0)

以下是描述问题的链接:http://engin.bzzzt.biz/2010/01/22/first-dojo-impression/

该家伙谈到如果它是一个跨域请求(我相信你的,因为端口),并且请求包含一些Access-Control- * HTTP标头,而不是浏览器将请求作为OPTIONS发送GET。

Dojo在确定您正在发出跨域请求时添加了Access-Control- *标头。您可以尝试通过转到dojo / _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");
}

我还没有尝试过这个修复程序,所以请告诉我它是否有效!