的端回覆消息,我想在我的行程的端部同時處理請求和響應消息。但是,我沒有看到如何訪問原始請求消息的方式。Apache的駱駝:訪問請求和在路線
我有可怕的感覺,我的一些基本概念掙扎。
這裏是DSL一個簡單的例子路線勾勒我的問題(streamCaching是整個上下文啓用):
from("activemq:queue:myQueue")
.to("log:" + getClass().getName() + "?showOut=true")
.to("http://localhost:8080/someBackend")
.log("Now in.Body returns this: ${in.body} and out.Body this: ${out.body}")
.to("log:" + getClass().getName() + "?showOut=true");
這裏是我的日誌的根據摘錄(換行符編輯以更好的閱讀) 。可以看到,一旦http服務器回覆,原始的SOAP消息就會丟失,並且SOAP響應對象存儲在消息的inBody中。
2012-09-25 17:28:08,312 local.bar.foo.MyRouteBuilder INFO -
Exchange[ExchangePattern:InOut, BodyType:byte[],
Body:<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header /><env:Body><urn:someRequest xmlns:urn="http://foo.bar.local/ns"></urn:someRequest></env:Body></env:Envelope>,
Out: null]
2012-09-25 17:28:08,398 org.apache.camel.component.http.HttpProducer DEBUG -
Executing http POST method: http://localhost:8080/someBackend
2012-09-25 17:28:09,389 org.apache.camel.component.http.HttpProducer DEBUG -
Http responseCode: 200
2012-09-25 17:28:09,392 route2 INFO -
Now in.Body returns this: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:someResponse xmlns:ns2="http://foo.bar.local/ns"</ns2:someResponse></soap:Body></soap:Envelope>
and out.Body this:
2012-09-25 17:28:09,392 local.bar.foo.MyRouteBuilder INFO -
Exchange[ExchangePattern:InOut,
BodyType:org.apache.camel.converter.stream.InputStreamCache,
Body:[Body is instance of org.apache.camel.StreamCache],
Out: null]
我本來會期望in.body和out.body被保留在整個路線?
替代方案,我考慮:
- 利用Correlation Identifier模式的關聯請求和迴應。但是,這是否也會保留郵件正文?另外,我的請求/回覆消息沒有用於關聯的唯一標識符。
- 編寫自定義豆,其執行呼叫到HTTP後端,處理請求和回覆對象(但是這基本上無駱駝溶液,重新發明輪子,因此不優選的)
已經失敗的方法:
我試圖用一個處理器在我的路線結束訪問原始請求消息是這樣,沒有成功:
process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Message originalInMessage = exchange.getUnitOfWork().getOriginalInMessage();
logger.debug(originalInMessage.getBody(String.class));
logger.debug(exchange.getIn().getBody(String.class));
}
});
感謝您的幫助
我面臨類似的情況,解決了:String payload = new String((byte [])exchange.getUnitOfWork()。getOriginalInMessage()。getBody()) – dkb