You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by Mark Aufdencamp <ma...@aufdencamp.com> on 2008/11/17 20:57:57 UTC
JNDI Context Lookup Help
Hi All,
It's been a while since I had to ask for help from the list, but I hit a
snag migrating an application from G-1.1.1 to G-2.1.3. Specifically,
I'm having a problem with a JNDI context lookup inside a
ServletContextListener. I presume this is a problem with the move to a
global JNDI namespace in G-1.2 and forward. I have had the same result
in 1.2-beta and 2.1.3. The Documentation and Google have not helped me
here.
I'm looking up an <env-entry> defined in the web.xml:
<env-entry>
<env-entry-name>web/ContentLocation</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>/SomeDirectoryHeirarchyName/</env-entry-value>
</env-entry>
Access code as follows:
String contentLocation = null;
String contentLocationJNDIName = "java:/comp/env/web/ContentLocation";
Context ctx = null;
boolean initialContextSuccess = false;
try {
ctx = new InitialContext();
initialContextSuccess = true;
} catch (NamingException namingException){
namingException.printStackTrace();
}
if(initialContextSuccess){
try{
contentLocation = (String) ctx.lookup(contentLocationJNDIName);
} catch(NamingException namingException){
namingException.printStackTrace();
}
} else{
// Error Handling
}
The ctx.lookup() throws a javax.naming.NotContextException:
comp/env/web/ContentLocation.
Do I need to define Properties for the InitialContext Factory, add
something to my geronimo-web.xml plan, or utilize a different JNDI name?
Thanks for your help,
Mark Aufdencamp
Mark@Aufdencamp.com
Re: JNDI Context Lookup Help
Posted by Łukasz Budnik <lu...@gmail.com>.
Hi Mark,
I had similar problems with Geronimo 2.1.
You can check out my simple method for traversing JNDI:
private void traverse(Context ctx, String path) throws NamingException {
// lists all contents of current context
NamingEnumeration<Binding> ne = ctx.listBindings("");
while (ne.hasMore()) {
Binding b = ne.next();
String name = path + "/" + b.getName();
// if current object is a context, traverse it
if (b.getObject() instanceof Context) {
traverse((Context) b.getObject(), name);
}
// otherwise print out object's name and its class
else {
logger.debug(name + " ==> " + b.getClassName());
}
}
}
invoke it like this:
Context c = new InitialContext();
traverse(c, "java:comp/env");
You can read more here:
http://jee-bpel-soa.blogspot.com/2008/09/traversing-jndi-directory.html
hope it helps :)
best regards
Łukasz
2008/11/17 Mark Aufdencamp <ma...@aufdencamp.com>:
> Hi All,
>
> It's been a while since I had to ask for help from the list, but I hit a
> snag migrating an application from G-1.1.1 to G-2.1.3. Specifically,
> I'm having a problem with a JNDI context lookup inside a
> ServletContextListener. I presume this is a problem with the move to a
> global JNDI namespace in G-1.2 and forward. I have had the same result
> in 1.2-beta and 2.1.3. The Documentation and Google have not helped me
> here.
>
> I'm looking up an <env-entry> defined in the web.xml:
>
> <env-entry>
> <env-entry-name>web/ContentLocation</env-entry-name>
> <env-entry-type>java.lang.String</env-entry-type>
> <env-entry-value>/SomeDirectoryHeirarchyName/</env-entry-value>
> </env-entry>
>
>
> Access code as follows:
>
> String contentLocation = null;
> String contentLocationJNDIName = "java:/comp/env/web/ContentLocation";
>
> Context ctx = null;
> boolean initialContextSuccess = false;
> try {
> ctx = new InitialContext();
> initialContextSuccess = true;
> } catch (NamingException namingException){
> namingException.printStackTrace();
> }
>
> if(initialContextSuccess){
> try{
> contentLocation = (String) ctx.lookup(contentLocationJNDIName);
> } catch(NamingException namingException){
> namingException.printStackTrace();
> }
> } else{
> // Error Handling
> }
>
>
> The ctx.lookup() throws a javax.naming.NotContextException:
> comp/env/web/ContentLocation.
>
> Do I need to define Properties for the InitialContext Factory, add
> something to my geronimo-web.xml plan, or utilize a different JNDI name?
>
> Thanks for your help,
>
> Mark Aufdencamp
> Mark@Aufdencamp.com
>
>
>
>
>
>
>
>
Re: JNDI Context Lookup Help
Posted by David Jencks <da...@yahoo.com>.
Shouldn't your name be java:comp/env/web/ContentLocation (no slash
before the comp)?
thanks
david jencks
On Nov 17, 2008, at 11:57 AM, Mark Aufdencamp wrote:
> Hi All,
>
> It's been a while since I had to ask for help from the list, but I
> hit a
> snag migrating an application from G-1.1.1 to G-2.1.3. Specifically,
> I'm having a problem with a JNDI context lookup inside a
> ServletContextListener. I presume this is a problem with the move
> to a
> global JNDI namespace in G-1.2 and forward. I have had the same
> result
> in 1.2-beta and 2.1.3. The Documentation and Google have not helped
> me
> here.
>
> I'm looking up an <env-entry> defined in the web.xml:
>
> <env-entry>
> <env-entry-name>web/ContentLocation</env-entry-name>
> <env-entry-type>java.lang.String</env-entry-type>
> <env-entry-value>/SomeDirectoryHeirarchyName/</env-entry-value>
> </env-entry>
>
>
> Access code as follows:
>
> String contentLocation = null;
> String contentLocationJNDIName = "java:/comp/env/web/ContentLocation";
>
> Context ctx = null;
> boolean initialContextSuccess = false;
> try {
> ctx = new InitialContext();
> initialContextSuccess = true;
> } catch (NamingException namingException){
> namingException.printStackTrace();
> }
>
> if(initialContextSuccess){
> try{
> contentLocation = (String) ctx.lookup(contentLocationJNDIName);
> } catch(NamingException namingException){
> namingException.printStackTrace();
> }
> } else{
> // Error Handling
> }
>
>
> The ctx.lookup() throws a javax.naming.NotContextException:
> comp/env/web/ContentLocation.
>
> Do I need to define Properties for the InitialContext Factory, add
> something to my geronimo-web.xml plan, or utilize a different JNDI
> name?
>
> Thanks for your help,
>
> Mark Aufdencamp
> Mark@Aufdencamp.com
>
>
>
>
>
>
>