Example usage for com.google.gwt.http.client RequestCallback RequestCallback

List of usage examples for com.google.gwt.http.client RequestCallback RequestCallback

Introduction

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

Prototype

RequestCallback

Source Link

Usage

From source file:org.apache.solr.explorer.client.core.manager.DefaultRequestManager.java

License:Apache License

public Request send(String url, RequestParams params, final int timeout,
        final AsyncCallback<XmlResponse> callback) {
    String data = params.buildEncodedQueryString();
    if (logger.isDebugEnabled()) {
        logger.debug("URL: " + url + "{" + params.buildQueryString() + "}");
    }/*from   w  w  w .jav  a2 s  . co m*/
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, "/solr");
    requestBuilder.setHeader(TARGET_URL_HEADER, url);
    requestBuilder.setHeader(CONTENT_TYPE_HEADER, "application/x-www-form-urlencoded");
    requestBuilder.setRequestData(data);
    requestBuilder.setTimeoutMillis(timeout);
    requestBuilder.setCallback(new RequestCallback() {
        public void onResponseReceived(Request request, Response response) {
            String rawText = response.getText();
            Document document = XMLParser.parse(rawText);
            callback.onSuccess(new XmlResponse(rawText, document));
        }

        public void onError(Request request, Throwable exception) {
            callback.onFailure(exception);
        }
    });
    try {
        return requestBuilder.send();
    } catch (RequestException re) {
        callback.onFailure(re);
        return null;
    }
}

From source file:org.apache.solr.explorer.client.core.manager.DefaultRequestManager.java

License:Apache License

public Request loadTextResource(String name, final AsyncCallback<String> callback) {
    String url = GWT.getHostPageBaseURL() + name;

    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);

    try {// w w w.  java2s . co  m

        return requestBuilder.sendRequest(null, new RequestCallback() {
            public void onResponseReceived(Request request, Response response) {
                callback.onSuccess(response.getText());
            }

            public void onError(Request request, Throwable exception) {
                callback.onFailure(exception);
            }
        });
    } catch (RequestException re) {
        callback.onFailure(re);
        return null;
    }
}

From source file:org.apache.thrift.async.TAsyncClientManager.java

License:Apache License

public void call(final TAsyncMethodCall method) throws TException {

    String data = new String(method.getRequestData());

    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(serviceUrl));

    builder.setHeader("Content-Type", "application/json");
    builder.setRequestData(new String(data));
    if (method.getClient().hasTimeout()) {
        builder.setTimeoutMillis((int) method.getClient().getTimeout());
    }/*from   w  ww  . ja v  a 2  s. c o m*/

    try {
        builder.sendRequest(new String(data), new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {

                if (response != null) {

                    switch (response.getStatusCode()) {
                    case Response.SC_OK:
                        method.onSuccess(response.getText());
                        break;

                    default:
                        method.onError(
                                new TTransportException("Bad HTTP status code: " + response.getStatusCode()));
                        break;
                    }
                } else {
                    method.onError(new TTransportException("HTTP response is null."));
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                method.onError(new TTransportException(exception));
            }
        });
    } catch (RequestException e) {
        method.onError(new TTransportException(e));
    }

}

From source file:org.appverse.web.framework.frontend.gwt.commands.impl.live.LogoutManagementRpcCommandImpl.java

License:Appverse Public License

@Override
public void onLogout() {
    RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, "j_spring_security_logout");
    try {//from w ww .  j  a v a 2 s . c  o m
        rb.sendRequest(null, new RequestCallback() {
            @Override
            public void onError(final Request request, final Throwable caught) {
                // Logout in server failed
            }

            @Override
            public void onResponseReceived(final Request request, final Response response) {
                // Reloading the page will clear GWT status.
                // As the user has been logged out, spring security will
                // show login page again
                Window.Location.reload();
            }
        });
    } catch (RequestException re) {

    }
}

From source file:org.bonitasoft.console.client.view.DashboardPanel.java

License:Open Source License

/**
 * @param aResult/*from  w  w  w . ja  v a 2 s  .  co m*/
 */
protected void displayReport(ReportItem aResult) {
    try {
        RequestBuilder theRequestBuilder = new RequestBuilder(RequestBuilder.GET,
                myReportingDataSource.buildReportURL(aResult, ReportScope.USER));
        theRequestBuilder.setCallback(new RequestCallback() {
            public void onError(Request aRequest, Throwable anException) {
                if (anException instanceof SessionTimeOutException) {
                    // reload the page.
                    Window.Location.reload();
                }
                myReportHTML.setHTML("");
                myOnGoingRequests--;
                nbOfErrors++;
                GWT.log("Unable to display report (error count:" + nbOfErrors + ")", anException);
                if (nbOfErrors >= 3) {
                    GWT.log("Disabling recurrent call after too many consecutive errors.", null);
                    myUpdateTimer.cancel();
                }
            }

            public void onResponseReceived(Request aRequest, Response aResponse) {
                if (1 == myOnGoingRequests) {
                    myReportHTML.setHTML("");
                    if (aResponse.getStatusCode() == Response.SC_OK) {
                        myReportHTML.setHTML(aResponse.getText());
                        nbOfErrors = 0;
                    } else {
                        myReportHTML.setHTML(constants.unableToDisplayReport());
                        nbOfErrors++;
                        GWT.log("Unable to display report (error count:" + nbOfErrors + ") "
                                + aResponse.getText(), null);
                        if (nbOfErrors >= 3) {
                            GWT.log("Disabling recurrent call after too many errors.", null);
                            myUpdateTimer.cancel();
                        }
                    }
                } else {
                    GWT.log("Skipping report result as there is still " + (myOnGoingRequests - 1)
                            + " requests in the pipe.", null);
                }
                myOnGoingRequests--;
            }
        });
        GWT.log("RPC: querying reporting", null);
        theRequestBuilder.send();
    } catch (RequestException e) {
        myReportHTML.setHTML("");
    }

}

From source file:org.bonitasoft.console.client.view.reporting.ReportParametersEditorWidget.java

License:Open Source License

protected void run() {

    if (validate()) {
        try {/*w  w w  .ja va 2  s .  c  o m*/
            RequestBuilder theRequestBuilder;
            final String theURL = myReportDataSource.buildReportURL(myItem, ReportScope.ADMIN);
            final String theCompleteURL = addParametersToURL(theURL);
            GWT.log("Calling the reporting engine with query: " + theCompleteURL);
            theRequestBuilder = new RequestBuilder(RequestBuilder.GET, theCompleteURL);
            theRequestBuilder.setCallback(new RequestCallback() {
                public void onError(Request aRequest, Throwable anException) {
                    myReportResultPanel.clear();
                    myReportResultPanel
                            .add(new HTML(constants.errorProcessingReport() + anException.getMessage()));
                    myDownloadLink.setHref(null);
                    myDownloadLink.setVisible(false);
                    myRefreshLink.setVisible(false);
                }

                public void onResponseReceived(Request aRequest, Response aResponse) {
                    myReportResultPanel.clear();
                    HTML theReport = new HTML();
                    theReport.setStyleName("bonita_report");
                    if (aResponse.getStatusCode() == Response.SC_OK) {
                        theReport.setHTML(aResponse.getText());
                        myDownloadLink.setHref(theCompleteURL + "&OutputFormat=pdf");
                        myDownloadLink.setVisible(true);
                        myRefreshLink.setVisible(true);
                    } else {
                        theReport.setHTML(constants.unableToDisplayReport() + "<BR/>" + aResponse.getText());
                        GWT.log("Unable to display report" + aResponse.getText(), null);
                        myDownloadLink.setHref(null);
                        myDownloadLink.setVisible(false);
                        myRefreshLink.setVisible(false);
                    }
                    myReportResultPanel.add(theReport);
                }
            });
            myReportResultPanel.clear();
            myReportResultPanel.add(new HTML(constants.loading()));
            theRequestBuilder.send();
        } catch (RequestException e) {
            Window.alert("Error while trying to query the reports:" + e.getMessage());
        }
    }
}

From source file:org.bonitasoft.console.client.view.UserSettingsEditionView.java

License:Open Source License

private void buildSelectableReport(final ReportItem aReportItem, final HTML aContainer) {
    if (aContainer == null) {
        GWT.log("Container must not be null. Exit.", null);
        return;//from www . j a  v  a  2s.  c o  m
    }

    try {
        if (aReportItem == null || aReportItem.getFileName() == null
                || aReportItem.getFileName().length() == 0) {
            GWT.log("Report name must neither be null nor empty. Exit.", null);
            return;
        }
        if (aReportItem.getUUID().equals(myUserProfile.getDefaultReportUUID())
                || (myUserProfile.getDefaultReportUUID() == null
                        && aReportItem.getUUID().equals(ConsoleConstants.DEFAULT_REPORT_UUID))) {
            // Select the report if it is the one used by the user.
            selectReportContainer(aContainer);
        }
        RequestBuilder theRequestBuilder = new RequestBuilder(RequestBuilder.GET, buildReportURL(aReportItem));
        theRequestBuilder.setCallback(new RequestCallback() {
            public void onError(Request aRequest, Throwable anException) {
                aContainer.setHTML(constants.unableToDisplayReport());
            }

            public void onResponseReceived(Request aRequest, Response aResponse) {
                if (aResponse.getStatusCode() == Response.SC_OK) {
                    aContainer.setHTML(aResponse.getText());
                } else {
                    aContainer.setHTML(constants.unableToDisplayReport());
                }
                aContainer.addClickHandler(new ClickHandler() {

                    public void onClick(ClickEvent anEvent) {
                        selectReportContainer(aContainer);
                        mySelectedReport = aReportItem;
                    }

                });
            }
        });
        aContainer.setHTML(loadingHTML);
        theRequestBuilder.send();
    } catch (RequestException e) {
        aContainer.setHTML(constants.unableToDisplayReport());
    }

}

From source file:org.celstec.arlearn2.gwtcommonlib.client.auth.OauthTwitter.java

License:Open Source License

public static void autenticate() {

    String url = "https://api.twitter.com/oauth/request_token";
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
    //        builder.setHeader("Content-Type", "application/json");
    builder.setHeader("Authorization",
            "oauth_callback=\"http%3A%2F%2Fmyapp.com%3A3005%2Ftwitter%2Fprocess_callback\"");

    try {/*from  w  w  w. j  av a  2s .  c  om*/
        Request request = builder.sendRequest("", new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                System.out.println("response received");
                if (200 == response.getStatusCode()) {

                }

            }

            @Override
            public void onError(Request request, Throwable exception) {

            }
        });
    } catch (RequestException e) {
        e.printStackTrace();
    }
}

From source file:org.chtijbug.workbench.drools.client.navbar.LogoWidgetView.java

License:Apache License

@PostConstruct
public void init() {
    final RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, "banner/banner.html");
    rb.setCallback(new RequestCallback() {
        @Override/*from w w w.  j  a v  a  2s .c  om*/
        public void onResponseReceived(final Request request, final Response response) {
            final HTMLPanel html = new HTMLPanel(response.getText());
            container.setWidget(html);
        }

        @Override
        public void onError(final Request request, final Throwable exception) {
            container.setWidget(new Label(AppConstants.INSTANCE.logoBannerError()));
        }
    });
    try {
        final Request r = rb.send();
    } catch (RequestException re) {
        container.setWidget(new Label(AppConstants.INSTANCE.logoBannerError()));
    }

    initWidget(container);
}

From source file:org.cleanlogic.cesiumjs4gwt.showcase.basic.AbstractSourceButton.java

License:Apache License

public void onClick(ClickEvent event) {
    RequestBuilder reqBuilder = new RequestBuilder(RequestBuilder.GET, this.sourceCodeURL);
    try {/*from  ww w .  ja  v a2  s .  c o m*/
        reqBuilder.sendRequest("", new RequestCallback() {

            public void onResponseReceived(Request request, Response response) {
                showSourceCode(response.getText());
            }

            public void onError(Request request, Throwable exception) {
            }

        });
    } catch (RequestException ex) {
    }

}