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 データ形式で機能している場合は、メッセージボディーに SOAP Fault メッセージを設定し、CxfMessageStreamExceptionTestのようにメッセージヘッダーで応答コードを設定できます。
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 ボディーに SOAPFault を設定できます。