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.opennms.features.gwt.snmpselect.list.client.rest.DefaultSnmpInterfaceRestService.java

License:Open Source License

@Override
public void updateCollection(int ifIndex, String collectFlag) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.PUT,
            URL.encode("rest/nodes/" + m_nodeId + "/snmpinterfaces/" + ifIndex));
    builder.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

    try {//www .j  a  va2 s.  c  om
        builder.sendRequest("collect=" + collectFlag, new RequestCallback() {

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

            }

            @Override
            public void onError(Request request, Throwable exception) {
                m_requestHandler.onError("There was an error when saving the interface collection value");
            }
        });
    } catch (RequestException e) {
        e.printStackTrace();
    }
}

From source file:org.opennms.features.node.list.gwt.client.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  w  w.  j a  v  a  2 s  . c  o m
        builder.sendRequest(null, callback);
    } catch (RequestException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.opennms.ipv6.summary.gui.client.DefaultChartService.java

License:Open Source License

private void sendRequest(String url, RequestCallback callback) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    builder.setHeader("Accept", "application/json");

    builder.setUser("ipv6Rest");
    builder.setPassword("ipv6Rest");
    try {//  ww w .  ja  va 2s .  c  o  m
        builder.sendRequest(null, callback);
    } catch (RequestException e) {
        e.printStackTrace();
    }
}

From source file:org.opennms.ipv6.summary.gui.client.Navigation.java

License:Open Source License

@UiHandler("m_link")
public void linkTopOpenNMSClicked(ClickEvent event) {
    StringBuffer postData = new StringBuffer();
    // note param pairs are separated by a '&' 
    // and each key-value pair is separated by a '='
    postData.append(URL.encode("j_username")).append("=").append(URL.encode("ipv6"));
    postData.append("&");
    postData.append(URL.encode("j_password")).append("=").append(URL.encode("ipv6"));
    postData.append("&");
    postData.append(URL.encode("Login")).append("=").append(URL.encode("login"));

    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
            URL.encode("/opennms/j_spring_security_check"));
    builder.setHeader("Content-type", "application/x-www-form-urlencoded");
    try {//from  ww  w. j  av a2 s  . co m
        builder.sendRequest(postData.toString(), new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == 200) {
                    Window.open("/opennms/index.jsp", "_target", null);
                } else {
                    Window.alert("Failed to login");
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                Window.alert("Problem Logging in");
            }
        });
    } catch (RequestException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    //Window.alert("Cliking link to OpenNMS");
}

From source file:org.openremote.web.console.util.BrowserUtils.java

License:Open Source License

public static void isURLSameOrigin_old(String url, final AsyncControllerCallback<Boolean> callback) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);

    try {// ww w  .  j  a  va  2s . co  m
        Request request = builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                callback.onSuccess(true);
            }

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == 0) {
                    // We get here for modern browsers that will allow CORS
                    callback.onSuccess(false);
                } else {
                    callback.onSuccess(true);
                }
            }
        });
    } catch (RequestException e) {
        // Violates SOP
        callback.onSuccess(false);
    }
}

From source file:org.openremote.web.console.util.BrowserUtils.java

License:Open Source License

public static void isURLSameOrigin(String url, final AsyncControllerCallback<Boolean> callback) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url + "rest/panels/");
    builder.setHeader("Accept", "application/json");
    builder.setTimeoutMillis(2000);/* w  w w.ja v a  2  s .c om*/

    try {
        Request request = builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                callback.onSuccess(true);
            }

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == 0) {
                    callback.onSuccess(false);
                } else {
                    callback.onSuccess(true);
                }
            }
        });
    } catch (RequestException e) {
        // Violates SOP
        callback.onSuccess(false);
    }
}

From source file:org.opentaps.gwt.common.voip.client.RedirectToCallingParty.java

License:Open Source License

protected void init() {
    try {/*from ww  w. ja v a  2  s .co  m*/
        //add random number avoid cache page
        RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL
                .encode(GWT.getHostPageBaseURL() + checkFrequencySecondsUrl + "?now=" + new Date().getTime()));
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                // display error message
                UtilUi.errorMessage(exception.toString());
            }

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == Response.SC_OK) {
                    String returnText = response.getText();
                    if (!returnText.equals("")) {
                        setCheckInBoundTimer(Integer.parseInt(returnText));
                    }
                }
            }

        });
    } catch (RequestException e) {
        // display error message
        UtilUi.errorMessage(e.toString());
    }
}

From source file:org.opentaps.gwt.common.voip.client.RedirectToCallingParty.java

License:Open Source License

/**
 * Sets the check in-bound timer./* ww w .ja  v  a2  s  .co m*/
 * @param seconds the number of seconds between checking in-bound calls
 */
private void setCheckInBoundTimer(int seconds) {
    Timer timer = new Timer() {
        @Override
        public void run() {
            try {
                //add random number avoid cache page
                RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
                        URL.encode(GWT.getHostPageBaseURL() + remoteUrl + "?now=" + new Date().getTime()));
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(Request request, Throwable exception) {
                        // display error message
                        UtilUi.errorMessage(exception.toString());
                    }

                    public void onResponseReceived(Request request, Response response) {
                        // when get correct response, clear the div insideHeadertext and display call in link.
                        if (response.getStatusCode() == Response.SC_OK) {
                            String returnText = response.getText();
                            if (!returnText.equals("")) {
                                RootPanel.get(voipkNotificationDiv).clear();
                                OpentapsConfig config = new OpentapsConfig();
                                HTML callInTips = new HTML(UtilUi.MSG
                                        .callInDisplayMessage(config.getCallInEventIcon(), returnText));
                                RootPanel.get(voipkNotificationDiv).add(callInTips);
                            }
                        }
                    }
                });
            } catch (RequestException e) {
                // display error message
                UtilUi.errorMessage(e.toString());
            }
        }
    };
    // Schedule the timer for every second
    timer.scheduleRepeating(seconds * 1000);
}

From source file:org.openxdata.designer.client.controller.FormDesignerController.java

private void prepareFormForLoading(RequestBuilder builder) throws RequestException {
    builder.sendRequest(null, new RequestCallback() {
        public void onResponseReceived(Request request, Response response) {

            if (response.getStatusCode() != Response.SC_OK) {
                FormUtil.displayReponseError(response);
                return;
            }/*from   www  .  java2  s.  c  o m*/

            String xml = response.getText();
            if (xml == null || xml.length() == 0) {
                FormUtil.dlg.hide();
                Window.alert(messages.noDataFound());
                return;
            }

            String xformXml, layoutXml = null, localeXml = null, javaScriptSrc = null;

            int pos = xml.indexOf(OpenXdataConstants.OPENXDATA_FORMDEF_LAYOUT_XML_SEPARATOR);
            int pos2 = xml.indexOf(OpenXdataConstants.OPENXDATA_FORMDEF_LOCALE_XML_SEPARATOR);
            int pos3 = xml.indexOf(OpenXdataConstants.OPENXDATA_FORMDEF_JAVASCRIPT_SRC_SEPARATOR);
            if (pos > 0) {
                xformXml = xml.substring(0, pos);
                layoutXml = FormUtil.formatXml(
                        xml.substring(pos + OpenXdataConstants.OPENXDATA_FORMDEF_LAYOUT_XML_SEPARATOR.length(),
                                (pos2 > 0 ? pos2 : (pos3 > 0 ? pos3 : xml.length()))));

                if (pos2 > 0)
                    localeXml = FormUtil.formatXml(xml.substring(
                            pos2 + OpenXdataConstants.OPENXDATA_FORMDEF_LOCALE_XML_SEPARATOR.length(),
                            pos3 > 0 ? pos3 : xml.length()));

                if (pos3 > 0)
                    javaScriptSrc = xml.substring(
                            pos3 + OpenXdataConstants.OPENXDATA_FORMDEF_JAVASCRIPT_SRC_SEPARATOR.length(),
                            xml.length());
            } else if (pos2 > 0) {
                xformXml = xml.substring(0, pos2);
                localeXml = FormUtil.formatXml(
                        xml.substring(pos2 + OpenXdataConstants.OPENXDATA_FORMDEF_LOCALE_XML_SEPARATOR.length(),
                                pos3 > 0 ? pos3 : xml.length()));

                if (pos3 > 0)
                    javaScriptSrc = xml.substring(
                            pos3 + OpenXdataConstants.OPENXDATA_FORMDEF_JAVASCRIPT_SRC_SEPARATOR.length(),
                            xml.length());
            } else if (pos3 > 0) {
                xformXml = xml.substring(0, pos3);
                javaScriptSrc = xml.substring(
                        pos3 + OpenXdataConstants.OPENXDATA_FORMDEF_JAVASCRIPT_SRC_SEPARATOR.length(),
                        xml.length());
            } else
                xformXml = xml;

            LanguageUtil.loadLanguageText(formId, localeXml, Context.getLanguageText());

            centerPanel.setXformsSource(FormUtil.formatXml(xformXml), false);
            centerPanel.setLayoutXml(layoutXml, false);
            centerPanel.setJavaScriptSource(javaScriptSrc);

            openFormDeffered(formId, false);

        }

        @Override
        public void onError(Request request, Throwable exception) {
            FormUtil.displayException(exception);

        }

    });
}