Search in sources :

Example 81 with Response

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

the class PageService method createPage.

public Request createPage(CreatePageRequest input, AsyncSuccess<CreatePageRequest, CreatePageResponse> onSuccess, AsyncFailure<CreatePageRequest> onFailure) {
    Request handle = null;
    try {
        handle = sendRequest(PageMethodCreatePage, input, new RequestCallback() {

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

            @Override
            public void onError(Request request, Throwable exception) {
                if (onFailure != null) {
                    onFailure.call(input, exception);
                }
                onCallFailure(PageService.this, PageMethodCreatePage, input, exception);
            }
        });
        onCallStart(PageService.this, PageMethodCreatePage, input, handle);
    } catch (RequestException exception) {
        if (onFailure != null) {
            onFailure.call(input, exception);
        }
        onCallFailure(PageService.this, PageMethodCreatePage, input, exception);
    }
    return handle;
}
Also used : GetPagesResponse(com.willshex.blogwt.shared.api.page.call.GetPagesResponse) UpdatePageResponse(com.willshex.blogwt.shared.api.page.call.UpdatePageResponse) SubmitFormResponse(com.willshex.blogwt.shared.api.page.call.SubmitFormResponse) CreatePageResponse(com.willshex.blogwt.shared.api.page.call.CreatePageResponse) GetPageResponse(com.willshex.blogwt.shared.api.page.call.GetPageResponse) Response(com.google.gwt.http.client.Response) DeletePageResponse(com.willshex.blogwt.shared.api.page.call.DeletePageResponse) CreatePageResponse(com.willshex.blogwt.shared.api.page.call.CreatePageResponse) RequestCallback(com.google.gwt.http.client.RequestCallback) GetPageRequest(com.willshex.blogwt.shared.api.page.call.GetPageRequest) CreatePageRequest(com.willshex.blogwt.shared.api.page.call.CreatePageRequest) Request(com.google.gwt.http.client.Request) GetPagesRequest(com.willshex.blogwt.shared.api.page.call.GetPagesRequest) SubmitFormRequest(com.willshex.blogwt.shared.api.page.call.SubmitFormRequest) DeletePageRequest(com.willshex.blogwt.shared.api.page.call.DeletePageRequest) UpdatePageRequest(com.willshex.blogwt.shared.api.page.call.UpdatePageRequest) JSONException(com.google.gwt.json.client.JSONException) HttpException(com.willshex.gson.web.service.client.HttpException) RequestException(com.google.gwt.http.client.RequestException)

Example 82 with Response

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

the class PageService method submitForm.

public Request submitForm(SubmitFormRequest input, AsyncSuccess<SubmitFormRequest, SubmitFormResponse> onSuccess, AsyncFailure<SubmitFormRequest> onFailure) {
    Request handle = null;
    try {
        handle = sendRequest(PageMethodSubmitForm, input, new RequestCallback() {

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

            @Override
            public void onError(Request request, Throwable exception) {
                if (onFailure != null) {
                    onFailure.call(input, exception);
                }
                onCallFailure(PageService.this, PageMethodSubmitForm, input, exception);
            }
        });
        onCallStart(PageService.this, PageMethodSubmitForm, input, handle);
    } catch (RequestException exception) {
        if (onFailure != null) {
            onFailure.call(input, exception);
        }
        onCallFailure(PageService.this, PageMethodSubmitForm, input, exception);
    }
    return handle;
}
Also used : GetPagesResponse(com.willshex.blogwt.shared.api.page.call.GetPagesResponse) UpdatePageResponse(com.willshex.blogwt.shared.api.page.call.UpdatePageResponse) SubmitFormResponse(com.willshex.blogwt.shared.api.page.call.SubmitFormResponse) CreatePageResponse(com.willshex.blogwt.shared.api.page.call.CreatePageResponse) GetPageResponse(com.willshex.blogwt.shared.api.page.call.GetPageResponse) Response(com.google.gwt.http.client.Response) DeletePageResponse(com.willshex.blogwt.shared.api.page.call.DeletePageResponse) SubmitFormResponse(com.willshex.blogwt.shared.api.page.call.SubmitFormResponse) RequestCallback(com.google.gwt.http.client.RequestCallback) GetPageRequest(com.willshex.blogwt.shared.api.page.call.GetPageRequest) CreatePageRequest(com.willshex.blogwt.shared.api.page.call.CreatePageRequest) Request(com.google.gwt.http.client.Request) GetPagesRequest(com.willshex.blogwt.shared.api.page.call.GetPagesRequest) SubmitFormRequest(com.willshex.blogwt.shared.api.page.call.SubmitFormRequest) DeletePageRequest(com.willshex.blogwt.shared.api.page.call.DeletePageRequest) UpdatePageRequest(com.willshex.blogwt.shared.api.page.call.UpdatePageRequest) JSONException(com.google.gwt.json.client.JSONException) HttpException(com.willshex.gson.web.service.client.HttpException) RequestException(com.google.gwt.http.client.RequestException)

Example 83 with Response

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

the class PageService method getPages.

public Request getPages(GetPagesRequest input, AsyncSuccess<GetPagesRequest, GetPagesResponse> onSuccess, AsyncFailure<GetPagesRequest> onFailure) {
    Request handle = null;
    try {
        handle = sendRequest(PageMethodGetPages, input, new RequestCallback() {

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

            @Override
            public void onError(Request request, Throwable exception) {
                if (onFailure != null) {
                    onFailure.call(input, exception);
                }
                onCallFailure(PageService.this, PageMethodGetPages, input, exception);
            }
        });
        onCallStart(PageService.this, PageMethodGetPages, input, handle);
    } catch (RequestException exception) {
        if (onFailure != null) {
            onFailure.call(input, exception);
        }
        onCallFailure(PageService.this, PageMethodGetPages, input, exception);
    }
    return handle;
}
Also used : GetPagesResponse(com.willshex.blogwt.shared.api.page.call.GetPagesResponse) UpdatePageResponse(com.willshex.blogwt.shared.api.page.call.UpdatePageResponse) SubmitFormResponse(com.willshex.blogwt.shared.api.page.call.SubmitFormResponse) CreatePageResponse(com.willshex.blogwt.shared.api.page.call.CreatePageResponse) GetPageResponse(com.willshex.blogwt.shared.api.page.call.GetPageResponse) Response(com.google.gwt.http.client.Response) DeletePageResponse(com.willshex.blogwt.shared.api.page.call.DeletePageResponse) RequestCallback(com.google.gwt.http.client.RequestCallback) GetPageRequest(com.willshex.blogwt.shared.api.page.call.GetPageRequest) CreatePageRequest(com.willshex.blogwt.shared.api.page.call.CreatePageRequest) Request(com.google.gwt.http.client.Request) GetPagesRequest(com.willshex.blogwt.shared.api.page.call.GetPagesRequest) SubmitFormRequest(com.willshex.blogwt.shared.api.page.call.SubmitFormRequest) DeletePageRequest(com.willshex.blogwt.shared.api.page.call.DeletePageRequest) UpdatePageRequest(com.willshex.blogwt.shared.api.page.call.UpdatePageRequest) JSONException(com.google.gwt.json.client.JSONException) HttpException(com.willshex.gson.web.service.client.HttpException) GetPagesResponse(com.willshex.blogwt.shared.api.page.call.GetPagesResponse) RequestException(com.google.gwt.http.client.RequestException)

Example 84 with Response

use of com.google.gwt.http.client.Response in project libgdx by libgdx.

the class GwtNet method sendHttpRequest.

@Override
public void sendHttpRequest(final HttpRequest httpRequest, final HttpResponseListener httpResultListener) {
    if (httpRequest.getUrl() == null) {
        httpResultListener.failed(new GdxRuntimeException("can't process a HTTP request without URL set"));
        return;
    }
    final String method = httpRequest.getMethod();
    final String value = httpRequest.getContent();
    final boolean valueInBody = method.equalsIgnoreCase(HttpMethods.POST) || method.equals(HttpMethods.PUT);
    RequestBuilder builder;
    String url = httpRequest.getUrl();
    if (method.equalsIgnoreCase(HttpMethods.GET)) {
        if (value != null) {
            url += "?" + value;
        }
        builder = new RequestBuilder(RequestBuilder.GET, url);
    } else if (method.equalsIgnoreCase(HttpMethods.POST)) {
        builder = new RequestBuilder(RequestBuilder.POST, url);
    } else if (method.equalsIgnoreCase(HttpMethods.DELETE)) {
        if (value != null) {
            url += "?" + value;
        }
        builder = new RequestBuilder(RequestBuilder.DELETE, url);
    } else if (method.equalsIgnoreCase(HttpMethods.PUT)) {
        builder = new RequestBuilder(RequestBuilder.PUT, url);
    } else {
        throw new GdxRuntimeException("Unsupported HTTP Method");
    }
    Map<String, String> content = httpRequest.getHeaders();
    Set<String> keySet = content.keySet();
    for (String name : keySet) {
        builder.setHeader(name, content.get(name));
    }
    builder.setTimeoutMillis(httpRequest.getTimeOut());
    builder.setIncludeCredentials(httpRequest.getIncludeCredentials());
    try {
        Request request = builder.sendRequest(valueInBody ? value : null, new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                httpResultListener.handleHttpResponse(new HttpClientResponse(response));
                requests.remove(httpRequest);
                listeners.remove(httpRequest);
            }

            @Override
            public void onError(Request request, Throwable exception) {
                httpResultListener.failed(exception);
                requests.remove(httpRequest);
                listeners.remove(httpRequest);
            }
        });
        requests.put(httpRequest, request);
        listeners.put(httpRequest, httpResultListener);
    } catch (Throwable e) {
        httpResultListener.failed(e);
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) 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)

Example 85 with Response

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

the class NewAgreementScreen method showCLA.

private void showCLA(AgreementInfo cla) {
    current = cla;
    String url = cla.url();
    if (url != null && url.length() > 0) {
        agreementGroup.setVisible(true);
        agreementHtml.setText(Gerrit.C.rpcStatusWorking());
        if (!url.startsWith("http:") && !url.startsWith("https:")) {
            url = GWT.getHostPageBaseURL() + url;
        }
        final RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url);
        rb.setCallback(new RequestCallback() {

            @Override
            public void onError(Request request, Throwable exception) {
                new ErrorDialog(exception).center();
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                final String ct = response.getHeader("Content-Type");
                if (response.getStatusCode() == 200 && ct != null && (ct.equals("text/html") || ct.startsWith("text/html;"))) {
                    agreementHtml.setHTML(response.getText());
                } else {
                    new ErrorDialog(response.getStatusText()).center();
                }
            }
        });
        try {
            rb.send();
        } catch (RequestException e) {
            new ErrorDialog(e).show();
        }
    } else {
        agreementGroup.setVisible(false);
    }
    finalGroup.setVisible(cla.autoVerifyGroup() != null);
    yesIAgreeBox.setText("");
    submit.setEnabled(false);
}
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) ErrorDialog(com.google.gerrit.client.ErrorDialog) NativeString(com.google.gerrit.client.rpc.NativeString) RequestException(com.google.gwt.http.client.RequestException)

Aggregations

Response (com.google.gwt.http.client.Response)168 Request (com.google.gwt.http.client.Request)166 RequestCallback (com.google.gwt.http.client.RequestCallback)165 RequestException (com.google.gwt.http.client.RequestException)158 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 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)17 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 FollowUsersResponse (com.willshex.blogwt.shared.api.user.call.FollowUsersResponse)12