325.9. 如何使用 MTOM attachments
BasicMessageFilter 提供 Apache Axiom 的所有所需信息,以便生成 MTOM 消息。如果要在 Apache Axiom 中使用 Apache Camel Spring WS,以下示例: - Simply 将 messageFactory 定义为 bellow,Spring-WS 将使用 MTOM 策略来填充您的 SOAP 消息,并带有优化的附件。
- 将以下依赖项添加到 pom.xml 中
- 将附加添加到管道中,例如使用 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))); }
}
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");
from("direct:send")
.process(new Attachement())
.to("spring-ws:http://localhost:8089/mySoapService?soapAction=mySoap&messageFactory=axiomMessageFactory");
- 现在,您的制作者将使用 otpmized attachments 生成 MTOM 消息。