Ejemplo n.º 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);
    }
  }
Ejemplo n.º 2
0
  /**
   * Local file-system (file://) does not return any status codes. Therefore - if we read from the
   * file-system we accept all codes.
   *
   * <p>This is for instance relevant when developing a PhoneGap application with restyGwt.
   */
  public boolean isExpected(int status) {

    String baseUrl = GWT.getHostPageBaseURL();
    String requestUrl = builder.getUrl();

    if (FileSystemHelper.isRequestGoingToFileSystem(baseUrl, requestUrl)) {
      return true;
    } else if (anyStatus) {
      return true;
    } else {
      return this.expectedStatuses.contains(status);
    }
  }
Ejemplo n.º 3
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);
   }
 }
Ejemplo n.º 4
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);
   }
 }