I have code that uses Spring's WebServiceTemplate
to invoke a SOAP service.
Currently it uses:
public Object marshalSendAndReceive(String uri, final Object requestPayload)
But I would like to manipulate the content both inbound and outbound. The most suitable public method appears to be:
public <T> T sendAndReceive(String uriString,
WebServiceMessageCallback requestCallback,
WebServiceMessageExtractor<T> responseExtractor)
... for which I would provide a custom callback and extractor.
The interfaces for those both specify methods that work with a WebServiceMessage
.
public interface WebServiceMessage {
Source getPayloadSource();
Result getPayloadResult();
void writeTo(OutputStream outputStream) throws IOException;
}
Source
and Result
are both interfaces from the javax.xml.transform
, and they don't seem to expose message content. Both just have a setter and getter for String systemId
, and nothing else.
I can see that there are various implementations of Source
, all providing different access to the payload. I could do something like this in my callback:
StreamSource source = (StreamSource) message.getPayloadSource();
But casting is dirty, and anyway, how do I know which implementations I should support?
How can I get at this content (ideally the raw XML)?