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

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

Introduction

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

Prototype

Method POST

To view the source code for com.google.gwt.http.client RequestBuilder POST.

Click Source Link

Document

Specifies that the HTTP POST method should be used.

Usage

From source file:org.freemedsoftware.gwt.client.Util.java

License:Open Source License

/**
 * Calls callModuleMethod method//  w  w w.  j av a 2  s . c  o  m
 * 
 * @param package - package name
 * 
 * @param module
 *            - module name
 * 
 * @param method
 *            - method name
 * 
 * @param paramsList
 *            - list of parameters of any type or multi-type
 * 
 * @param requestCallback
 *            - calls its onError & jsonifiedData function on getting
 *            response from server
 * 
 * @param responseType
 *            - type of response e.g
 *            Integer,HashMap<String,String>,String[],String[][] etc
 */
@SuppressWarnings("rawtypes")
public static void callModuleMethod(final String className, final String method, final List paramsList,
        final CustomRequestCallback requestCallback, final String responseType) {
    callServerMethod("org.freemedsoftware.module", className, method, paramsList, requestCallback, responseType,
            RequestBuilder.POST);
}

From source file:org.freemedsoftware.gwt.client.Util.java

License:Open Source License

/**
 * Calls callModuleMethod method/* w ww.j  a v a  2  s.  c  o  m*/
 * 
 * @param package - package name
 * 
 * @param module
 *            - module name
 * 
 * @param method
 *            - method name
 * 
 * @param id
 *            - Integer
 * 
 * @param requestCallback
 *            - calls its onError & jsonifiedData function on getting
 *            response from server
 * 
 * @param responseType
 *            - type of response e.g
 *            Integer,HashMap<String,String>,String[],String[][] etc
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void callModuleMethod(final String className, final String method, final Integer id,
        final CustomRequestCallback requestCallback, final String responseType) {
    List paramlst = new ArrayList();
    paramlst.add(id);
    callServerMethod("org.freemedsoftware.module", className, method, paramlst, requestCallback, responseType,
            RequestBuilder.POST);
}

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);/*from w w w .j  av  a2 s  .c  om*/
    } 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  w w . ja v a  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 = { 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 av  a2  s  . c o m*/
    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.
 *//*w w  w .  ja v a 2 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);/* w w w  .  ja v a 2 s  .  c  o m*/
    } 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  a2s . co  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  ww .  j ava2s.  c  om
 * @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();/*from   w w w .j av a2  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);
            }

        });
    }
}