Example usage for com.google.gwt.http.client RequestBuilder send

List of usage examples for com.google.gwt.http.client RequestBuilder send

Introduction

In this page you can find the example usage for com.google.gwt.http.client RequestBuilder send.

Prototype

public Request send() throws RequestException 

Source Link

Document

Sends an HTTP request based on the current builder configuration.

Usage

From source file:com.gloopics.g3viewer.client.G3Viewer.java

License:Apache License

public void doJSONRequest(final String a_URL, final HttpSuccessHandler a_Handler, final boolean a_hasParams,
        final boolean a_IncludeCSRF, String a_Data) {
    try {//from w  ww. j a  v a 2s  .c  o  m
        String url;
        if (m_CSRF != null && a_IncludeCSRF) {
            url = a_URL + (a_hasParams ? "&csrf=" : "?csrf=") + m_CSRF;
        } else {
            url = a_URL;
        }
        RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, url);
        requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded");
        requestBuilder.setHeader("X-Requested-With", "XMLHttpRequest");
        requestBuilder.setCallback(new JSONResponseTextHandler(new JSONResponseCallback() {

            @Override
            public void onResponse(JSONValue aValue) {
                a_Handler.success(aValue);
            }

            @Override
            public void onError(Throwable aThrowable) {

                if (aThrowable.getCause() != null) {
                    StringBuffer stack = new StringBuffer();
                    StackTraceElement[] stes = aThrowable.getCause().getStackTrace();
                    for (StackTraceElement ste : stes) {
                        stack.append(ste.toString());
                        stack.append(" \n ");
                    }
                    displayError("a Unexpected Error ",
                            aThrowable.toString() + " - " + a_URL + "\n " + stack.toString());

                } else {
                    displayError("a Unexpected Error ", aThrowable.toString() + " - " + a_URL);
                }
            }
        }));

        requestBuilder.setRequestData(a_Data);
        requestBuilder.send();
    } catch (RequestException ex) {
        displayError("Request Exception", ex.toString() + " - " + a_URL);
    }
}

From source file:com.google.gerrit.client.account.NewAgreementScreen.java

License:Apache License

private void showCLA(final ContributorAgreement cla) {
    current = cla;/*  ww w  .ja va2s . c  om*/
    String url = cla.getAgreementUrl();
    if (url != null && url.length() > 0) {
        agreementGroup.setVisible(true);
        agreementHtml.setText(Gerrit.C.rpcStatusWorking());
        if (!url.startsWith("http:") && !url.startsWith("https:")) {
            url = GWT.getHostPageBaseURL() + url;
        }
        final RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url);
        rb.setCallback(new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                new ErrorDialog(exception).center();
            }

            public void onResponseReceived(Request request, Response response) {
                final String ct = response.getHeader("Content-Type");
                if (response.getStatusCode() == 200 && ct != null
                        && (ct.equals("text/html") || ct.startsWith("text/html;"))) {
                    agreementHtml.setHTML(response.getText());
                } else {
                    new ErrorDialog(response.getStatusText()).center();
                }
            }
        });
        try {
            rb.send();
        } catch (RequestException e) {
            new ErrorDialog(e).show();
        }
    } else {
        agreementGroup.setVisible(false);
    }

    if (contactPanel == null && cla.isRequireContactInformation()) {
        contactPanel = new ContactPanelFull();
        contactGroup.add(contactPanel);
        contactPanel.hideSaveButton();
    }
    contactGroup.setVisible(cla.isRequireContactInformation() && cla.getAutoVerify() != null);
    finalGroup.setVisible(cla.getAutoVerify() != null);
    yesIAgreeBox.setText("");
    submit.setEnabled(false);
}

From source file:com.google.gwt.sample.showcase.client.ContentWidget.java

License:Apache License

/**
 * Send a request for source code./*from www . j  av  a  2s.c  om*/
 * 
 * @param callback the {@link RequestCallback} to send
 * @param url the URL to target
 */
private void sendSourceRequest(RequestCallback callback, String url) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, GWT.getModuleBaseURL() + url);
    builder.setCallback(callback);
    try {
        builder.send();
    } catch (RequestException e) {
        callback.onError(null, e);
    }
}

From source file:com.google.web.bindery.requestfactory.gwt.client.DefaultRequestTransport.java

License:Apache License

public void send(String payload, TransportReceiver receiver) {
    RequestBuilder builder = createRequestBuilder();
    configureRequestBuilder(builder);/*from   w  ww. j a v a2  s .c o  m*/

    builder.setRequestData(payload);
    builder.setCallback(createRequestCallback(receiver));

    try {
        wireLogger.finest("Sending fire request");
        builder.send();
    } catch (RequestException e) {
        wireLogger.log(Level.SEVERE, SERVER_ERROR + " (" + e.getMessage() + ")", e);
    }
}

From source file:com.gwtplatform.dispatch.client.rest.RestDispatchAsync.java

License:Apache License

@Override
protected <A extends Action<R>, R extends Result> DispatchRequest doExecute(String securityCookie, A action,
        final AsyncCallback<R> callback) {
    if (!(action instanceof RestAction)) {
        throw new IllegalArgumentException(
                "RestDispatchAsync should be used with actions implementing " + "RestAction.");
    }//from  w  w  w . j a v  a  2 s.  c  o m

    RestAction<R> restAction = castRestAction(action);

    try {
        RequestBuilder requestBuilder = requestBuilderFactory.build(restAction, securityCookie);
        requestBuilder.setCallback(createRequestCallback(restAction, callback));

        return new GwtHttpDispatchRequest(requestBuilder.send());
    } catch (RequestException e) {
        onExecuteFailure(action, e, callback);
    } catch (ActionException e) {
        onExecuteFailure(action, e, callback);
    }

    return new CompletedDispatchRequest();
}

From source file:com.gwtplatform.dispatch.rest.client.core.RestDispatchCall.java

License:Apache License

@Override
protected DispatchRequest processCall() {
    try {//from w  w  w.j a  va2 s  . c  om
        RequestBuilder requestBuilder = buildRequest();
        cookieManager.saveCookiesFromAction(getAction());

        return new GwtHttpDispatchRequest(requestBuilder.send());
    } catch (RequestException e) {
        onExecuteFailure(e);
    } catch (ActionException e) {
        onExecuteFailure(e);
    }
    return new CompletedDispatchRequest();
}

From source file:com.gwtplatform.dispatch.rest.client.RestDispatchCall.java

License:Apache License

@Override
protected DispatchRequest processCall() {
    try {/* ww w. j  a  va 2s . c om*/
        RequestBuilder requestBuilder = buildRequest();

        return new GwtHttpDispatchRequest(requestBuilder.send());
    } catch (RequestException e) {
        onExecuteFailure(e);
    } catch (ActionException e) {
        onExecuteFailure(e);
    }
    return new CompletedDispatchRequest();
}

From source file:com.isotrol.impe3.pms.gui.client.Pms.java

License:Open Source License

private void getPropertiesFileAndShowLogin(final LoginPanel loginPanel) {
    RequestBuilder json = new RequestBuilder(RequestBuilder.GET, "properties.json");
    json.setCallback(new RequestCallback() {

        public void onResponseReceived(Request request, Response response) {
            loginPanel.getPmsUtil().loadProperties(response);
            showLogin(loginPanel);//from w w w  . j a  v a2  s  .  co  m
        }

        public void onError(Request request, Throwable exception) {
            GWT.log("Throwable: " + exception.getMessage());
            exception.printStackTrace();
        }
    });
    try {
        json.send();
    } catch (RequestException e) {
        GWT.log("RequestException: " + e.getMessage());
        e.printStackTrace();
    }

}

From source file:com.isotrol.impe3.pms.gui.client.util.PmsUtil.java

License:Open Source License

/**
 * Read the json file "frameColumns.json" to build the arrays to show the default columns in columns palette in the
 * page design./*from w  ww . java  2 s.  co m*/
 */
public void loadDesignColumns() {
    RequestBuilder json = new RequestBuilder(RequestBuilder.GET, "properties.json");
    json.setCallback(new RequestCallback() {

        public void onResponseReceived(Request request, Response response) {
            JSONObject fileJson = null;
            try {
                fileJson = (JSONObject) JSONParser.parseLenient(response.getText()).isObject();
            } catch (JSONException e) {
                util.error(pmsMessages.msgErrorParseColumnsJson());
            }

            if (fileJson != null) {
                JSONObject properties = fileJson.get("properties").isObject();
                JSONObject oProp = properties.isObject();
                // read frame columns
                parseFrameColumns(oProp);
                // read visibility of external services menus and disable login
                parseOtherProperties(oProp);
            }
        }

        public void onError(Request request, Throwable exception) {
            GWT.log("Throwable: " + exception.getMessage());
            exception.printStackTrace();
        }
    });
    try {
        json.send();
    } catch (RequestException e) {
        GWT.log("RequestException: " + e.getMessage());
        e.printStackTrace();
    }
}

From source file:com.nanosim.client.ContentWidget.java

License:Apache License

/**
 * Load the contents of a remote file into the specified widget.
 * //from w  ww .ja v  a  2 s .  com
 * @param url a partial path relative to the module base URL
 * @param target the target Widget to place the contents
 * @param callback the callback when the call completes
 */
protected void requestSourceContents(String url, final HTML target, final RequestCallback callback) {
    // Show the loading image
    if (loadingImage == null) {
        loadingImage = "<img src=\"" + GWT.getModuleBaseURL() + "images/loading.gif\">";
    }
    DOM.setStyleAttribute(target.getElement(), "textAlign", "left");
    target.setHTML("&nbsp;&nbsp;" + loadingImage);

    // Request the contents of the file
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, GWT.getModuleBaseURL() + url);
    RequestCallback realCallback = new RequestCallback() {
        public void onError(Request request, Throwable exception) {
            target.setHTML("Cannot find resource");
            if (callback != null) {
                callback.onError(request, exception);
            }
        }

        public void onResponseReceived(Request request, Response response) {
            target.setHTML(response.getText());
            if (callback != null) {
                callback.onResponseReceived(request, response);
            }
        }
    };
    builder.setCallback(realCallback);

    // Send the request
    Request request = null;
    try {
        request = builder.send();
    } catch (RequestException e) {
        realCallback.onError(request, e);
    }
}