Search in sources :

Example 1 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder in project gerrit by GerritCodeReview.

the class RestApi method request.

private RequestBuilder request(Method method) {
    RequestBuilder req = new RequestBuilder(method, url());
    if (ifNoneMatch != null) {
        req.setHeader("If-None-Match", ifNoneMatch);
    }
    req.setHeader("Accept", JSON_TYPE);
    if (Gerrit.getXGerritAuth() != null) {
        req.setHeader(HostPageData.XSRF_HEADER_NAME, Gerrit.getXGerritAuth());
    }
    return req;
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder)

Example 2 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder in project gerrit by GerritCodeReview.

the class Gerrit method getDocIndex.

private static void getDocIndex(final AsyncCallback<DocInfo> cb) {
    RequestBuilder req = new RequestBuilder(RequestBuilder.HEAD, GWT.getHostPageBaseURL() + INDEX);
    req.setCallback(new RequestCallback() {

        @Override
        public void onResponseReceived(Request req, Response resp) {
            switch(resp.getStatusCode()) {
                case Response.SC_OK:
                case Response.SC_MOVED_PERMANENTLY:
                case Response.SC_MOVED_TEMPORARILY:
                    cb.onSuccess(DocInfo.create());
                    break;
                default:
                    cb.onSuccess(null);
                    break;
            }
        }

        @Override
        public void onError(Request request, Throwable e) {
            cb.onFailure(e);
        }
    });
    try {
        req.send();
    } catch (RequestException e) {
        cb.onFailure(e);
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException)

Example 3 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder in project opennms by OpenNMS.

the class Navigation method linkTopOpenNMSClicked.

@UiHandler("m_link")
public void linkTopOpenNMSClicked(ClickEvent event) {
    StringBuffer postData = new StringBuffer();
    // note param pairs are separated by a '&'
    // and each key-value pair is separated by a '='
    postData.append(URL.encode("j_username")).append("=").append(URL.encode("ipv6"));
    postData.append("&");
    postData.append(URL.encode("j_password")).append("=").append(URL.encode("ipv6"));
    postData.append("&");
    postData.append(URL.encode("Login")).append("=").append(URL.encode("login"));
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode("/opennms/j_spring_security_check"));
    builder.setHeader("Content-type", "application/x-www-form-urlencoded");
    try {
        builder.sendRequest(postData.toString(), new RequestCallback() {

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

            @Override
            public void onError(Request request, Throwable exception) {
                Window.alert("Problem Logging in");
            }
        });
    } catch (RequestException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
// Window.alert("Cliking link to OpenNMS");
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException) UiHandler(com.google.gwt.uibinder.client.UiHandler)

Example 4 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder in project pentaho-platform by pentaho.

the class UserRolesAdminPanelController method initializeActionBaseSecurityElements.

private void initializeActionBaseSecurityElements() {
    final String url = GWT.getHostPageBaseURL() + "api/userroledao/logicalRoleMap";
    RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    executableTypesRequestBuilder.setHeader("accept", "application/json");
    try {
        executableTypesRequestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
            }

            public void onResponseReceived(Request request, Response response) {
                String roleMappings = response.getText();
                rolesPermissionsPanel.initializeActionBaseSecurityElements(roleMappings);
                systemRolesPermissionsPanel.initializeActionBaseSecurityElements(roleMappings);
            }
        });
    } catch (RequestException e) {
    // ignored
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException)

Example 5 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder in project pentaho-platform by pentaho.

the class UserRolesAdminPanelController method getUsersInRole.

private void getUsersInRole(String role) {
    final String url = GWT.getHostPageBaseURL() + "api/userroledao/roleMembers?roleName=" + encodeUri(role);
    RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    executableTypesRequestBuilder.setHeader("accept", "application/xml");
    try {
        executableTypesRequestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
                displayErrorInMessageBox(Messages.getString("Error"), exception.getLocalizedMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                selectedMembersListBox.clear();
                for (String user : getSortedItems("users", response)) {
                    selectedMembersListBox.addItem(user);
                }
                updateHelperDiv(HorizontalScrollWrapper.getListBoxWrapperUIId(selectedMembersListBox));
                Timer t = new Timer() {

                    public void run() {
                        if (usersListBox.getItemCount() > 0) {
                            cancel();
                            // availableMembersListBox = usersListBox - selectedMembersListBox
                            availableMembersListBox.clear();
                            for (int i = 0; i < usersListBox.getItemCount(); i++) {
                                String user = usersListBox.getValue(i);
                                boolean isSelected = false;
                                for (int j = 0; j < selectedMembersListBox.getItemCount(); j++) {
                                    if (selectedMembersListBox.getValue(j).equals(user)) {
                                        isSelected = true;
                                    }
                                }
                                if (!isSelected) {
                                    availableMembersListBox.addItem(user);
                                }
                            }
                            updateHelperDiv(HorizontalScrollWrapper.getListBoxWrapperUIId(availableMembersListBox));
                        }
                    }
                };
                t.scheduleRepeating(100);
            }
        });
    } catch (RequestException e) {
        displayErrorInMessageBox(Messages.getString("Error"), e.getLocalizedMessage());
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) Timer(com.google.gwt.user.client.Timer) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException)

Aggregations

RequestBuilder (com.google.gwt.http.client.RequestBuilder)121 RequestCallback (com.google.gwt.http.client.RequestCallback)109 RequestException (com.google.gwt.http.client.RequestException)109 Response (com.google.gwt.http.client.Response)108 Request (com.google.gwt.http.client.Request)107 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)28 JSONString (com.google.gwt.json.client.JSONString)17 ArrayList (java.util.ArrayList)15 Bindable (org.pentaho.ui.xul.stereotype.Bindable)15 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)13 JSONObject (com.google.gwt.json.client.JSONObject)11 List (java.util.List)8 IDialogCallback (org.pentaho.gwt.widgets.client.dialogs.IDialogCallback)8 JsArrayString (com.google.gwt.core.client.JsArrayString)7 HTML (com.google.gwt.user.client.ui.HTML)7 PromptDialogBox (org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox)7 JSONArray (com.google.gwt.json.client.JSONArray)6 RepositoryFile (org.pentaho.gwt.widgets.client.filechooser.RepositoryFile)6 Label (com.google.gwt.user.client.ui.Label)5 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)5