Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Exception accessing Local EJB

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.naming:org.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
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic