I have read few tutorials about soap handlers and some of them uses only handler chain but some of them use both @resource annotation and handler chain xml. I am confused if @resource is needed to use or not. If yes why exactly I need to use it?
1 Answers
The @Resource
annotation marks a resource that is needed by the application. This annotation may be applied to an application component class, or to fields or methods of the component class. When the annotation is applied to a field or method, the container will inject an instance of the requested resource into the application component when the component is initialized. If the annotation is applied to the component class, the annotation declares a resource that the application will look up at runtime.
The WebServiceContext
object that injected by using @Resource
annotation, wraps the MessageContext
that includes the SOAPMessage
, and also includes various information about the HTTP connection that carried the SOAPMessage
. The web container will then initialize the WebServiceContext
reference whenever a service request arrives. This allows web methods to have access to the HTTP headers in the HTTP request that is carrying the request, as well as to the SOAPMessageContext
, SOAP headers, and SOAPMessage
.
Why in one case uses @Resource
annotation and in other case not? Because in one case all necessary information can be retrieved from objects of these classes (SOAPMessageContext
, SOAPMessage
, etc) and these objects available via implementation of LogicalHandler
interface or SOAPMessageContext
interface. In other case all necessary information can be retrieved directly from injected WebServiceContext
.
See Also: