wood burning stoves*
The moose likes EJB and other Java EE Technologies and the fly likes JNDI not creating for EJB Local interfaces example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JNDI not creating for EJB Local interfaces example" Watch "JNDI not creating for EJB Local interfaces example" New topic
Author

JNDI not creating for EJB Local interfaces example

murali kankanala
Ranch Hand

Joined: Nov 15, 2004
Posts: 110
Hi Friends,

I have created an EJB example with Local interfaces. My problem is its not creating a JNDI name inside JNDI tree.
Its not showing any issues when i start the weblogic server. Other Session beans are deplolyed properly.

Below i am giving the code.

EJBLocal Interface:



EJBLocal Home Interface:



Bean Impl:



ejb-jar.xml



weblogic-ejb-jar.xml

Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 787

murali wrote:My problem is its not creating a JNDI name inside JNDI tree.

How you know that JNDI is not creating?
According to my thinking by using JNDI we will get to reference of remote.
Please clear me


SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
murali kankanala
Ranch Hand

Joined: Nov 15, 2004
Posts: 110
Hi,

I forgot to paste my client code ( stand alone but not web app).




When i deploy the local interfaces ejb its success.



But in the JNDI tree the name is not there, so when i run my client code its giving me the following error.



Even i tried differently as follows:



Then i got the following exception.


Please help me with.
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 787

@ Murali
1. Check if JNDI is created or not in your weblogic server
2. Use and cast it to CalculatorLocalHome then use that reference and call create method then you will get CalculatorLocal object then call your required method

Correct me if wrong
murali kankanala
Ranch Hand

Joined: Nov 15, 2004
Posts: 110
JNDI name not created in the Weblogic JNDI tree.

I tried as you mentioned

No luck.
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 787

Then JNDI name should be created in you weblogic server
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 787

Which version of weblogic server you are using?
Vishwanath Krishnamurthi
Ranch Hand

Joined: Jun 04, 2007
Posts: 331
Hi Murali,

When you want to get a session bean instance from a standalone-java-client, get it through a remote interface.

This is because, the standalone-java-client runs in one JVM instance and the web-app code in another JVM instance. If the client is a the web-client running in the same JVM, local interface should suffice.

HTH,
Vishwa


Blog
murali kankanala
Ranch Hand

Joined: Nov 15, 2004
Posts: 110
Hi Vishwanath,

Now i realized that Local EJB means that should be part the same JVM/inside same server ( i knew this basics for forgot - thanks for reminding me).
As you said i moved this look up code from my standalone program to the another EJB impl Bean i have written some test method in that bean impl and pasted this local interface look up code. There also its giving same exception

Vj Vjj
Greenhorn

Joined: Aug 11, 2010
Posts: 1
Even I am getting the same exception:
My Directory structure is given in attachment
This is the code of clientBean.java which is accessing the EJB:

package example;

import java.rmi.RemoteException;
import java.util.Hashtable;

import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;

public class ClientBean {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
TestSessionBeanHome testSessionBean;
try {
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:5070");
InitialContext ctx = new InitialContext(ht);
//Look up the home or factory object on the WebLogic JNDI tree
Object objref = ctx.lookup("TestSessionBean");
if (objref == null)
{
System.out.println("problem in getting Home object");
}
testSessionBean= (TestSessionBeanHome)objref;
//testSessionBean = (TestSessionBeanHome)PortableRemoteObject.narrow(objref,TestSessionBeanHome.class);
System.out.println("Calling Session Bean");
TestSessionBean beanRemote;
beanRemote = testSessionBean.create();
beanRemote.SayHello();
beanRemote.remove();
//close the InitialContext
ctx.close( );


} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CreateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoveException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}




}

}

This is the Remote Object TestSessionBean.java

package example;
import javax.ejb.*;
public interface TestSessionBean extends javax.ejb.EJBObject{
public String SayHello() throws java.rmi.RemoteException;

}

This is the Home Interface TestSessionBeanHome.java

package example;
import javax.ejb.*;
public interface TestSessionBeanHome extends javax.ejb.EJBHome {
public example.TestSessionBean create()throws javax.ejb.CreateException,java.rmi.RemoteException;
}

This is the SessionBean MyTestSessionBean.java


package example;

import javax.ejb.*;
import java.rmi.RemoteException;

public class MyTestSessionBean implements SessionBean{
public void ejbCreate()throws CreateException{

}
public void setSessionContext(SessionContext aContext)throws EJBException{

}
public void ejbActivate()throws EJBException{

}
public void ejbPassivate()throws EJBException{

}
public void ejbRemove()throws EJBException{

}
public String SayHello(){
String msg="Hello World";
System.out.println(msg);
return msg;
}
}

EJB-JAR:
\<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>

<description>EJB Examples</description>
<display-name>EJB Examples</display-name>

<enterprise-beans>

<!-- Session Beans -->
<session>
<description>EJB Test Session Bean</description>
<display-name>EJB Test Session Bean</display-name>

<ejb-name>TestSessionBean</ejb-name>

<home>example.TestSessionBeanHome</home>
<remote>example.TestSessionBean</remote>
<ejb-class>example.MyTestSessionBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>

<env-entry>
<env-entry-name>TestSessionBean</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>Test Bean</env-entry-value>
</env-entry>

</session>

</enterprise-beans>
</ejb-jar>

WEBLOGIC_EJB_JAR:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC
"-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN"
"http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd" >


<weblogic-ejb-jar>
<description>Session Bean Example</description>
<weblogic-enterprise-bean>
<ejb-name>TestSessionBean</ejb-name>
<stateless-session-descriptor>
</stateless-session-descriptor>
<reference-descriptor>
</reference-descriptor>
<jndi-name>TestSessionBean</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>

and finally the error while running the client code in ecclipse after deploying the jar on weblogic 8.1 server:

javax.naming.NameNotFoundException: Unable to resolve 'TestSessionBean' Resolved [Root exception is javax.naming.NameNotFoundException: Unable to resolve 'TestSessionBean' Resolved ]; remaining name 'TestSessionBean'
at weblogic.rjvm.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:108)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:290)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:248)
at weblogic.jndi.internal.ServerNamingNode_816_WLStub.lookup(Unknown Source)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:375)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:363)
at javax.naming.InitialContext.lookup(Unknown Source)
at example.ClientBean.main(ClientBean.java:24)
Caused by: javax.naming.NameNotFoundException: Unable to resolve 'TestSessionBean' Resolved
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:924)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:230)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:154)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:188)
at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:491)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:120)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:434)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:429)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:35)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)

Please help


[Thumbnail for Directory_Structure.JPG]

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JNDI not creating for EJB Local interfaces example