Skip to Content
author's profile photo Former Member
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 a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on 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 a 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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.