65.11. 如何使用 MTOM attachments
BasicMessageFilter 提供 Apache Axiom 的所有所需信息,以便生成 MTOM 消息。如果要在 Apache Axiom 中使用 Apache Camel Spring WS,以下示例: - 定义 messageFactory
,如下所示,Spring-WS 使用优化附件填充 SOAP 消息,并通过 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 信息,其中包含优化的附件。