I am working on spring web services. I need to add some custom elements in the request and response message.which should look like this:
This is probably only half the answer you need but I think you can read the soapheaders by getting the (Saaj)SoapMessage from the messagecontext, like this:
@PayloadRoot(
localPart = "GetHiredCandidatesRequest",
namespace = DEFAULT_NAMESPACE
)
@ResponsePayload
public GetHiredCandidatesResponse getKandidaat (
@RequestPayload GetHiredCandidatesRequest getCandidate,
MessageContext messageContext) {
SaajSoapMessage request = (SaajSoapMessage) messageContext.getRequest();
SoapHeader header = request.getSoapHeader();
GetHiredCandidatesResponse response = objectFactory.createGetHiredCandidatesResponse();
response.getCandidate().addAll(
candidateService.getHiredCandidates(
getCandidate.getFrom(),
getCandidate.getTo()
)
);
return response;
}
Since version 2 you can automatically 'add' some objects to your method's signature, like I add the MessageContext here. I have used this to get the attachments from a soap message for instance. You can probably use other subclasses of AbstractSoapMessage as well since the the getSoapHeder method is in that class.
[edit] BTW: Perhaps you can use Interceptors as well since the request / response is provided there. Take a look at the org.springframework.ws.soap.server.endpoint.interceptor package for some default examples. [/edit]