[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [jetty-users] Binding Weld BeanManager to JNDI in servlet.Context // Installing Weld / Seam-Wicket programatically
|
Hi Ondra,
FYI the jetty jndi libary allows you to bind your jndi entries to
the context, or to the server, or to the jvm as a whole (== new
Resource (null, "BeanManager", ref)).
To retrieve an object bound using the NamingEntry classes, try
using the NamingEntryUtil.lookup() method. Supposing you have bound
"BeanManager" as:
new Resource( ctx, "BeanManager", ref );
then you can retrieve it with:
NamingEntryUtil.lookup(ctx, "BeanManager");
Alternatively, you not use jetty's convenience classes for scoping
names to servlet contexts/servers etc, and simply manage the namespace
yourself using standard jndi calls. The underlying
jndi impl will be provided by jetty, if you have jetty-jndi jar
in your classpath:
InitialContext ic = new InitialContext();
ic.bind("BeanManager", ref);
...
ic.lookup("BeanManager");
hope that helps,
Jan
On 13/04/11 13:07, Ondřej Žižka wrote:
I am still struggling with $SUBJ.
The problem narrowed down to not being able to bind JNDI to a
servlet.Context with context path "/".
All examples show how to work with WebAppContext.
I don't want to use WebAppContext because I don't have a WAR with
files, only a servlet class, and Jetty bootstrapped manually.
Inside it works so that the JNDI prefix is context.toString(), thus
the whole name is "org.mortbay.jetty.servlet.Context@1a8dfb3
<mailto:org.mortbay.jetty.servlet.Context@1a8dfb3>{_,null}/__/BeanManager"
which is obviously wrong.
I've tried to put the object to JNDI every way I could think up, even
"manually" (see below), but nothing worked. Weld still says,
SEVERE: unavailable
org.jboss.seam.solder.beanManager.BeanManagerUnavailableException:
Failed to locate BeanManager using any of these providers:
org.jboss.seam.solder.beanManager.DefaultJndiBeanManagerProvider(11),
org.jboss.seam.solder.beanManager.ServletContainerJndiBeanManagerProvider(10)
at
org.jboss.seam.solder.beanManager.BeanManagerLocator.getBeanManager(BeanManagerLocator.java:91)
at
org.jboss.seam.wicket.SeamApplication.internalInit(SeamApplication.java:54)
at
org.apache.wicket.protocol.http.WicketFilter.init(WicketFilter.java:723)
...
Whole app, as it is now, is here:
https://ondrazizka.googlecode.com/svn/trunk/bots/JawaBot/branches/2.0/
Any ideas?
Any examples on how to bind object to Context's JNDI?
Thanks,
Ondra
---------
Server server = new Server( 8080 );
Context ctx = new Context( server, "/", Context.NO_SECURITY |
Context.SESSIONS );
// Wicket.
final ServletHolder wicketSH = new ServletHolder( new
MyReloadingWicketServlet() );
wicketSH.setInitParameter( "applicationClassName",
WicketApplication.class.getName() );
ctx.addServlet( wicketSH, "/*" );
XmlConfiguration confJettyEnv = new XmlConfiguration(
RunInJetty.class.getResourceAsStream("/WEB-INF/jetty-env.xml") );
confJettyEnv.configure(ctx);
javax.naming.Reference ref =
new javax.naming.Reference(
javax.enterprise.inject.spi.BeanManager.class.getName(),
//"org.jboss.weld.resources.ManagerObjectFactory",
org.jboss.weld.resources.ManagerObjectFactory.class.getName(),
null
);
//BeanManagerLookup.getBeanManagerJndiName();
Resource resource = new org.mortbay.jetty.plus.naming.Resource( ctx,
"BeanManager", ref );
EnvEntry envEntry = new org.mortbay.jetty.plus.naming.EnvEntry( ctx,
"BeanManager", ref, true );
InitialContext ic = new InitialContext();
NameParser parser = ic.getNameParser("");
//Name prefix = NamingEntryUtil.getNameForScope(scope);
Name prefix = parser.parse("").add("_");
//bind the NamingEntry into the context
Name namingEntryName = NamingEntryUtil.makeNamingEntryName(parser,
"BeanManager");
namingEntryName.addAll(0, prefix);
String namingEntryNameString = namingEntryName.toString();
NamingUtil.bind( ic, namingEntryNameString, envEntry );
//bind the object as well
Name objectName = parser.parse("BeanManager");
objectName.addAll(0, prefix);
String objectNameString = objectName.toString();
NamingUtil.bind(ic, objectNameString, ref);
NamingUtil.bind(ic, "BeanManager", ref);
NamingUtil.bind(ic, "/BeanManager", ref);
NamingUtil.bind(ic, "env/BeanManager", ref);
NamingUtil.bind(ic, "/env/BeanManager", ref);
NamingUtil.bind(ic, "_/BeanManager", ref);
NamingUtil.bind(ic, "_/env/BeanManager", ref);
// Add WELD listener by hand.
ctx.addEventListener( new org.jboss.weld.environment.servlet.Listener() );
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users
--
Jan Bartel, Webtide LLC | janb@xxxxxxxxxxx | http://www.webtide.com