cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with InitialContest bind method

Former Member
0 Kudos

I have a servlet that do a bind to the InitialContextm but i'm not able to retrieve it from the ejb.

All is in a Enterprise Application (EAR).

in the web.xml:

....

<resource-env-ref>

<description>Unique Identification for cache</description>

<resource-env-ref-name>cache/UniqueId</resource-env-ref-name>

<resource-env-ref-type>java.lang.String</resource-env-ref-type>

</resource-env-ref>

...

in the web-j2ee-engine.xml:

...

<resource-env-ref>

<resource-env-ref-name>cache/UniqueId</resource-env-ref-name>

<jndi-name>com.dat.abs.run.ABSCache</jndi-name>

</resource-env-ref>

...

In my Servlet:

...

new InitialContext().bind("com.dat.abs.run.ABSCache", "MyTextValue");

...

in a stateless ejb session:

...

String vName = (String) (new InitialContext()).lookup("java:comp/env/cache/UniqueId");

...

But ejb cannot retrieve it, a name not found exception.

i try also to execute the bind in the same stateless ejb session, but the same problem occurs.

I get a look to the JNDI registry.

When i execute the bind from the Servlet, the bind is done under the webContainer context and when i do it in the EJB

the bind is done under the stateless ejb session context.

Instead i would like to register this bind as "server" root, like all other EJB (entity and session).

Bindig from the servlet works fine in JBoss and Websphere, but not in SAP NetWeaver Sneak Preview 6.40 SR1.

Is this a bug or there is another way to obtain this result?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Roberto,

to get the JNDI root you need to set the "domain" parameter to "true" when creating the InitialContext. If you do not set it, then the application will get the root context of its namespace (in your case, the servlet get the context relative to the webContainer namespace.)

This is also described in the J2EE Engine's documentation:

http://help.sap.com/saphelp_nw04/helpdata/en/8d/41ee1b22797c4b9d9b7ad67aa7333f/frameset.htm

Hope that helps!

Former Member
0 Kudos

Many Thanks!

Answers (0)