XML Request from GWT
From Zanecorpwiki
GWT attempts to hide all the details of request and response. So the question may arise, how does one hook into regular old web services? What's the equivalent of JavaScripts XMLHttpRequest?
The answer is RequestBuilder.
To use the RequestBuilder, you need to inherit the HTTP module:
<module> ... <inherits name="com.google.gwt.http.HTTP"/> ... </module>
Then you use the RequestBuilder much like the XMLHttpRequest.
/* Note: I have not tested this code, it's demonstrative only. */
final RequestBuilder request = new RequestBuilder(RequestBuilder.GET, "some.xml");
try {
requestBuilder.sendRequest(null, new RequestCallback() {
publilc void onError(Request request, Throwable t)
requestFailed(t);
}
public void onResponseReceived(Request request, Response responses) {
try { handleData(XMLParser.parse(response.getText())); }
catch (DOMParseException e) { badResponse(response.getText()); }
}
});
}
catch (RequestException e) {
requestFailed(e);
}
Unlike the XMLHttpRequest object, RequestBuilder does not provide direct access to an XML response, so we have to add the parse call when handling the text.


