In the frame of restlets, or even more generally RESTFul applications, we focus more on scalability of the application and portability of the data which are exchanged. Nevertheless we may choose an architecture where communication betwwen server and clients could mimic the GWT-RPC one, ie by transmitting serialized objects through the network.
This possible by using some classes provided by the GWT framework. For instance :
* on the client side : SerializationStreamFactory, SerailizationStreamReader
* on the server side : RPC.encodeResponseForSuccess
Example :
1) on the client side
// Create the serialization stream factory
SerializationStreamFactory serializationFactory =
GWT.create(MyClass.class);
// Create a stream reader : the argument is the serialized string from the server
SerializationStreamReader streamReader =
serializationFactory.createStreamReader(aStringReturnedFromRestletCommunication);
// Deserialize the instance
MyClass aClass= (MyClass)(streamReader.readObject());
2) on the server side
String encoded =null;
try {
String encoded = RPC.encodeResponseForSuccess(MyClass.getMethod("aMethodName"),myClass);
} catch (SecurityException e) {
e.printStackTrace();
} catch (SerializationException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
return encoded;
No comments:
Post a Comment