Spring WS Web 服务.使用 SAAJ 向响应添加附件 - 端点没有适配器 [英] Spring WS web service. Adding an attachment to the response using SAAJ - No adapter for endpoint
问题描述
我真的很难让 Spring-WS 返回带有附件的响应.我已经设法让 MTOM 版本工作,但这对客户端有一些先决条件,因为我相信客户端也必须启用 MTOM(如果这不正确,请纠正我).
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).
我现在想要做的是使用标准 SOAP 和使用 SAAJ 和 Spring-WS 的附件实现.
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.
@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 属性依赖注入,如下所示:
The Saaj properties are depency injected 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<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>
编辑 7 月 13 日
我今天注意到我更改了方法签名以删除 MessageContext 参数,如下所示,然后我没有收到该错误:
Edit 13th July
I noticed today that i change the method signature to remove the MessageContext parameters as shown below then i dont get that error:
public JAXBElement<DownloadResponseSaajType> invoke(@RequestPayload DownloadMessageRequestSaaj req)
然而,问题是我需要访问 MessageContext 才能添加附件.可能是我的配置有问题?
The problem however is that i need to access the MessageContext to be able to add the attachment. Could be that maybe my configuration is wrong somewhere?
推荐答案
我相信在任何一种情况下,您的客户都需要知道附件,所以我建议坚持使用 mtom(因为它正在成为标准)
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)
检查您使用的是哪个版本的 spring-ws 以及您使用的是哪个 maven group-id.我遇到了同样的错误,因为最近添加了此功能(我认为?).
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 feature was recently added (I think?).
尝试此条目并删除您制作的任何其他 spring-ws 导入
try this entry and remove any other spring-ws imports your making
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
这篇关于Spring WS Web 服务.使用 SAAJ 向响应添加附件 - 端点没有适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!