After some poking around if found a slightly different solution. I'm using JAXB for marshalling my payload and the possible header classes have also been generated with JAXB from the WSDL.
In my case I am addressing Microsoft Reporting Services and have pass on an ExecutionID as SOAP header.
public class ReportExecution2005Client extends WebServiceGatewaySupport {
private static final String SET_EXECUTION_PARAMETERS_ACTION = "http://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices/SetExecutionParameters";
private final class SoapActionExecutionIdCallback implements WebServiceMessageCallback {
private final String soapAction;
private final String executionId;
public SoapActionExecutionIdCallback(String soapAction, String executionId) {
super();
this.soapAction = soapAction;
this.executionId = executionId;
}
@Override
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
SoapMessage soapMessage = (SoapMessage) message;
soapMessage.setSoapAction(soapAction);
ExecutionHeader executionHeader = new ExecutionHeader();
executionHeader.setExecutionID(executionId);
getMarshaller().marshal(executionHeader, soapMessage.getSoapHeader().getResult());
}
}
public void setExecutionParameters(String executionId){
SetExecutionParameters request = new SetExecutionParameters();
request.setParameters(new ArrayOfParameterValue());
SetExecutionParametersResponse response = (SetExecutionParametersResponse) getWebServiceTemplate().marshalSendAndReceive(request,
new SoapActionExecutionIdCallback(
SET_EXECUTION_PARAMETERS_ACTION,
executionId));
}
}
Basically the WebServiceGatewaySupport already knows the Marshaller to convert JAXB Pojos. I'm using this one to attach my own header classes to the SoapHeader with this line:
getMarshaller().marshal(executionHeader, soapMessage.getSoapHeader().getResult());
in my nested WebServiceMessageCallback.