I'm trying to find a way to add header elements to a SOAP message.
If I use @WebParam
with header
set to true
then it works fine, that parameter is nicely in <soap:header>
. However, the requires adding a bunch of parameters to my API which is hardly an option.
At first view interceptors do not appear to be possible so I was looking at SOAPHandlers but it is so difficult to find clear information about this.
This is my spring config:
<bean id="testWebservice" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean" >
<property name="serviceInterface" value="com...TestWebService"/>
<property name="wsdlDocumentUrl" value="http://localhost:9062/test-ws/remoting/test?wsdl"/>
<property name="serviceName" value="TestWebService"/>
<property name="namespaceUri" value="http://test.com"/>
<property name="portName" value="TestServicePort"/>
<property name="lookupServiceOnStartup" value="false"/>
<property name="handlerResolver" ref="myResolver"/>
</bean>
<bean id="myResolver" class="com...TestHandlerResolver" />
My Handler (chained in the TestHandlerResolver):
public class TestHandler implements SOAPHandler<SOAPMessageContext> {
@Override
public void close(MessageContext context) {
}
@Override
public Set<QName> getHeaders() {
return null;
}
@Override
public boolean handleFault(SOAPMessageContext context) {
return true;
}
@Override
public boolean handleMessage(SOAPMessageContext context) {
if (Boolean.TRUE.equals(context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY))) {
try {
List<Header> headers = new ArrayList<Header>();
Header dummyHeader;
dummyHeader = new Header(new QName("dummy"), "decapitated", new JAXBDataBinding(String.class));
headers.add(dummyHeader);
context.put(Header.HEADER_LIST, headers);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return true;
}
}
The problem is that I'm a bit at a loss. Is using handler the right way to do this and if so can you give or point me to a nice example? Is there a way to do it with interceptors? Or am I completely of the target here...