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.freemedsoftware.gwt.client.widget.UserWidget.java

License:Open Source License

/**
 * Set value of current widget based on integer value, asynchronously.
 * /*from   w ww. j  a  v  a  2s .  c  o m*/
 * @param widgetValue
 */
public void setValue(Integer widgetValue) {
    value = widgetValue;
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        searchBox.setText("Stub Value");
        searchBox.setTitle("Stub Value");
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        if (widgetValue.compareTo(0) == 0) {
            searchBox.setText("");
            searchBox.setTitle("");
        } else {
            String[] params = { widgetValue.toString() };
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                    URL.encode(Util.getJsonRequest("org.freemedsoftware.api.UserInterface.GetRecord", params)));
            try {
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                    }

                    @SuppressWarnings("unchecked")
                    public void onResponseReceived(com.google.gwt.http.client.Request request,
                            com.google.gwt.http.client.Response response) {
                        if (Util.checkValidSessionResponse(response.getText())) {
                            if (200 == response.getStatusCode()) {
                                HashMap<String, String> result = (HashMap<String, String>) JsonUtil
                                        .shoehornJson(JSONParser.parseStrict(response.getText()),
                                                "HashMap<String,String>");
                                if (result != null) {
                                    searchBox.setText(result.get("userdescrip"));
                                    searchBox.setTitle(result.get("userdescrip"));
                                }
                            } else {
                                Window.alert(response.toString());
                            }
                        }
                    }
                });
            } catch (RequestException e) {

            }
        }
    } else {
        UserInterfaceAsync service = null;
        try {
            service = ((UserInterfaceAsync) Util.getProxy("org.freemedsoftware.gwt.client.Api.UserInterface"));
        } catch (Exception e) {
        }

        service.GetRecord(widgetValue, new AsyncCallback<HashMap<String, String>>() {
            public void onSuccess(HashMap<String, String> r) {
                searchBox.setText(r.get("userdescrip"));
                searchBox.setTitle(r.get("userdescrip"));
            }

            public void onFailure(Throwable t) {

            }
        });

    }
}

From source file:org.freemedsoftware.gwt.client.widget.UserWidget.java

License:Open Source License

protected void loadSuggestions(String req, final Request r, final Callback cb) {
    if (req.length() < CurrentState.getMinCharCountForSmartSearch())
        return;/*from  w ww  .j a va  2 s  .c om*/
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // Handle in a stubbed sort of way
        List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
        map.clear();
        addKeyValuePair(items, new String("Hackenbush, Hugo Z"), new String("1"));
        addKeyValuePair(items, new String("Firefly, Rufus T"), new String("2"));
        cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {

        RequestBuilder builder = null;
        if (userType.equals("")) {
            String[] params = { req };
            builder = new RequestBuilder(RequestBuilder.POST,
                    URL.encode(Util.getJsonRequest("org.freemedsoftware.api.UserInterface.GetUsers", params)));
        } else {
            String[] params = { req, userType };
            builder = new RequestBuilder(RequestBuilder.POST,
                    URL.encode(Util.getJsonRequest("org.freemedsoftware.api.UserInterface.GetUsers", params)));
        }
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                }

                public void onResponseReceived(com.google.gwt.http.client.Request request,
                        com.google.gwt.http.client.Response response) {
                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            String[][] result = (String[][]) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()), "String[][]");
                            if (result != null) {
                                List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
                                map.clear();
                                for (int iter = 0; iter < result.length; iter++) {
                                    String[] x = result[iter];
                                    final String key = x[1];
                                    final String val = x[0];
                                    addKeyValuePair(items, val, key);
                                }
                                cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
                            }
                        } else {
                            GWT.log("Result " + response.getStatusText(), null);
                        }
                    }
                }
            });
        } catch (RequestException e) {
            GWT.log("Exception thrown: ", e);
        }
    } else {
        UserInterfaceAsync service = null;
        try {
            service = ((UserInterfaceAsync) Util.getProxy("org.freemedsoftware.gwt.client.Api.UserInterface"));
        } catch (Exception e) {
        }

        service.GetUsers(req, new AsyncCallback<String[][]>() {
            public void onSuccess(String[][] result) {
                List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
                map.clear();
                for (int iter = 0; iter < result.length; iter++) {
                    String[] x = result[iter];
                    final String key = x[1];
                    final String val = x[0];
                    addKeyValuePair(items, val, key);
                }
                cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
            }

            public void onFailure(Throwable t) {
                GWT.log("Exception thrown: ", t);
            }

        });
    }
}

From source file:org.freemedsoftware.gwt.client.widget.UserWidget.java

License:Open Source License

@Override
public void getTextForValue(Integer val) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        searchBox.setText("Hackenbush, Hugo Z (STUB)");
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { val.toString() };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.api.UserInterface.GetRecord", params)));
        try {//from  w  w  w  .j a v a  2 s  .c  o m
            builder.sendRequest(null, new RequestCallback() {
                public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(com.google.gwt.http.client.Request request,
                        com.google.gwt.http.client.Response response) {
                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            HashMap<String, String> result = (HashMap<String, String>) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,String>");
                            if (result != null) {
                                searchBox.setText(result.get("userdescrip"));
                            }
                        } else {
                            GWT.log("Result " + response.getStatusText(), null);
                        }
                    }
                }
            });
        } catch (RequestException e) {
            GWT.log("Exception thrown: ", e);
        }
    } else {
        UserInterfaceAsync service = null;
        try {
            service = ((UserInterfaceAsync) Util.getProxy("org.freemedsoftware.gwt.client.Api.UserInterface"));
        } catch (Exception e) {
        }
        service.GetRecord(val, new AsyncCallback<HashMap<String, String>>() {
            public void onSuccess(HashMap<String, String> r) {
                searchBox.setText(r.get("userdescrip"));
            }

            public void onFailure(Throwable t) {
                GWT.log("Exception", t);
            }
        });
    }
}

From source file:org.freemedsoftware.gwt.client.widget.WorkList.java

License:Open Source License

private void changeStatus(Widget w1, Widget w2, String appid, String patid, String st, int i) {
    final int index = i;
    final Widget wDisplay = w1;
    final Widget wHide = w2;
    final String statusid = st;
    HashMap<String, String> map = new HashMap<String, String>();
    map.put((String) "cspatient", patid);
    map.put((String) "csappt", appid);
    map.put((String) "csstatus", st);
    JsonUtil.debug("before saving");
    String[] params = { JsonUtil.jsonify(map) };
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
            URL.encode(Util.getJsonRequest("org.freemedsoftware.module.SchedulerPatientStatus.add", params)));

    try {//w ww.j av  a2s  .  c o m
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable ex) {
            }

            public void onResponseReceived(Request request, Response response) {

                if (200 == response.getStatusCode()) {
                    wHide.setVisible(false);
                    wDisplay.setVisible(true);
                    int currRow = workListsTables[index].getActionRow();
                    workListsTables[index].getFlexTable().getRowFormatter().getElement(currRow).getStyle()
                            .setProperty("backgroundColor", statusColorsMap.get(statusid));

                } else {
                    Util.showErrorMsg("Patient Status", _("Patient status change failed."));

                    // printLabelForAllTakeHome();
                }
            }
        });
    } catch (RequestException e) {

    }

}

From source file:org.freemedsoftware.gwt.client.widget.WorkList.java

License:Open Source License

public void populateStatus() {

    if (Util.getProgramMode() == ProgramMode.STUBBED) {

    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = {};/*from  www .  j a v  a2s  .  com*/
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.module.SchedulerStatusType.getStatusType", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(com.google.gwt.http.client.Request request,
                        com.google.gwt.http.client.Response response) {
                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            HashMap<String, String>[] result = (HashMap<String, String>[]) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()),
                                            "HashMap<String,String>[]");
                            if (result != null) {
                                statusNamesMap = new HashMap<String, String>();
                                statusColorsMap = new HashMap<String, String>();
                                for (int i = 0; i < result.length; i++) {
                                    statusNamesMap.put(result[i].get("Id"), result[i].get("descp"));
                                    statusColorsMap.put(result[i].get("Id"), result[i].get("status_color"));
                                }

                            } else {
                            }
                        } else {
                            GWT.log("Result " + response.getStatusText(), null);
                        }
                    }
                }
            });
        } catch (RequestException e) {
            GWT.log("Exception thrown: ", e);
        }
    } else {

    }
}

From source file:org.freemedsoftware.gwt.client.widget.WorkList.java

License:Open Source License

public void retrieveData() {
    vPanel.add(paneltop);//from   w  ww  .  ja v  a2  s. c  om
    vPanel.add(message);
    if (CurrentState.getDefaultProvider() == 0) {
        providerGroupId = CurrentState.defaultProviderGroup;
        if (Util.getProgramMode() == ProgramMode.JSONRPC) {
            String[] params = { providerGroupId.toString() };
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                    Util.getJsonRequest("org.freemedsoftware.module.ProviderGroups.getProviderIds", params)));
            try {
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                        Window.alert(ex.toString() + "error1");

                    }

                    public void onResponseReceived(com.google.gwt.http.client.Request request,
                            com.google.gwt.http.client.Response response) {
                        if (200 == response.getStatusCode()) {
                            if (Util.checkValidSessionResponse(response.getText())) {
                                String provs[] = (String[]) JsonUtil
                                        .shoehornJson(JSONParser.parseStrict(response.getText()), "String[]");
                                if (provs != null) {
                                    if (provs.length != 0) {
                                        providers = new Integer[provs.length];
                                        workListsTables = new CustomTable[provs.length];
                                        providersLb = new Label[provs.length];
                                        for (int i = 0; i < provs.length; i++) {
                                            providers[i] = new Integer(provs[i]);
                                            getProviderInfo(i);
                                        }
                                    } else {

                                    }
                                }

                            }
                        } else {
                            Window.alert(response.toString() + "error2");
                        }
                    }
                });
            } catch (RequestException e) {
                Window.alert(e.toString());
            }

        } else {
        }
    } else {
        providers = new Integer[1];
        workListsTables = new CustomTable[1];
        providersLb = new Label[1];
        providers[0] = new Integer(CurrentState.getDefaultProvider());
        getProviderInfo(0);
    }
}

From source file:org.freemedsoftware.gwt.client.widget.WorkList.java

License:Open Source License

private void getProviderInfo(int i) {
    final int index = i;
    providersLb[i] = new Label();
    providersLb[i].setVisible(false);//from w w  w .  ja  v  a2  s .com
    providersLb[i].getElement().getStyle().setProperty("cursor", "pointer");
    providersLb[i].getElement().getStyle().setProperty("fontWeight", "bold");
    providersLb[i].getElement().getStyle().setProperty("textDecoration", "underline");
    providersLb[i].getElement().getStyle().setProperty("verticalAlign", "middle");
    providersLb[i].setHeight("20");
    providersLb[i].addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent e) {
            if (workListsTables[index].isVisible()) {
                workListsTables[index].setVisible(false);
            } else {
                workListsTables[index].setVisible(true);
            }
        }
    });
    if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { "" + providers[i] };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.module.ProviderModule.fullName", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                    Window.alert(ex.toString() + "error1");

                }

                public void onResponseReceived(com.google.gwt.http.client.Request request,
                        com.google.gwt.http.client.Response response) {
                    if (200 == response.getStatusCode()) {
                        if (Util.checkValidSessionResponse(response.getText())) {
                            String provInfo = (String) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()), "String");
                            if (provInfo != null) {
                                providersLb[index].setText(provInfo);
                                createWorkListTableForProvider(index);
                            }

                        }
                    } else {
                        Window.alert(response.toString() + "error2");
                    }
                }
            });
        } catch (RequestException e) {
            Window.alert(e.toString());
        }

    } else {
    }
}

From source file:org.freemedsoftware.gwt.client.widget.WorkList.java

License:Open Source License

private void retrieveData(int i) {
    final int index = i;
    if ((providerGroupId != null && providerGroupId != 0) || CurrentState.getDefaultProvider() > 0) {
        if (Util.getProgramMode() == ProgramMode.STUBBED) {

        } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
            // JSON-RPC
            String[] params = { "" + providers[i] };
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util
                    .getJsonRequest("org.freemedsoftware.module.WorkListsModule.GenerateWorkList", params)));
            try {
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(Request request, Throwable ex) {
                        Util.showErrorMsg("WorkLists", _("Failed to get work list."));
                    }/*  www .  j  a v a2s .c o m*/

                    @SuppressWarnings("unchecked")
                    public void onResponseReceived(Request request, Response response) {
                        if (200 == response.getStatusCode()) {

                            try {
                                if (response.getText().compareToIgnoreCase("null") != 0
                                        && response.getText().compareTo("[[]]") != 0
                                        && response.getText().compareToIgnoreCase("false") != 0) {
                                    HashMap<String, String>[] r = (HashMap<String, String>[]) JsonUtil
                                            .shoehornJson(JSONParser.parseStrict(response.getText()),
                                                    "HashMap<String,String>[]");
                                    // Window.alert(r[0].toString());
                                    if (r != null) {
                                        if (r.length > 0) {

                                            // workListsTables[index].setVisible(true);
                                            if (r.length >= 10)
                                                workListsTables[index].setMaximumRows(10);
                                            else
                                                workListsTables[index].setMaximumRows(r.length);
                                            VerticalPanel vp = new VerticalPanel();
                                            vp.add(providersLb[index]);
                                            vp.add(workListsTables[index]);
                                            tablesVPanel.add(vp);

                                            providersLb[index].setVisible(true);
                                            // workListsTables[index].setVisible(true);
                                            workListsTables[index].loadData(r);
                                        }
                                    }
                                } else {

                                }
                            } catch (Exception ex) {

                            }
                        } else {
                            Util.showErrorMsg("WorkLists", _("Failed to get work list."));
                        }
                    }
                });
            } catch (RequestException e) {
                Util.showErrorMsg("WorkLists", _("Failed to get work list."));
            }
        } else {
            // GWT-RPC
        }
    } else {
        // workListTable.setVisible(false);
        providerLabel.setVisible(true);
        providerLabel.setText(_("Provider not available."));
    }
}

From source file:org.geomajas.gwt2.plugin.tms.client.TmsClient.java

License:Open Source License

/**
 * Fetch the capabilities of a TileMapService and parse it. This is the base URL that contains a list of TileMaps.
 *
 * @param baseUrl  The URL that points to the TileMapService.
 * @param callback The callback tat contains the parsed capabilities as a {@link org.geomajas.gwt2.plugin.tms.client
 *                 .configuration.TileMapServiceInfo} object.
 *///from w ww  . j  a  v  a  2s . co m
public void getTileMapService(final String baseUrl, final Callback<TileMapServiceInfo, String> callback) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, baseUrl);
    builder.setHeader("Cache-Control", "no-cache");
    builder.setHeader("Pragma", "no-cache");
    try {
        builder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable e) {
                callback.onFailure(e.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    Document messageDom = XMLParser.parse(response.getText());
                    callback.onSuccess(new TileMapServiceInfo100(messageDom.getDocumentElement()));
                } else {
                    callback.onFailure(response.getText());
                }
            }
        });
    } catch (RequestException e) {
        // Couldn't connect to server
        callback.onFailure(e.getMessage());
    }
}

From source file:org.geomajas.gwt2.plugin.tms.client.TmsClient.java

License:Open Source License

/**
 * Fetch the capabilities of a single TileMap configuration XML and parse it. A single TileMap can be used to create
 * a {@link org.geomajas.gwt2.plugin.tms.client.layer.TmsLayer}.
 *
 * @param baseUrl  The URL that points to the TileMap XML.
 * @param callback The callback that contains the parsed capabilities as a
 *       {@link org.geomajas.gwt2.plugin.tms.client.configuration.TileMapInfo} object.
 *///  w  ww  .  j  av a 2s. c o  m
public void getTileMap(final String baseUrl, final Callback<TileMapInfo, String> callback) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, baseUrl);
    builder.setHeader("Cache-Control", "no-cache");
    builder.setHeader("Pragma", "no-cache");
    try {
        builder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable e) {
                callback.onFailure(e.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    Document messageDom = XMLParser.parse(response.getText());
                    callback.onSuccess(new TileMapInfo100(messageDom.getDocumentElement()));
                } else {
                    callback.onFailure(response.getText());
                }
            }
        });
    } catch (RequestException e) {
        // Couldn't connect to server
        callback.onFailure(e.getMessage());
    }
}