以下是我的网络服务请求,路由和请求验证器,
网络服务请求:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<stlh:SabreHeader xmlns:stlh="http://services.sabre.com/STL_Header/v02_01">
<stlh:Service version="1.0.0">GetHotelMediaRQ</stlh:Service>
<stlh:Identification>
<stlh:CustomerID>CID12345</stlh:CustomerID>
<stlh:CustomerAppID>AppTest</stlh:CustomerAppID>
<stlh:ConversationID>05EFPElI2A4KudU75863JIxqAhQJtAx0</stlh:ConversationID>
<stlh:MessageID>4DTTQaHGSifFUtmSoMHAiq</stlh:MessageID>
<stlh:TimeStamp>2014-11-07T14:45:42.725-06:00</stlh:TimeStamp>
</stlh:Identification>
</stlh:SabreHeader>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" wsu:Id="athId">${athId}</wsse:BinarySecurityToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<GetHotelMediaRQ xmlns="http://services.sabre.com/hotel/media/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://services.sabre.com/hotel/media/v1 GetHotelMediaRQ.xsd">
<HotelRefs>
<HotelRef HotelCode="184769" CodeContext="Sabre">
<ImageRef MaxImages="1">
<Images>
<Image Type="ORI"/>
</Images>
<AdditionalInfo>
<Info Type="CAPTION">true</Info>
</AdditionalInfo>
<Languages>
<Language Code="EN"/>
</Languages>
</ImageRef>
</HotelRef>
</HotelRefs>
</GetHotelMediaRQ>
</soap:Body>
</soap:Envelope>
RequestValidator:
public void validate(GetHotelMediaRQ request, Exchange exchange) throws Exception {
TransactionContext context = BusExtensions.getTransactionContext(exchange);
Collection<HotelRef> hotelRefList = getInstance().convert(request, Collection.class);
Set<Property> properties = new HashSet<>();
String customerAppId = exchange.getIn().getHeader("customerAppID", String.class);
String customerId = exchange.getIn().getHeader("customerID", String.class);
但是当我尝试通过Exchange对象访问时,customerAppId(AppTest)和CustomerId(CI12345)将变为null。
答案 0 :(得分:1)
&#34;自定义&#34; Soap标头不会复制到camel标头。你必须手动将soap标头添加到camel exchange header中。
方法1)
CamelCxfMessage - 您可以提取/处理自定义soap标头camel cxf消息,该消息存在于camel exchange header
在骆驼中 - SoapMessage soapMessage =(SoapMessage)exchange.getIn()。getHeader(&#34; CamelCxfMessage&#34; );
这将为您提供soap消息及其soapMessage.getExchange,并尝试从soap消息中获取soap标头并对其进行处理。
方法2)
Camel Cxf Binding - 您可以在端点定义中使用camel cxf绑定功能,例如cxfBinding =# bindingName 。
使用org.apache.camel.component.cxf.DefaultCxfBinding创建一个类并进行扩展,bean名称应为 bindingName 。
它有一个你必须覆盖的方法 - propagateHeadersFromCxfToCamel (camelmessage,cxfmessage,exchage)。
在这里获取您的soap标头并将其放入带有标识符的camel标头中,并在处理器中的camel exchange标头中访问标头或使用相同标识符的路由。
答案 1 :(得分:0)
将org.apache.camel的日志记录设置为DEBUG,并记录标题值,您可以确定该组件是否正在删除它们。
此外,您可能正在使用cxf soap端点。请查看文档中的[relayHeaders选项说明]部分:
答案 2 :(得分:0)
我必须提取标题信息,但在第一次尝试时在对象中获取null。过了一会儿我就可以把它钓掉了。这是(在处理器中):
@Override
public void process(Exchange exc) throws Exception {
@SuppressWarnings("unchecked")
List<SoapHeader> headers = exc.getIn().getHeader(Header.HEADER_LIST, List.class);
for (int i=0; i < headers.size(); i++) {
if (headers.get(i).getObject() instanceof ElementNSImpl) {
ElementNSImpl elementNSImpl = (ElementNSImpl) headers.get(i).getObject();
Node firstChild = elementNSImpl.getFirstChild();
log.trace("header: name=" + elementNSImpl.getLocalName() + ", value=" + firstChild.getNodeValue());
}
}