Search in sources :

Example 6 with RequestException

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

the class JdbcDatasourceService method remove.

/* (non-Javadoc)
   * @see org.pentaho.platform.dataaccess.datasource.ui.service.IUIDatasourceAdminService#remove(org.pentaho.platform
   * .dataaccess.datasource.IDatasourceInfo)
   */
@Override
public void remove(IDatasourceInfo dsInfo, Object callback) {
    final XulServiceCallback<Boolean> responseCallback = (XulServiceCallback<Boolean>) callback;
    RequestBuilder deleteConnectionBuilder = new RequestBuilder(RequestBuilder.DELETE, getBaseURL() + NameUtils.URLEncode("deletebyname?name={0}", dsInfo.getId()));
    try {
        deleteConnectionBuilder.sendRequest(null, new RequestCallback() {

            public void onResponseReceived(Request request, Response response) {
                responseCallback.success(response.getStatusCode() == Response.SC_OK);
            }

            public void onError(Request request, Throwable error) {
                responseCallback.error(error.getLocalizedMessage(), error);
            }
        });
    } catch (RequestException e) {
        responseCallback.error(e.getLocalizedMessage(), e);
    }
}
Also used : XulServiceCallback(org.pentaho.ui.xul.XulServiceCallback) 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 7 with RequestException

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

the class WizardConnectionController method handleDialogAccept.

@Bindable
public void handleDialogAccept() {
    // first, test the connection
    RequestBuilder testConnectionBuilder = new RequestBuilder(RequestBuilder.PUT, ConnectionController.getServiceURL("test"));
    testConnectionBuilder.setHeader("Content-Type", "application/json");
    try {
        // AutoBean<IDatabaseConnection> bean = AutoBeanUtils.getAutoBean(currentConnection);
        AutoBean<IDatabaseConnection> bean = createIDatabaseConnectionBean(currentConnection);
        testConnectionBuilder.sendRequest(AutoBeanCodex.encode(bean).getPayload(), new RequestCallback() {

            @Override
            public void onError(Request request, Throwable exception) {
                saveConnectionConfirmationDialog.show();
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                try {
                    if (response.getStatusCode() == Response.SC_OK) {
                        // test is ok, now check if we are renaming
                        renameCheck();
                    } else {
                        // confirm if we should continu saving this invalid connection.
                        saveConnectionConfirmationDialog.show();
                    }
                } 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) 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)

Example 8 with RequestException

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

the class WizardConnectionController method addConnection.

@Bindable
public void addConnection() {
    RequestBuilder addConnectionBuilder = new RequestBuilder(RequestBuilder.POST, ConnectionController.getServiceURL("add"));
    addConnectionBuilder.setHeader("Content-Type", "application/json");
    try {
        // AutoBean<IDatabaseConnection> bean = AutoBeanUtils.getAutoBean(currentConnection);
        AutoBean<IDatabaseConnection> bean = createIDatabaseConnectionBean(currentConnection);
        addConnectionBuilder.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) {
                        IDatabaseConnection conn = AutobeanUtilities.connectionBeanToImpl(currentConnection);
                        datasourceModel.getGuiStateModel().addConnection(conn);
                        datasourceModel.setSelectedRelationalConnection(conn);
                    } else {
                        openErrorDialog(MessageHandler.getString("ERROR"), // $NON-NLS-1$
                        MessageHandler.getString(// $NON-NLS-1$
                        "ConnectionController.ERROR_0001_UNABLE_TO_ADD_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) 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)

Example 9 with RequestException

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

the class QueryUi method asyncGetJson.

private void asyncGetJson(final String url, final GotJsonCallback callback) {
    final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    try {
        builder.sendRequest(null, new RequestCallback() {

            public void onError(final Request request, final Throwable e) {
                displayError("Failed to get " + url + ": " + e.getMessage());
                // Since we don't call the callback we've been given, reset this
                // bit of state as we're not going to retry anything right now.
                pending_requests = 0;
            }

            public void onResponseReceived(final Request request, final Response response) {
                final int code = response.getStatusCode();
                if (code == Response.SC_OK) {
                    clearError();
                    callback.got(JSONParser.parse(response.getText()));
                    return;
                } else if (code >= Response.SC_BAD_REQUEST) {
                    // 400+ => Oops.
                    // Since we don't call the callback we've been given, reset this
                    // bit of state as we're not going to retry anything right now.
                    pending_requests = 0;
                    String err = response.getText();
                    // an error message.
                    if (!err.isEmpty() && err.charAt(0) == '{') {
                        final JSONValue json = JSONParser.parse(err);
                        final JSONObject result = json == null ? null : json.isObject();
                        final JSONValue jerr = result == null ? null : result.get("err");
                        final JSONString serr = jerr == null ? null : jerr.isString();
                        err = serr.stringValue();
                        // If the error message has multiple lines (which is common if
                        // it contains a stack trace), show only the first line and
                        // hide the rest in a panel users can expand.
                        final int newline = err.indexOf('\n', 1);
                        final String msg = "Request failed: " + response.getStatusText();
                        if (newline < 0) {
                            displayError(msg + ": " + err);
                        } else {
                            displayError(msg);
                            final DisclosurePanel dp = new DisclosurePanel(err.substring(0, newline));
                            // Attach the widget.
                            RootPanel.get("queryuimain").add(dp);
                            final InlineLabel content = new InlineLabel(err.substring(newline, err.length()));
                            // For readable stack traces.
                            content.addStyleName("fwf");
                            dp.setContent(content);
                            current_error.getElement().appendChild(dp.getElement());
                        }
                    } else {
                        displayError("Request failed while getting " + url + ": " + response.getStatusText());
                        // Since we don't call the callback we've been given, reset this
                        // bit of state as we're not going to retry anything right now.
                        pending_requests = 0;
                    }
                    graphstatus.setText("");
                }
            }
        });
    } catch (RequestException e) {
        displayError("Failed to get " + url + ": " + e.getMessage());
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) Request(com.google.gwt.http.client.Request) DisclosurePanel(com.google.gwt.user.client.ui.DisclosurePanel) JSONString(com.google.gwt.json.client.JSONString) RequestException(com.google.gwt.http.client.RequestException) EntryPoint(com.google.gwt.core.client.EntryPoint) Response(com.google.gwt.http.client.Response) JSONValue(com.google.gwt.json.client.JSONValue) RequestCallback(com.google.gwt.http.client.RequestCallback) JSONObject(com.google.gwt.json.client.JSONObject) InlineLabel(com.google.gwt.user.client.ui.InlineLabel) JSONString(com.google.gwt.json.client.JSONString)

Example 10 with RequestException

use of com.google.gwt.http.client.RequestException in project blogwt by billy1380.

the class BlogService method getRatings.

public Request getRatings(GetRatingsRequest input, AsyncSuccess<GetRatingsRequest, GetRatingsResponse> onSuccess, AsyncFailure<GetRatingsRequest> onFailure) {
    Request handle = null;
    try {
        handle = sendRequest(BlogMethodGetRatings, input, new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                try {
                    GetRatingsResponse outputParameter = new GetRatingsResponse();
                    parseResponse(response, outputParameter);
                    if (onSuccess != null) {
                        onSuccess.call(input, outputParameter);
                    }
                    onCallSuccess(BlogService.this, BlogMethodGetRatings, input, outputParameter);
                } catch (JSONException | HttpException exception) {
                    if (onFailure != null) {
                        onFailure.call(input, exception);
                    }
                    onCallFailure(BlogService.this, BlogMethodGetRatings, input, exception);
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                if (onFailure != null) {
                    onFailure.call(input, exception);
                }
                onCallFailure(BlogService.this, BlogMethodGetRatings, input, exception);
            }
        });
        onCallStart(BlogService.this, BlogMethodGetRatings, input, handle);
    } catch (RequestException exception) {
        if (onFailure != null) {
            onFailure.call(input, exception);
        }
        onCallFailure(BlogService.this, BlogMethodGetRatings, input, exception);
    }
    return handle;
}
Also used : GetRatingsResponse(com.willshex.blogwt.shared.api.blog.call.GetRatingsResponse) UpdatePropertiesResponse(com.willshex.blogwt.shared.api.blog.call.UpdatePropertiesResponse) SubmitRatingResponse(com.willshex.blogwt.shared.api.blog.call.SubmitRatingResponse) UpdatePostResponse(com.willshex.blogwt.shared.api.blog.call.UpdatePostResponse) GetTagsResponse(com.willshex.blogwt.shared.api.blog.call.GetTagsResponse) DeleteResourceResponse(com.willshex.blogwt.shared.api.blog.call.DeleteResourceResponse) GetArchiveEntriesResponse(com.willshex.blogwt.shared.api.blog.call.GetArchiveEntriesResponse) Response(com.google.gwt.http.client.Response) GetPostResponse(com.willshex.blogwt.shared.api.blog.call.GetPostResponse) SetupBlogResponse(com.willshex.blogwt.shared.api.blog.call.SetupBlogResponse) GetResourcesResponse(com.willshex.blogwt.shared.api.blog.call.GetResourcesResponse) CreatePostResponse(com.willshex.blogwt.shared.api.blog.call.CreatePostResponse) GetRelatedPostsResponse(com.willshex.blogwt.shared.api.blog.call.GetRelatedPostsResponse) GetResourceResponse(com.willshex.blogwt.shared.api.blog.call.GetResourceResponse) GetPostsResponse(com.willshex.blogwt.shared.api.blog.call.GetPostsResponse) UpdateResourceResponse(com.willshex.blogwt.shared.api.blog.call.UpdateResourceResponse) DeletePostResponse(com.willshex.blogwt.shared.api.blog.call.DeletePostResponse) GetPropertiesResponse(com.willshex.blogwt.shared.api.blog.call.GetPropertiesResponse) GetRatingsResponse(com.willshex.blogwt.shared.api.blog.call.GetRatingsResponse) RequestCallback(com.google.gwt.http.client.RequestCallback) UpdatePostRequest(com.willshex.blogwt.shared.api.blog.call.UpdatePostRequest) GetResourcesRequest(com.willshex.blogwt.shared.api.blog.call.GetResourcesRequest) GetResourceRequest(com.willshex.blogwt.shared.api.blog.call.GetResourceRequest) DeleteResourceRequest(com.willshex.blogwt.shared.api.blog.call.DeleteResourceRequest) GetRelatedPostsRequest(com.willshex.blogwt.shared.api.blog.call.GetRelatedPostsRequest) GetTagsRequest(com.willshex.blogwt.shared.api.blog.call.GetTagsRequest) UpdatePropertiesRequest(com.willshex.blogwt.shared.api.blog.call.UpdatePropertiesRequest) GetRatingsRequest(com.willshex.blogwt.shared.api.blog.call.GetRatingsRequest) DeletePostRequest(com.willshex.blogwt.shared.api.blog.call.DeletePostRequest) SubmitRatingRequest(com.willshex.blogwt.shared.api.blog.call.SubmitRatingRequest) CreatePostRequest(com.willshex.blogwt.shared.api.blog.call.CreatePostRequest) GetArchiveEntriesRequest(com.willshex.blogwt.shared.api.blog.call.GetArchiveEntriesRequest) Request(com.google.gwt.http.client.Request) UpdateResourceRequest(com.willshex.blogwt.shared.api.blog.call.UpdateResourceRequest) GetPostsRequest(com.willshex.blogwt.shared.api.blog.call.GetPostsRequest) GetPropertiesRequest(com.willshex.blogwt.shared.api.blog.call.GetPropertiesRequest) GetPostRequest(com.willshex.blogwt.shared.api.blog.call.GetPostRequest) SetupBlogRequest(com.willshex.blogwt.shared.api.blog.call.SetupBlogRequest) JSONException(com.google.gwt.json.client.JSONException) HttpException(com.willshex.gson.web.service.client.HttpException) RequestException(com.google.gwt.http.client.RequestException)

Aggregations

RequestException (com.google.gwt.http.client.RequestException)164 RequestCallback (com.google.gwt.http.client.RequestCallback)154 Response (com.google.gwt.http.client.Response)153 Request (com.google.gwt.http.client.Request)152 RequestBuilder (com.google.gwt.http.client.RequestBuilder)108 JSONException (com.google.gwt.json.client.JSONException)55 HttpException (com.willshex.gson.web.service.client.HttpException)55 CsrfRequestBuilder (org.pentaho.mantle.client.csrf.CsrfRequestBuilder)17 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)16 BlockUsersRequest (com.willshex.blogwt.shared.api.user.call.BlockUsersRequest)12 BlockUsersResponse (com.willshex.blogwt.shared.api.user.call.BlockUsersResponse)12 ChangePasswordRequest (com.willshex.blogwt.shared.api.user.call.ChangePasswordRequest)12 ChangePasswordResponse (com.willshex.blogwt.shared.api.user.call.ChangePasswordResponse)12 ChangeUserAccessRequest (com.willshex.blogwt.shared.api.user.call.ChangeUserAccessRequest)12 ChangeUserAccessResponse (com.willshex.blogwt.shared.api.user.call.ChangeUserAccessResponse)12 ChangeUserDetailsRequest (com.willshex.blogwt.shared.api.user.call.ChangeUserDetailsRequest)12 ChangeUserDetailsResponse (com.willshex.blogwt.shared.api.user.call.ChangeUserDetailsResponse)12 CheckUsernameRequest (com.willshex.blogwt.shared.api.user.call.CheckUsernameRequest)12 CheckUsernameResponse (com.willshex.blogwt.shared.api.user.call.CheckUsernameResponse)12 FollowUsersRequest (com.willshex.blogwt.shared.api.user.call.FollowUsersRequest)12