GuiceRemoteServiceServlet is a wrapper servlet for GWT RPC utilizing Guice for managing RemoteService implementation object's lifecycle.
<servlet>
<servlet-name>GWT-RPCServlet</servlet-name>
<servlet-class>com.gc.gwt.server.GuiceRemoteServiceServlet</servlet-class>
<init-param>
<param-name>guice.module</param-name>
<param-value>com.test.guice.MyGuiceModule</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>GWT-RPCServlet</servlet-name>
<url-pattern>/GWT.rpc</url-pattern>
</servlet-mapping>
- map all you remote service implementations in Guice Module
- define and map GuiceRemoteServiceServlet as shown above
- point ALL services to the same /GWT.rpc
The source for the GuiceRemoteServiceServlet can be found here.
Good luck.
PS: GuiceRemoteServiceServlet depends on Guice and apache-commons beanutils.
PS2: The source of GuiceRemoteServiceServlet is distributed under Apache 2.0 License.
6 comments:
Hi,
The httpServlet(Request|Session) should be injected by Guice, using GuiceFilter which set them (request|session) in a thread local variable.
hih
In which case the servlet becomes simply
public class GuiceRemoteServiceServlet extends RemoteServiceServlet {
@Inject
private Injector injector;
@Override
public String processCall(String payload) throws SerializationException {
try {
RPCRequest rpcRequest = RPC.decodeRequest(payload);
RemoteService service = getServiceInstance(rpcRequest.getMethod()
.getDeclaringClass());
return RPC.invokeAndEncodeResponse(service, rpcRequest.getMethod(),
rpcRequest.getParameters(), rpcRequest
.getSerializationPolicy());
} catch (IncompatibleRemoteServiceException ex) {
getServletContext()
.log(
"An IncompatibleRemoteServiceException was thrown while processing this call.",
ex);
return RPC.encodeResponseForFailure(null, ex);
}
}
@SuppressWarnings("unchecked")
private RemoteService getServiceInstance(Class serviceClass) {
try {
RemoteService remoteService = (RemoteService) injector
.getInstance(serviceClass);
return remoteService;
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}
Hello
How do i call the servlet from the Presenter
And about the RemoteService of the Servlet say
interface MyGuiceService
It does not to be included ?
I can not start the Service
Do you have a complete example or so
regards toine
Please check this post out for a newer version based on Guice 2.0.
http://stuffthathappens.com/blog/2009/09/14/guice-with-gwt/
Hello again
I tried to use it but i get the error
Error 404: SRVE0190E: File not found: /bw_gxt_01/GWT.rpc
protected void configureServlets() {
serve(”/bw_gxt_01/GWT.rpc”).with(GuiceRemoteServiceImpl.class);
System.out.println(”BwServletModel.configureServlets()”);
bind(ListService.class).to(ListServiceImpl.class);
}
@RemoteServiceRelativePath(”GWT.rpc”)
public interface ListService extends RemoteService {
Am i forgetting something
regards toine
Try:
serve("/GWT.rpc").with(GuiceRemoteServiceImpl.class);
I'm assuming "/bw_gxt_01" is the context path of your webapp, so you don't need to specify it when calling "serve()".
Post a Comment