Sagun Khatri

Greenhorn
+ Follow
since Dec 21, 2007
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sagun Khatri

Hello again, please follow this link to the NetBeans 6.0 tutorial on how to create a Secure Enterprise Bean in Java EE 5.

http://www.netbeans.org/kb/60/javaee/secure-ejb.html
[ December 24, 2007: Message edited by: Sagun Khatri ]
The solution to the above NullPointer Exception in EJB 3.0 is as follows:

1) Create an Enterprise Application Project in NetBeans 6.0

2) Create new Session Bean, write your session bean code in here.

3) Create a Remote Interface, include the method(s) from the above Session Bean.

4) Create a Application Client in Secure-apple-client node.

5) Write an annotation to call the EJB in the application client.

6) In Java EE 5 we are not required to write a deployment descriptor (ejb-jar.xml). However, if we do have security for the application, we need to specify that in the deployment descriptor.
I am sorry if someone has already posted this question before. If someone please point me towards the right direction I would be really grateful.

I am writing a very simple EJB 3.0 Session Bean (Stateless) using Netbeans 6 and GlassFish server.

I am trying to invoke the Remote Interface from an Application Client, but I get a NullPointerException. The problem is my Client Application can't find the Remote Interface. Here is my code

*************** Remote Interface *****************
package ejb30;

import javax.ejb.Remote;

@Remote
public interface StateLessRemote {
public String hello();
}


************** Stateless Session Bean *************
package ejb30;

import javax.ejb.Stateless;

@Stateless
public class StateLessBean implements StateLessRemote {
public StateLessBean() {}

public String hello()
{
return "*** Hello World! ***";
}
}


*************** Aplication Client ******************
package stateLessClient;

import javax.ejb.EJB;
import ejb30.StateLessRemote;

public class StateLessAppClient
{
@EJB(mappedName="ejb03.StateLessRemote")
private static StateLessRemote stateLessBean;

public static void main(String[] args)
{
System.out.println("*** Calling Stateless bean ****");
System.out.println(stateLessBean.hello());
}
}


********** Error from Netbeans *******************
Dec 21, 2007 3:15:12 PM com.sun.enterprise.appclient.MainWithModuleSupport <init>
WARNING: ACC003: Application threw an exception.
java.lang.NullPointerException
at stateLessClient.StateLessAppClient.main(StateLessAppClient.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)