Hi devs,
Following
http://stuffthathappens.com/blog/2009/09/14/guice-with-gwt/
I've made a simple servlet that dispatches GWT requests to corresponding
components. Here's the code:
public class XWikiRemoteServiceServlet extends RemoteServiceServlet
{
public String processCall(String payload) throws SerializationException
{
try {
RPCRequest req = RPC.decodeRequest(payload, null, this);
RemoteService service = (RemoteService)
Utils.getComponent(req.getMethod().getDeclaringClass());
return RPC.invokeAndEncodeResponse(service,
req.getMethod(), req.getParameters(), req
.getSerializationPolicy());
} catch (IncompatibleRemoteServiceException ex) {
log("IncompatibleRemoteServiceException in the
processCall(String) method.", ex);
return RPC.encodeResponseForFailure(null, ex);
}
}
}
I tested it with the new MacroService component (to be committed in
WYSIWYG code) and it works great. I'm wondering where to place this
servlet since it's generic and should be used by all GWT applications
that use services. I'm hesitating to place it in web/gwt because I think
this is "new" code, component oriented while the gwt module depends on
the old xwiki-core.
Another question is if it's OK to use Utils.getComponent(Class) or
should we find a way to inject the component manager. They use a
GuiceFilter to do this in the tutorial I pointed out.
WDYT?
Thanks,
Marius