Gwt Request builder - how to return the response string

后端 未结 3 1664
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-11 17:46

I need to implement a function that calls a web service and return the response.

I tried

public String getFolderJson(String path) {  
           Stri         


        
3条回答
  •  忘掉有多难
    2021-01-11 18:08

    Try the same solution offered above except not with an anonymous Callback.

    public String getFolderJson(String path) { 
    
        RequestBuilder builder = new RequestBuilder(...);
        HttpCallback cb=new HttpCallback();
    
        try {
          builder.sendRequest(null, cb);
        } catch (RequestException e) {
        // exception handling
            logger.severe(cb.err);
        }  
    
        return cb.result;
    }
    
    class HttpCallback implements RequestCallback{
    
        String result;
        String err;
    
        HttpCallback(){}
    
        @Override
        public void onResponseReceived(Request request, Response response) {            
            result=response.getText());     
        }
    
        @Override
        public void onError(Request request, Throwable exception) {
            err=exception.getMessage();     
        }       
    }
    

提交回复
热议问题