Search in sources :

Example 81 with RequestBuilder

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

the class FooterPresenterTest method testSetupUrlWhenMakeRequestRaisesAnError.

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

Example 82 with RequestBuilder

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

the class FooterPresenter method makeRequest.

RequestBuilder makeRequest(final String url, final Command onSuccess, final Command onError) {
    final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    final String none = "none";
    builder.setUser(none);
    builder.setPassword(none);
    builder.setCallback(makeCallback(onSuccess, onError));
    builder.setHeader("Accept", "*/*");
    return builder;
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder)

Example 83 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder in project opentsdb by OpenTSDB.

the class RemoteOracle method requestSuggestions.

@Override
public void requestSuggestions(final Request request, final Callback callback) {
    if (current != null) {
        pending_req = request;
        pending_cb = callback;
        return;
    }
    current = callback;
    {
        final String this_query = request.getQuery();
        // range of results covering the new request.
        if ((last_query != null && last_query.compareTo(this_query) <= 0 && this_query.compareTo(last_suggestion) < 0) || queries_seen.check(this_query)) {
            current = null;
            cache.requestSuggestions(request, callback);
            return;
        }
        last_query = this_query;
    }
    final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, SUGGEST_URL + type + "&q=" + last_query);
    try {
        builder.sendRequest(null, new RequestCallback() {

            public void onError(final com.google.gwt.http.client.Request r, final Throwable e) {
                // Something bad happened, drop the current request.
                current = null;
                if (pending_req != null) {
                    // But if we have another waiting...
                    // ... try it now.
                    requestSuggestions(pending_req, pending_cb);
                }
            }

            // Need to use fully-qualified names as this class inherits already
            // from a pair of inner classes called Request / Response :-/
            public void onResponseReceived(final com.google.gwt.http.client.Request r, final com.google.gwt.http.client.Response response) {
                if (response.getStatusCode() == com.google.gwt.http.client.Response.SC_OK) {
                    final JSONValue json = JSONParser.parse(response.getText());
                    // In case this request returned nothing, we pretend the last
                    // suggestion ended with the largest character possible, so we
                    // won't send more requests to the server if the user keeps
                    // adding extra characters.
                    last_suggestion = last_query + "\377";
                    if (json != null && json.isArray() != null) {
                        final JSONArray results = json.isArray();
                        final int n = Math.min(request.getLimit(), results.size());
                        for (int i = 0; i < n; i++) {
                            final JSONValue suggestion = results.get(i);
                            if (suggestion == null || suggestion.isString() == null) {
                                continue;
                            }
                            final String suggestionstr = suggestion.isString().stringValue();
                            last_suggestion = suggestionstr;
                            cache.add(suggestionstr);
                        }
                        // Is this response still relevant to what the requester wants?
                        if (requester.getText().startsWith(last_query)) {
                            cache.requestSuggestions(request, callback);
                            pending_req = null;
                            pending_cb = null;
                        }
                    }
                }
                // Regardless of what happened above, this is done.
                current = null;
                if (pending_req != null) {
                    final Request req = pending_req;
                    final Callback cb = pending_cb;
                    pending_req = null;
                    pending_cb = null;
                    requestSuggestions(req, cb);
                }
            }
        });
    } catch (RequestException ignore) {
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) JSONArray(com.google.gwt.json.client.JSONArray) RequestException(com.google.gwt.http.client.RequestException) JSONValue(com.google.gwt.json.client.JSONValue) RequestCallback(com.google.gwt.http.client.RequestCallback) RequestCallback(com.google.gwt.http.client.RequestCallback)

Example 84 with RequestBuilder

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

the class GwtDatasourceEditorEntryPoint method onModuleLoad.

public void onModuleLoad() {
    datasourceServiceManager = new DatasourceServiceManagerGwtImpl();
    datasourceServiceManager.isAdmin(new XulServiceCallback<Boolean>() {

        public void error(String message, Throwable error) {
        }

        public void success(Boolean retVal) {
            isAdmin = retVal;
            datasourceService = new DSWDatasourceServiceGwtImpl();
            modelerService = new GwtModelerServiceImpl();
            BogoPojo bogo = new BogoPojo();
            modelerService.gwtWorkaround(bogo, new XulServiceCallback<BogoPojo>() {

                public void success(BogoPojo retVal) {
                }

                public void error(String message, Throwable error) {
                }
            });
            // only init the app if the user has permissions
            // $NON-NLS-1$
            final String url = GWT.getHostPageBaseURL() + "plugin/data-access/api/permissions/hasDataAccess";
            RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
            builder.setHeader("accept", "application/json");
            builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
            try {
                builder.sendRequest(null, new RequestCallback() {

                    public void onError(Request request, Throwable exception) {
                        setupStandardNativeHooks(GwtDatasourceEditorEntryPoint.this);
                        initDashboardButtons(false);
                    }

                    public void onResponseReceived(Request request, Response response) {
                        hasPermissions = new Boolean(response.getText());
                        setupStandardNativeHooks(GwtDatasourceEditorEntryPoint.this);
                        if (hasPermissions) {
                            csvService = (ICsvDatasourceServiceAsync) GWT.create(ICsvDatasourceService.class);
                            setupPrivilegedNativeHooks(GwtDatasourceEditorEntryPoint.this);
                            loadOverlay("startup.dataaccess");
                        }
                        initDashboardButtons(hasPermissions);
                    }
                });
            } catch (RequestException e) {
            // TODO Auto-generated catch block
            }
        }
    });
    XulServiceCallback<List<IDatabaseType>> callback = new XulServiceCallback<List<IDatabaseType>>() {

        public void error(String message, Throwable error) {
            error.printStackTrace();
        }

        public void success(List<IDatabaseType> retVal) {
            databaseTypeHelper = new DatabaseTypeHelper(retVal);
            databaseConnectionConverter = new DatabaseConnectionConverter(databaseTypeHelper);
        }
    };
    dialectService.getDatabaseTypes(callback);
    UIDatasourceServiceManager manager = UIDatasourceServiceManager.getInstance();
    manager.registerService(new JdbcDatasourceService());
    manager.registerService(new MondrianUIDatasourceService(datasourceServiceManager));
    manager.registerService(new MetadataUIDatasourceService(datasourceServiceManager));
    manager.registerService(new DSWUIDatasourceService(datasourceServiceManager));
    manager.getIds(null);
}
Also used : GwtModelerServiceImpl(org.pentaho.agilebi.modeler.services.impl.GwtModelerServiceImpl) RequestBuilder(com.google.gwt.http.client.RequestBuilder) JdbcDatasourceService(org.pentaho.platform.dataaccess.datasource.ui.service.JdbcDatasourceService) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException) UIDatasourceServiceManager(org.pentaho.platform.dataaccess.datasource.ui.service.UIDatasourceServiceManager) XulServiceCallback(org.pentaho.ui.xul.XulServiceCallback) Response(com.google.gwt.http.client.Response) IDatabaseType(org.pentaho.database.model.IDatabaseType) DatasourceServiceManagerGwtImpl(org.pentaho.platform.dataaccess.datasource.wizard.service.impl.DatasourceServiceManagerGwtImpl) RequestCallback(com.google.gwt.http.client.RequestCallback) DatabaseTypeHelper(org.pentaho.database.util.DatabaseTypeHelper) MondrianUIDatasourceService(org.pentaho.platform.dataaccess.datasource.ui.service.MondrianUIDatasourceService) List(java.util.List) DSWDatasourceServiceGwtImpl(org.pentaho.platform.dataaccess.datasource.wizard.service.impl.DSWDatasourceServiceGwtImpl) DSWUIDatasourceService(org.pentaho.platform.dataaccess.datasource.ui.service.DSWUIDatasourceService) MetadataUIDatasourceService(org.pentaho.platform.dataaccess.datasource.ui.service.MetadataUIDatasourceService) BogoPojo(org.pentaho.agilebi.modeler.gwt.BogoPojo)

Example 85 with RequestBuilder

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

the class WizardConnectionController method updateConnection.

@Bindable
public void updateConnection() {
    RequestBuilder updateConnectionBuilder = new RequestBuilder(RequestBuilder.POST, ConnectionController.getServiceURL("update"));
    updateConnectionBuilder.setHeader("Content-Type", "application/json");
    try {
        // AutoBean<IDatabaseConnection> bean = AutoBeanUtils.getAutoBean(currentConnection);
        AutoBean<IDatabaseConnection> bean = createIDatabaseConnectionBean(currentConnection);
        updateConnectionBuilder.sendRequest(AutoBeanCodex.encode(bean).getPayload(), new RequestCallback() {

            @Override
            public void onError(Request request, Throwable exception) {
                displayErrorMessage(exception);
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                try {
                    if (response.getStatusCode() == Response.SC_OK) {
                        currentConnection = AutobeanUtilities.connectionBeanToImpl(currentConnection);
                        datasourceModel.getGuiStateModel().updateConnection(existingConnectionName, currentConnection);
                        datasourceModel.setSelectedRelationalConnection(currentConnection);
                    } else if (response.getStatusCode() == Response.SC_INTERNAL_SERVER_ERROR) {
                        // We assume that this means the connection doesn't exist to
                        // update so we'll add it
                        RequestBuilder deleteConnectionBuilder = new RequestBuilder(RequestBuilder.DELETE, ConnectionController.getServiceURL("deletebyname", new String[][] { { "name", previousConnectionName } }));
                        try {
                            deleteConnectionBuilder.sendRequest(null, new RequestCallback() {

                                @Override
                                public void onError(Request request, Throwable exception) {
                                    displayErrorMessage(exception);
                                }

                                @Override
                                public void onResponseReceived(Request request, Response response) {
                                    try {
                                        if (response.getStatusCode() == Response.SC_OK) {
                                            datasourceModel.getGuiStateModel().deleteConnection(datasourceModel.getSelectedRelationalConnection().getName());
                                            List<IDatabaseConnection> connections = datasourceModel.getGuiStateModel().getConnections();
                                            if (connections != null && connections.size() > 0) {
                                                datasourceModel.setSelectedRelationalConnection(connections.get(connections.size() - 1));
                                            } else {
                                                datasourceModel.setSelectedRelationalConnection(null);
                                            }
                                            addConnection();
                                        } else {
                                            openErrorDialog(MessageHandler.getString("ERROR"), // $NON-NLS-1$
                                            MessageHandler.getString(// $NON-NLS-1$
                                            "ConnectionController.ERROR_0002_UNABLE_TO_DELETE_CONNECTION"));
                                        }
                                    } catch (Exception e) {
                                        displayErrorMessage(e);
                                    }
                                }
                            });
                        } catch (RequestException e) {
                            displayErrorMessage(e);
                        }
                    } else {
                        openErrorDialog(MessageHandler.getString("ERROR"), // $NON-NLS-1$
                        MessageHandler.getString(// $NON-NLS-1$
                        "ConnectionController.ERROR_0004_UNABLE_TO_UPDATE_CONNECTION"));
                    }
                } catch (Exception e) {
                    displayErrorMessage(e);
                }
            }
        });
    } catch (RequestException e) {
        displayErrorMessage(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) ArrayList(java.util.ArrayList) List(java.util.List) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) RequestException(com.google.gwt.http.client.RequestException) RequestException(com.google.gwt.http.client.RequestException) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

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