Trying to integrate GWT into an OSGi bundle
I am trying to integrate GWT with OSGi (Equinox) to provide a web based UI for the rest of my modular system. So far I've managed to embed the GWT servlet in the OSGi module.
I am using the GWT sample code project generated by the Eclipse GWT plugin, which consists of 3 packages: client, server and shared. The class in the server package (ui.server.GreetingServiceImpl
) implements the interface in the client package (ui.client.GreetingService
), and all of them are in the same bundle.
When I try to make a Remote Procedure Call from the client side web page I get the error:
IncompatibleRemoteServiceException: Could no开发者_JAVA百科t locate requested interface 'ui.client.GreetingService' in default classloader
I gather that the class was not found by the classloader, but I don't know how to fix this. I can access classes in other bundles by requiring or importing them, but not the interface that is in the same bundle as the implementing class. Could anyone point me in the right direction? I've been googling for hours.
It is needed to override method 'service' from HttpServlet on your GreetingServiceImpl:
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// Cache the current thread
Thread currentThread = Thread.currentThread();
// We are going to swap the class loader
ClassLoader oldContextClassLoader =
currentThread.getContextClassLoader();
currentThread.setContextClassLoader(this.getClass().getClassLoader());
super.service(req, resp);
currentThread.setContextClassLoader(oldContextClassLoader);
}
Thus, the application runs on Equinox!!
IncompatibleRemoteServiceException means that the RPC call from the GUI didn't found the interface specified by the @RemoteService annotation.
Can you post your project with source codes ?
BTW you can also have a look at this project: http://code.google.com/p/gwt-in-osgi/
精彩评论