Most of my application uses GWT-RPC to communicate between the servet and client. However a few classes need to build a get request manually by "string smashing" the URL with various params like this...
public static String getTemplateImage(String templateInstanceId, PageImage pageImage) {
return GWT.getHostPageBaseURL() + TEMPLATE_INSTANCE_IMAGE_SERVLET_PATH
+ "?templateInstanceId=" + templateInstanceId
+ "&fileName=" + pageImage.getImageId()
+ "&isBackground=false"
+ "&cropX=" + pageImage.getCropX()
+ "&cropY=" + pageImage.getCropY()
+ "&cropWidth=" + pageImage.getCropWidth()
+ "&cropHeight=" + pageImage.getCropHeight();
}
I was wondering, is there a way to piggyback GWT's rather awesome GWT-RPC object marshaller to do this?
public static String getTemplateImage(String templateInstanceId, PageImage pageImage) {
return GWT.getHostPageBaseURL() + TEMPLATE_INSTANCE_IMAGE_SERVLET_PATH
+ "?templateInstanceId=" + templateInstanceId
+ "&pageImage=" + SomeGWTClass.toRpcString(pageImage)
;
}
Then on the servlet side do this...
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final String templateInstanceId = req.getParameter("templateInstanceId");
final String strPageImage= req.getParameter("pageImage");
**final PageImage pageImage = SomeGWTClass.unmarshallString(PageImage.class,strPageImage);**
}