I'd like to know if it is possible to use the serializer of GWT. When using the rpc-mechnism of GWT, GWT serializes the objects on the client and deserializes the objects on the server. For this mechanism you have to use special servlets ( RemoteServiceServlet
) of GWT. But i want to use the normal HttpServlets and therefore i have to serialize and deserialize the objects by myself.
All the code you need to look at is in the RemoteServiceServlet.java . Focus on the processCall method.
The RPC.decodeRequest(payload, ...) will give you a RPCRequest object which includes the method to be called and the deserialized parameters.
To encode the response focus on RPC.invokeAndEncodeResponse() and RPC.encodeResponseForSuccess() methods.
[EDITED]
In client-side it's worth to take a look to the proxy classes generated by the RPC generator, concretely the YourService_Proxy.java
file. Generated files are left somewhere in your project's folder structure after compiling a project (you can indicate this folder with the -gen
though).
The interesting code is in in the RemoteServiceProxy , looking at the createStreamWritter method, you can see how to serialize your objects. In the createStreamReader you can see how to deserialize a message from the server.
SerializerInt ser = new Serializer();
ser.writeValue("test");
ser.writeValue(new int[]{5,1,6});
String buffer = ser.getBuffer();
SerializerInt des = new Serializer(buffer);
des.readString()
des.readIntegerArr()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.