Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Jetty to WAR Class Comunication

You can make any arbitrary object in the parent app available to the
servlet via WebAppContext.setAttribute/getAttribute:

        MyService myService = new MyService();
        jetty = new Server(httpPort);
        wac = new WebAppContext();
        wac.setContextPath(...);
        wac.setWar(...);
        wac.setAttribute("myService", myService);
        jetty.setHandler(wac);
        jetty.start();

Then, in a servlet:

        MyService myService = (MyService)
            getServletContext().getAttribute("myService");

Hope that helps.

  -- Guy


On 08/23/2012 07:29 AM, Evan Ruff wrote:
> Hey guys,
> So I'm looking to create an embedded Jetty server that uses WAR deployment to start my webapp.
> I'm also going to be spinning up an embedded Felix container inside of Jetty to get some plugin functionality for some services. 
> One question I have is, how can the classes in my WAR file reach out and communicate with some classes that I have in my parent application?
> I've made a silly diagram to describe what I'm talking about here: http://www.hendersonsawmill.com/arch.png
> The red arrows are the part I'm unclear on. Let's assume that there's an interface that FuntimeService implements that it is my WAR application and one of the servlets would like to use it.
> Has anyone tried something like this?
> E


Back to the top