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:org.aksw.TripleCheckMate.client.widgets.SparqlSuggestOracle.java

License:Apache License

@Override
public void requestSuggestions(final Request request, final Callback callback) {
    // TODO Auto-generated method stub
    String addressQuery = request.getQuery();
    // look up for suggestions, only if at least 2 letters have been typed
    if (addressQuery.length() > 2) {
        try {/*from w  w w .ja  va 2 s  .c o  m*/
            String query = SessionContext.endpoint.getQueryforAutocomplete(addressQuery);
            String queryURL = SessionContext.endpoint.generateQueryURL(query);

            RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, queryURL);
            rb.setCallback(new com.google.gwt.http.client.RequestCallback() {

                public void onResponseReceived(com.google.gwt.http.client.Request req,
                        com.google.gwt.http.client.Response res) {
                    try {
                        JsonSparqlResult result = new JsonSparqlResult(res.getText());
                        Collection<Suggestion> suggestions = new ArrayList<Suggestion>();
                        for (List<ResultItem> i : result.data) {
                            if (i.size() == 1) {
                                suggestions.add(new SparqlSuggestItem(i.get(0).value));
                            }
                        }

                        callback.onSuggestionsReady(request, new Response(suggestions));
                    } catch (Exception e) {
                        e.printStackTrace();
                        Window.alert("Error communicating with SPARQL Endpoint!");
                    }
                }

                public void onError(com.google.gwt.http.client.Request request, Throwable exception) {

                }
            });
            rb.send();
        } catch (RequestException e) {
            Window.alert("Error occurred" + e.getMessage());
        }

    } else {
        Response response = new Response(Collections.<Suggestion>emptyList());
        callback.onSuggestionsReady(request, response);
    }
}

From source file:org.aksw.TripleCheckMate.client.widgets.StartPage.java

License:Apache License

private final void handleUserInfo(String authToken) {
    try {//  w w  w.  j  av a  2 s  .c  om
        String profileURL = "https://www.googleapis.com/oauth2/v1/userinfo";
        RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, profileURL);
        rb.setHeader("Content-type", "application/atom+xml");
        rb.setHeader("Host", "spreadsheets.google.com");
        rb.setHeader("Authorization", "Bearer " + authToken);
        rb.setCallback(new RequestCallback() {

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == 200) {
                    JSONValue value = JSONParser.parseLenient(response.getText());
                    JSONObject obj = value.isObject();

                    if (obj.get("id") != null && obj.get("id").isString() != null)
                        SessionContext.user.googleID = obj.get("id").isString().stringValue();
                    if (obj.get("name") != null && obj.get("name").isString() != null)
                        SessionContext.user.name = obj.get("name").isString().stringValue();
                    if (obj.get("picture") != null && obj.get("picture").isString() != null)
                        SessionContext.user.picture = obj.get("picture").isString().stringValue();
                    if (obj.get("link") != null && obj.get("link").isString() != null)
                        SessionContext.user.profile = obj.get("link").isString().stringValue();
                    if (SessionContext.user.picture.equals(""))
                        SessionContext.user.picture = "https://ssl.gstatic.com/s2/profiles/images/silhouette96.png";

                    // uses SessionContext.user
                    searchForUserinStorageService();

                } else {
                    Window.alert("Cannot retrieve user info!\n Return HTTP Code: " + response.getStatusCode()
                            + " / " + response.getText());
                    SessionContext.hidePopup();
                }
            }

            public void onError(Request request, Throwable exception) {
                Window.alert("Cannot retrieve user info!\nERROR : " + exception.getMessage());
                SessionContext.hidePopup();
            }
        });
        rb.send();
    } catch (RequestException e) {
        Window.alert("Cannot retrieve user info!\nERROR : " + e.getMessage());
        SessionContext.hidePopup();
    }

}

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() + "}");
    }/*  w w  w.  j  av  a2  s.com*/
    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.appverse.web.framework.frontend.gwt.helpers.dispatcher.AppverseDispatcher.java

License:Appverse Public License

@Override
public Request send(Method method, RequestBuilder requestBuilder) throws RequestException {
    if (xsrfToken != null && xsrfToken.length() > 0) {
        requestBuilder.setHeader(SecurityHelper.XSRF_TOKEN_NAME, xsrfToken);
    }/*from   w ww .  j  a v a2 s.  c o  m*/
    return requestBuilder.send();

}

From source file:org.bonitasoft.console.client.admin.page.view.DeleteCustomPage.java

License:Open Source License

private void searchFormMappingDependenciesForPage(String pageId) {
    final Map<String, String> filter = new HashMap<String, String>();
    filter.put(ApplicationPageItem.ATTRIBUTE_PAGE_ID, pageId);
    RequestBuilder requestBuilder;
    requestBuilder = new RequestBuilder(RequestBuilder.GET, "../API/form/mapping?c=10&p=0&f=pageId=" + pageId);
    requestBuilder.setCallback(new DeletePageProblemFormCallback(pageId));
    try {/*from   w  w  w . ja v a 2  s .  co m*/
        requestBuilder.send();
    } catch (RequestException e) {
        e.printStackTrace();
    }
}

From source file:org.bonitasoft.console.client.user.task.action.CheckFormMappingAndDisplayPerformTaskPageAction.java

License:Open Source License

protected void searchFormMappingForTask(final TreeIndexed<String> parameters) {
    RequestBuilder requestBuilder;
    final String processIdFilter = URL
            .encodeQueryString(PageItem.ATTRIBUTE_PROCESS_ID + "=" + processDefinitionId);
    final String taskNameFilter = URL.encodeQueryString(ATTRIBUTE_FORM_MAPPING_TASK + "=" + taskName);
    requestBuilder = new RequestBuilder(RequestBuilder.GET,
            "../API/form/mapping?c=10&p=0&f=" + processIdFilter + "&f=" + taskNameFilter);
    requestBuilder.setCallback(new FormMappingCallback(parameters));
    try {//from   ww  w  .java  2 s. co m
        requestBuilder.send();
    } catch (final RequestException e) {
        GWT.log("Error while creating the from mapping request", e);
    }
}

From source file:org.bonitasoft.console.client.user.task.action.CheckFormMappingAndDisplayPerformTaskPageAction.java

License:Open Source License

protected void executeTask(final String taskId, final TreeIndexed<String> parameters) {
    RequestBuilder requestBuilder;
    requestBuilder = new RequestBuilder(RequestBuilder.POST, "../API/bpm/userTask/" + taskId + "/execution");
    requestBuilder.setCallback(new ExecuteTaskCallback(taskId, taskDisplayName));
    try {/* ww  w .  j av a 2  s  .  com*/
        requestBuilder.send();
    } catch (final RequestException e) {
        GWT.log("Error while creating the task execution request", e);
    }
}

From source file:org.bonitasoft.console.client.user.task.action.CheckFormMappingAndDisplayProcessInstanciationFormAction.java

License:Open Source License

protected void searchFormMappingForProcess(final TreeIndexed<String> parameters) {
    final String processId = parameters.getValue(ProcessItem.ATTRIBUTE_ID);
    RequestBuilder requestBuilder;
    final String processIdFilter = URL.encodeQueryString(PageItem.ATTRIBUTE_PROCESS_ID + "=" + processId);
    final String mappingTypeFilter = URL
            .encodeQueryString(ATTRIBUTE_FORM_MAPPING_TYPE + "=" + PROCESS_START_FORM_MAPPING);
    requestBuilder = new RequestBuilder(RequestBuilder.GET,
            "../API/form/mapping?c=10&p=0&f=" + processIdFilter + "&f=" + mappingTypeFilter);
    requestBuilder.setCallback(new FormMappingCallback(processId, parameters));
    try {//from www. j  a  va2  s.  c  o m
        requestBuilder.send();
    } catch (final RequestException e) {
        GWT.log("Error while creating the from mapping request", e);
    }
}

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

License:Open Source License

/**
 * @param aResult/*from  w w w. j  a  va  2s .  c o  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 {//from  w  w w  .ja v a2 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());
        }
    }
}