Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT request payload understanding

Tags:

java

rpc

gwt

If you look below is my payload going to server when I made a RPC call in my application

7|0|14|http://domain.com/ager-online/tracklay/|7FCCBC6F7B44BB2BEB84AAB8B47DB2E4|com.d.g4.consumer.w.client.rpcservice.ConsumerService|placeService|java.util.List|java.util.ArrayList/4159755760|co.g.consumer.wager.client.model.ConsumernseType/2494043886|java.lang.Double/858496421|java.lang.Integer/3438268394|2|1|WIN|java.lang.Long/4227064769|java.util.Date/3385151746|1|2|3|4|1|5|6|1|7|8|2|8|2|9|1|10|11|11|12|13|Co3|14|**Uzc1OKs**|9|309158|-5|

I know its being serialized and sending data to server. What I want to know is the keys in middle. like Uzc1OKs I marked them in the request.

What exactly they are ?

Any ideas ?

like image 516
Suresh Atta Avatar asked Nov 09 '22 15:11

Suresh Atta


2 Answers

Have you tried this open-source tool? https://code.google.com/p/gwt-payload-deserializer/

Here is payload elements explanation: https://code.google.com/p/gwt-payload-deserializer/wiki/GwtPayloadDefinition

like image 73
Tomek Avatar answered Nov 15 '22 04:11

Tomek


You can use GWT RPC in the following way on the client:

Creating a service

private void refreshWatchList() {
    final double MAX_PRICE = 100.0; // $100.00
    final double MAX_PRICE_CHANGE = 0.02; // +/- 2%

    StockPrice[] prices = new StockPrice[stocks.size()];
    for (int i = 0; i < stocks.size(); i++) {
      double price = Random.nextDouble() * MAX_PRICE;
      double change = price * MAX_PRICE_CHANGE
          * (Random.nextDouble() * 2.0 - 1.0);

      prices[i] = new StockPrice(stocks.get(i), price, change);
    }

    updateTable(prices);
  }

Defining the service

@RemoteServiceRelativePath("stockPrices")
public interface StockPriceService extends RemoteService {

      StockPrice[] getPrices(String[] symbols);
}

Implementing the service

public class StockPriceServiceImpl extends RemoteServiceServlet implements StockPriceService {

    public StockPrice[] getPrices(String[] symbols) {
        // TODO Auto-generated method stub
        return null;
    }
}

Invoking the service from the client and making the remote procedure call:

private ArrayList<String> stocks = new ArrayList<String>();
private StockPriceServiceAsync stockPriceSvc = GWT.create(StockPriceService.class);

private void refreshWatchList() {
    // Initialize the service proxy.
    if (stockPriceSvc == null) {
      stockPriceSvc = GWT.create(StockPriceService.class);
    }

     // Set up the callback object.
    AsyncCallback<StockPrice[]> callback = new AsyncCallback<StockPrice[]>() {
      public void onFailure(Throwable caught) {
        // TODO: Do something with errors.
      }

      public void onSuccess(StockPrice[] result) {
        updateTable(result);
      }
    };

     // Make the call to the stock price service.
    stockPriceSvc.getPrices(stocks.toArray(new String[0]), callback);
}

This is basically what RPC is done.

Your

keys in middle

is probably the result of serialization your objects. If you don't like that 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 of the format and what is being transported.

like image 41
confile Avatar answered Nov 15 '22 05:11

confile