[英]Spring WS web service. Adding an attachment to the response using SAAJ - No adapter for endpoint
I am really struggling getting Spring-WS to return a response with attachments. 我真的很难让Spring-WS返回带附件的响应。 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).
我已经设法让MTOM版本工作,但这在客户端有一些先决条件,因为我相信客户端也必须启用MTOM(如果这不正确,请纠正我)。
What i am trying to do now is to use the standard SOAP with attachment implementation using SAAJ and Spring-WS. 我现在要做的是使用标准的SOAP和附件实现,使用SAAJ和Spring-WS。
To do this i implemented an endpoint that just attaches an image from the local filesystem 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;
}
}
The Saaj properties are depency injected as shown below: Saaj属性是依赖注入,如下所示:
<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<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>
I noticed today that i change the method signature to remove the MessageContext parameters as shown below then i dont get that error: 我今天注意到我更改了方法签名以删除MessageContext参数,如下所示,然后我没有收到该错误:
public JAXBElement<DownloadResponseSaajType> invoke(@RequestPayload DownloadMessageRequestSaaj req)
The problem however is that i need to access the MessageContext to be able to add the attachment. 但问题是我需要访问MessageContext才能添加附件。 Could be that maybe my configuration is wrong somewhere?
也许这可能是我的配置在某处错了?
I believe in either case your client will need to be aware of the attachment so I would recommend sticking with mtom (as it is becoming the standard) 我相信在任何一种情况下你的客户都需要知道附件,所以我建议坚持使用mtom(因为它正在成为标准)
check which version of spring-ws you are using and which maven group-id you are using. 检查您正在使用的spring-ws版本以及您正在使用的maven group-id。 i was getting the same error because this feature was recently added (I think?).
我得到了同样的错误,因为最近添加了这个功能(我想?)。
try this entry and remove any other spring-ws imports your making 尝试此条目并删除任何其他spring-ws导入您的制作
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.