Example #1
0
 public void onReadyStateChange(XMLHttpRequest xhr) {
   if (xhr.getReadyState() == XMLHttpRequest.DONE) {
     if (xhr.getStatus() == 200) {
       callback.onSuccess(xhr);
       xhr.clearOnReadyStateChange();
       return;
     }
     callback.onFail(xhr);
     xhr.clearOnReadyStateChange();
   }
 }
Example #2
0
 private static void request(
     XMLHttpRequest xhr, String method, String url, final XhrCallback callback) {
   try {
     xhr.setOnReadyStateChange(new Handler(callback));
     xhr.open(method, url);
     xhr.send();
   } catch (Exception e) {
     // Just fail.
     callback.onFail(xhr);
     xhr.clearOnReadyStateChange();
   }
 }
Example #3
0
 private static void request(
     XMLHttpRequest xhr,
     String method,
     String url,
     String requestData,
     String contentType,
     XhrCallback callback) {
   try {
     xhr.setOnReadyStateChange(new Handler(callback));
     xhr.open(method, url);
     xhr.setRequestHeader("Content-type", contentType);
     xhr.send(requestData);
   } catch (Exception e) {
     // Just fail.
     callback.onFail(xhr);
     xhr.clearOnReadyStateChange();
   }
 }
  @Override
  public Header[] getHeaders() {
    String allHeaders = xmlHttpRequest.getAllResponseHeaders();
    String[] unparsedHeaders = allHeaders.split("\n");
    Header[] parsedHeaders = new Header[unparsedHeaders.length];

    for (int i = 0, n = unparsedHeaders.length; i < n; ++i) {
      String unparsedHeader = unparsedHeaders[i];

      if (unparsedHeader.length() == 0) {
        continue;
      }

      int endOfNameIdx = unparsedHeader.indexOf(':');
      if (endOfNameIdx < 0) {
        continue;
      }

      final String name = unparsedHeader.substring(0, endOfNameIdx).trim();
      final String value = unparsedHeader.substring(endOfNameIdx + 1).trim();
      Header header =
          new Header() {
            @Override
            public String getName() {
              return name;
            }

            @Override
            public String getValue() {
              return value;
            }

            @Override
            public String toString() {
              return name + " : " + value;
            }
          };

      parsedHeaders[i] = header;
    }

    return parsedHeaders;
  }
 @Override
 public String getText() {
   return xmlHttpRequest.getResponseText();
 }
 @Override
 public String getStatusText() {
   return xmlHttpRequest.getStatusText();
 }
 @Override
 public int getStatusCode() {
   return xmlHttpRequest.getStatus();
 }
 @Override
 public String getHeadersAsString() {
   return xmlHttpRequest.getAllResponseHeaders();
 }
  @Override
  public String getHeader(String header) {
    StringValidator.throwIfEmptyOrNull("header", header);

    return xmlHttpRequest.getResponseHeader(header);
  }
 private boolean isResponseReady() {
   return xmlHttpRequest.getReadyState() == XMLHttpRequest.DONE;
 }