Search in sources :

Example 66 with RequestBuilder

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

the class PurgeMondrianSchemaCacheCommand method performOperation.

protected void performOperation() {
    String url = GWT.getHostPageBaseURL() + "api/system/refresh/mondrianSchemaCache";
    RequestBuilder requestBuilder = new CsrfRequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    requestBuilder.setHeader("accept", "text/plain");
    try {
        requestBuilder.sendRequest(null, new RequestCallback() {

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

            public void onResponseReceived(Request request, Response response) {
                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("info"), Messages.getString("mondrianSchemaCacheFlushedSuccessfully"), false, false, true);
                dialogBox.center();
            }
        });
    } catch (RequestException e) {
        Window.alert(e.getMessage());
    // showError(e);
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) CsrfRequestBuilder(org.pentaho.mantle.client.csrf.CsrfRequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) CsrfRequestBuilder(org.pentaho.mantle.client.csrf.CsrfRequestBuilder) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException)

Example 67 with RequestBuilder

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

the class RefreshMetaDataCommand method performOperation.

protected void performOperation() {
    // $NON-NLS-1$
    final String url = GWT.getHostPageBaseURL() + "api/system/refresh/metadata";
    RequestBuilder requestBuilder = new CsrfRequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("accept", "text/plain");
    requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
        requestBuilder.sendRequest(null, new RequestCallback() {

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

            public void onResponseReceived(Request request, Response response) {
                MessageDialogBox dialogBox = // $NON-NLS-1$
                new MessageDialogBox(Messages.getString("info"), response.getText(), true, false, true);
                dialogBox.center();
            }
        });
    } catch (RequestException e) {
        Window.alert(e.getMessage());
    // showError(e);
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) CsrfRequestBuilder(org.pentaho.mantle.client.csrf.CsrfRequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) CsrfRequestBuilder(org.pentaho.mantle.client.csrf.CsrfRequestBuilder) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException)

Example 68 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder 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 69 with RequestBuilder

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

the class RestApi method sendText.

private <T extends JavaScriptObject> void sendText(Method method, String body, HttpCallback<T> cb) {
    HttpImpl<T> httpCallback = new HttpImpl<>(background, cb);
    try {
        if (!background) {
            RpcStatus.INSTANCE.onRpcStart();
        }
        RequestBuilder req = request(method);
        req.setHeader("Content-Type", TEXT_UTF8);
        req.sendRequest(body, httpCallback);
    } catch (RequestException e) {
        httpCallback.onError(null, e);
    }
}
Also used : GWT(com.google.gwt.core.client.GWT) PUT(com.google.gwt.http.client.RequestBuilder.PUT) POST(com.google.gwt.http.client.RequestBuilder.POST) GET(com.google.gwt.http.client.RequestBuilder.GET) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestException(com.google.gwt.http.client.RequestException)

Example 70 with RequestBuilder

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

the class RestApi method sendJSON.

private <T extends JavaScriptObject> void sendJSON(Method method, JavaScriptObject content, HttpCallback<T> cb) {
    HttpImpl<T> httpCallback = new HttpImpl<>(background, cb);
    try {
        if (!background) {
            RpcStatus.INSTANCE.onRpcStart();
        }
        RequestBuilder req = request(method);
        req.setHeader("Content-Type", JSON_UTF8);
        req.sendRequest(str(content), httpCallback);
    } catch (RequestException e) {
        httpCallback.onError(null, e);
    }
}
Also used : GWT(com.google.gwt.core.client.GWT) PUT(com.google.gwt.http.client.RequestBuilder.PUT) POST(com.google.gwt.http.client.RequestBuilder.POST) GET(com.google.gwt.http.client.RequestBuilder.GET) RequestBuilder(com.google.gwt.http.client.RequestBuilder) 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