Skip to Content
avatar image
Former Member

Adressing an object via JNDI in SAP Netweaver AS Java with Multiple Nodes

Hi,

I am trying to create a simple cache for some values in Netweaver AS Java. For that purpose I created a session bean which is accessible via web service and has two simple operations storeValue(String key, String value) and getValue(String key).

My first idea was to create a singleton object that holds the values. That fails because singletons apprently exist one time per node. Another idea was to create a serializable object and bind it in the JNDI context. Binding the object is not a problem, I can see it in the JNDI browser. But retrieving the object in my session bean is sometimes successful and sometimes it fails. It seems that it also depends on the node on which my session bean is executed.

I found this thread regarding the same topic but no answer:

https://archive.sap.com/discussions/thread/1408219

In the constructor of my session bean I have the following code:

Context ctx = null;

try {

ctx = new InitialContext();

Map<String, String> cacheValues = (Map) ctx.lookup("CacheValues");

location.infoT("LookupResult of 'CacheValues' " + cacheValues);

if (ctx != null && cacheValues == null) {

cacheValues = new HashMap<String, String>();

ctx.bind("CacheValues", cacheValues);

location.infoT("Bound new object to JNDI context");

}

} catch (Exception e) {

location.errorT("Unable to retrieve 'CacheValues'");

}

Questions:
* Is there anything wrong with my code?
* Are there distinct JNDI contexts per server node?

Any hint is appreciated.

Thanks,
Stefan

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Nov 30, 2017 at 08:09 AM

    Hello, Stefan. According to your description, Apparently the bindings are not be replicated across the JNDI tree of each server process within the cluster, That could be the root cause of your issue.

    If you need bindings to be replicated across the JNDI tree of each server process within the cluster, it has to use

    com.sap.engine.services.jndi.InitialReplicatingContextFactoryImpl instead of

    com.sap.engine.services.jndi.InitialContextFactoryImpl . when you create initialContext

    Context ctx = new InitialContext();

    If you want to get more information about NW JNDI. You can refer the link below.

    https://help.sap.com/viewer/c591e2679e104fcdb8dc8e77771ff524/7.5.9/en-US/4aeac9a0cd2823aee10000000a42189c.html

    Add comment
    10|10000 characters needed characters exceeded