web service component injection is null
mdurant.mark.durant.fiserv.com Dec 4, 2009 6:32 PMI've created a bare-bones Seam project for web service testing using JBoss Tools in Eclipse, and I've modified its default AuthenticatorAction to this:
@Stateless(name = "AuthenticatorAction") @Name("authenticator") public class AuthenticatorAction implements Authenticator { public boolean authenticate() { return true; } public String getEchoBack() { return "echoBack!"; } }
I've deployed the project successfully to the server, and am able to log in through the generated home/login process. The getEchoBack method is used by a web service SLSB which I've also added to the project:
@Stateless @Name("echo") @WebService(name = "EchoService", serviceName = "EchoService") public class EchoService implements EchoServiceInterface { @In AuthenticatorAction authenticator; @WebMethod public String echo(String in) { return authenticator.getEchoBack() + ": " + in; } }
And the EchoServiceInterface is simply:
@Local public interface EchoServiceInterface { public String echo(String in); }
When I deploy this to my app server, I see the service successfully deployed inside of the main ear, and I'm able to view the server-generated WSDL. I can also do a test request/response against the service, so long as I don't try to get anything from the authenticator. When I add the call to authenticator.getEchoBack(), though, the authenticator object is always null, and the service call fails.
I've tried many little adjustments to make it work, including adding create=true to the @In annotation for the authenticator, as well as taking out the injection altogether and using:
AuthenticatorAction authenticator = (AuthenticatorAction)Component.getInstance(AuthenticatorAction.class);
When I try that, though, I get the following error:
Caused by: java.lang.IllegalStateException: No application context active at org.jboss.seam.Component.forName(Component.java:1945) at org.jboss.seam.Component.getInstance(Component.java:2005) ...
I read this morning where I can add LifeCycle calls to fix that problem, so I next tried:
@WebMethod public String echo(String in) { Lifecycle.beginCall(); AuthenticatorAction authenticator = (AuthenticatorAction) Component .getInstance(AuthenticatorAction.class); Lifecycle.endCall(); return authenticator.getEchoBack() + ": " + in; }
When I do that, though, I hit the next wall:
EJB Exception: : org.jboss.seam.InstantiationException: Could not instantiate Seam component: authenticator at org.jboss.seam.Component.newInstance(Component.java:2144) at org.jboss.seam.Component.getInstance(Component.java:2021) at org.jboss.seam.Component.getInstance(Component.java:1983) ... Caused by: javax.naming.NameNotFoundException: While trying to look up comp/env/main-ear/AuthenticatorAction/local in /app/ejb/main-ejb.jar#EchoService.; remaining name 'comp/env/main-ear/AuthenticatorAction/local' at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1139) at weblogic.jndi.internal.ApplicationNamingNode.lookup(ApplicationNamingNode.java:144) at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254) at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:380)...
I'm at a loss as to what to try next. Please help!
Thanks,
Mark