use of com.google.gwt.http.client.Response in project data-access by pentaho.
the class WizardConnectionController method overwriteCheck.
@Bindable
public void overwriteCheck() {
if (!saveConnectionConfirmationDialog.isHidden()) {
closeSaveConnectionConfirmationDialog();
}
if (!renameConnectionConfirmationDialog.isHidden()) {
closeRenameConnectionConfirmationDialog();
}
if (datasourceModel.isEditing() && previousConnectionName.equals(currentConnection.getName())) {
// if editing and no name change, proceed.
updateConnection();
} else {
String cacheBuster = String.valueOf(new java.util.Date().getTime());
// either new connection, or editing involved a name change.
RequestBuilder getConnectionBuilder = new RequestBuilder(RequestBuilder.GET, ConnectionController.getServiceURL("get", new String[][] { { "name", currentConnection.getName() }, { "ts", cacheBuster } }));
getConnectionBuilder.setHeader("Content-Type", "application/json");
try {
AutoBean<IDatabaseConnection> bean = createIDatabaseConnectionBean(currentConnection);
getConnectionBuilder.sendRequest(AutoBeanCodex.encode(bean).getPayload(), new RequestCallback() {
public void onResponseReceived(Request request, Response response) {
switch(response.getStatusCode()) {
case Response.SC_OK:
showOverwriteConnectionConfirmationDialog();
break;
case Response.SC_NOT_FOUND:
saveConnection();
break;
default:
// TODO: error message
saveConnection();
}
}
public void onError(Request request, Throwable exception) {
displayErrorMessage(exception);
}
});
} catch (Exception e) {
displayErrorMessage(e);
}
}
}
use of com.google.gwt.http.client.Response 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.Response 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;
}
use of com.google.gwt.http.client.Response in project blogwt by billy1380.
the class BlogService method getResources.
public Request getResources(GetResourcesRequest input, AsyncSuccess<GetResourcesRequest, GetResourcesResponse> onSuccess, AsyncFailure<GetResourcesRequest> onFailure) {
Request handle = null;
try {
handle = sendRequest(BlogMethodGetResources, input, new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
try {
GetResourcesResponse outputParameter = new GetResourcesResponse();
parseResponse(response, outputParameter);
if (onSuccess != null) {
onSuccess.call(input, outputParameter);
}
onCallSuccess(BlogService.this, BlogMethodGetResources, input, outputParameter);
} catch (JSONException | HttpException exception) {
if (onFailure != null) {
onFailure.call(input, exception);
}
onCallFailure(BlogService.this, BlogMethodGetResources, input, exception);
}
}
@Override
public void onError(Request request, Throwable exception) {
if (onFailure != null) {
onFailure.call(input, exception);
}
onCallFailure(BlogService.this, BlogMethodGetResources, input, exception);
}
});
onCallStart(BlogService.this, BlogMethodGetResources, input, handle);
} catch (RequestException exception) {
if (onFailure != null) {
onFailure.call(input, exception);
}
onCallFailure(BlogService.this, BlogMethodGetResources, input, exception);
}
return handle;
}
use of com.google.gwt.http.client.Response in project blogwt by billy1380.
the class BlogService method createPost.
public Request createPost(CreatePostRequest input, AsyncSuccess<CreatePostRequest, CreatePostResponse> onSuccess, AsyncFailure<CreatePostRequest> onFailure) {
Request handle = null;
try {
handle = sendRequest(BlogMethodCreatePost, input, new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
try {
CreatePostResponse outputParameter = new CreatePostResponse();
parseResponse(response, outputParameter);
if (onSuccess != null) {
onSuccess.call(input, outputParameter);
}
onCallSuccess(BlogService.this, BlogMethodCreatePost, input, outputParameter);
} catch (JSONException | HttpException exception) {
if (onFailure != null) {
onFailure.call(input, exception);
}
onCallFailure(BlogService.this, BlogMethodCreatePost, input, exception);
}
}
@Override
public void onError(Request request, Throwable exception) {
if (onFailure != null) {
onFailure.call(input, exception);
}
onCallFailure(BlogService.this, BlogMethodCreatePost, input, exception);
}
});
onCallStart(BlogService.this, BlogMethodCreatePost, input, handle);
} catch (RequestException exception) {
if (onFailure != null) {
onFailure.call(input, exception);
}
onCallFailure(BlogService.this, BlogMethodCreatePost, input, exception);
}
return handle;
}
Aggregations