2016-09-24 99 views
0

下面是我的网络的服务请求,路线和RequestValidator,头值来了为空在Apache的骆驼交易所

网络服务请求:

<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)即将为空。

+0

尝试使用“客户ID”或“STLH:客户ID”,而不是“的customerID” – Pat

+0

我想这两个选项拍拍,它不工作,当我调试的值不出现在标题! – Raghavan

+0

然后更好地将其设置在身体并尝试传球 – Pat

回答

0

将org.apache.camel的日志记录设置为DEBUG,并且会记录标题值,您可以确定组件是否正在删除它们。

另外,看起来您可能正在使用cxf soap端点。看看这里的文档的部分的[relayHeaders选项的说明]:

http://camel.apache.org/cxf.html

1

“自定义” SOAP头不会被复制到骆驼头。您必须手动将肥皂头添加到骆驼交换头中。

方法1)

CamelCxfMessage -可以提取/处理定制SOAP头骆驼CXF消息,其是存在于骆驼交换报头

在骆驼

- 的SOAPMessage的SOAPMessage =(的SOAPMessage)exchange.getIn ().getHeader(“CamelCxfMessage”);

这会给你soap消息和它的soapMessage.getExchange,并尝试从肥皂消息中获取肥皂标题并处理它。

方法2)

骆驼的CxF绑定 -you可以使用骆驼CXF在像cxfBinding =#bindingName端点定义的结合特征。

创建一个类并使用org.apache.camel.component.cxf.DefaultCxfBinding进行扩展,并且bean名称应为bindingName

它有一个方法,你必须覆盖 - propagateHeadersFromCxfToCamel(camelmessage,cxfmessage,exchage)。

这里得到你的肥皂头,并把它放在骆驼头与骆驼交换顶部标识和访问头处理器或路线与同一标识符

0

我不得不提取头信息,但在第一次尝试时在对象中得到空值。然后过了一段时间我就可以钓鱼了。这里是如何(在处理器中):

@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()); 
     } 
    }