Initial Context property values for EJB lookup
Asked Answered
P

1

5

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.

Pill answered 30/3, 2012 at 5:12 Comment(0)
D
7

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
Dashed answered 30/3, 2012 at 5:24 Comment(15)
Currently I am behind firewall and the site is blocked! Thanks for reply. But can I get better explanation as to why it is used?Pill
This is funny, URL is official RedHat Jboss documentation.I can sent you by mail if you want.This document you "must" read to undrestand why it is used.Dashed
yea I know. Sure, you can send it to [email protected] . Also, I have asked the admin guys to look into it! Thanks.Pill
Just sent, when you finish reading and have more questions, let me knowDashed
yea, got it now.. I will go through it and let you know. Thanks a lot.Pill
hey I went thorough the doc you sent me. Got a question, does package prefixes mean 'jnp:' in jnp://www.jboss.org:1099/ ?? I mean , first part of the URL provider?Pill
The jnp: portion of the URL is the protocol and refers to the socket/RMI based protocol used by JBoss.In other words is URL scheme prefix for java.naming.provider.Dashed
is it same as the package prefix used by java.naming.factory.url.pkgs? Also they have mentioned 2 package prefix, one is java: and other jnp: . is this the same used for java naming provider?Pill
No, it's fully qualified class name like org.jboss.naming:org.jnp.interfaces without any prefix.See my updated answerDashed
The package prefix in org.jboss.naming:org.jnp.interfaces is used to locate jnp: , java: and the likes??Pill
Well, I have gone through it again and this is my understanding, Please tell me if I am correct. 'org.jboss.naming' and/or 'org.jnp.interfaces' are the package prefixes used to search for the URL "SampleEjbBean/remote" passed to lookup() in the 'jnp:' and 'java:' URL context factories of the JBoss JNDI provider. Is this correct? P.S : Please see my updated code.Pill
Did you have anything to add?? I mean , what could have been your bigger answer ? :)Pill
In longer answer, yes. I'm just wondering why you need to know this detail.Do you have some problem with it?I mean some error, stacktrace, etc ..Dashed
@rkosegi.. oh, I am not facing any problem, Just for knowledge. I want to clearly know why I am using each line of my JAVA code. I do not want to just copy and paste my codes. Thanks a lot for your patience and support.Pill
You're welcome, it's best approach to know what your coding.Thumbs up.Dashed

© 2022 - 2024 — McMap. All rights reserved.