136.12. 如何使用 MTOM attachments
BasicMessageFilter 提供 Apache Axiom 的所有必要信息,以便生成 MTOM 消息。如果要在 Apache Axiom 中使用 Apache Camel Spring WS,如下是一个示例: - 定义 messageFactory,如下所示,Spring-WS 通过 MTOM 策略填充 SOAP 消息。
<bean id="axiomMessageFactory"
class="org.springframework.ws.soap.axiom.AxiomSoapMessageFactory">
<property name="payloadCaching" value="false" />
<property name="attachmentCaching" value="true" />
<property name="attachmentCacheThreshold" value="1024" />
</bean>
- 将以下依赖项添加到 pom.xml 中
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
<version>1.2.13</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-impl</artifactId>
<version>1.2.13</version>
<scope>runtime</scope>
</dependency>
- 将您的附件添加到管道中,例如使用 Processor 实现。
private class Attachement implements Processor {
public void process(Exchange exchange) throws Exception
{ exchange.getOut().copyFrom(exchange.getIn()); File file = new File("testAttachment.txt"); exchange.getOut().addAttachment("test", new DataHandler(new FileDataSource(file))); }
}
- 将 endpoint (producer)定义为 ussual,例如:
from("direct:send")
.process(new Attachement())
.to("spring-ws:http://localhost:8089/mySoapService?soapAction=mySoap&messageFactory=axiomMessageFactory");
- 您的生成者现在生成带有优化附件的 MTOM 信息。