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

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

Introduction

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

Prototype

public Request sendRequest(String requestData, RequestCallback callback) throws RequestException 

Source Link

Document

Sends an HTTP request based on the current builder configuration with the specified data and callback.

Usage

From source file:org.nuxeo.ecm.platform.annotations.gwt.client.annotea.AnnoteaClient.java

License:Apache License

public void deleteAnnotation(String annotates, final Annotation annotation) {
    if (annotates.contains("?")) {
        annotates = annotates.substring(0, annotates.indexOf('?'));
    }/*from   w  w w.j  a va2  s .  c  o m*/

    String url = controller.getAnnoteaServerUrl() + "/" + annotation.getUUID();
    url += "?document_url=" + annotates;
    RequestBuilder req = new RequestBuilder("DELETE", url) {
        // nothing to override... used to make a *real* HTTP DELETE request
    };

    try {
        req.sendRequest(null, new RequestCallback() {
            public void onError(Request arg0, Throwable arg1) {
            }

            public void onResponseReceived(Request arg0, Response arg1) {
                getAnnotationList(Window.Location.getHref(), true);
                controller.reloadAnnotations();
            }
        });
    } catch (RequestException e) {
        GWT.log("Error while deleting an annotation: " + url, e);
        Log.debug("Error while deleting an annotation: " + url, e);
    }
}

From source file:org.nuxeo.ecm.platform.pictures.tiles.gwt.client.model.TilingInfo.java

License:Apache License

public void updateTilingInfo(final TilingInfoCallback callback) {
    RequestBuilder getRequest = new RequestBuilder(RequestBuilder.GET, getBaseUrl() + "?format=json");
    try {/*w ww  .  j  ava 2 s. c om*/
        getRequest.sendRequest(null, new RequestCallback() {

            public void onError(Request arg0, Throwable arg1) {
                Log.error("Error sending tiling info request: " + arg1);
            }

            public void onResponseReceived(Request arg0, Response resp) {
                parseResponse(resp.getText());
                if (callback != null) {
                    callback.tilingInfoUpdated();
                }
            }
        });
    } catch (RequestException e) {
        Window.alert("Error getting the tiling server: " + e);
    }
}

From source file:org.onecmdb.ui.gwt.desktop.client.widget.mdr.MDRStartWidget.java

License:Open Source License

public void doStop() {
    for (TabItem item : advanced.getItems()) {
        final CIModel model = (CIModel) item.getData("model");

        // Do a HTTP request..
        RequestBuilder req = new RequestBuilder(RequestBuilder.GET, getStopURL(model));

        try {//  www. j a v  a  2  s.c om
            Info.display("Stop", "Send stop to " + model.getDisplayName());
            req.sendRequest(null, new RequestCallback() {

                public void onResponseReceived(Request request, Response response) {
                    Info.display("Stop", "COMPLETED. Stop sent to " + model.getDisplayName());
                }

                public void onError(Request arg0, Throwable arg1) {
                    Info.display("Stop", "FAILED. to stop " + model.getDisplayName());
                }
            });

        } catch (RequestException e) {
            Info.display("Stop", "ERROR. to stop " + model.getDisplayName());
        }
    }
}

From source file:org.opendatakit.aggregate.client.widgets.EnketoWebformButton.java

License:Apache License

public void onClick(ClickEvent event) {
    super.onClick(event);

    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, UIConsts.ENKETO_API_HANDLER_ADDR);
    builder.setHeader("Content-type", "application/x-www-form-urlencoded");

    StringBuffer requestdata = new StringBuffer();
    if (selectedInstanceId == null) {
        String enketoURL = ENKETO_API_URL + Preferences.getEnketoApiUrl() + ENKETO_SURVEY_ID;
        requestdata.append(enketoURL);/*from w  ww. ja v  a  2  s. c  om*/
        requestdata.append(ENKETO_API_FORM_ID + selectedForm);
        requestdata.append(ENKETO_API_TOKEN + Preferences.getEnketoApiToken());
    }
    try {
        builder.sendRequest(requestdata.toString(), new RequestCallback() {
            public void onError(Request request, Throwable e) {
                Window.alert(e.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                int statusCode = response.getStatusCode();
                EnketoRedirectErrorPopup popup;
                switch (statusCode) {
                case 200:
                    Window.open(response.getHeader("enketo_url"), "_self", "");
                    break;
                case 201:
                    Window.open(response.getHeader("enketo_url"), "_self", "");
                    break;
                case 400:
                    popup = new EnketoRedirectErrorPopup(ENKETO_ERROR_400);
                    popup.setPopupPositionAndShow(popup.getPositionCallBack());
                    break;
                case 401:
                    popup = new EnketoRedirectErrorPopup(ENKETO_ERROR_401);
                    popup.setPopupPositionAndShow(popup.getPositionCallBack());
                    break;
                case 403:
                    popup = new EnketoRedirectErrorPopup(ENKETO_ERROR_403);
                    popup.setPopupPositionAndShow(popup.getPositionCallBack());
                    break;
                case 404:
                    popup = new EnketoRedirectErrorPopup(ENKETO_ERROR_404);
                    popup.setPopupPositionAndShow(popup.getPositionCallBack());
                    break;
                case 405:
                    popup = new EnketoRedirectErrorPopup(ENKETO_ERROR_405);
                    popup.setPopupPositionAndShow(popup.getPositionCallBack());
                    break;
                case 410:
                    popup = new EnketoRedirectErrorPopup(ENKETO_ERROR_410);
                    popup.setPopupPositionAndShow(popup.getPositionCallBack());
                    break;
                case 411:
                    popup = new EnketoRedirectErrorPopup(ENKETO_ERROR_411);
                    popup.setPopupPositionAndShow(popup.getPositionCallBack());
                    break;
                default:
                    popup = new EnketoRedirectErrorPopup(response.getHeader("error"));
                    popup.setPopupPositionAndShow(popup.getPositionCallBack());
                    break;
                }
            }

        });
    } catch (RequestException e) {
        // Couldn't connect to server
        EnketoRedirectErrorPopup popup = new EnketoRedirectErrorPopup(e.getMessage());
        popup.setPopupPositionAndShow(popup.getPositionCallBack());
        // }

    }
}

From source file:org.openehealth.ipf.platform.camel.flow.admin.client.Rest.java

License:Apache License

public void get(RequestCallback callback) {
    try {/*from   w  w  w  .ja  v  a 2  s .  c  o  m*/
        RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
        builder.setHeader("Cache-Control", "no-cache");
        builder.sendRequest(null, callback);
    } catch (RequestException e) {
        callback.onError(null, e);
    }
}

From source file:org.openehealth.ipf.platform.camel.flow.admin.client.Rest.java

License:Apache License

public void post(String content, RequestCallback callback) {
    try {//from  w  w  w.j  ava  2  s.co m
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
        builder.setHeader("Cache-Control", "no-cache");
        builder.setHeader("Content-Type", "application/json");
        builder.sendRequest(content, callback);
    } catch (RequestException e) {
        callback.onError(null, e);
    }
}

From source file:org.openehealth.ipf.platform.camel.flow.admin.client.Rest.java

License:Apache License

public void delete(RequestCallback callback) {
    try {/*  w w w . ja  va  2s.co  m*/
        RequestBuilder builder = new WorkaroundRequestBuilder("delete", url);
        builder.setHeader("Cache-Control", "no-cache");
        builder.sendRequest(null, callback);
    } catch (RequestException e) {
        callback.onError(null, e);
    }
}

From source file:org.opennms.features.gwt.combobox.client.rest.DefaultNodeService.java

License:Open Source License

private void sendRequest(RequestCallback callback, String url) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    builder.setHeader("accept", "application/json");
    try {/*  w ww. ja va  2 s  .  c o  m*/
        builder.sendRequest(null, callback);
    } catch (RequestException e) {
        e.printStackTrace();
    }
}

From source file:org.opennms.features.gwt.ksc.add.client.rest.DefaultKscReportService.java

License:Open Source License

private void sendRequest(final RequestCallback callback, final Method method, final String url) {
    final RequestBuilder builder = new RequestBuilder(method, url);
    builder.setHeader("accept", "application/json");
    try {//from w w  w. j  av  a  2s . co m
        builder.sendRequest(null, callback);
    } catch (final RequestException e) {
        e.printStackTrace();
    }
}

From source file:org.opennms.features.gwt.snmpselect.list.client.rest.DefaultSnmpInterfaceRestService.java

License:Open Source License

@Override
public void getInterfaceList() {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
            URL.encode("rest/nodes/" + m_nodeId + "/snmpinterfaces?limit=0"));
    builder.setHeader("accept", "application/json");

    try {/*  ww w. ja v a 2 s.c  o m*/
        builder.sendRequest(null, new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == 200) {
                    m_requestHandler.onResponse(parseJSONData(response.getText()));
                } else {
                    m_requestHandler.onError("An Error Occurred retreiving the SNMP Interfaces for this node.\n"
                            + "Status Code: " + response.getStatusCode());
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                m_requestHandler.onError(exception.getMessage());

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

}