I would like to set/get SOAP Headers (specifically wsa:ReplyTo
and wsa:MessageId
) in my Asynchronouse Webservice running on JBoss.
Since, this is a JBoss platform, I cannot use com.sun.xml.ws.developer.WSBindingProvider
(as recommended in JAX-WS - Adding SOAP Headers).
One option would be to use SOAPHandler
. Is there any other way similar to the WSBindingProvider
solution?
Unfortunately, you will need to use a specific handler for this. Previous versions of JBOSS EAP did support the javax.xml.ws.addressing
packages however it looks like these packages are not a part of EE6.
Define the handler e.g. jaxws-handlers.xml
as:
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee javaee_web_services_1_3.xsd">
<handler-chain>
<protocol-bindings>##SOAP11_HTTP</protocol-bindings>
<handler>
<handler-name>Application Server Handler</handler-name>
<handler-class>com.handler.ServerHandler</handler-class>
</handler>
</handler-chain>
Add @HandlerChain
into the Service class definition:
@WebService (...)
@HandlerChain(file="jaxws-handlers.xml")
public class TestServiceImpl implements TestService {
public String sayHello(String name) {
return "Hello " + name + "!";
}
}
And implement the Handler itself as :
public class ServerHandler implements SOAPHandler<SOAPMessageContext> {
@Override
public boolean handleMessage(final SOAPMessageContext context) {
final Boolean outbound = (Boolean)context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if ((outbound != null) && !outbound) {
//...
}
return true;
}
}