use of com.google.gwt.http.client.RequestCallback 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.RequestCallback in project gerrit by GerritCodeReview.
the class Gerrit method getDocIndex.
private static void getDocIndex(final AsyncCallback<DocInfo> cb) {
RequestBuilder req = new RequestBuilder(RequestBuilder.HEAD, GWT.getHostPageBaseURL() + INDEX);
req.setCallback(new RequestCallback() {
@Override
public void onResponseReceived(Request req, Response resp) {
switch(resp.getStatusCode()) {
case Response.SC_OK:
case Response.SC_MOVED_PERMANENTLY:
case Response.SC_MOVED_TEMPORARILY:
cb.onSuccess(DocInfo.create());
break;
default:
cb.onSuccess(null);
break;
}
}
@Override
public void onError(Request request, Throwable e) {
cb.onFailure(e);
}
});
try {
req.send();
} catch (RequestException e) {
cb.onFailure(e);
}
}
use of com.google.gwt.http.client.RequestCallback in project opennms by OpenNMS.
the class Navigation method linkTopOpenNMSClicked.
@UiHandler("m_link")
public void linkTopOpenNMSClicked(ClickEvent event) {
StringBuffer postData = new StringBuffer();
// note param pairs are separated by a '&'
// and each key-value pair is separated by a '='
postData.append(URL.encode("j_username")).append("=").append(URL.encode("ipv6"));
postData.append("&");
postData.append(URL.encode("j_password")).append("=").append(URL.encode("ipv6"));
postData.append("&");
postData.append(URL.encode("Login")).append("=").append(URL.encode("login"));
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode("/opennms/j_spring_security_check"));
builder.setHeader("Content-type", "application/x-www-form-urlencoded");
try {
builder.sendRequest(postData.toString(), new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
if (response.getStatusCode() == 200) {
Window.open("/opennms/index.jsp", "_target", null);
} else {
Window.alert("Failed to login");
}
}
@Override
public void onError(Request request, Throwable exception) {
Window.alert("Problem Logging in");
}
});
} catch (RequestException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Window.alert("Cliking link to OpenNMS");
}
use of com.google.gwt.http.client.RequestCallback in project blogwt by billy1380.
the class PageService method getPages.
public Request getPages(GetPagesRequest input, AsyncSuccess<GetPagesRequest, GetPagesResponse> onSuccess, AsyncFailure<GetPagesRequest> onFailure) {
Request handle = null;
try {
handle = sendRequest(PageMethodGetPages, input, new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
try {
GetPagesResponse outputParameter = new GetPagesResponse();
parseResponse(response, outputParameter);
if (onSuccess != null) {
onSuccess.call(input, outputParameter);
}
onCallSuccess(PageService.this, PageMethodGetPages, input, outputParameter);
} catch (JSONException | HttpException exception) {
if (onFailure != null) {
onFailure.call(input, exception);
}
onCallFailure(PageService.this, PageMethodGetPages, input, exception);
}
}
@Override
public void onError(Request request, Throwable exception) {
if (onFailure != null) {
onFailure.call(input, exception);
}
onCallFailure(PageService.this, PageMethodGetPages, input, exception);
}
});
onCallStart(PageService.this, PageMethodGetPages, input, handle);
} catch (RequestException exception) {
if (onFailure != null) {
onFailure.call(input, exception);
}
onCallFailure(PageService.this, PageMethodGetPages, input, exception);
}
return handle;
}
use of com.google.gwt.http.client.RequestCallback in project blogwt by billy1380.
the class PageService method submitForm.
public Request submitForm(SubmitFormRequest input, AsyncSuccess<SubmitFormRequest, SubmitFormResponse> onSuccess, AsyncFailure<SubmitFormRequest> onFailure) {
Request handle = null;
try {
handle = sendRequest(PageMethodSubmitForm, input, new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
try {
SubmitFormResponse outputParameter = new SubmitFormResponse();
parseResponse(response, outputParameter);
if (onSuccess != null) {
onSuccess.call(input, outputParameter);
}
onCallSuccess(PageService.this, PageMethodSubmitForm, input, outputParameter);
} catch (JSONException | HttpException exception) {
if (onFailure != null) {
onFailure.call(input, exception);
}
onCallFailure(PageService.this, PageMethodSubmitForm, input, exception);
}
}
@Override
public void onError(Request request, Throwable exception) {
if (onFailure != null) {
onFailure.call(input, exception);
}
onCallFailure(PageService.this, PageMethodSubmitForm, input, exception);
}
});
onCallStart(PageService.this, PageMethodSubmitForm, input, handle);
} catch (RequestException exception) {
if (onFailure != null) {
onFailure.call(input, exception);
}
onCallFailure(PageService.this, PageMethodSubmitForm, input, exception);
}
return handle;
}
Aggregations