119.12. MTOM アタッチメントの使用方法
BasicMessageFilter は、MTOM メッセージを生成するために Apache Axiom に必要なすべての情報を提供します。Apache Axiom 内で Apache Camel Spring WS を使用する場合の例を次に示します。- 以下に示すように messageFactory を定義すると、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))); }
}
- エンドポイント (プロデューサー) を通常どおりに定義します。たとえば、次のようになります。
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");
- プロデューサは、最適化された添付ファイルを含む MTOM メッセージを生成するようになりました。