Search in sources :

Example 16 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder in project kie-wb-common by kiegroup.

the class FooterPresenterTest method testSetupUrlWhenRequestIsValid.

@Test
public void testSetupUrlWhenRequestIsValid() throws RequestException {
    final String url = "http://localhost:8080/kie-server/services/rest/server";
    final RequestBuilder builder = mock(RequestBuilder.class);
    doReturn(builder).when(presenter).makeRequest(url, onSuccess, onError);
    presenter.setupUrl(url);
    verify(builder).send();
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 17 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder in project kie-wb-common by kiegroup.

the class FooterPresenterTest method testMakeRequest.

@Test
public void testMakeRequest() {
    final String url = "http://localhost:8080/kie-server/services/rest/server";
    final String none = "none";
    final RequestCallback callback = mock(RequestCallback.class);
    final String expectedHTTPMethod = RequestBuilder.GET.toString();
    doReturn(callback).when(presenter).makeCallback(onSuccess, onError);
    final RequestBuilder builder = presenter.makeRequest(url, onSuccess, onError);
    assertEquals(expectedHTTPMethod, builder.getHTTPMethod());
    assertEquals(url, builder.getUrl());
    assertEquals(none, builder.getUser());
    assertEquals(none, builder.getPassword());
    assertEquals(callback, builder.getCallback());
    assertEquals("*/*", builder.getHeader("Accept"));
}
Also used : RequestCallback(com.google.gwt.http.client.RequestCallback) RequestBuilder(com.google.gwt.http.client.RequestBuilder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 18 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder in project activityinfo by bedatadriven.

the class AdminGeometryProvider method fetchGeometry.

private void fetchGeometry(final int levelId, final AsyncCallback<AdminGeometry> callback) {
    RequestBuilder request = new RequestBuilder(RequestBuilder.GET, "/resources/adminLevel/" + levelId + "/entities/polylines");
    request.setCallback(new RequestCallback() {

        @Override
        public void onResponseReceived(Request request, Response response) {
            try {
                AdminGeometry geometry = AdminGeometry.fromJson(response.getText());
                cache.put(levelId, geometry);
                callback.onSuccess(geometry);
            } catch (Exception e) {
                callback.onFailure(e);
            }
        }

        @Override
        public void onError(Request request, Throwable exception) {
            callback.onFailure(exception);
        }
    });
    try {
        request.send();
    } catch (RequestException e) {
        callback.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) RequestException(com.google.gwt.http.client.RequestException)

Example 19 with RequestBuilder

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

the class UserRolesAdminPanelController method getRolesForUser.

private void getRolesForUser(String user) {
    final String url = GWT.getHostPageBaseURL() + "api/userroledao/userRoles?userName=" + encodeUri(user);
    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) {
                selectedRolesListBox.clear();
                for (String role : getSortedItems("roles", response)) {
                    selectedRolesListBox.addItem(role);
                }
                updateHelperDiv(HorizontalScrollWrapper.getListBoxWrapperUIId(selectedRolesListBox));
                Timer t = new Timer() {

                    public void run() {
                        if (rolesListBox.getItemCount() > 0) {
                            cancel();
                            // availableRolesListBox = rolesListBox - selectedRolesListBox
                            availableRolesListBox.clear();
                            for (int i = 0; i < rolesListBox.getItemCount(); i++) {
                                String role = rolesListBox.getValue(i);
                                boolean isSelected = false;
                                for (int j = 0; j < selectedRolesListBox.getItemCount(); j++) {
                                    if (selectedRolesListBox.getValue(j).equals(role)) {
                                        isSelected = true;
                                    }
                                }
                                if (!isSelected) {
                                    availableRolesListBox.addItem(role);
                                }
                            }
                            updateHelperDiv(HorizontalScrollWrapper.getListBoxWrapperUIId(availableRolesListBox));
                        }
                    }
                };
                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)

Example 20 with RequestBuilder

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

the class UserRolesAdminPanelController method modifyUserRoles.

private void modifyUserRoles(final String userName, String serviceUrl) {
    RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.PUT, serviceUrl);
    try {
        executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        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) {
                checkForError(Messages.getString("Error"), response);
                getRolesForUser(userName);
                initializeRoles(rolesListBox.getValue(rolesListBox.getSelectedIndex()), "api/userroledao/roles", rolesListBox);
            }
        });
    } 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) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException)

Aggregations

RequestBuilder (com.google.gwt.http.client.RequestBuilder)132 RequestException (com.google.gwt.http.client.RequestException)116 RequestCallback (com.google.gwt.http.client.RequestCallback)113 Response (com.google.gwt.http.client.Response)111 Request (com.google.gwt.http.client.Request)110 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)27 CsrfRequestBuilder (org.pentaho.mantle.client.csrf.CsrfRequestBuilder)22 JSONString (com.google.gwt.json.client.JSONString)19 ArrayList (java.util.ArrayList)16 Bindable (org.pentaho.ui.xul.stereotype.Bindable)15 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)13 JSONObject (com.google.gwt.json.client.JSONObject)11 JsArrayString (com.google.gwt.core.client.JsArrayString)9 JSONArray (com.google.gwt.json.client.JSONArray)8 List (java.util.List)8 HTML (com.google.gwt.user.client.ui.HTML)7 IDialogCallback (org.pentaho.gwt.widgets.client.dialogs.IDialogCallback)7 EmptyRequestCallback (org.pentaho.mantle.client.EmptyRequestCallback)7 PromptDialogBox (org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox)6 RepositoryFile (org.pentaho.gwt.widgets.client.filechooser.RepositoryFile)6