Ejemplo n.º 1
0
  protected <T extends JavaScriptObject> void requestObject(
      final RequestBuilder builder, final AsyncCallback<T> callback) {

    builder.setUser(DEFAULT_USER);
    builder.setPassword(DEFAULT_PASSWORD);
    builder.setCallback(
        new RequestCallback() {
          @SuppressWarnings("unchecked")
          @Override
          public void onResponseReceived(Request request, Response response) {
            if (200 == response.getStatusCode()) {
              callback.onSuccess((T) JsonUtils.safeEval(response.getText()));
            } else {
              final StatusCodeException exception =
                  new StatusCodeException(response.getStatusCode(), response.getStatusText());
              callback.onFailure(exception);
            }
          }

          @Override
          public void onError(Request request, Throwable exception) {
            callback.onFailure(exception);
          }
        });
    try {
      builder.send();
    } catch (RequestException exception) {
      callback.onFailure(exception);
    }
  }
Ejemplo n.º 2
0
  public static RequestBuilder request(Method httpMethod, String url, String user, String secret) {

    RequestBuilder request = new RequestBuilder(httpMethod, url);
    // request.setHeader("Authorization", "Basic " + Base64.encode(user + ":" + secret));
    request.setUser(user.replace("@", ".at-."));
    request.setPassword(secret);
    return request;
  }
Ejemplo n.º 3
0
 public Method user(String user) {
   builder.setUser(user);
   return this;
 }