This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I didn't run my client

 
Carlos Rincon
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone, I am using the Sun's RI (J2EE1.4 y Sun Java System Application Server Platform Edition 8 update 1), I created one cliente to access my EJB.

a)When I run my EJB client in this way:
java -cp .;adviceEarClient.jar AdviceClient1
where AdviceClient1 is the client class and adviceEarClient.jar containts stubs for the client.
I recive an error like:
--------------------------
javax.naming.NoInitialContextException: Need to specify class name in environmen
t or system property, or as an applet parameter, or in an application resource f
ile: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at AdviceClient1.main(AdviceClient1.java:13)
---------------------------------------------------
b)But when I run it in this way (using appclient):
appclient -client adviceEarClient.jar
it work.

c)Here is my code:
Context initial = new InitialContext();
Object o = initial.lookup("MyAdviceBean"); // <--- here is the error
AdviceHome h =(AdviceHome)PortableRemoteObject.narrow(o, AdviceHome.class);
Advice adv = home.create();

My questions are:
1) Why
java -cp .;adviceEarClient.jar AdviceClient1
dont't work, but
appclient -client adviceEarClient.jar
does?

2) I saw some book use a property o hashtable to create the initial context, something like
Hashtable props = new Hashtable();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
props.put(Context.PROVIDER_URL, "t3://weblogic:7001");
props.put(Context.SECURITY_PRINCIPAL, "fred");
props.put(Context.SECURITY_CREDENTIALS, "seafood");
Context initial = new InitialContext(props);

what are the values for Context.INITIAL_CONTEXT_FACTORY and Context.PROVIDER_URL in the case of the Sun Java System Application Server Platform Edition 8 update 1??
 
Marco Barenkamp
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

you need to specifiy how the jndi context should establish a connection.
Search for jndi.properties in the samples, e.g. and copy it into your CLASSPATH.
[ September 07, 2005: Message edited by: Marco Barenkamp ]
 
Carlos Rincon
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for repley, but the Sun Java System Application Platform's samples dont't come with
jndi.properties, either the j2eetutorial samples...
What about my 3 questions?...
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carlos,


1) Why
java -cp .;adviceEarClient.jar AdviceClient1
dont't work, but
appclient -client adviceEarClient.jar
does?

As a rule of thumb the INITIAL_CONTEXT_FACTORY and the PROVIDER_URL system properties must be defined within the environment your client code runs. The reason why your code works with the appclient is because the client container sets those properties for you. For the same very reason the same client code will work if it is deployed within a jsp or servlet (the server will initialize the environment when it starts). A local client on the other hand needs to initialize the environment using a code similar to that you�ve posted.

2) I saw some book use a property o hashtable to create the initial context, something like
Hashtable props = new Hashtable();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
props.put(Context.PROVIDER_URL, "t3://weblogic:7001");
props.put(Context.SECURITY_PRINCIPAL, "fred");
props.put(Context.SECURITY_CREDENTIALS, "seafood");
Context initial = new InitialContext(props);

what are the values for Context.INITIAL_CONTEXT_FACTORY and Context.PROVIDER_URL in the case of the Sun Java System Application Server Platform Edition 8 update 1??

I�ve never used the Sun Java System Application Server and I cannot tell you what those properties are. There is however a very easy way to find out. Modify your AdviceClient1 to print those variable just after running main():

As for the other two properties you shouldn�t bother too much. They are required only when your ejbs are jndi-protected. However this is not a good practice and j2ee recommends using JAAS. Usually anonymous binding to the jndi should always work. You can always use the System class and print all the environment variables your client container sets if you�d like to make sure whether any jndi credentials should be set.
Regards.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic