16.15. Camel から SOAP Fault を出力する方法
camel-cxf エンドポイントを使用して SOAP リクエストを使用している場合は、camel コンテキストから SOAP Fault を出力する必要がある場合があります。
基本的に、これを行うには throwFault DSL を使用できます。POJO、PAYLOAD、および MESSAGE データ形式で機能します。
CxfCustomizedExceptionTest に示すように、SOAP 障害を定義できます。
SOAP_FAULT = new SoapFault(EXCEPTION_MESSAGE, SoapFault.FAULT_CODE_CLIENT);
Element detail = SOAP_FAULT.getOrCreateDetail();
Document doc = detail.getOwnerDocument();
Text tn = doc.createTextNode(DETAIL_TEXT);
detail.appendChild(tn);
あとは好きなように投げてください
from(routerEndpointURI).setFaultBody(constant(SOAP_FAULT));
CXF エンドポイントが MESSAGE データ形式で動作している場合、CxfMessageStreamExceptionTest で示されているように、メッセージ本文に SOAP Fault メッセージを設定し、メッセージヘッダーに応答コードを設定できます。
from(routerEndpointURI).process(new Processor() {
public void process(Exchange exchange) throws Exception {
Message out = exchange.getOut();
// Set the message body with the
out.setBody(this.getClass().getResourceAsStream("SoapFaultMessage.xml"));
// Set the response code here
out.setHeader(org.apache.cxf.message.Message.RESPONSE_CODE, new Integer(500));
}
});
POJO データ形式を使用する場合も同様です。out body に SOAPFault を設定できます。