以下是我的网络服务请求,路由和请求验证器,

Web服务请求:

<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。

最佳答案

“自定义” Soap标头不会复制到骆驼标头。您必须手动将soap标头添加到骆驼交换标头中。

方法1)

CamelCxfMessage-您可以提取/处理骆驼交换标头中存在的自定义肥皂标头骆驼cxf消息

在骆驼中-
SoapMessage soapMessage =(SoapMessage)exchange.getIn()。getHeader(“ CamelCxfMessage”);

这将为您提供肥皂消息及其soapMessage.getExchange,并尝试从soap消息中获取soap标头并进行处理。

方法2)

骆驼Cxf绑定-您可以在端点定义中使用骆驼cxf绑定功能,例如cxfBinding =#bindingName。

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

它有一种您必须覆盖的方法-propertyHeadersFromCxfToCamel(camelmessage,cxfmessage,exchage)。

在这里获取您的soap标头,并将其放入带有标识符的骆驼标头中,并将访问标头放入处理器或具有相同标识符的路由的骆驼交换标头中。

10-07 16:20