cancel
Showing results for 
Search instead for 
Did you mean: 

Arbitrary JNDI names

Former Member
0 Kudos

I am trying to deploy a session bean by specifying an arbitrary JNDI name in the file ejb-j2ee-engine.xml

as below

<?xml version="1.0" encoding="UTF-8"?>
<ejb-j2ee-engine xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ejb-j2ee-engine_3_0.xsd">
	<enterprise-beans>
		<enterprise-bean>
			<ejb-name>XyzServiceImpl</ejb-name>
			<jndi-name>XyzBean</jndi-name>
		</enterprise-bean>
	</enterprise-beans>
</ejb-j2ee-engine>

My client is a pure java client (not residing in the container). When I try to lookup the using the JNDI name in the client, I get the following exception. For some reason the lookup fails when I use the JNID name from ejb-j2ee-engine.xml. But when I lookup using the default name provided by the container when the session bean is deployed the lookup works.

com.sap.engine.services.jndi.persistent.exceptions.NameNotFoundException: Object not found in lookup of XyzBean.
	at com.sap.engine.services.jndi.implserver.ServerContextImpl.lookup(ServerContextImpl.java:633)
	at com.sap.engine.services.jndi.implserver.ServerContextRedirectableImpl.lookup(ServerContextRedirectableImpl.java:80)
	at com.sap.engine.services.jndi.implserver.ServerContextRedirectableImplp4_Skel.dispatch(ServerContextRedirectableImplp4_Skel.java:872)
	at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:447)
	at com.sap.engine.services.rmi_p4.server.ServerDispatchImpl.run(ServerDispatchImpl.java:69)
	at com.sap.engine.services.rmi_p4.P4Message.process(P4Message.java:67)
	at com.sap.engine.services.rmi_p4.P4Message.execute(P4Message.java:41)
	at com.sap.engine.services.cross.fca.FCAConnectorImpl.executeRequest(FCAConnectorImpl.java:977)
	at com.sap.engine.services.rmi_p4.P4Message.process(P4Message.java:57)
	at com.sap.engine.services.cross.fca.MessageReader.run(MessageReader.java:55)
	at com.sap.engine.core.thread.execution.Executable.run(Executable.java:110)
	at com.sap.engine.core.thread.execution.CentralExecutor$SingleThread.run(CentralExecutor.java:314)

My sample client code looks like this

	public TnAService lookupXyzBean() {
		InitialContext context = getContext();
		XyzRemote service = null;
		try {
			if(context!=null) {
				service= (XyzRemote )context.lookup(JNDI);
				context.lookup("XyzBean");
				if(service!=null)
					System.out.println("Lookup succeeded......");
				else
					System.out.println("No object bound to "+JNDI);
			}
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return service;
	}
	
	private static InitialContext getContext() {

		Properties context = new Properties();
		context.put(InitialContext.PROVIDER_URL, PROVIDER_URL);
		context.put(InitialContext.INITIAL_CONTEXT_FACTORY, 
				INIT_CTX_FACT);
		context.put(InitialContext.SECURITY_PRINCIPAL, "user");
		context.put(InitialContext.SECURITY_CREDENTIALS, "password");
		context.put(InitialContext.URL_PKG_PREFIXES, "com.sap.engine.services");
		InitialContext ctx = null;
		try {
			ctx = new InitialContext(context);
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		return ctx;
	}

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Vladimir,

Thanks for the clarification. But then is there anyway we can have control over the JNDI names if jndi-name is not supported for EJB3.0 ? I want all the beans we develop to follow a certain naming standard and thats the reason why I am looking for a solution for this.

Best Regards,

Chris

Vlado
Advisor
Advisor
0 Kudos

Hi Chris,

Have you gone through the help page linked above? I believe you have control over all names that can be used in the EJB scheme (i.e. appName, jarName, beanName, interfaceName).

btw, are you trying to lookup a home interface or a business interface?

\-- Vladimir

Former Member
0 Kudos

Hi Vladimir,

Yes I have gone through the help document and it was helpful. By the way I am trying to lookup a business interface. Yes we do have control in the means of appName, jarName, beanName, interfaceName. But I understand that having arbitrary names is discouraged as there could be name clashes...and hence an automatically constructed string from appName, jarName, beanName, interfaceName will be used to lookup. Thanks for your help.

Best Regards,

Chris

Vlado
Advisor
Advisor
0 Kudos

This jndi-name is only for EJB 2.x style home interfaces. It's not applicable to EJB 3.0 business interfaces. Please refer to this [help page|http://help.sap.com/saphelp_nwce10/helpdata/en/45/e692b2cfaa5591e10000000a1553f7/frameset.htm] for more info.

HTH!

\-- Vladimir