Using RWT jars in a standard servlet for instanting a (non visible) Display [message #1706567] |
Thu, 27 August 2015 17:49 |
|
Hi all,
we are evaluating to use some part of RAP project for a limited goal that we are facing.
We would need to get a Display instance in a standard Java server-side environment (non Equinox/OSGi, just JEE) without showing any graphical content, just in a headless context (a servlet).
We already had success in instantiating a Display instance both under Windows and Linux, but with the following constraints:
- relying on Eclipse SWT Jars specific for each operating system
- a graphical server (e.g. XServer on Linux) must be installed
Consider that we are using a set of Eclipse plugins (from EMF, JFace, and other frameworks) as simple Jars inside the /WEB-INF/lib of a webapp deployed on a non-OSGi container (e.g. Tomcat).
The above constraints are not so 'friendly', so we looked for a cross-OS SWT implementation less tied to the native SWT single implementations.
This search leads naturally to RAP, which, with RWT, does exactly this!
In the end what we would like is to being able to do something like:
Display d = new Display(); (or similar)
but without having to set up a RAP application (we are in a pure JEE environment, with servlets and so on).
We already made some test for this, but the RAP initialization process seems to need a quite complex architecture, which is clearly good and powerful for a RAP application, but too much for our 'simple' goal.
Could you give us hints for a minimum set of instructions to get a Display instance, let's say from inside a standard servlet?
Thank you very much in advance
Vincenzo
|
|
|
|
Re: Using RWT jars in a standard servlet for instanting a (non visible) Display [message #1707096 is a reply to message #1706955] |
Wed, 02 September 2015 09:46 |
|
Thank you Ivan,
your suggestion seems to be very useful!
But we need a little more help to go further.
We set up the RWTServletContextListener, but then we have a standard HttpServlet (that doesn't extend RWTServlet) and would like to just get an instance of Display.
We tried do replicate the code that RWTServlet does, see the code below
ServletContext servletContext = getServletContext();
ApplicationContextImpl applicationContext = ApplicationContextImpl.getFrom(servletContext);
ServiceContext context = new ServiceContext(request, response, applicationContext);
context.setServiceStore(new ServiceStore());
ContextProvider.setContext(context);
prepareUISession(context);
UISession uiSession = context.getUISession();
IUIThreadHolder uiThreadHolder = new SimpleUIThreadHolder(Thread.currentThread());
LifeCycleUtil.setUIThread(uiSession, uiThreadHolder);
IUIThreadHolder uiThread = LifeCycleUtil.getUIThread(uiSession);
Display display = LifeCycleUtil.getSessionDisplay(uiSession);
System.out.println(display);
but still get a null Display.
What should we do to get the Display instance from the UIThread?
Thank you
Vincenzo
|
|
|
|
Re: Using RWT jars in a standard servlet for instanting a (non visible) Display [message #1707187 is a reply to message #1707132] |
Wed, 02 September 2015 22:47 |
|
Hi Ivan,
ok, we can make our servlet extend RWTServlet.
So we did it and then tried to execute the LifeCycleServiceHandler, as you suggested (calling the service() method I suppose), but had a NullPointer exception (see below) when trying to get the Display.
Our trials ended up to the following code:
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
super.doGet(request, response);
ServletContext servletContext = getServletContext();
ApplicationContextImpl applicationContext = ApplicationContextImpl.getFrom(servletContext);
ServiceContext context = new ServiceContext(request, response, applicationContext);
context.setServiceStore(new ServiceStore());
ContextProvider.setContext(context);
LifeCycleServiceHandler lcsh = (LifeCycleServiceHandler) applicationContext.getServiceManager().getHandler();
lcsh.service(request, response);
Display display = LifeCycleUtil.getSessionDisplay(context.getUISession());
System.out.println(display);
what are we doing wrong?
(please consider that obviously our servlet has to return a custom response, different from the json content that would be returned by the RWTServlet)
java.lang.NullPointerException
at org.eclipse.rap.rwt.internal.lifecycle.LifeCycleUtil.getSessionDisplay(LifeCycleUtil.java:37)
|
|
|
|
Powered by
FUDForum. Page generated in 0.02814 seconds