use of com.google.gwt.http.client.RequestBuilder in project kie-wb-common by kiegroup.
the class FooterPresenterTest method testSetupUrlWhenMakeRequestRaisesAnError.
@Test
public void testSetupUrlWhenMakeRequestRaisesAnError() throws RequestException {
final String url = "http://localhost:8080/kie-server/services/rest/server";
final RequestBuilder builder = mock(RequestBuilder.class);
final RequestException requestException = mock(RequestException.class);
doReturn(builder).when(presenter).makeRequest(url, onSuccess, onError);
doThrow(requestException).when(builder).send();
presenter.setupUrl(url);
verify(onError).execute();
}
use of com.google.gwt.http.client.RequestBuilder in project kie-wb-common by kiegroup.
the class FooterPresenter method makeRequest.
RequestBuilder makeRequest(final String url, final Command onSuccess, final Command onError) {
final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
final String none = "none";
builder.setUser(none);
builder.setPassword(none);
builder.setCallback(makeCallback(onSuccess, onError));
builder.setHeader("Accept", "*/*");
return builder;
}
use of com.google.gwt.http.client.RequestBuilder in project opentsdb by OpenTSDB.
the class RemoteOracle method requestSuggestions.
@Override
public void requestSuggestions(final Request request, final Callback callback) {
if (current != null) {
pending_req = request;
pending_cb = callback;
return;
}
current = callback;
{
final String this_query = request.getQuery();
// range of results covering the new request.
if ((last_query != null && last_query.compareTo(this_query) <= 0 && this_query.compareTo(last_suggestion) < 0) || queries_seen.check(this_query)) {
current = null;
cache.requestSuggestions(request, callback);
return;
}
last_query = this_query;
}
final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, SUGGEST_URL + type + "&q=" + last_query);
try {
builder.sendRequest(null, new RequestCallback() {
public void onError(final com.google.gwt.http.client.Request r, final Throwable e) {
// Something bad happened, drop the current request.
current = null;
if (pending_req != null) {
// But if we have another waiting...
// ... try it now.
requestSuggestions(pending_req, pending_cb);
}
}
// Need to use fully-qualified names as this class inherits already
// from a pair of inner classes called Request / Response :-/
public void onResponseReceived(final com.google.gwt.http.client.Request r, final com.google.gwt.http.client.Response response) {
if (response.getStatusCode() == com.google.gwt.http.client.Response.SC_OK) {
final JSONValue json = JSONParser.parse(response.getText());
// In case this request returned nothing, we pretend the last
// suggestion ended with the largest character possible, so we
// won't send more requests to the server if the user keeps
// adding extra characters.
last_suggestion = last_query + "\377";
if (json != null && json.isArray() != null) {
final JSONArray results = json.isArray();
final int n = Math.min(request.getLimit(), results.size());
for (int i = 0; i < n; i++) {
final JSONValue suggestion = results.get(i);
if (suggestion == null || suggestion.isString() == null) {
continue;
}
final String suggestionstr = suggestion.isString().stringValue();
last_suggestion = suggestionstr;
cache.add(suggestionstr);
}
// Is this response still relevant to what the requester wants?
if (requester.getText().startsWith(last_query)) {
cache.requestSuggestions(request, callback);
pending_req = null;
pending_cb = null;
}
}
}
// Regardless of what happened above, this is done.
current = null;
if (pending_req != null) {
final Request req = pending_req;
final Callback cb = pending_cb;
pending_req = null;
pending_cb = null;
requestSuggestions(req, cb);
}
}
});
} catch (RequestException ignore) {
}
}
use of com.google.gwt.http.client.RequestBuilder in project data-access by pentaho.
the class GwtDatasourceEditorEntryPoint method onModuleLoad.
public void onModuleLoad() {
datasourceServiceManager = new DatasourceServiceManagerGwtImpl();
datasourceServiceManager.isAdmin(new XulServiceCallback<Boolean>() {
public void error(String message, Throwable error) {
}
public void success(Boolean retVal) {
isAdmin = retVal;
datasourceService = new DSWDatasourceServiceGwtImpl();
modelerService = new GwtModelerServiceImpl();
BogoPojo bogo = new BogoPojo();
modelerService.gwtWorkaround(bogo, new XulServiceCallback<BogoPojo>() {
public void success(BogoPojo retVal) {
}
public void error(String message, Throwable error) {
}
});
// only init the app if the user has permissions
// $NON-NLS-1$
final String url = GWT.getHostPageBaseURL() + "plugin/data-access/api/permissions/hasDataAccess";
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
builder.setHeader("accept", "application/json");
builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
try {
builder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
setupStandardNativeHooks(GwtDatasourceEditorEntryPoint.this);
initDashboardButtons(false);
}
public void onResponseReceived(Request request, Response response) {
hasPermissions = new Boolean(response.getText());
setupStandardNativeHooks(GwtDatasourceEditorEntryPoint.this);
if (hasPermissions) {
csvService = (ICsvDatasourceServiceAsync) GWT.create(ICsvDatasourceService.class);
setupPrivilegedNativeHooks(GwtDatasourceEditorEntryPoint.this);
loadOverlay("startup.dataaccess");
}
initDashboardButtons(hasPermissions);
}
});
} catch (RequestException e) {
// TODO Auto-generated catch block
}
}
});
XulServiceCallback<List<IDatabaseType>> callback = new XulServiceCallback<List<IDatabaseType>>() {
public void error(String message, Throwable error) {
error.printStackTrace();
}
public void success(List<IDatabaseType> retVal) {
databaseTypeHelper = new DatabaseTypeHelper(retVal);
databaseConnectionConverter = new DatabaseConnectionConverter(databaseTypeHelper);
}
};
dialectService.getDatabaseTypes(callback);
UIDatasourceServiceManager manager = UIDatasourceServiceManager.getInstance();
manager.registerService(new JdbcDatasourceService());
manager.registerService(new MondrianUIDatasourceService(datasourceServiceManager));
manager.registerService(new MetadataUIDatasourceService(datasourceServiceManager));
manager.registerService(new DSWUIDatasourceService(datasourceServiceManager));
manager.getIds(null);
}
use of com.google.gwt.http.client.RequestBuilder in project data-access by pentaho.
the class WizardConnectionController method updateConnection.
@Bindable
public void updateConnection() {
RequestBuilder updateConnectionBuilder = new RequestBuilder(RequestBuilder.POST, ConnectionController.getServiceURL("update"));
updateConnectionBuilder.setHeader("Content-Type", "application/json");
try {
// AutoBean<IDatabaseConnection> bean = AutoBeanUtils.getAutoBean(currentConnection);
AutoBean<IDatabaseConnection> bean = createIDatabaseConnectionBean(currentConnection);
updateConnectionBuilder.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) {
currentConnection = AutobeanUtilities.connectionBeanToImpl(currentConnection);
datasourceModel.getGuiStateModel().updateConnection(existingConnectionName, currentConnection);
datasourceModel.setSelectedRelationalConnection(currentConnection);
} else if (response.getStatusCode() == Response.SC_INTERNAL_SERVER_ERROR) {
// We assume that this means the connection doesn't exist to
// update so we'll add it
RequestBuilder deleteConnectionBuilder = new RequestBuilder(RequestBuilder.DELETE, ConnectionController.getServiceURL("deletebyname", new String[][] { { "name", previousConnectionName } }));
try {
deleteConnectionBuilder.sendRequest(null, 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) {
datasourceModel.getGuiStateModel().deleteConnection(datasourceModel.getSelectedRelationalConnection().getName());
List<IDatabaseConnection> connections = datasourceModel.getGuiStateModel().getConnections();
if (connections != null && connections.size() > 0) {
datasourceModel.setSelectedRelationalConnection(connections.get(connections.size() - 1));
} else {
datasourceModel.setSelectedRelationalConnection(null);
}
addConnection();
} else {
openErrorDialog(MessageHandler.getString("ERROR"), // $NON-NLS-1$
MessageHandler.getString(// $NON-NLS-1$
"ConnectionController.ERROR_0002_UNABLE_TO_DELETE_CONNECTION"));
}
} catch (Exception e) {
displayErrorMessage(e);
}
}
});
} catch (RequestException e) {
displayErrorMessage(e);
}
} else {
openErrorDialog(MessageHandler.getString("ERROR"), // $NON-NLS-1$
MessageHandler.getString(// $NON-NLS-1$
"ConnectionController.ERROR_0004_UNABLE_TO_UPDATE_CONNECTION"));
}
} catch (Exception e) {
displayErrorMessage(e);
}
}
});
} catch (RequestException e) {
displayErrorMessage(e);
}
}
Aggregations