Reputation: 103
I have an REST server as backend, it provides a set of services, also, it uses basic authentication method for access.
Now I need to create an GWT frontend,so, I need to perform http calls to the REST backend from the GWT frontend
After some research I found the HttpBuilder to handle http requests to the backend, but it seem to be a pain when trying to perform cross-site requests, and also it comes with some restricions related with Safari browser.
Then I found this https://developers.google.com/web-toolkit/doc/latest/tutorial/Xsite article, where it talks about an "Proxy on your own server", so it looks to be the solution I was looking for, but I did not find more information, or an example. It says that I could create server-side code to download the data from remote server (backend), so, should I create a http client like the apache client on server-side code, and implement a set of services that use it to make request to the backend?, if yes, how to handle the user authentication and the session? if not, give me a light please.
Thanks
Upvotes: 1
Views: 1277
Reputation: 7640
it seem to be a pain when trying to perform cross-site requests,
Actually you can make Cross Site Requests from GWT RequestBuilder if we can set in Servlet Response Header
Response.setHeader("Access-Control-Allow-Origin","http://yourrestserviceur.com/url");
should I create a http client like the apache client on server-side code, and implement
a set of services that use it to make request to the backend?
No, it is not required. use RequestBuilder
RequestBuilder Example:
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
try {
Request request = builder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
displayError("Couldn't retrieve JSON");
}
public void onResponseReceived(Request request, Response response) {
if (200 == response.getStatusCode()) {
updateTable(asArrayOfStockData(response.getText()));
} else {
displayError("Couldn't retrieve JSON (" + response.getStatusText()
+ ")");
}
}
});
} catch (RequestException e) {
displayError("Couldn't retrieve JSON");
}
Upvotes: 1