Jun 26th, 2009, 07:39 AM
mtom without marshaller?
Iīm using spring-ws 1.5.5 with PayloadRootAnnotationMethodEndpointMapping without a marshaller (the endpoint-methods get a DOMSource as parameter).
Now I want to send binary files. If I understood it correctly, this is not possible in this way, because I only get the body of the SOAP-message. Is it possible to send files using MessageEndpoint or something else (without a marshaller)? I couldnīt find an example for that.
Jul 9th, 2009, 05:24 AM
It can be done. I am currently trying something similar. The solution I am giving is not very 'clean', but it works.
On the client side you can use as a client a subclass of WebServiceGatewaySupport. Then you get a WebServiceTemplate by invoking getWebServiceTemplate().
Then cast it (ouch!) to a SaajSoapMessageFactory.
Then, you can follow Chapter 5, section "Tutorial" of ttp://java.sun.com/webservices/docs/2.0/tutorial/doc/ (it uses a MessageFactory, you use a SaajSoapMessageFactory).
There you can see how to build your request, add attachments, create a connection and send the whole request with attachments.
The problem of this approach is that you actually *need* to know that the MessageFactory *is* a SaajSoapMessageFactory and, of course, config your spring-ws-servlet.xml (or equivalent) "messageFactory" bean as a SaajSoapMessageFactory.
You can also read http://www.ibm.com/developerworks/xm...ry/x-jaxmsoap/ and http://www.ibm.com/developerworks/xm...GX06&S_CMP=EDU
On the server side you need an endpoint that implements org.springframework.ws.server.endpoint.MessageEndp oint. You don't need to extend any particular class.
Then you have a method like
public void invoke (MessageContext messageContext)
The MessageContext has a getRequest() that returns a WebServiceMessage.
This is actually a subclass like SaajSoapMessage, AxiomSoapMessage, etc.
Again, you need to know (ouch!) that you are using a SaajSoapMessageFactory (the "messageFactory" bean, in your spring-ws-servlet.xml or equivalent XML config file) so the request message is actually a SaajSoapMessage (cast it).
SaajSoapMessage provides some methods: getAttachments(), getAttachment(String) and others.
I tried this with SaajSoapMessageFactory and SaajSoapMessage objects. I checked that it works.
SaajSoapMessage also provides a "SOAPMessage getSaajMessage()" method, wich returns a SOAPMessage object that represents the SOAP request, with the SOAP envelope, the SOAP body and the contents of the body (the payload).
I have not tried this yet but I am very positive it will work.
MessageContext also provides a getResponse() method tah may allow you to fill a response, even with attachments.
In the client side (see the tutorial), you receive a SOAPMessage that allows to receive the response, including the attachments.
I neither tried this yet.
Just a couple of minor comments:
I think you can follow this approach also with an AxiomSoapMessageFactory. The point is that the SOAPMessage objects you finally get or build follow the AXIOM model, which is different to the DOM model used by SaajSoapMessageFactory. I have not experimented with this yet.
In the client side, I think you don't actually need to subclass WebServiceGatewaySupport. I think you can't get the WebServiceTemplate by other means (a factory?).
(I am probably too late, but at least for the records...)