• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

I have deployed my ejb with Weblogic and I have a problem with my client

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my class, is it correct. My ejb was deployed successfully with Weblogic. I have this error when I run the class below.
error:
C:\working\Ant\client>java HelperClient name
Exception!
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 HelperClient.main(HelperClient.java:19)

<code>
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.util.Properties;
import HelperRemote;
import HelperHome;
public class HelperClient{
public static void main(String[] args) throws Exception {

//Get a reference to the bean's home interface. MyHelper01 is the JNDI name for the bean.
try {
Properties props = System.getProperties();
Context initial = new InitialContext(props);
//Context initial = new InitialContext();
Object objRef = initial.lookup("Helper01JAR");
HelperHome refToHome = (HelperHome)PortableRemoteObject.narrow(
objRef, HelperHome.class);
//Use the home reference to create the bean object and get a remote reference.
HelperRemote refToRemote = refToHome.create();

//Invoke a business method on the remote reference to the bean
String returnValue = refToRemote.aBusinessMethod("Dick Baldwin");
System.out.println("Bean returned: " + returnValue);
//Remove the bean
refToRemote.remove();
}catch (Exception ex) {
System.err.println("Exception!");
ex.printStackTrace();
}//end catch
}//end main
}//end class
</code>
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use InitialContext() without any argument only when you are calling an EJB from a servlet or another EJB.
Since, in your case, your client is ran from the command line, use this...
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"));
h.put(Context.PROVIDER_URL, "t3://localhost:7001");
Context c = new InitialContext(h);
You should change t3://localhost:7001 to reflect your own host and port settings for WLS.
SAF
 
bobby, morkos
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It still gives the same error even when I have made the changes you asked me to. My code is the following:
<code>
package examples;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Properties;
/**
* This class is an example of client code which invokes
* methods on a simple stateless session bean.
*/
public class HelloClient {
public static void main(String[] args) throws Exception {
/*
* Setup properties for JNDI initialization.
*
* These properties will be read-in from
* the command-line.
*/
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
props.put(Context.PROVIDER_URL, "http://localhost:80");
Context ctx = new InitialContext(props );
// Needs this for Servlet
//Properties props = System.getProperties();
//Context ctx = new InitialContext(props);
/*
* Obtain the JNDI initial context.
*
* The initial context is a starting point for
* connecting to a JNDI tree. We choose our JNDI
* driver, the network location of the server, etc
* by passing in the environment properties.
*/

/*
* Get a reference to the home object - the
* factory for Hello EJB Objects
*/
Object obj = ctx.lookup("HelloHome");

/*
* Home objects are RMI-IIOP objects, and so
* they must be cast into RMI-IIOP objects
* using a special RMI-IIOP cast.
*
* See Appendix X for more details on this.
*/
HelloHome home = (HelloHome)
javax.rmi.PortableRemoteObject.narrow(
obj, HelloHome.class);
/*
* Use the factory to create the Hello EJB Object
*/
Hello hello = home.create();
/*
* Call the hello() method on the EJB object. The
* EJB object will delegate the call to the bean,
* receive the result, and return it to us.
*
* We then print the result to the screen.
*/
System.out.println(hello.hello());
/*
* Done with EJB Object, so remove it.
* The container will destroy the EJB object.
*/
hello.remove();
}
}
<code>

Originally posted by SAFROLE YUTANI:
You can use InitialContext() without any argument only when you are calling an EJB from a servlet or another EJB.
Since, in your case, your client is ran from the command line, use this...
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"));
h.put(Context.PROVIDER_URL, "t3://localhost:7001");
Context c = new InitialContext(h);
You should change t3://localhost:7001 to reflect your own host and port settings for WLS.
SAF

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The port and protocol in your code is pointing to the http server:
http://localhost:80
You need to specify the protocol and port of the naming service provider. Change to:
t3://localhost:7001
Port 7001 is the default and should be correct unless you have changed it.
KJ
 
bobby, morkos
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have changed my port back from 80 to 7001 in Weblogic settings. My code is still not working,
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
props.put(Context.PROVIDER_URL, "t3://localhost:7001");
props.put(Context.SECURITY_PRINCIPAL, "system");
props.put(Context.SECURITY_CREDENTIALS, "12345678");
// Needs this for Servlet
//Properties props = System.getProperties();
Context ctx= new InitialContext(props);
Could somoene please help? Thanks in advance.

Originally posted by Kirt Henrie:
The port and protocol in your code is pointing to the http server:
http://localhost:80
You need to specify the protocol and port of the naming service provider. Change to:
t3://localhost:7001
Port 7001 is the default and should be correct unless you have changed it.
KJ

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
did u get the same error after u changed the port to 7001 ?
the solution should work...
if u can delibrate more then maybe we might find a solution
 
bobby, morkos
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works fine now. Thanks a lot.

Originally posted by zingaroo:
did u get the same error after u changed the port to 7001 ?
the solution should work...
if u can delibrate more then maybe we might find a solution

 
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic