Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initial Context property values for EJB lookup

I am learning basics of EJB 3.0. I have managed to get a sample code up and running. Now I am doing a line by line analysis to have in-depth knowledge. But I am stuck at few lines where there is a lookup to find the required bean.

Can anyone please explain me in simple language the meaning and the need of the following lines?

Properties properties = new Properties();
properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs", "org.jboss.naming rg.jnp.interfaces");
properties.setProperty(Context.PROVIDER_URL, "localhost:1099");

IniialContext context = null;
SamleEjbRemote cl = null;
try {
    context = new InitialContext(properties);
    cl = (SampleEjbRemote) context.lookup("SampleEjbBean/remote");
} catch (NamingException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}


What is the exact meaning of each of the 'key' and 'value' that is used in properties?

Rest of it is to put the 'properties' in the initial context instance. I have had a very vague idea of the above, but I want to clarify it very clearly. I would be glad if anyone could point me to any links or insights about the above lines.

Thanks in advance.

like image 884
h-kach Avatar asked Mar 30 '12 05:03

h-kach


People also ask

What is Initial context JNDI?

This class is the starting context for performing naming operations. All naming operations are relative to a context. The initial context implements the Context interface and provides the starting point for resolution of names. The initial context implementation is determined at runtime.

How does EJB lookup work?

The actual home lookup name is determined by the application's deployment descriptors. The enterprise bean (EJB) resides in an EJB container, which provides an interface between the bean and the application server on which it resides.

What are JNDI properties?

An application resource file has the name jndi. properties. It contains a list of key/value pairs presented in the properties file format (see java. util.

What is initial context factory in Java?

Interface InitialContextFactoryThis interface represents a factory that creates an initial context. The JNDI framework allows for different initial context implementations to be specified at runtime. The initial context is created using an initial context factory.


1 Answers

Both properties configures JBoss JNDI HTTP InitialContext Factory Implementation

Official document here : http://docs.jboss.org/jbossas/jboss4guide/r1/html/ch3.chapter.html

See chapter 3.2.1.2. The HTTP InitialContext Factory Implementation

java.naming.factory.initial: The name of the environment property for specifying the initial context factory, which must be org.jboss.naming.HttpNamingContextFactory.

java.naming.factory.url.pkgs: For all JBoss JNDI provider this must be org.jboss.naming:org.jnp.interfaces. This property is essential for locating the jnp: and java: URL context factories of the JBoss JNDI provider.

UPDATE:

I would recommend to use jndi.properties file in your class path

### JBossNS properties
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
like image 76
rkosegi Avatar answered Sep 24 '22 20:09

rkosegi