com.google.gwt.http.client.Request Java Examples

The following examples show how to use com.google.gwt.http.client.Request. 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 File: GitHubUpdateFileExporter.java    From geowe-core with GNU General Public License v3.0 6 votes vote down vote up
private RestErrorCallback getErrorCallback() {
	return new RestErrorCallback() {

		@Override
		public boolean error(Request request, Throwable throwable) {
			autoMessageBox.hide();
			String message = "";
			int defaultCodeError = Response.SC_NOT_MODIFIED;
			try {
				throw throwable;
			} catch (ResponseException e) {
				Response response = e.getResponse();					
				message = response.getStatusText(); 
				defaultCodeError = response.getStatusCode();
				
			} catch (Throwable t) {
				message = t.getMessage();
			}
			
			messageDialogBuilder.createError(UIMessages.INSTANCE.warning() + " " + defaultCodeError, message).show();
			
			return false;
		}
	};
}
 
Example #2
Source File: RetryLocalStorageServiceProxy.java    From shortyz with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Request listPuzzles(final AsyncCallback<PuzzleDescriptor[]> callback) {
    return super.listPuzzles( new AsyncCallback<PuzzleDescriptor[]>(){

        @Override
        public void onFailure(Throwable caught) {
            if(caught instanceof InvocationException){
                RetryLocalStorageServiceProxy.super.listPuzzles(callback);
            } else {
                callback.onFailure(caught);
            }
        }

        @Override
        public void onSuccess(PuzzleDescriptor[] result) {
            callback.onSuccess(result);
        }

    });
}
 
Example #3
Source File: RetryLocalStorageServiceProxy.java    From shortyz with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Request findPuzzle(final Long puzzleId, final AsyncCallback<Puzzle> callback) {
    return super.findPuzzle(puzzleId, new AsyncCallback<Puzzle>(){

        @Override
        public void onFailure(Throwable caught) {
            if(caught instanceof InvocationException ){
                RetryLocalStorageServiceProxy.super.findPuzzle(puzzleId, callback);
            } else {
                callback.onFailure(caught);
            }
        }

        @Override
        public void onSuccess(Puzzle result) {
            callback.onSuccess(result);
        }

    });
}
 
Example #4
Source File: LocalStorageServiceProxy.java    From shortyz with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Request savePuzzle(final Long listingId, final Puzzle puzzle, final AsyncCallback callback) {
    if(!WindowContext.INSTANCE.isInitialized()){
        WindowContext.INSTANCE.initialize( new WindowContextCallback(){

            @Override
            public void onInitialized() {
                saveInternal(listingId, puzzle, callback);
            }

        });
    } else {

        saveInternal(listingId, puzzle, callback);
    }
    return new FakeRequest();
}
 
Example #5
Source File: GitHubGetFileRequest.java    From geowe-core with GNU General Public License v3.0 6 votes vote down vote up
private RestErrorCallback getErrorCallback() {
	return new RestErrorCallback() {

		@Override
		public boolean error(Request request, Throwable throwable) {
			autoMessageBox.hide();
			String message = "";
			int defaultCodeError = Response.SC_NOT_MODIFIED;
			try {
				throw throwable;
			} catch (ResponseException e) {
				Response response = e.getResponse();					
				message = response.getStatusText(); 
				defaultCodeError = response.getStatusCode();
				
			} catch (Throwable t) {
				message = t.getMessage();
			}
			
			messageDialogBuilder.createError(UIMessages.INSTANCE.warning() + " " + defaultCodeError, message).show();
			
			return false;
		}
	};
}
 
Example #6
Source File: GitHubGetRepositoryListRequest.java    From geowe-core with GNU General Public License v3.0 6 votes vote down vote up
private RestErrorCallback getErrorCallback() {
	return new RestErrorCallback() {

		@Override
		public boolean error(Request request, Throwable throwable) {
			autoMessageBox.hide();
			String message = "";
			int defaultCodeError = Response.SC_NOT_MODIFIED;
			try {
				throw throwable;
			} catch (ResponseException e) {
				Response response = e.getResponse();					
				message = response.getStatusText(); 
				defaultCodeError = response.getStatusCode();
				
			} catch (Throwable t) {
				message = t.getMessage();
			}
			
			messageDialogBuilder.createError(UIMessages.INSTANCE.warning() + " " + defaultCodeError, message).show();
			
			return false;
		}
	};
}
 
Example #7
Source File: AbstractGitHubGetListRequest.java    From geowe-core with GNU General Public License v3.0 6 votes vote down vote up
protected RestErrorCallback getErrorCallback() {
	return new RestErrorCallback() {

		@Override
		public boolean error(Request request, Throwable throwable) {
			autoMessageBox.hide();
			String message = "";
			int defaultCodeError = Response.SC_NOT_MODIFIED;
			try {
				throw throwable;
			} catch (ResponseException e) {
				Response response = e.getResponse();					
				message = response.getStatusText(); 
				defaultCodeError = response.getStatusCode();
				
			} catch (Throwable t) {
				message = t.getMessage();
			}
			
			messageDialogBuilder.createError(UIMessages.INSTANCE.warning() + " " + defaultCodeError, message).show();
			
			return false;
		}
	};
}
 
Example #8
Source File: FakeSearchService.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@Override
public Request search(String query, final int index, final int numResults, final Callback callback) {
  timer.scheduleDelayed(new Task() {
    @Override
    public void execute() {
      int from = Math.min(index, canned.size() - 1);
      int to = Math.max(index + numResults, canned.size());
      callback.onSuccess(canned.size(), canned.subList(from, to));
    }
  }, FAKE_DELAY_MS);
  return null;
}
 
Example #9
Source File: GwtRpcProxy.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
   protected <T> Request doInvoke(ResponseReader responseReader, final String methodName, RpcStatsContext statsContext, String requestData, final AsyncCallback<T> callback) {
	return super.doInvoke(responseReader, methodName, statsContext, requestData, new AsyncCallback<T>() {
		@Override
		public void onFailure(Throwable caught) {
			UniTimeNotifications.error("Request " + methodName.replace("_Proxy", "") + " failed: " + caught.getMessage(), caught);
			callback.onFailure(caught);
		}
		@Override
		public void onSuccess(T result) {
			callback.onSuccess(result);
		}
	});
}
 
Example #10
Source File: GitHubCreateFileExporter.java    From geowe-core with GNU General Public License v3.0 5 votes vote down vote up
private RestErrorCallback getErrorCallback() {
	return new RestErrorCallback() {

		@Override
		public boolean error(Request request, Throwable throwable) {
			autoMessageBox.hide();
			String message = "";
			int defaultCodeError = Response.SC_NOT_MODIFIED;
			try {
				throw throwable;
			} catch (ResponseException e) {
				Response response = e.getResponse();
				message = response.getStatusText();
				defaultCodeError = response.getStatusCode();

			} catch (Throwable t) {
				message = t.getMessage();
			}

			messageDialogBuilder.createError(
					UIMessages.INSTANCE.warning() + " " + defaultCodeError,
					message).show();

			return false;
		}
	};
}
 
Example #11
Source File: URLVectorLayerDef.java    From geowe-core with GNU General Public License v3.0 5 votes vote down vote up
protected void createLayerFromURL() {
	final ProgressBarDialog autoMessageBox = new ProgressBarDialog(false,
			UIMessages.INSTANCE.processing());
	try {
		autoMessageBox.show();
		RestClient.create(URLFileRestService.class, URL_BASE,
				new RemoteCallback<String>() {
					@Override
					public void callback(String response) {
						final VectorLayerConfig layerConfig = getVectorLayerConfig();
						layerConfig.setGeoDataString(response);
						VectorLayer layer = VectorLayerFactory
								.createVectorLayerFromGeoData(layerConfig);
						LayerLoader.load(layer);
						autoMessageBox.hide();
					}
				}, new RestErrorCallback() {
					@Override
					public boolean error(Request message,
							Throwable throwable) {
						autoMessageBox.hide();

						showDialog("Error",
								UIMessages.INSTANCE.unexpectedError());
						return false;
					}
				}, Response.SC_OK).getContent(getUrl());
	} catch (Exception e) {
		autoMessageBox.hide();
		showDialog(
				UIMessages.INSTANCE.errorLoadingLayer(getVectorLayerConfig()
						.getLayerName()),
				UIMessages.INSTANCE.unexpectedError());
	}
}
 
Example #12
Source File: JoinDataTool.java    From geowe-core with GNU General Public License v3.0 5 votes vote down vote up
private void lodaDataFromURL(final String url) {
	final String urlBase = GWT.getHostPageBaseURL() + "gwtOpenLayersProxy";
	try {
		autoMessageBox.show();
		RestClient.create(URLFileRestService.class, urlBase,
				new RemoteCallback<String>() {
					@Override
					public void callback(String response) {
						parseCsvData(response);
						autoMessageBox.hide();
					}
				}, new RestErrorCallback() {
					@Override
					public boolean error(Request message,
							Throwable throwable) {
						autoMessageBox.hide();

						showAlert("Error"
								+ UIMessages.INSTANCE.unexpectedError());
						return false;
					}
				}, Response.SC_OK).getContent(url);
	} catch (Exception e) {
		autoMessageBox.hide();
		showAlert("Error loading data..." + e.getMessage());
	}
}
 
Example #13
Source File: Module.java    From shortyz with GNU General Public License v3.0 5 votes vote down vote up
@Override
public PuzzleServiceProxy get() {
    return new RetryLocalStorageServiceProxy(service,  new CallStrategy(){

    @Override
    public Request makeRequest(RequestBuilder builder) {
         ShortyzWave.makePostRequest(builder.getUrl(), builder.getRequestData(), builder.getCallback());
         return new FakeRequest();
    }

}){

        @Override
        public Request savePuzzle(Long listingId, Puzzle puzzle, final AsyncCallback callback) {
            DeferredCommand.add(new Command(){

                @Override
                public void execute() {
                    callback.onSuccess(null);
                }
                
            });
            return new FakeRequest();
        }

};
}
 
Example #14
Source File: LocalStorageServiceProxy.java    From shortyz with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Request findPuzzle(final Long puzzleId, final AsyncCallback<Puzzle> callback) {
    GWT.log(WindowContext.INSTANCE.isInitialized() +" init", null);
    if(!WindowContext.INSTANCE.isInitialized()){
        WindowContext.INSTANCE.initialize(new WindowContextCallback(){

            @Override
            public void onInitialized() {
                GWT.log("Init callback", null);
                findPuzzle(puzzleId, callback);
            }

        });
        return new FakeRequest();
    }

    if(WindowContext.INSTANCE.get(puzzleId.toString()) != null){
        GWT.log("Found local data.", null);
        DeferredCommand.addCommand(new Command(){

            @Override
            public void execute() {
                loadInternal(puzzleId, callback);
            }

        });
        return new FakeRequest();
    }
    return super.findPuzzle(puzzleId, callback);
}
 
Example #15
Source File: PuzzleServiceProxy.java    From shortyz with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Request makeRequest(RequestBuilder builder) {
    try{
        return builder.send();
    } catch(Exception e){
        throw new RuntimeException(e.toString(), e);
    }
}
 
Example #16
Source File: FakeSearchService.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@Override
public Request search(String query, final int index, final int numResults, final Callback callback) {
  timer.scheduleDelayed(new Task() {
    @Override
    public void execute() {
      int from = Math.min(index, canned.size() - 1);
      int to = Math.max(index + numResults, canned.size());
      callback.onSuccess(canned.size(), canned.subList(from, to));
    }
  }, FAKE_DELAY_MS);
  return null;
}
 
Example #17
Source File: LogStore.java    From core with 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);
    }
}
 
Example #18
Source File: Module.java    From shortyz with GNU General Public License v3.0 5 votes vote down vote up
@Override
public PuzzleServiceProxy get() {
    return new RetryLocalStorageServiceProxy(service,  new CallStrategy(){

    @Override
    public Request makeRequest(RequestBuilder builder) {
         ShortyzGadget.makePostRequest(builder.getUrl(), builder.getRequestData(), builder.getCallback());
         return new FakeRequest();
    }

});
}
 
Example #19
Source File: LogStore.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private PendingStreamingRequest(final String logFile, final Request request, final Dispatcher.Channel channel) {
    this.logFile = logFile;
    this.request = request;
    this.channel = channel;
}
 
Example #20
Source File: RemoteSearchService.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
@Override
public Request search(String query, int index, int numResults, Callback callback) {
  return searcher.newSearch().setQuery(query).setIndex(index).setNumResults(numResults)
      .search(callback);
}
 
Example #21
Source File: SearchServiceImpl.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
@Override
public Request search(String query, int index, int numResults, Callback callback) {
  return SEARCH_BUILDER.newSearch().setQuery(query).setIndex(index).setNumResults(numResults)
      .search(callback);
}
 
Example #22
Source File: DMRHandler.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
DispatchRequestHandle(Request delegate)
{
    this.delegate = delegate;
}
 
Example #23
Source File: RemoteSearchService.java    From swellrt with Apache License 2.0 4 votes vote down vote up
@Override
public Request search(String query, int index, int numResults, Callback callback) {
  return searcher.newSearch().setQuery(query).setIndex(index).setNumResults(numResults)
      .search(callback);
}
 
Example #24
Source File: SearchServiceImpl.java    From swellrt with Apache License 2.0 4 votes vote down vote up
@Override
public Request search(String query, int index, int numResults, Callback callback) {
  return SEARCH_BUILDER.newSearch().setQuery(query).setIndex(index).setNumResults(numResults)
      .search(callback);
}
 
Example #25
Source File: PuzzleServiceProxy.java    From shortyz with GNU General Public License v3.0 4 votes vote down vote up
public Request savePuzzle(Long listingId, Puzzle puzzle, AsyncCallback callback){
    RequestBuilder builder = service.savePuzzle(listingId, puzzle, callback);
    return strat.makeRequest(builder);
}
 
Example #26
Source File: PuzzleServiceProxy.java    From shortyz with GNU General Public License v3.0 4 votes vote down vote up
public Request listPuzzles(AsyncCallback<PuzzleDescriptor[]> callback){
    RequestBuilder builder = service.listPuzzles(callback);
    return strat.makeRequest(builder);
}
 
Example #27
Source File: PuzzleServiceProxy.java    From shortyz with GNU General Public License v3.0 4 votes vote down vote up
public Request findPuzzle(Long puzzleId, AsyncCallback<Puzzle> callback){
    RequestBuilder builder = service.findPuzzle(puzzleId, callback);
    return strat.makeRequest(builder);
}
 
Example #28
Source File: SearchService.java    From swellrt with Apache License 2.0 2 votes vote down vote up
/**
 * Performs a search.
 *
 * @param query the query to execute.
 * @param index the index from which to return results.
 * @param numResults the maximum number of results to return.
 * @param callback callback through which the search query results are
 *        returned.
 */
Request search(String query, int index, int numResults, Callback callback);
 
Example #29
Source File: SearchBuilder.java    From swellrt with Apache License 2.0 2 votes vote down vote up
/**
 * Performs a full text search on the waves.
 *
 * @param callback the callback through which the search query results are returned.
 * @return the http request
 */
Request search(final Callback callback);
 
Example #30
Source File: SearchBuilder.java    From incubator-retired-wave with Apache License 2.0 2 votes vote down vote up
/**
 * Performs a full text search on the waves.
 *
 * @param callback the callback through which the search query results are returned.
 * @return the http request
 */
Request search(final Callback callback);