我真的很挣扎越来越春-WS返回带有附件的响应。 我设法得到一个MTOM版本工作,但这个有客户端上的一些先决条件,因为我相信客户端必须是MTOM启用以及(请纠正我,如果这是不正确的)。
我试图现在要做的是使用标准的SOAP用SAAJ和Spring-WS附件执行。
要做到这一点,我实现,只是从本地文件系统到响应的附加图像的端点。
@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的性质depency注入,如下所示:
<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>
当我尝试拨打上述服务我得到以下错误:
<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的参数如下图所示的话,我不明白的错误:
public JAXBElement<DownloadResponseSaajType> invoke(@RequestPayload DownloadMessageRequestSaaj req)
然而,问题是,我需要访问MessageContext来可以添加附件。 可能是因为也许我的配置是错误的地方吗?