Java Code Examples for com.google.gwt.http.client.RequestCallback

The following examples show how to use com.google.gwt.http.client.RequestCallback. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: shortyz   Source File: ShortyzGadget.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static native void makePostRequest(String url, String postdata,
    RequestCallback callback) /*-{
var response = function(obj) { 
    @com.totsp.crossword.web.gadget.ShortyzGadget::onSuccessInternal(Lcom/totsp/crossword/web/client/GadgetResponse;Lcom/google/gwt/http/client/RequestCallback;)(obj, callback);
};
var params = {};
params[$wnd.gadgets.io.RequestParameters.HEADERS] = {
"Content-Type": "text/x-gwt-rpc"
};
params[$wnd.gadgets.io.RequestParameters.METHOD] = $wnd.gadgets.io.MethodType.POST; 
params[$wnd.gadgets.io.RequestParameters.POST_DATA]= postdata; 
$wnd.gadgets.io.makeRequest(url, response, params);


}-*/;
 
Example 2
Source Project: shortyz   Source File: ShortyzGadget.java    License: GNU General Public License v3.0 5 votes vote down vote up
static void onSuccessInternal(final GadgetResponse response,
    RequestCallback callback) {
    try {
        callback.onResponseReceived(null, new FakeResponse(response));
    } catch (Exception e) {
        callback.onError(null, e);
    }
}
 
Example 3
Source Project: shortyz   Source File: ShortyzWave.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static native void makePostRequest(String url, String postdata,
    RequestCallback callback) /*-{
var response = function(obj) {
@com.totsp.crossword.web.wave.ShortyzWave::onSuccessInternal(Lcom/totsp/crossword/web/client/GadgetResponse;Lcom/google/gwt/http/client/RequestCallback;)(obj, callback);
};
var params = {};
params[$wnd.gadgets.io.RequestParameters.HEADERS] = {
"Content-Type": "text/x-gwt-rpc"
};
params[$wnd.gadgets.io.RequestParameters.METHOD] = $wnd.gadgets.io.MethodType.POST;
params[$wnd.gadgets.io.RequestParameters.POST_DATA]= postdata;
$wnd.gadgets.io.makeRequest(url, response, params);


}-*/;
 
Example 4
Source Project: shortyz   Source File: ShortyzWave.java    License: GNU General Public License v3.0 5 votes vote down vote up
static void onSuccessInternal(final GadgetResponse response,
    RequestCallback callback) {
    try {
        callback.onResponseReceived(null, new FakeResponse(response));
    } catch (Exception e) {
        callback.onError(null, e);
    }
}
 
Example 5
Source Project: core   Source File: LogStore.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
private void doStreamLogFile(final String fileName, final Dispatcher.Channel channel) {
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, encode(streamUrl(fileName)));
    requestBuilder.setHeader("Accept", "text/plain");
    requestBuilder.setHeader("Content-Type", "text/plain");
    String bearerToken = DMRHandler.getBearerToken();
    if (bearerToken != null)
        requestBuilder.setHeader("Authorization", "Bearer " + bearerToken);
        
    requestBuilder.setIncludeCredentials(true);
    try {
        // store the request in order to cancel it later
        pendingStreamingRequest = new PendingStreamingRequest(fileName,
                requestBuilder.sendRequest(null, new RequestCallback() {
                    @Override
                    public void onResponseReceived(Request request, Response response) {
                        if (response.getStatusCode() >= 400) {
                            channel.nack(new IllegalStateException("Failed to stream log file " +
                                    fileName + ": " + response.getStatusCode() + " - " +
                                    response.getStatusText()));
                        } else {
                            LogFile newLogFile = new LogFile(fileName, response.getText());
                            newLogFile.setFollow(false);
                            states.put(fileName, newLogFile);
                            activate(newLogFile);
                            channel.ack();
                        }
                    }

                    @Override
                    public void onError(Request request, Throwable exception) {
                        channel.nack(exception);
                    }
                }), channel);
    } catch (RequestException e) {
        channel.nack(e);
    }
}