Spring web service WS. Adding attachments for a response using SAAJ - No adapter for the endpoint

I am really trying to get Spring-WS to return a response with attachments. I managed to get the MTOM version, but it has some prerequisites for the client, since I believe that the client should also include MTOM (please correct me if this is incorrect).

Now I am trying to use standard SOAP with insertion using SAAJ and Spring -WS.

To do this, I implemented an endpoint that simply attaches the image from the local file system to the response.

@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; } } 

Saaj's properties are injection, as shown below:


 <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> 

When I try to call the above service, I get the following error:

 <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&lt;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> 

Edit July 13th

Today I noticed that I am changing the method signature to remove MessageContext parameters as shown below, after which I do not get this error:

 public JAXBElement<DownloadResponseSaajType> invoke(@RequestPayload DownloadMessageRequestSaaj req) 

However, the problem is that I need to access MessageContext in order to be able to add an attachment. Maybe my configuration is somewhere wrong?

+3
java spring soap spring-ws web-services
source share
1 answer

I believe that in any case, your client will need to know about this application, so I recommend sticking with mtom (as it becomes the standard)

check which version of spring-ws you are using and which maven-group-id you are using. I was getting the same error because this function was recently added (I think?).

try this entry and remove any other spring-ws that import your ad

  <dependency> <groupId>org.springframework.ws</groupId> <artifactId>spring-ws-core</artifactId> <version>2.0.2.RELEASE</version> </dependency> 
+1
source share

All Articles