Skip to Content
avatar image
Former Member

Only a Single Environment Entry?

I have an EJB project with a stateless session bean and an entity bean. When I run the session bean and call showContext from my ejbCreate, I get only a single environment entry. Why would I only be able to see one environment entry when there are three in the ejb-jar file?

Dale

public void ejbCreate() throws CreateException {
	try {
		InitialContext ic = new InitialContext();
		showContext(ic, "");
// etc............

private void showContext(InitialContext ic, String starting) throws NamingException {
	NamingEnumeration e = null;
	try {
		e = ic.list(starting);
	} catch (NamingException ignore) {
	}
	if (e != null && e.hasMoreElements()) {
		while (e.hasMoreElements()) {
			showContext(ic,	starting + "/" + ((NameClassPair) e.next()).getName());
		}
	} else {
		myLogger("Endpoint Element [" + starting + "]");
	}
}

Here's the output I get:

1.7 : Endpoint Element [/java:comp/ORB]
1.7 : Endpoint Element [/java:comp/HandleDelegate]
1.7 : Endpoint Element [/java:comp/env/MyEnvEntryUnderLeague]

But looking in my ejb-jar file, I have several environment entries:

<ejb-jar>
..
	<enterprise-beans>
		<session>
..
			<env-entry>
				<description>this is description of blah blah blah</description>
				<env-entry-name>MyEnvEntryUnderLeague</env-entry-name>
				<env-entry-type>java.lang.String</env-entry-type>
				<env-entry-value>blahblahblah</env-entry-value>
			</env-entry>
		</session>
		<entity>
..
			<env-entry>
				<description>description of player env ent</description>
				<env-entry-name>NewestEnvEntryUnderPlayer</env-entry-name>
				<env-entry-type>java.lang.String</env-entry-type>
				<env-entry-value>blah</env-entry-value>
			</env-entry>
		</entity>
		<entity>
..
			<env-entry>
				<description>description of entry under team</description>
				<env-entry-name>EnvEntryUnderTeam</env-entry-name>
				<env-entry-type>java.lang.String</env-entry-type>
				<env-entry-value>teamdata</env-entry-value>
			</env-entry>
		</entity>
	</enterprise-beans>
...

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Jul 02, 2004 at 05:53 PM

    Hi Dale,

    well, if you use

    showContext(ic,	starting + "/" + ((NameClassPair) e.next()).getName());

    recursively and always use the last found name plus "starting" for the next invocation, you will only get the first one and the next, if it starts with the complete last part. Too complex? Ok, the following virtual entry names would work:

    [/java:comp/env/MyEnvEntryUnderLeague]
    [/java:comp/env/MyEnvEntryUnderLeague/EnvEntryUnderTeam]
    [/java:comp/env/MyEnvEntryUnderLeague/EnvEntryUnderTeam/NewestEnvEntryUnderPlayer]

    but what you have is:

    [/java:comp/env/MyEnvEntryUnderLeague]
    [/java:comp/env/EnvEntryUnderTeam]
    [/java:comp/env/NewestEnvEntryUnderPlayer]

    Better luck next time 😉

    Hope that helps.

    Regards

    Stefan

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Stefan, Thanks for the pointer to the JNDI stuff in the visual admin. I had not thought of checking there. Good idea.

      I think that the reason I can't see the environment entries from other beans is that you're not supposed to be able to see them! So the platform is doing what it's supposed to be doing... keeping the env for this bean only for this bean and no other.

      Dale