aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Exception accessing Local EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Exception accessing Local EJB" Watch "Exception accessing Local EJB" New topic
Author

Exception accessing Local EJB

satyajit bhosale
Greenhorn

Joined: Jun 15, 2006
Posts: 10
hi,

I am getting following exception while accessing LOCAL ejb --

Exception in thread "main" java.lang.NullPointerException
at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java:110)
at $Proxy0.create(Unknown Source)
at MyLocalEJBClient.main(MyLocalEJBClient.java:26)

I am using JBoss.
And this is my Client code --
-------------------------------------------------------------------
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "localhost");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming rg.jnp.interfaces");
MyLocalEJB localEJB;

try {
Context ctx = new InitialContext(env);
Object obj = ctx.lookup("MyLocalEJB");

MyLocalEJBHome home = (MyLocalEJBHome) obj;
localEJB = home.create();
localEJB.hi();

} catch (NamingException e) {
e.printStackTrace();
} catch (CreateException e) {
e.printStackTrace();
}

-------------------------------------------------------------------

Can anybody please help?


Thanks,
Satyajit
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
It's good to note that you are using EJB 2.0.

Also, Use Code Tags, and there's a check box at the bottom of the post/edit page where you can turn off smiley interpretation.

Sorry, don't know your problem.

More stack trace, and more code would be useful.


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
satyajit bhosale
Greenhorn

Joined: Jun 15, 2006
Posts: 10
hi,

I am using JBoss as Application Server.
These are the details of my code for accessing Local ejb -

1. Client : MyLocalEJBClient.java -
----------------------------------

public static void main(String[] args) {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "localhost");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.namingrg.jnp.interfaces");
MyLocalEJB localEJB;

try {
Context ctx = new InitialContext(env);
Object obj = ctx.lookup("MyLocalEJB");

MyLocalEJBHome home = (MyLocalEJBHome) obj;
localEJB = home.create();
localEJB.hi();

} catch (NamingException e) {
e.printStackTrace();
} catch (CreateException e) {
e.printStackTrace();
}

}
==================================================================

2. Local interface : MyLocalEJB.java -
---------------------------------
public interface MyLocalEJB extends EJBLocalObject {
public void hi();
}
==================================================================

3. LocalHome interface : MyLocalEJBHome.java
-------------------
public interface MyLocalEJBHome extends EJBLocalHome {
public MyLocalEJB create() throws CreateException;
}
==================================================================

4. Bean class: MyLocalEJBBean -
---------------------------

public class MyLocalEJBBean implements SessionBean {

SessionContext ctx = null;

public void ejbCreate() throws EJBException {
System.out.println("ejbCreate() ...");
}

public void ejbActivate() throws EJBException {
System.out.println("ejbActivate()...");
}

public void ejbPassivate() throws EJBException {
System.out.println("ejbPassivate()...");
}

public void ejbRemove() throws EJBException {
System.out.println("ejbRemove()...");
}

public void setSessionContext(SessionContext ctx) throws EJBException {
this.ctx = ctx;
}

public void hi() {
System.out.println("hi() ....");
}
}
==================================================================

5. ejb-jar.xml -

<ejb-jar>
<enterprise-beans>
<session>
<ejb-name> MyLocalEJB </ejb-name>
<local-home> MyLocalEJBHome </local-home>
<local> MyLocalEJB </local>
<ejb-class> MyLocalEJBBean </ejb-class>
<session-type> Stateless </session-type>
<transaction-type> Container </transaction-type>
</session>
</enterprise-beans>

<assembly-descriptor>
<security-role>
<role-name>everyone</role-name>
</security-role>

<method-permission>
<description><![CDATA[description not supported yet by ejbdoclet]]></description>
<role-name>everyone</role-name>
<!--<unchecked/> -->
<method>
<ejb-name>MyLocalEJB</ejb-name>
<method-intf>Local</method-intf>
<method-name>*</method-name>
</method>
</method-permission>
</assembly-descriptor>

</ejb-jar>

==================================================================

5. jboss.xml -

<jboss>
<enterprise-beans>
<session>
<ejb-name> MyLocalEJB </ejb-name>
<local-jndi-name> MyLocalEJB </local-jndi-name>
</session>
</enterprise-beans>
</jboss>

==================================================================

Thanks,
satyajit
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Is the client in the same application as the EJB? If it isn't, then it won't work.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
satyajit bhosale
Greenhorn

Joined: Jun 15, 2006
Posts: 10
yes, client is in the same application. I deployed a jar including
6 files given above.
I am using Eclipse as an editor.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception accessing Local EJB