I am really struggling getting Spring-WS to return a response with attachments. I have managed to get an MTOM version to work but this has some pre-requisites on the client as i believe that the client has to be MTOM enabled as well (please correct me if this is not correct).
What i am trying to do now is to use the standard SOAP with attachment implementation using SAAJ and Spring-WS.
To do this i implemented an endpoint that just attaches an image from the local filesystem to the response.
The Saaj properties are depency injected as shown below:Code:@Endpoint public class TestEndPoint { private SaajSoapMessageFactory saajMessageFactory; @PayloadRoot(namespace="http://ws.mypackage.com", localPart="downloadMessageRequestSaaj") @ResponsePayload public JAXBElement<DownloadResponseSaajType> invoke(@RequestPayload DownloadMessageRequestSaaj req, MessageContext context ) throws Exception { DownloadResponseSaajType response = new DownloadResponseSaajType(); DownloadResponseSaajType.PayLoad payload = new DownloadResponseSaajType.PayLoad(); DataHandler handler = new javax.activation.DataHandler(new FileDataSource("c:\\temp\\maven-feather.png")); SaajSoapMessage message = saajMessageFactory.createWebServiceMessage(); message.addAttachment("picture", handler); context.setResponse(message); payload.setMessagePayLoad(handler); return objectFactory.createDownloadMessageResponseSaaj(response); } public void setSaajMessageFactory(SaajSoapMessageFactory saajMessageFactory){ this.saajMessageFactory = saajMessageFactory; } public SaajSoapMessageFactory getSaajMessageFactory(){ return saajMessageFactory; } }
When i try to call the above service i get the following error:Code:<context:annotation-config/> <context:component-scan base-package="com.mypackage"/> <sws:annotation-driven/> <bean id="soapMessageFactory" class="javax.xml.soap.MessageFactory" factory-method="newInstance" /> <bean id="saajMessageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"> <constructor-arg ref="soapMessageFactory" /> </bean> <bean id="myService" class="com.mypackage.TestEndPoint"> <property name="saajMessageFactory" ref="saajMessageFactory" /> </bean>
Code:<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>SOAP-ENV:Server</faultcode> <faultstring xml:lang="en">No adapter for endpoint [public javax.xml.bind.JAXBElement<com.mypackage.ws.DownloadResponseSaajType> com.mypackage.TestEndPoint.invoke(com.mypackage.ws.DownloadMessageRequestSaaj,org.springframework.ws.context.MessageContext) throws java.lang.Exception]: Is your endpoint annotated with @Endpoint, or does it implement a supported interface like MessageHandler or PayloadEndpoint?</faultstring> </SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope>


Reply With Quote