-
1. Re: FakeInitialContext and java:/ root names
kabirkhan Apr 13, 2004 6:31 AM (in response to kabirkhan)Hi,
I'm having a slight problem with the jndi stuff for the testing. I am trying to use the jboss naming service rather than the fake contet stuff.
I have set up the jndi.properties file to be:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Next I stepped through the org.jboss.naming.NamingService.startService() method. The first bit loads up the properties from the jndi.properties file and sets the in System.properties, as expected there is no java.naming.provider.url there. Also, when I do a System.getProperty("java.naming.provider.url") at any stage nothing is returned.
However, once the first InitialContext is created and it's environment got, java.naming.provider.url is there! (i.e. it is in env below)InitialContext iniCtx = new InitialContext(); Hashtable env = iniCtx.getEnvironment();
I followed this through, and new InitialContext()
calls javax.naming.InitialContext.init() //This initialises the environment for the InitialContext
which calls javax.naming.internal.ResourceManager.getInitialEnvironment()
which calls javax.naming.internal.VersionHelper.getJndiProperties()
VersionHelper.getProperties() looks like thisString[] getJndiProperties() { if (getSystemPropsFailed) { return null; // after one failure, don't bother trying again } Properties sysProps = (Properties) AccessController.doPrivileged( new PrivilegedAction() { public Object run() { try { return System.getProperties(); } catch (SecurityException e) { getSystemPropsFailed = true; return null; } } } ); if (sysProps == null) { return null; } String[] jProps = new String[PROPS.length]; for (int i = 0; i < PROPS.length; i++) { jProps = sysProps.getProperty(PROPS); } return jProps; } String getJndiProperty(final int i) { return (String) AccessController.doPrivileged( new PrivilegedAction() { public Object run() { try { return System.getProperty(PROPS); } catch (SecurityException e) { return null; } } } ); }
In this funky looking code (which to be honest I don't understand the special bits) java.naming.provider.url and jnp://localhost:1099 are returned. I'm wondering
a) Why doesn't this appear in JBoss when starting that without the java.naming.provider.url in the jndi.properties
b) What the AccessController stuff does special to magically create the java.naming.provider.url=jnp://localhost:1099
Any ideas?
Cheers,
Kab -
2. Re: FakeInitialContext and java:/ root names
acoliver Apr 14, 2004 8:25 PM (in response to kabirkhan)Awsome, so its fixed? That was driving me nuts. Anything need to change in jndi.properties?
-
3. Re: FakeInitialContext and java:/ root names
kabirkhan Apr 15, 2004 3:18 AM (in response to kabirkhan)jndi.properties is the same
-
4. Re: FakeInitialContext and java:/ root names
kabirkhan Apr 15, 2004 6:14 AM (in response to kabirkhan)"kabkhan" wrote:
maybe it goes a bit away from the original intent, by us simply calling new InitialContext().bind()? I'm a bit confused!!!
Been reading up on naming and think it is kosher. I reckon the idea behind the FakeInitialContext is to use the contained HashMap of bindings, and not to have to rely on the NamingService. Is that correct? -
5. Re: FakeInitialContext and java:/ root names
acoliver Apr 15, 2004 6:15 AM (in response to kabirkhan)Calling the standard jboss InitialContext would have to connect to JBoss's naming service which we'd have to set up and bind stuff etc. Might work just as well if we take server/default/conf/jndi.properties and do it locally and register it in the depends-service.xml but for some reason I couldn't get it to work when I tried. I might have just left a step out so you could try it if you like.
-
6. Re: FakeInitialContext and java:/ root names
kabirkhan Apr 15, 2004 1:51 PM (in response to kabirkhan)Hi,
I'm having a slight problem with the jndi stuff for the testing. I am trying to use the jboss naming service rather than the fake contet stuff.
I have set up the jndi.properties file to be:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Next I stepped through the org.jboss.naming.NamingService.startService() method. The first bit loads up the properties from the jndi.properties file and sets the in System.properties, as expected there is no java.naming.provider.url there. Also, when I do a System.getProperty("java.naming.provider.url") at any stage nothing is returned.
However, once the first InitialContext is created and it's environment got, java.naming.provider.url is there! (i.e. it is in env below)InitialContext iniCtx = new InitialContext(); Hashtable env = iniCtx.getEnvironment();
I followed this through, and new InitialContext()
calls javax.naming.InitialContext.init() //This initialises the environment for the InitialContext
which calls javax.naming.internal.ResourceManager.getInitialEnvironment()
which calls javax.naming.internal.VersionHelper.getJndiProperties()
VersionHelper.getProperties() looks like thisString[] getJndiProperties() { if (getSystemPropsFailed) { return null; // after one failure, don't bother trying again } Properties sysProps = (Properties) AccessController.doPrivileged( new PrivilegedAction() { public Object run() { try { return System.getProperties(); } catch (SecurityException e) { getSystemPropsFailed = true; return null; } } } ); if (sysProps == null) { return null; } String[] jProps = new String[PROPS.length]; for (int i = 0; i < PROPS.length; i++) { jProps = sysProps.getProperty(PROPS); } return jProps; } String getJndiProperty(final int i) { return (String) AccessController.doPrivileged( new PrivilegedAction() { public Object run() { try { return System.getProperty(PROPS); } catch (SecurityException e) { return null; } } } ); }
In this funky looking code (which to be honest I don't understand the special bits) java.naming.provider.url and jnp://localhost:1099 are returned. I'm wondering
a) Why doesn't this appear in JBoss when starting that without the java.naming.provider.url in the jndi.properties
b) What the AccessController stuff does special to magically create the java.naming.provider.url=jnp://localhost:1099
Any ideas?
Cheers,
Kab -
7. Re: FakeInitialContext and java:/ root names
acoliver Apr 15, 2004 10:06 PM (in response to kabirkhan)Great questions. I think this is probably about where I got when I gave up and did FakeIntialContext :-)
-
8. Re: FakeInitialContext and java:/ root names
kabirkhan Apr 19, 2004 4:05 AM (in response to kabirkhan)I've been very naughty and have done a cross post regarding the jndi properties in order to reach a wider audience.
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3830929#3830929
Adrian has some comments regarding how we set up our MBeans, Andy what do you think? -
9. Re: FakeInitialContext and java:/ root names
kabirkhan Apr 19, 2004 8:34 AM (in response to kabirkhan)I have commited the changes to the head branch, so that the mail services tests now use the normal jboss naming service.
Using Adrian's suggestion
Thread.currentThread().getContextClassLoader().getResources("jndi.properties");
uncovered that java.naming.provider.url is present in twiddle.jar.
To run the unit tests, REMOVE java.naming.provider.url from jndi.properties from twiddle.jar used in your classpath.
I'm slightly curious if this could have any implications on the twiddle stuff, but it shouldn't be too important at present?
Kab -
10. Re: FakeInitialContext and java:/ root names
kabirkhan Apr 19, 2004 8:36 AM (in response to kabirkhan)PS I could only get the NamingService to work "in-jvm", setting the ports to > 0 caused whole bunch of other problems.
-
11. Re: FakeInitialContext and java:/ root names
acoliver Apr 21, 2004 1:26 PM (in response to kabirkhan)Twiddle is not the best written code in all of JBoss. Do not be afraid to make fixes to it, itself. At some point I want to make the twiddle stuff work as an example of *other* things that could be done as protocols on our stack. Plus there are things that could be done with it that might be useful (like a convienient way to set up temporary users, etc. in our script runner and an answer to JAMES's admin console thingy)..
-
12. Re: FakeInitialContext and java:/ root names
kabirkhan May 4, 2004 3:35 AM (in response to kabirkhan)No longer any need to play around with twiddle.jar. Getting the naming service to work both "in-jvm" and with sockets was simply a case of setting the bind addresses in depens-service.xml.
Cheers,
Kab