Package com.google.gwt.http.client

Examples of com.google.gwt.http.client.RequestCallback


            // etc.), which would corrupt the request if not encoded.
            String encodedUsername = URL.encodeQueryString(username);
            String encodedPassword = URL.encodeQueryString(password);
            String requestData = "j_username=" + encodedUsername + "&j_password=" + encodedPassword;
            requestBuilder.setRequestData(requestData);
            requestBuilder.setCallback(new RequestCallback() {
                public void onResponseReceived(Request request, Response response) {
                    int statusCode = response.getStatusCode();
                    if (statusCode == 200) {
                        window.destroy();
                        fakeForm.setVisible(false);
View Full Code Here


    public static void checkLoginStatus(final String user, final String password, final AsyncCallback<Subject> callback) {
        //initiate request to portal.war(SessionAccessServlet) to retrieve existing session info if exists
        //session has valid user then <subjectId>:<sessionId>:<lastAccess> else ""
        final RequestBuilder b = createSessionAccessRequestBuilder();
        try {
            b.setCallback(new RequestCallback() {
                public void onResponseReceived(final Request request, final Response response) {

                    Log.info("response text = " + response.getText());
                    String sessionIdString = response.getText();
View Full Code Here

    private static void scheduleWebUserUpdate(final Subject loggedInSubject) {
        final RequestBuilder b = createSessionAccessRequestBuilder();
        //add header to signal SessionAccessServlet to update the WebUser for the successfully logged in user
        b.setHeader(HEADER_WEB_USER_UPDATE, String.valueOf(loggedInSubject.getSessionId()));
        try {
            b.setCallback(new RequestCallback() {
                public void onResponseReceived(final Request request, final Response response) {
                    Log.trace("Successfully submitted request to update server side WebUser for subject '"
                        + loggedInSubject.getName() + "'.");
                }
View Full Code Here

        final RequestBuilder b = createSessionAccessRequestBuilder();
        // add header to signal SessionAccessServlet to refresh the http lastAccess time (basically a no-op as the
        // request will make that happen).
        b.setHeader(HEADER_LAST_ACCESS_UPDATE, "dummy");
        try {
            b.setCallback(new RequestCallback() {
                public void onResponseReceived(final Request request, final Response response) {
                    Log.trace("Successfully submitted request to update HTTP accessTime");
                }

                @Override
View Full Code Here

    // TODO: add handled to capture timeout failure and retry (at least once) to add resilience to GWT service calls?
    @Override
    protected <T> RequestCallback doCreateRequestCallback(ResponseReader responseReader, String methodName,
        RpcStatsContext statsContext, AsyncCallback<T> callback) {

        RequestCallback original = super.doCreateRequestCallback(responseReader, methodName, statsContext, callback);
        TrackingRequestCallback trackingCallback = new TrackingRequestCallback(statsContext.getRequestId(), methodName,
                original);

        RPCTracker.getInstance().register(trackingCallback);
View Full Code Here

     *            true if the request should be synchronous, false otherwise
     */
    protected void doUidlRequest(final String uri, final String payload,
            final boolean synchronous) {
        if (!synchronous) {
            RequestCallback requestCallback = new RequestCallback() {
                public void onError(Request request, Throwable exception) {
                    showCommunicationError(exception.getMessage(), -1);
                    endRequest();
                    if (!applicationRunning) {
                        // start failed, let's try to start the next app
View Full Code Here

     * @return a RequestControl implementation to return back out.
     */
    protected XHRRequestControl doRequest(RequestBuilder builder, final RequestCallback callback) {
        doPreHook(builder);

        RequestCallback innerCallback = new RequestCallback() {
                public void onResponseReceived(Request request, Response response) {
                    response = doPostHook(response);
                    callback.onResponseReceived(request, response);
                }

View Full Code Here

        username = requestUser;
    if (password == null)
      if (requestPassword != null)
        password = requestPassword;

    RequestCallback handler = new RequestCallback() {
      public void onResponseReceived(Request request, Response response) {
        try {
          String resp = response.getText();
          if (resp.equals(""))
            throw new RuntimeException("empty");
          HashMap reply = (HashMap) decode(resp);

          if (reply == null) {
            RuntimeException runtimeException = new RuntimeException(
                "parse: " + response.getText());
            fireFailure(runtimeException);
            callback.onFailure(runtimeException);
          }

          if (isErrorResponse(reply)) {
            RuntimeException runtimeException = new RuntimeException(
                "error: " + reply.get("error"));
            fireFailure(runtimeException);
            callback.onFailure(runtimeException);
          } else if (isSuccessfulResponse(reply)) {
            callback.onSuccess(reply.get("result"));
          } else {
            RuntimeException runtimeException = new RuntimeException(
                "syntax: " + response.getText());
            fireFailure(runtimeException);
            callback.onFailure(runtimeException);
          }
        } catch (RuntimeException e) {
          fireFailure(e);
          callback.onFailure(e);
        } finally {
          decreaseRequestCounter();
        }
      }

      public void onError(Request request, Throwable exception) {
        try {
          if (exception instanceof RequestTimeoutException) {
            RuntimeException runtimeException = new RuntimeException(
                "timeout");
            fireFailure(runtimeException);
            callback.onFailure(runtimeException);
          } else {
            RuntimeException runtimeException = new RuntimeException(
                "other");
            fireFailure(runtimeException);
            callback.onFailure(runtimeException);
          }
        } catch (RuntimeException e) {
          fireFailure(e);
          callback.onFailure(e);
        } finally {
          decreaseRequestCounter();
        }
      }

      private boolean isErrorResponse(HashMap response) {
        return response.get("error") != null
            && response.get("result") == null;
      }

      private boolean isSuccessfulResponse(HashMap response) {
        return response.get("error") == null
            && response.containsKey("result");
      }
    };

    increaseRequestCounter();

    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
    if (requestTimeout > 0)
      builder.setTimeoutMillis(requestTimeout);
    builder.setHeader("Content-Type", "application/json; charset=utf-8");
    String body = new String(encode(request));
    builder.setHeader("Content-Length", Integer.toString(body.length()));
    if (requestCookie != null)
      if (Cookies.getCookie(requestCookie) != null)
        builder.setHeader("X-Cookie", Cookies.getCookie(requestCookie));
    if (username != null)
      builder.setUser(username);
    if (password != null)
      builder.setPassword(password);
    try {
      builder.sendRequest(body, handler);
    } catch (RequestException exception) {
      handler.onError(null, exception);
    }
  }
View Full Code Here

  @Override
  public void loadResource(final String resourceUrl, final AsyncXmlLoaderCallback callback) {
    String currentResourceUrl = resourceUrl + ((resourceUrl.indexOf("?") == -1) ? ("?ts=" + System.currentTimeMillis()) : ("&ts=" + + System.currentTimeMillis()));
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, currentResourceUrl);
    requestBuilder.setCallback(new RequestCallback() {
      public void onError(Request request, Throwable exception) {
        callback.onError(resourceUrl, exception);
      }

      private void onSuccess(Request request, Response response) {
View Full Code Here

      // get substring to send
      // Send request to server and catch any errors.
        RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, prefixURL);
        System.out.println("sending to " + prefixURL);
        builder.sendRequest(
            null, new RequestCallback() {
           
            public void onError(Request request, Throwable exception) {
               displayError("Couldn't retrieve JSON");
            }
 
View Full Code Here

TOP

Related Classes of com.google.gwt.http.client.RequestCallback

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.