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.screen.UserManagementScreen.java

License:Open Source License

public void retrieveAllUsers() {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // Do nothing
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        // Use JSON-RPC to retrieve the data
        String[] params = {};//from  w  w  w. j  av a2s .c o  m

        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.api.UserInterface.GetRecords", params)));
        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) {
                            wUsers.clearData();
                            wUsers.loadData(data);
                        }
                    }
                }
            });
        } 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.screen.UserManagementScreen.java

License:Open Source License

public void getACLGroups() {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // Do nothing
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        // Use JSON-RPC to retrieve the data
        String[] params = {};//from   w  ww . ja v a  2 s.  co  m

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

                public void onResponseReceived(Request request, Response response) {
                    if (response.getStatusCode() == 200) {
                        String[][] data = (String[][]) JsonUtil
                                .shoehornJson(JSONParser.parseStrict(response.getText()), "String[][]");
                        if (data != null) {
                            addACLGroup(data);
                        }
                    }
                }
            });
        } 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.screen.UserManagementScreen.java

License:Open Source License

public void getUserDetails(final Integer userId) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // Do nothing
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        // Use JSON-RPC to retrieve the data
        String[] params = { JsonUtil.jsonify(userId) };

        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(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) {
                            tbUsername.setText(data.get("username"));
                            tbDescription.setText(data.get("userdescrip"));
                            tbUserFirstName.setText(data.get("userfname"));
                            tbUserLastName.setText(data.get("userlname"));
                            tbUserMiddleName.setText(data.get("usermname"));
                            tbUserTitle.setWidgetValue(data.get("usertitle"));
                            lbUserType.setWidgetValue(data.get("usertype"));
                            if (data.get("usertype") != null && data.get("usertype").equalsIgnoreCase("phy")) {
                                lbActualPhysician.setValue(Integer.parseInt(data.get("userrealphy")));
                                lbActualPhysician.setVisible(true);
                            }

                            if (data.get("userfac") != null && data.get("userfac").length() > 0) {
                                String[] userFacilities = data.get("userfac").split(",");
                                for (int i = 0; i < userFacilities.length; i++) {
                                    Integer id = Integer.parseInt(userFacilities[i]);
                                    CheckBox checkBox = facilitiesCheckBoxesMap.get(id);
                                    if (checkBox != null)
                                        checkBox.setValue(true);
                                }
                            }

                            addUserButton.setText(_("Modify User"));
                            changePasswordLink.setVisible(true);
                            tbPassword.setEnabled(false);
                            tbPasswordverify.setEnabled(false);
                            deleteUserButton.setVisible(true);
                            copyButton.setVisible(true);
                        }
                    }
                }
            });
        } 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.screen.UserManagementScreen.java

License:Open Source License

public void getUserGroup(final Integer userId) {
    aclSelectedGroupsIdsList.clear();/*from  w  w  w . java 2s.c o m*/
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // Do nothing
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        // Use JSON-RPC to retrieve the data
        String[] params = { JsonUtil.jsonify(userId) };

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

                public void onResponseReceived(Request request, Response response) {
                    if (response.getStatusCode() == 200) {
                        String[] data = (String[]) JsonUtil
                                .shoehornJson(JSONParser.parseStrict(response.getText()), "String[]");
                        if (data != null) {
                            Integer groupId = null;
                            for (int i = 0; i < data.length; i++) {
                                groupId = Integer.parseInt(data[i]);
                                CheckBox checkBox = aclGroupsCheckBoxesMap.get(groupId);
                                checkBox.setValue(true);
                                aclSelectedGroupsIdsList.add(groupId);
                            }
                        }
                    }
                }
            });
        } 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.SystemNotifications.java

License:Open Source License

/**
 * Asynchronously poll for new system notifications
 *//*from  w ww .ja v  a 2  s.  co m*/
public boolean poll() {
    JsonUtil.debug("SystemNotifications.poll() called");

    // if (mutexStatus) {
    // JsonUtil.debug("mutexStatus indicates run in progress.");
    // return false;
    // }

    mutexStatus = true;
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // Nothing. Do nothing.
        mutexStatus = false;
        return true;
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        // JSON-RPC
        String[] params = { Long.toString(mutexTimestamp) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util
                .getJsonRequest("org.freemedsoftware.module.SystemNotifications.GetFromTimestamp", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    Util.showErrorMsg("SystemNotifications", _("Failed to get system notifications."));
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                        if (response.getText().compareToIgnoreCase("false") != 0) {
                            if (response.getText().trim().equalsIgnoreCase(AppConstants.INVALID_SESSION)) {
                                Util.logout(new Command() {

                                    @Override
                                    public void execute() {
                                        stop();
                                    }

                                });
                                mutexStatus = false;
                                return;
                            }
                            HashMap<String, String>[] r = (HashMap<String, String>[]) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,String>[]");
                            if (r != null) {
                                if (r.length > 0) {
                                    // Update our working timestamp
                                    try {
                                        mutexTimestamp = Long.parseLong(r[0].get("timestamp"));
                                        JsonUtil.debug("SystemNotifications(): Received timestamp "
                                                + r[0].get("timestamp"));
                                        JsonUtil.debug(
                                                "SystemNotifications(): Parsed timestamp as " + mutexTimestamp);
                                    } catch (Exception ex) {
                                        JsonUtil.debug(
                                                "SystemNotifications(): Exception parsing mutex timestamp"
                                                        + r[0].get("timestamp"));
                                    }
                                    for (int iter = 0; iter < r.length; iter++) {
                                        handleNotification(r[iter]);
                                    }
                                }
                            }
                        } else {
                            JsonUtil.debug("SystemNotifications(): Received dummy response from JSON backend");
                        }
                    } else {
                        Util.showErrorMsg("SystemNotifications", _("Failed to get system notifications."));
                    }

                    // Release mutex
                    mutexStatus = false;
                }
            });
        } catch (RequestException e) {
            Util.showErrorMsg("SystemNotifications", _("Failed to get system notifications."));
        }
    } else {
        // GWT-RPC
    }

    return true;
}

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

License:Open Source License

public static void login(String username, String password, String location, final CustomCommand whenDone,
        final CustomCommand whenFail) {
    List<String> paramList = new ArrayList<String>();
    paramList.add(username);// www.  ja v a 2  s .c o m
    paramList.add(password);
    if (location != null)
        paramList.add(location);
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
            URL.encode(Util.getJsonRequest("org.freemedsoftware.public.Login.Validate",
                    (String[]) paramList.toArray(new String[0]))));
    try {
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable ex) {
                Window.alert(ex.toString());
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    String res = (String) JsonUtil.shoehornJson(JSONParser.parseStrict(response.getText()),
                            "String");
                    if (res == null)
                        res = response.getText().trim();
                    if (res.compareToIgnoreCase("true") == 0) {
                        whenDone.execute(null);
                    } else if (res.compareToIgnoreCase("false") == 0) {
                        whenFail.execute(AppConstants.INVALID_USER);
                    } else if (res.compareToIgnoreCase(AppConstants.NOT_IN_FACILITY) == 0)
                        whenFail.execute(AppConstants.NOT_IN_FACILITY);
                } else {
                    whenFail.execute(AppConstants.INVALID_RESPONSE);
                }
            }
        });
    } catch (RequestException e) {
        whenFail.execute(AppConstants.INVALID_RESPONSE);
    }
}

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

License:Open Source License

/**
 * Logout of the system and pop up a login dialog.
 * /*  www.java 2 s.  com*/
 * @param state
 */
public static void logout(final Command onSuccess) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {

    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = {};
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.public.Login.Logout", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                    GWT.log("Exception", ex);
                    Window.alert(_("Failed to log out."));
                }

                public void onResponseReceived(com.google.gwt.http.client.Request request,
                        com.google.gwt.http.client.Response response) {
                    if (200 == response.getStatusCode()) {
                        // closeAllTabs();
                        if (onSuccess != null)
                            onSuccess.execute();
                        CurrentState.getMainScreen().setVisible(false);
                        UIObject.setVisible(RootPanel.get("loginScreenOuter").getElement(), true);
                        CurrentState.getFreemedInterface().getLoginDialog().center();
                        CurrentState.getFreemedInterface().getLoginDialog().setFocusToPasswordField();
                    } else {
                        Window.alert(_("Failed to log out."));
                    }
                }
            });
        } catch (RequestException e) {
            GWT.log("Exception", e);
            Window.alert("Failed to log out.");
        }

    } else {
        try {
            LoginAsync service = (LoginAsync) Util.getProxy("org.freemedsoftware.gwt.client.Public.Login");
            service.Logout(new AsyncCallback<Void>() {
                public void onSuccess(Void r) {
                    CurrentState.getMainScreen().hide();
                    UIObject.setVisible(RootPanel.get("loginScreenOuter").getElement(), true);
                    CurrentState.getFreemedInterface().getLoginDialog().center();
                }

                public void onFailure(Throwable t) {
                    Window.alert("Failed to log out.");
                }
            });
        } catch (Exception e) {
            Window.alert("Could not create proxy for Login");
        }
    }
}

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

License:Open Source License

/**
 * Calls server method// w  w w  .j  a  va2s  .co  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")
private static void callServerMethod(final String packageName, final String className, final String method,
        final List paramsList, final CustomRequestCallback requestCallback, final String responseType,
        Method requestMethod) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // TODO: STUBBED
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        // JSON-RPC
        String params = "";
        List<String> paramsStr = new ArrayList<String>();
        if (paramsList != null) {
            int i = 0;
            Iterator iterator = paramsList.iterator();
            while (iterator.hasNext()) {
                Object object = iterator.next();
                if (requestMethod == RequestBuilder.GET)
                    paramsStr.add(JsonUtil.jsonify(object));
                else {
                    if (params.length() > 0)
                        params += "&";
                    params += "param" + i++ + "=" + JsonUtil.jsonify(object);
                }
            }
        }

        String methodURL = packageName + "." + className + "." + method;

        RequestBuilder builder = null;
        if (requestMethod == RequestBuilder.POST) {
            builder = new RequestBuilder(requestMethod, URL.encode(Util.getJsonRequest(methodURL)));
            builder.setHeader("Content-type", "application/x-www-form-urlencoded");
            builder.setHeader("Content-length", params.length() + "");
            builder.setHeader("Connection", "close");
        } else {
            builder = new RequestBuilder(requestMethod,
                    URL.encode(Util.getJsonRequest(methodURL, paramsStr.toArray(new String[0]))));
        }
        try {
            builder.sendRequest(params, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    if (requestCallback != null)
                        requestCallback.onError();
                }

                public void onResponseReceived(Request request, Response response) {
                    if (requestCallback != null) {
                        if (200 == response.getStatusCode()) {
                            Object result = JsonUtil.shoehornJson(JSONParser.parseStrict(response.getText()),
                                    responseType);
                            requestCallback.jsonifiedData(result);
                        } else
                            requestCallback.onError();
                    }
                }
            });
        } catch (RequestException e) {
        }
    } else {
        // GWT-RPC
    }
}

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

License:Open Source License

/**
 * Calls callApiMethod method//from   ww w  .  ja v a2s.  c om
 * 
 * @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 callApiMethod(final String className, final String method, final List paramsList,
        final CustomRequestCallback requestCallback, final String responseType) {
    callServerMethod("org.freemedsoftware.api", className, method, paramsList, requestCallback, responseType,
            RequestBuilder.POST);
}

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

License:Open Source License

/**
 * Calls callApiMethod method//w  ww  . ja v  a  2  s  .com
 * 
 * @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 callApiMethod(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.api", className, method, paramlst, requestCallback, responseType,
            RequestBuilder.POST);
}