Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Using RWT jars in a standard servlet for instanting a (non visible) Display
Using RWT jars in a standard servlet for instanting a (non visible) Display [message #1706567] Thu, 27 August 2015 17:49 Go to next message
Vincenzo Caselli is currently offline Vincenzo CaselliFriend
Messages: 235
Registered: January 2012
Senior Member

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 #1706955 is a reply to message #1706567] Tue, 01 September 2015 07:39 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi Vincenzo,
the standalone RAP application is what you need. Please have a look at
RAP Developers Guide [1].

[1]
https://eclipse.org/rap/developers-guide/devguide.php?topic=rwt-standalone.html&version=3.0
HTH,
Ivan

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
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 Go to previous messageGo to next message
Vincenzo Caselli is currently offline Vincenzo CaselliFriend
Messages: 235
Registered: January 2012
Senior Member

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 #1707132 is a reply to message #1707096] Wed, 02 September 2015 13:37 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi Vincenzo,
the display instance is created by the programmer code in
EntryPoint#createUI method. But in order to go there you have to execute
the LifeCycleServiceHandler. What is your use case? Why you don't want
to use RWTServlet? Probably servlet filter is an option?
Regards,
Ivan

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
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 Go to previous messageGo to next message
Vincenzo Caselli is currently offline Vincenzo CaselliFriend
Messages: 235
Registered: January 2012
Senior Member

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)
Re: Using RWT jars in a standard servlet for instanting a (non visible) Display [message #1707283 is a reply to message #1707187] Thu, 03 September 2015 13:07 Go to previous message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Vincenzo,
there is no UISession set in the context. Look at RWTServlet code more
precisely especially the method prepareUISession( context ).
Regards,
Ivan

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Previous Topic:StyledCellLabelProvider class not in org.eclipse.rap.jface 3.0
Next Topic:Canvas and FILL_HOrizontal
Goto Forum:
  


Current Time: Thu Mar 28 18:02:00 GMT 2024

Powered by FUDForum. Page generated in 0.04657 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top