use of com.google.gwt.http.client.RequestException in project data-access by pentaho.
the class JdbcDatasourceService method remove.
/* (non-Javadoc)
* @see org.pentaho.platform.dataaccess.datasource.ui.service.IUIDatasourceAdminService#remove(org.pentaho.platform
* .dataaccess.datasource.IDatasourceInfo)
*/
@Override
public void remove(IDatasourceInfo dsInfo, Object callback) {
final XulServiceCallback<Boolean> responseCallback = (XulServiceCallback<Boolean>) callback;
RequestBuilder deleteConnectionBuilder = new RequestBuilder(RequestBuilder.DELETE, getBaseURL() + NameUtils.URLEncode("deletebyname?name={0}", dsInfo.getId()));
try {
deleteConnectionBuilder.sendRequest(null, new RequestCallback() {
public void onResponseReceived(Request request, Response response) {
responseCallback.success(response.getStatusCode() == Response.SC_OK);
}
public void onError(Request request, Throwable error) {
responseCallback.error(error.getLocalizedMessage(), error);
}
});
} catch (RequestException e) {
responseCallback.error(e.getLocalizedMessage(), e);
}
}
use of com.google.gwt.http.client.RequestException in project data-access by pentaho.
the class WizardConnectionController method handleDialogAccept.
@Bindable
public void handleDialogAccept() {
// first, test the connection
RequestBuilder testConnectionBuilder = new RequestBuilder(RequestBuilder.PUT, ConnectionController.getServiceURL("test"));
testConnectionBuilder.setHeader("Content-Type", "application/json");
try {
// AutoBean<IDatabaseConnection> bean = AutoBeanUtils.getAutoBean(currentConnection);
AutoBean<IDatabaseConnection> bean = createIDatabaseConnectionBean(currentConnection);
testConnectionBuilder.sendRequest(AutoBeanCodex.encode(bean).getPayload(), new RequestCallback() {
@Override
public void onError(Request request, Throwable exception) {
saveConnectionConfirmationDialog.show();
}
@Override
public void onResponseReceived(Request request, Response response) {
try {
if (response.getStatusCode() == Response.SC_OK) {
// test is ok, now check if we are renaming
renameCheck();
} else {
// confirm if we should continu saving this invalid connection.
saveConnectionConfirmationDialog.show();
}
} catch (Exception e) {
displayErrorMessage(e);
}
}
});
} catch (RequestException e) {
displayErrorMessage(e);
}
}
use of com.google.gwt.http.client.RequestException in project data-access by pentaho.
the class WizardConnectionController method addConnection.
@Bindable
public void addConnection() {
RequestBuilder addConnectionBuilder = new RequestBuilder(RequestBuilder.POST, ConnectionController.getServiceURL("add"));
addConnectionBuilder.setHeader("Content-Type", "application/json");
try {
// AutoBean<IDatabaseConnection> bean = AutoBeanUtils.getAutoBean(currentConnection);
AutoBean<IDatabaseConnection> bean = createIDatabaseConnectionBean(currentConnection);
addConnectionBuilder.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) {
IDatabaseConnection conn = AutobeanUtilities.connectionBeanToImpl(currentConnection);
datasourceModel.getGuiStateModel().addConnection(conn);
datasourceModel.setSelectedRelationalConnection(conn);
} else {
openErrorDialog(MessageHandler.getString("ERROR"), // $NON-NLS-1$
MessageHandler.getString(// $NON-NLS-1$
"ConnectionController.ERROR_0001_UNABLE_TO_ADD_CONNECTION"));
}
} catch (Exception e) {
displayErrorMessage(e);
}
}
});
} catch (RequestException e) {
displayErrorMessage(e);
}
}
use of com.google.gwt.http.client.RequestException in project opentsdb by OpenTSDB.
the class QueryUi method asyncGetJson.
private void asyncGetJson(final String url, final GotJsonCallback callback) {
final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
try {
builder.sendRequest(null, new RequestCallback() {
public void onError(final Request request, final Throwable e) {
displayError("Failed to get " + url + ": " + e.getMessage());
// Since we don't call the callback we've been given, reset this
// bit of state as we're not going to retry anything right now.
pending_requests = 0;
}
public void onResponseReceived(final Request request, final Response response) {
final int code = response.getStatusCode();
if (code == Response.SC_OK) {
clearError();
callback.got(JSONParser.parse(response.getText()));
return;
} else if (code >= Response.SC_BAD_REQUEST) {
// 400+ => Oops.
// Since we don't call the callback we've been given, reset this
// bit of state as we're not going to retry anything right now.
pending_requests = 0;
String err = response.getText();
// an error message.
if (!err.isEmpty() && err.charAt(0) == '{') {
final JSONValue json = JSONParser.parse(err);
final JSONObject result = json == null ? null : json.isObject();
final JSONValue jerr = result == null ? null : result.get("err");
final JSONString serr = jerr == null ? null : jerr.isString();
err = serr.stringValue();
// If the error message has multiple lines (which is common if
// it contains a stack trace), show only the first line and
// hide the rest in a panel users can expand.
final int newline = err.indexOf('\n', 1);
final String msg = "Request failed: " + response.getStatusText();
if (newline < 0) {
displayError(msg + ": " + err);
} else {
displayError(msg);
final DisclosurePanel dp = new DisclosurePanel(err.substring(0, newline));
// Attach the widget.
RootPanel.get("queryuimain").add(dp);
final InlineLabel content = new InlineLabel(err.substring(newline, err.length()));
// For readable stack traces.
content.addStyleName("fwf");
dp.setContent(content);
current_error.getElement().appendChild(dp.getElement());
}
} else {
displayError("Request failed while getting " + url + ": " + response.getStatusText());
// Since we don't call the callback we've been given, reset this
// bit of state as we're not going to retry anything right now.
pending_requests = 0;
}
graphstatus.setText("");
}
}
});
} catch (RequestException e) {
displayError("Failed to get " + url + ": " + e.getMessage());
}
}
use of com.google.gwt.http.client.RequestException in project blogwt by billy1380.
the class BlogService method getRatings.
public Request getRatings(GetRatingsRequest input, AsyncSuccess<GetRatingsRequest, GetRatingsResponse> onSuccess, AsyncFailure<GetRatingsRequest> onFailure) {
Request handle = null;
try {
handle = sendRequest(BlogMethodGetRatings, input, new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
try {
GetRatingsResponse outputParameter = new GetRatingsResponse();
parseResponse(response, outputParameter);
if (onSuccess != null) {
onSuccess.call(input, outputParameter);
}
onCallSuccess(BlogService.this, BlogMethodGetRatings, input, outputParameter);
} catch (JSONException | HttpException exception) {
if (onFailure != null) {
onFailure.call(input, exception);
}
onCallFailure(BlogService.this, BlogMethodGetRatings, input, exception);
}
}
@Override
public void onError(Request request, Throwable exception) {
if (onFailure != null) {
onFailure.call(input, exception);
}
onCallFailure(BlogService.this, BlogMethodGetRatings, input, exception);
}
});
onCallStart(BlogService.this, BlogMethodGetRatings, input, handle);
} catch (RequestException exception) {
if (onFailure != null) {
onFailure.call(input, exception);
}
onCallFailure(BlogService.this, BlogMethodGetRatings, input, exception);
}
return handle;
}
Aggregations