I’m using GWT-RPC to get the client data and my requirement is to parse the payload to retrieve the data inside. I need to log or persist this data for metrics/monitoring purpose.
I’m using the Servlet Filter to intercept the HTTP requests. I can see that the request looks something like this –
5|0|7|http://localhost:8080/testproject|
29F4EA1240F157649C12466F01F46F60|com.test.client.GreetingService|
greetServer|java.lang.String|myInput1|myInput2|1|2|3|4|2|5|5|6|7|
Is there any standard mechanism to parse this data? I’m afraid writing my own code to parse this is not a good solution as this request payload is going to be complex when we pass custom objects to/from RPC and GWT-RPC internal parsing mechanism could change in future, which can break my code. I came across this, but not sure if it is robust/maintained.
Is there any alternative? Any pointers will be appreciated.
Use the
RPCclass from GWT.You’ll have to provide the serialization policy, whose strong name is passed in a request header.
Decoding responses is harder. You can use
com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.ResponseReaderalong with acom.google.gwt.user.client.rpc.impl.ClientSerializationStreamReaderbut you’ll need to have theJsParserfromgwt-dev.jarin the classpath; and you cannot havegwt-dev.jarin a web application as it contains the servlet API (among others); so you’ll have to extract the relevant classes fromgwt-dev.jarto use them in your web app.Note that in both cases, you’ll reconstruct the same objects as will be deserialized for processing the request “for real”, or were serialized as the result of the request processing.
All-in-all, you’ll probably have better luck and better performances with using AOP on the methods of your
RemoteServiceServlets.