My JAX-WS war contains following entries.
WEB-INF/lib/
WEB-INF/beans.xml // empty
WEB-INF/lib/commons-logging-1.1.1.jar
WEB-INF/lib/corrs-beans-1.0-alpha-1-SNAPSHOT.jar // EJBs are here
WEB-INF/lib/corrs-entities-1.0-alpha-1-SNAPSHOT.jar
WEB-INF/lib/joda-time-1.6.2.jar
WEB-INF/lib/opensaml-2.5.1-1.jar
WEB-INF/lib/openws-1.4.2-1.jar
WEB-INF/lib/slf4j-api-1.6.1.jar
WEB-INF/lib/wss4j-1.6.8.jar
WEB-INF/lib/xmlsec-1.5.3.jar
WEB-INF/lib/xmltooling-1.3.2-1.jar
WEB-INF/web.xml
META-INF/maven/
META-INF/maven/kr.co.ticomms.corrs/
META-INF/maven/kr.co.ticomms.corrs/corrs-services/
META-INF/maven/kr.co.ticomms.corrs/corrs-services/pom.xml
META-INF/maven/kr.co.ticomms.corrs/corrs-services/pom.properties
One of my SOAPHandlers trying to call EJB.
@HandlerChain(file=...)
@WebService(...)
public class MyService {
}
public class MyHandler implements SOAPHandler<SOAPMessageContext> {
@Override
public boolean handleMessage(final SOAPMessageContext context) {
// MyEJB null
}
@Inject
private MyEJB myEJB; // << NULL
}
MyEJB is just an nointerface-view EJB.
@LocalBean
@Stateless
public class MyEJB {
}
Can anybody please tell me how to inject EJBs into SOAPHandlers?
UPDATE / (maybe)ANSWER
I changed @Inject
to @EJB
and it works.
Is there any way to work with @Inject
? I looks IMHO better. :)
If I'm not mistaken, SOAPHandler
s are invoked before the web service invocation. According to the CDI spec (see scopes and contexts), in a web services context all the normal scopes are only active during the web service invocation. In addition to all the normal scopes, there is also the @Dependent
pseudo scope. Unless otherwise specified, this is the default scope. It's life cycle depends on one of the normal scopes and as such cannot exist by itself.
Now, a stateless EJB since it has no CDI related annotations, it is automatically @Dependent
and cannot be injected (using @Inject
) anywhere a normal scope is not active. In your case, inside a SOAPHandler
there is no scope active so you cannot use @Inject
.
Use @EJB
, nothing wrong with that.
If you annotate your soap handler class with CDI "@named" annotation, you can inject any EJB component. By doing so, your soap handler class becomes a container managed bean and you start to be able to use other container managed beans as EJBs.
@Named
public class MyHandler implements SOAPHandler'<'SOAPMessageContext'>' {
....
@Inject
private MyEJB myEJB;
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With