예제 #1
0
  public <T extends JavaScriptObject> void send(final OverlayCallback<T> callback) {

    defaultAcceptType(Resource.CONTENT_TYPE_JSON);
    try {
      send(
          new AbstractRequestCallback<T>(this, callback) {
            protected T parseResult() throws Exception {
              try {
                JSONValue val = JSONParser.parse(response.getText());
                if (val.isObject() != null) {
                  return (T) val.isObject().getJavaScriptObject();
                } else if (val.isArray() != null) {
                  return (T) val.isArray().getJavaScriptObject();
                } else {
                  throw new ResponseFormatException("Response was NOT a JSON object");
                }
              } catch (JSONException e) {
                throw new ResponseFormatException("Response was NOT a valid JSON document", e);
              } catch (IllegalArgumentException e) {
                throw new ResponseFormatException("Response was NOT a valid JSON document", e);
              }
            }
          });
    } catch (Throwable e) {
      GWT.log("Received http error for: " + builder.getHTTPMethod() + " " + builder.getUrl(), e);
      callback.onFailure(this, e);
    }
  }
예제 #2
0
 public void send(final TextCallback callback) {
   defaultAcceptType(Resource.CONTENT_TYPE_TEXT);
   try {
     send(
         new AbstractRequestCallback<String>(this, callback) {
           protected String parseResult() throws Exception {
             return response.getText();
           }
         });
   } catch (Throwable e) {
     GWT.log("Received http error for: " + builder.getHTTPMethod() + " " + builder.getUrl(), e);
     callback.onFailure(this, e);
   }
 }
예제 #3
0
 public void send(final XmlCallback callback) {
   defaultAcceptType(Resource.CONTENT_TYPE_XML);
   try {
     send(
         new AbstractRequestCallback<Document>(this, callback) {
           protected Document parseResult() throws Exception {
             try {
               return XMLParser.parse(response.getText());
             } catch (Throwable e) {
               throw new ResponseFormatException("Response was NOT a valid XML document", e);
             }
           }
         });
   } catch (Throwable e) {
     GWT.log("Received http error for: " + builder.getHTTPMethod() + " " + builder.getUrl(), e);
     callback.onFailure(this, e);
   }
 }