You can use GWT RPC as follows on the client:
Service Creation
private void refreshWatchList() { final double MAX_PRICE = 100.0;
Service definition
@RemoteServiceRelativePath("stockPrices") public interface StockPriceService extends RemoteService { StockPrice[] getPrices(String[] symbols); }
Service implementation
public class StockPriceServiceImpl extends RemoteServiceServlet implements StockPriceService { public StockPrice[] getPrices(String[] symbols) {
Calling a service from a client and calling a remote call:
private ArrayList<String> stocks = new ArrayList<String>(); private StockPriceServiceAsync stockPriceSvc = GWT.create(StockPriceService.class); private void refreshWatchList() {
This is mainly RPC.
Your
In the middle
probably the result of serializing your objects. If you don't like this, you can also use the GWT RequestBuilder .
RequestBuilder requestBuilder = new RequestBuilder(requestMethod, url); requestBuilder.setHeader("Content-Type", "application/json"); requestBuilder.setRequestData(bodyString); requestBuilder.setCallback(new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { callback.onResponse(response.getStatusCode(), response.getText()); } @Override public void onError(Request request, Throwable exception) { callback.onError(new Exception(exception)); } }); try { requestBuilder.send(); } catch(RequestException ex) { callback.onError(ex); }
When using RequestBuilder you have more control over the format and what is being transported.
source share