WebAppContext.setAttribute() is at the entire WebApp level.
Yet ServletContext is at a specific Servlet level.

Using embedded mode, one way to accomplish what you want is to to specify
the ServletContexts manually,
http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ManyServletContexts.java?h=jetty-8

And the ServletContextHandler.setAttribute() calls would have the effect
you are looking for.

--
Joakim Erdfelt <[email protected]>
webtide.com <http://www.webtide.com/>
Developer advice, services and support
from the Jetty & CometD experts
eclipse.org/jetty - cometd.org



On Sat, Nov 10, 2012 at 7:07 PM, Michael Karrys <[email protected]> wrote:

>
>
> 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
>
> _______________________________________________
> jetty-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
_______________________________________________
jetty-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/jetty-users

Reply via email to