users@glassfish.java.net

Re: application-client.xml :: <callback-handler> ignores my class.

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Wed, 6 Dec 2006 21:18:22 +0100

2006/12/6, Tim Quinn <Timothy.Quinn_at_sun.com>:
> The GlassFish unit tests include several that test annotations and
> injection. One in particular is the test in this directory:
>
> appserv-tests/devtests/ejb/ejb30/hello/session
>
> The client/Client.java class uses @EJB, and I just now ran the test and it
> passed, meaning that the annotation processing and the injection worked
> correctly.
>
> I wish I could compare that scenario with what you have been working with
> to try to see what the key differences are, but I'm afraid I don't have the
> time right now.
>
> - Tim
>

Hello there,
I am really surprised now, as I just made a simple 'hello world' with
EJB3+Client App, where client is using @EJB and it just works. I
investigated it a little bit (because I know id did not work for me)
and here is what I can see:
if injection is to be made in the class which starts client
application, then injection works. But, when injection is to be
performed in some another class - then it doesn't work.

This is how it looks when it fails:
----------------------------------------------------------------------
public class Main {
   public static void main(String[] args) {
      HelloFrame.main(args); // calling another class' method
   }
}
----------------------------------------------------------------------
public class HelloFrame extends JFrame {
   @EJB static SomeSessionRemote someSession;
   ............
   ............
   public static void main(String args[]) {
      java.awt.EventQueue.invokeLater(new Runnable() {
         public void run() {
            HelloFrame frame = new HelloFrame();
            try {
               frame.getJTextArea1().setText(someSession.sayHello("World"));
            } catch (NullPointerException e) {
               frame.getJTextArea1().setText("@EJB injection does not work.");
            }
            frame.setVisible(true);
         }
      });
   }
}
----------------------------------------------------------------------


And this is the code that works:

----------------------------------------------------------------------
public class Main {
   @EJB static SomeSessionRemote someSession;
   public static void main(String[] args) {
      HelloFrame.main(args); // calling another class' method
   }
}
----------------------------------------------------------------------
public class HelloFrame extends JFrame {
   ............
   ............
   public static void main(String args[]) {
      java.awt.EventQueue.invokeLater(new Runnable() {
         public void run() {
            HelloFrame frame = new HelloFrame();
            try {
               frame.getJTextArea1().setText(Main.someSession.sayHello("World"));
            } catch (NullPointerException e) {
               frame.getJTextArea1().setText("@EJB injection does not work");
            }
            frame.setVisible(true);
         }
      });
   }
}
----------------------------------------------------------------------

As you can see, when injection is in Main class, then it works (I can
see "Hello: world"), but when I move SessionRemote field to other
class, then what I see is "@EJB injection does not work".