2011-11-02 55 views
0

我正在为Google Apps市场开发GWT应用程序。我在服务器端使用带Restlet的AppEngine。客户端我使用Restlet的GWT版本。这是一个很好的组合。我有我的域对象在客户端和服务器之间共享,因此不需要DTO或代理等等。在客户端,我可以简单地调用的Restlet资源:Google小工具中的Restlet GWT

CustomerResourceProxy customerResource = GWT.create(CustomerResourceProxy.class); 
customerResource.getClientResource().setReference("/customer"); 
customerResource.retrieve(new Result<Customer>() { .... } 

不需要解析底层的XML或使用JSNI解释传入的JSON。

但是...应用程序的一部分是GMAIL上下文小工具,我不能简单地使用上面的代码,因为小工具和服务器之间的所有通信都必须通过GadgetsIO makeRequest。

所以......只是为了小工具,我将不得不努力解析XML或使用JSNI来解释传入的JSON。

überhaupt是否有可能破解Restlet GWT客户端以通过GadgetsIO传递所有通信,需要什么?任何指针非常欢迎!

K.

+0

PUT,GET,POST,HEAD都支持该规范,请参阅http://opensocial-resources.googlecode.com/svn/spec/2.0/Core-Gadget。 XML#gadgets.io。可以将响应作为TEXT和响应标题进行检索。我相信,小工具容器/代理会过滤一些请求头。 – koma

+0

如果我从Restlet GWT版本中替换了RequestBuilder和朋友,并将其替换为其小工具副本http://code.google.com/p/gwt-google-apis/source/browse/trunk/gadgets/gadgets/src/ com/google/gwt/gadgets/client/rpc /?r = 1792? – koma

回答

0

我设法得到的Restlet资源小工具中使用GWT通过进行一些改变的Restlet GWT编辑工作:

  • 在GwtClientCall我被代替标准GWT requestbuilder GadgetRequestBuilder(这将IoProvider.makeRequest),像这样:

    public GwtClientCall(GwtHttpClientHelper helper, String method, String requestUri, boolean hasEntity) { 
        super(helper, method, requestUri); 
        Reference requestRef = new Reference(requestUri); 
        if (requestRef.isRelative() || requestRef.getScheme().startsWith("http")) { 
        this.requestBuilder = new GadgetsRequestBuilder(method, requestUri); 
        this.requestBuilder.setTimeoutMillis(getHelper().getSocketConnectTimeoutMs()); 
        this.responseHeadersAdded = false; 
        } else { 
        throw new IllegalArgumentException("Only HTTP or HTTPS resource URIs are allowed here"); 
        } 
    } 
    
  • 在gadgetsrequestbuilder,我不得不做出一些变化,从而它会传递的标头中的请求:

    private GadgetsRequest doSend(String requestData, final RequestCallback callback) throws RequestException { 
    
    final RequestOptions options = RequestOptions.newInstance(); 
    options.setMethodType(methodType); 
    if (requestData != null && requestData.length() > 0) { 
        options.setPostData(requestData); 
    } 
    options.setAuthorizationType(AuthorizationType.SIGNED); 
    options.setContentType(ContentType.DOM); 
    setHeaders(options); 
    
    final GadgetsRequest gadgetsRequest = new GadgetsRequest(getTimeoutMillis(), callback); 
    gadgetsRequest.setPending(true); 
    
    IoProvider.get().makeRequest(getUrl(), new ResponseReceivedHandler<Object>() { 
        public void onResponseReceived(ResponseReceivedEvent<Object> event) { 
         gadgetsRequest.fireOnResponseReceived(event, callback); 
        } 
    
    }, options); 
    
    return gadgetsRequest; 
    } 
    
  • 默认带响应头的小工具的容器中,所以我手动添加MediaType.APPLICATION_JAVA_OBJECT_GWT

    @Override 
    public Series<org.restlet.client.engine.header.Header> getResponseHeaders() { 
    final Series<org.restlet.client.engine.header.Header> result = super.getResponseHeaders(); 
    if (!this.responseHeadersAdded && (getResponse() != null)) { 
        Header[] headers = getResponse().getHeaders(); 
        for (int i = 0; i < headers.length; i++) { 
         if (headers[i] != null) { 
          result.add(headers[i].getName(), headers[i].getValue()); 
         } 
        } 
        result.add(HeaderConstants.HEADER_CONTENT_TYPE, MediaType.APPLICATION_JAVA_OBJECT_GWT.toString()); 
        this.responseHeadersAdded = true; 
    } 
    
    return result; 
    } 
    

很多对话框用于以后调试,它可以工作:-)

+0

有人帮我布置这个答案有点? – koma

+0

管理修复布局 – koma

+0

原来不能在FF上工作,但在Chrome上工作...需要考虑这一点。 – koma