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.ActionItemsBox.java

License:Open Source License

@SuppressWarnings({ "rawtypes", "unchecked" })
public void retrieveData() {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // Runs in STUBBED MODE => Feed with Sample Data
        HashMap<String, String>[] sampleData = getSampleData();
        loadData(sampleData);//  ww  w  .  ja v a  2s .c o m
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        // Use JSON-RPC to retrieve the data

        String[] actionsParams = {};
        if (patientId != null) {
            List params = new ArrayList();
            params.add(patientId.toString());
            actionsParams = (String[]) params.toArray(new String[0]);
        }
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.api.ActionItems.getActionItemsCount", actionsParams)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                @Override
                public void onError(Request request, Throwable ex) {
                    GWT.log(request.toString(), ex);
                }

                @Override
                public void onResponseReceived(Request request, Response response) {
                    if (response.getStatusCode() == 200) {
                        Integer data = (Integer) JsonUtil
                                .shoehornJson(JSONParser.parseStrict(response.getText()), "Integer");
                        if (data != null) {
                            JsonUtil.debug("Action Items count from server is:" + data);
                            loadCounter(data);
                        }
                    }
                }
            });
        } catch (RequestException e) {
            // nothing here right now
        }

        actionItemsTable.showloading(true);
        // Get data
        RequestBuilder dataBuilder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.api.ActionItems.getActionItems", actionsParams)));
        try {
            dataBuilder.sendRequest(null, new RequestCallback() {
                @Override
                public void onError(Request request, Throwable ex) {
                    GWT.log(request.toString(), ex);
                }

                @Override
                public void onResponseReceived(Request request, Response response) {
                    if (response.getStatusCode() == 200) {
                        HashMap<String, String>[] data = (HashMap<String, String>[]) JsonUtil.shoehornJson(
                                JSONParser.parseStrict(response.getText()), "HashMap<String,String>[]");
                        if (data != null && data.length > 0) {
                            setResult(data);
                            loadData(data);
                        } else
                            actionItemsTable.showloading(false);
                    }
                }
            });
        } catch (RequestException e) {
            actionItemsTable.showloading(false);
            // nothing here right now
        }
    } else if (Util.getProgramMode() == ProgramMode.NORMAL) {
        // Use GWT-RPC to retrieve the data
        // TODO: Create that stuff
    }
}

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

License:Open Source License

protected void loadSuggestions(String req, final Request r, final Callback cb) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // Handle in a stubbed sort of way
        List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
        map.clear();//from  w ww  .  ja  v a  2  s.  co  m
        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) {
        String[] params = { req };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware." + moduleName, 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) {
                                Set<String> keys = result.keySet();
                                Iterator<String> iter = keys.iterator();

                                List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
                                map.clear();
                                while (iter.hasNext()) {
                                    final String key = (String) iter.next();
                                    final String val = (String) result.get(key);
                                    addKeyValuePair(items, val, key);
                                }
                                cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
                            } else
                                // if no result then set value to 0
                                setValue(0);
                        } else {
                            GWT.log("Result " + response.getStatusText(), null);
                        }
                    }
                }
            });
        } catch (RequestException e) {
            GWT.log("Exception thrown: ", e);
        }
    } else {
        ModuleInterfaceAsync service = null;
        try {
            service = ((ModuleInterfaceAsync) Util
                    .getProxy("org.freemedsoftware.gwt.client.Api.ModuleInterface"));
        } catch (Exception e) {
        }

        service.ModuleSupportPicklistMethod(moduleName, req, new AsyncCallback<HashMap<String, String>>() {
            public void onSuccess(HashMap<String, String> result) {
                Set<String> keys = result.keySet();
                Iterator<String> iter = keys.iterator();

                List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
                map.clear();
                while (iter.hasNext()) {
                    final String key = (String) iter.next();
                    final String val = (String) result.get(key);
                    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.CustomMulltiSelectListBox.java

License:Open Source License

public void populateMultiList(String sval) {
    selVal = sval;//from  w w w. j a  v  a2 s  .  com
    if (Util.getProgramMode() == ProgramMode.STUBBED) {

    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { module };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util.getJsonRequest(
                "org.freemedsoftware.api.ModuleInterface.ModuleSupportPicklistMethod", 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) {
                                multiLBox.clear();
                                Set<String> keys = result.keySet();
                                Iterator<String> iter = keys.iterator();

                                while (iter.hasNext()) {

                                    final String key = (String) iter.next();
                                    final String val = (String) result.get(key);
                                    JsonUtil.debug(val);
                                    multiLBox.addItem(val, key);
                                    // addKeyValuePair(items, val, key);
                                }
                                if (!(selVal == null || selVal.equals("")))
                                    setValue();
                                // cb.onSuggestionsReady(r,
                                // new SuggestOracle.Response(items));
                            } else {
                            } // if no result then set value to 0
                              // setValue(0);
                        } else {
                            GWT.log("Result " + response.getStatusText(), null);
                        }
                    }
                }
            });
        } catch (RequestException e) {
            GWT.log("Exception thrown: ", e);
        }
    } else {

    }
}

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

License:Open Source License

/**
 * Retrieve the current number of pages for the internal document.
 *//*from  w w  w .j a  v a2 s .c  o m*/
protected boolean getNumberOfPages() {
    if (internalId.intValue() == 0) {
        GWT.log("getNUmberOfPages called without initializing internalId", null);
        return false;
    }
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        numberOfPages = 1;
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { JsonUtil.jsonify(internalId) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest(resolveNamespace() + ".NumberOfPages", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                }

                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                        Integer r = (Integer) JsonUtil.shoehornJson(JSONParser.parseStrict(response.getText()),
                                "Integer");
                        if (r != null) {
                            numberOfPages = r;
                            try {
                                loadPage(1);
                            } catch (Exception e) {
                                JsonUtil.debug(e.getMessage());
                            }
                            setVisible(true);
                        }
                    } else {
                    }
                }
            });
        } catch (RequestException e) {
        }
    } else {
        if (viewerType == UNFILED_DOCUMENTS) {
            UnfiledDocumentsAsync p = null;
            try {
                p = (UnfiledDocumentsAsync) Util
                        .getProxy("org.freemedsoftware.gwt.client.Module.UnfiledDocuments");
            } catch (Exception e) {
                GWT.log("Exception", e);
            }
            p.NumberOfPages(internalId, new AsyncCallback<Integer>() {
                public void onSuccess(Integer o) {
                    numberOfPages = o.intValue();
                }

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

        if (viewerType == UNREAD_DOCUMENTS) {
            UnreadDocumentsAsync p = null;
            try {
                p = (UnreadDocumentsAsync) Util
                        .getProxy("org.freemedsoftware.gwt.client.Module.UnreadDocuments");
            } catch (Exception e) {
                GWT.log("Exception", e);
            }
            p.NumberOfPages(internalId, new AsyncCallback<Integer>() {
                public void onSuccess(Integer o) {
                    numberOfPages = o.intValue();
                }

                public void onFailure(Throwable t) {
                    GWT.log("Exception", t);
                }
            });
        }
        if (viewerType == SCANNED_DOCUMENTS) {
            // TODO: make this work for scanned documents
        }
    }
    return true;
}

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

License:Open Source License

public void retrieveData() {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // Runs in STUBBED MODE => Feed with Sample Data
        HashMap<String, String>[] sampleData = getSampleData();
        loadData(sampleData);/*from  w  w  w .ja va 2 s  . c  om*/
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        wDocuments.showloading(true);
        // Use JSON-RPC to retrieve the data
        String[] documentparams = {};

        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.module.UnfiledDocuments.GetAll", documentparams)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    GWT.log(request.toString(), ex);
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(Request request, Response response) {
                    if (response.getStatusCode() == 200) {
                        HashMap<String, String>[] data = (HashMap<String, String>[]) JsonUtil.shoehornJson(
                                JSONParser.parseStrict(response.getText()), "HashMap<String,String>[]");
                        if (data != null) {
                            loadData(data);
                        } else
                            wDocuments.showloading(false);
                    }
                }
            });
        } catch (RequestException e) {
            // nothing here right now
        }
    } else if (Util.getProgramMode() == ProgramMode.NORMAL) {
        // Use GWT-RPC to retrieve the data
        // TODO: Create that stuff
    }

}

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

License:Open Source License

protected void populateStrength(Integer drugValue, final Command after) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        drugStrength.addItem("125MG", "1");
        drugStrength.addItem("500MG", "2");
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { drugValue.toString() };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL
                .encode(Util.getJsonRequest("org.freemedsoftware.module.NDCLexicon.DosagesForDrug", params)));
        try {/*w  w w.  j a  v  a2 s .c o  m*/
            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[][] r = (String[][]) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()), "String[][]");
                            if (r != null) {
                                drugStrength.clear();
                                for (int iter = 0; iter < r.length; iter++) {
                                    drugStrength.addItem(r[iter][0], r[iter][1]);
                                }
                                if (after != null) {
                                    after.execute();
                                }
                            }
                        } else {
                            GWT.log("Result " + response.getStatusText(), null);
                        }
                    }
                }
            });
        } catch (RequestException e) {
            GWT.log("Exception thrown: ", e);
        }
    } else {
        // FIXME: GWT-RPC NOT IMPLEMENTED YET!
    }
}

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

License:Open Source License

/**
 * Set value of current widget based on integer value, asynchronously.
 * /* w  w w.  ja  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 {
            // textBox.setEnabled(false);
            String[] params = { moduleName, widgetValue.toString() };
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                    Util.getJsonRequest("org.freemedsoftware.api.ModuleInterface.ModuleToTextMethod", params)));
            try {
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                        textBox.setEnabled(true);
                    }

                    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");
                                // textBox.setEnabled(true);
                                if (result != null) {
                                    searchBox.setText(result);
                                    searchBox.setTitle(result);
                                }
                            } else {
                                Window.alert(response.toString());
                            }
                        }
                    }
                });
            } catch (RequestException e) {
                textBox.setEnabled(true);
            }
        }
    } else {
        ModuleInterfaceAsync service = null;
        try {
            service = ((ModuleInterfaceAsync) Util
                    .getProxy("org.freemedsoftware.gwt.client.Api.ModuleInterface"));
        } catch (Exception e) {
        }
        textBox.setEnabled(false);
        service.ModuleToTextMethod(moduleName, widgetValue, new AsyncCallback<String>() {
            public void onSuccess(String textual) {
                textBox.setEnabled(true);
                searchBox.setText(textual);
                searchBox.setTitle(textual);
            }

            public void onFailure(Throwable t) {

            }
        });

    }
}

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

License:Open Source License

protected void loadSuggestions(String req, final Request r, final Callback cb) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // Handle in a stubbed sort of way
        List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
        map.clear();/*  www  .j  a  va  2  s.c  o m*/
        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) {
        String[] params = { moduleName, patientId.toString(), req };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util
                .getJsonRequest("org.freemedsoftware.api.ModuleInterface.EMRSupportPicklistMethod", 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) {
                                Set<String> keys = result.keySet();
                                Iterator<String> iter = keys.iterator();

                                List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
                                map.clear();
                                while (iter.hasNext()) {
                                    final String key = (String) iter.next();
                                    final String val = (String) result.get(key);
                                    addKeyValuePair(items, val, key);
                                }
                                cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
                            } else
                                // if no result then set value to 0
                                setValue(0);
                        } else {
                            GWT.log("Result " + response.getStatusText(), null);
                        }
                    }
                }
            });
        } catch (RequestException e) {
            GWT.log("Exception thrown: ", e);
        }
    } else {
        ModuleInterfaceAsync service = null;
        try {
            service = ((ModuleInterfaceAsync) Util
                    .getProxy("org.freemedsoftware.gwt.client.Api.ModuleInterface"));
        } catch (Exception e) {
        }

        service.ModuleSupportPicklistMethod(moduleName, req, new AsyncCallback<HashMap<String, String>>() {
            public void onSuccess(HashMap<String, String> result) {
                Set<String> keys = result.keySet();
                Iterator<String> iter = keys.iterator();

                List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
                map.clear();
                while (iter.hasNext()) {
                    final String key = (String) iter.next();
                    final String val = (String) result.get(key);
                    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.EMRModuleWidget.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 = { moduleName, val.toString() };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.api.ModuleInterface.ModuleToTextMethod", params)));
        try {//from w  ww .j av a  2 s.c o m
            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) {
                            }
                        } else {
                            GWT.log("Result " + response.getStatusText(), null);
                        }
                    }
                }
            });
        } catch (RequestException e) {
            GWT.log("Exception thrown: ", e);
        }
    } else {
        ModuleInterfaceAsync service = null;
        try {
            service = ((ModuleInterfaceAsync) Util
                    .getProxy("org.freemedsoftware.gwt.client.Api.ModuleInterface"));
        } catch (Exception e) {
        }
        service.ModuleToTextMethod(moduleName, val, new AsyncCallback<String>() {
            public void onSuccess(String r) {
                searchBox.setText(r);
            }

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

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

License:Open Source License

public void loadTemplates() {
    if (Util.getProgramMode() == ProgramMode.JSONRPC) {

        String[] params = {};//from  ww  w .  j av a  2 s  .c  om
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.module.EncounterNotesTemplate.getTemplates", params)));

        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(Request request, Response response) {

                    if (200 == response.getStatusCode()) {
                        try {
                            HashMap<String, String>[] r = (HashMap<String, String>[]) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,String>[]");
                            if (r != null) {
                                if (r.length > 0) {
                                    templatesCustomTable.loadData(r);
                                } else {
                                }
                            } else {

                            }
                        } catch (Exception e) {

                        }

                    } else {

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