318.8. MTOM アタッチメントの使用方法

BasicMessageFilter は、MTOM メッセージを生成するために Apache Axiom に必要なすべての情報を提供します。Apache Axiom 内で Apache Spring Spring WS を使用する場合の例を次に示します。

<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)));  }
}
  • エンドポイント (プロデューサー) を通常どおりに定義します。たとえば、次のようになります。
from("direct:send")
.process(new Attachement())
.to("spring-ws:http://localhost:8089/mySoapService?soapAction=mySoap&messageFactory=axiomMessageFactory");
  • これで、プロデューサーは最適化された添付を含む MTOM メッセージを生成します。