Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] WebAppContext setAttribute()


I have setup the following Jetty embedded server and my own object in the following way.

            MessagebusContainer messagebus  = new MessagebusContainer();
            server = new Server(serverPort);
 
            WebAppContext webapp = new WebAppContext();
            webapp.setContextPath("/");
            webapp.setWar(user_dir + "/webapps/my.war");
            webapp.setAttribute("messagebus", messagebus);

            HandlerCollection handlers = new HandlerCollection();
            handlers.setHandlers(new Handler[]{webapp, new DefaultHandler()});

            server.setHandler(handlers);

            server.start();
            server.join();

Then in my war I have the following code in my servlet.

        MessagebusContainer messagebus = (MessagebusContainer) request.getServletContext().getAttribute("messagebus");

and I have tried.

        MessagebusContainer messagebus = (MessagebusContainer) request.getAttribute("messagebus");
 
but messagebus object is always NULL. Is there a way to pass objects to servlets through the context? 

The following is maven dependency list that is compiled into the jar.

INFO]    javax.el:javax.el-api:jar:2.2.4:compile
[INFO]    javax.servlet.jsp:javax.servlet.jsp-api:jar:2.2.1:compile
[INFO]    javax.servlet.jsp:jsp-api:jar:2.2:compile
[INFO]    junit:junit:jar:4.10:test
[INFO]    org.eclipse.jetty:jetty-continuation:jar:8.1.7.v20120910:compile
[INFO]    org.eclipse.jetty:jetty-http:jar:8.1.7.v20120910:compile
[INFO]    org.eclipse.jetty:jetty-io:jar:8.1.7.v20120910:compile
[INFO]    org.eclipse.jetty:jetty-security:jar:8.1.7.v20120910:compile
[INFO]    org.eclipse.jetty:jetty-server:jar:8.1.7.v20120910:compile
[INFO]    org.eclipse.jetty:jetty-servlet:jar:8.1.7.v20120910:compile
[INFO]    org.eclipse.jetty:jetty-util:jar:8.1.7.v20120910:compile
[INFO]    org.eclipse.jetty:jetty-webapp:jar:8.1.7.v20120910:compile
[INFO]    org.eclipse.jetty:jetty-xml:jar:8.1.7.v20120910:compile
[INFO]    org.eclipse.jetty.aggregate:jetty-all:jar:8.1.7.v20120910:compile
[INFO]    org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016:compile
[INFO]    org.glassfish.web:javax.el:jar:2.2.4:compile
[INFO]    org.glassfish.web:javax.servlet.jsp:jar:2.2.4:compile
[INFO]    org.glassfish.web:javax.servlet.jsp.jstl:jar:1.2.2:compile
[INFO]    org.hamcrest:hamcrest-core:jar:1.1:test
[INFO]    org.jeuron:jeuron-all:jar:1.3.0:compile
[INFO]    org.jeuron:jeuron-boot:jar:1.3.0:compile
[INFO]    org.jeuron:jeuron-common:jar:1.3.0:compile
[INFO]    org.jeuron:jeuron-deployer:jar:1.3.0:compile
[INFO]    org.jeuron:jeuron-loader:jar:1.3.0:compile
[INFO]    org.jeuron:jeuron-messagebus:jar:1.3.0:compile
[INFO]    org.jeuron:jeuron-transport:jar:1.3.0:compile

Thanks in advance,
Mike Karrys



Back to the top