This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception accessing Local EJB

 
satyajit bhosale
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
satyajit bhosale
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the client in the same application as the EJB? If it isn't, then it won't work.
 
satyajit bhosale
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, client is in the same application. I deployed a jar including
6 files given above.
I am using Eclipse as an editor.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic