0

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

网络服务请求:

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

请求验证器:

  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。

4

3 回答 3

1

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

方法1)

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

在骆驼 - SoapMessage soapMessage = (SoapMessage)exchange.getIn().getHeader(" CamelCxfMessage" );

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

方法2)

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

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

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

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

于 2016-09-29T20:08:34.683 回答
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());
        }
    }
于 2017-03-16T08:02:13.573 回答
0

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

此外,看起来您可能正在使用 cxf soap 端点。在此处查看文档的 [Description of relayHeaders option] 部分:

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

于 2016-09-28T21:22:09.470 回答