Camel-CXF 在 Apache Karaf 中 运行 时不会将 soap:Header 添加到请求

Camel-CXF doesn't add soap:Header to Request when run inside Apache Karaf

我正在使用 Camel (2.16.3) 调用 Web 服务(请参阅下面的 WSDL)。如果我 运行 我的 Route Standalone 使用 camel:运行 maven 命令,一切正常,请求如下:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <soap:Header>
        <Action xmlns="http://www.w3.org/2005/08/addressing">http://tempuri.org/OutboundItemTransferIISWebService/OutboundItemTransferIISWebService/ItemTransfer</Action>
        <MessageID xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:17fba6c9-daa8-41cb-a5a5-2806165d705b</MessageID>
        <To xmlns="http://www.w3.org/2005/08/addressing">http://localhost:8765/wc3/entw/OutboundItemTransferIISWebService.svc</To>
        <ReplyTo xmlns="http://www.w3.org/2005/08/addressing">
            <Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
        </ReplyTo>
    </soap:Header>
    <soap:Body>
        <ns2:ItemTransfer xmlns="urn:microsoft-dynamics-nav/xmlports/x60780" xmlns:ns2="http://tempuri.org/OutboundItemTransferIISWebService/"><ns2:p_OutboundItem/>
            <ns2:p_ItemFilter></ns2:p_ItemFilter>
            <ns2:p_ItemMaxFilter>100</ns2:p_ItemMaxFilter>
        </ns2:ItemTransfer>
    </soap:Body>
</soap:Envelope>

但是如果我将项目部署到 Karaf (4.0.4) 安装并触发请求,soap:Header 会丢失:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <soap:Body>
        <ns2:ItemTransfer xmlns="urn:microsoft-dynamics-nav/xmlports/x60780" xmlns:ns2="http://tempuri.org/OutboundItemTransferIISWebService/"><ns2:p_OutboundItem/>
            <ns2:p_ItemFilter></ns2:p_ItemFilter>
            <ns2:p_ItemMaxFilter>100</ns2:p_ItemMaxFilter>
        </ns2 :ItemTransfer>
    </soap:Body>
</soap:Envelope>

因为对于被调用的服务器,Header 是必需的,我得到了一个 SOAP 故障。


附件

遵循定义 CXF 端点的 Spring 配置:

<cxf:cxfEndpoint id="itemTransfer"
    address="${navision.ws.base.url}/OutboundItemTransferIISWebService.svc"
    wsdlURL="wsdl/OutboundItemTransferIISWebService.wsdl"
    serviceClass="org.tempuri.outbounditemtransferiiswebservice.OutboundItemTransferIISWebService"
    endpointName="ns:WSHttpBinding_OutboundItemTransferIISWebService"
    serviceName="ns:OutboundItemTransferIISWebService"
    xmlns:ns="http://tempuri.org/OutboundItemTransferIISWebService/"
    loggingFeatureEnabled="true">
</cxf:cxfEndpoint>

和触发请求的路由(在 Java DSL 中):

from(ACTIVEMQ_UPDATE_ITEMS).routeId("Read all Items from the Webservice into MongoDB")
    .log(LoggingLevel.INFO, logger, "Read the next {{navision.ws.chunk.size}} Items! Filter: '${body}'")
    .setHeader(Masterdata.HEADER_CHUNK_SIZE).simple("{{navision.ws.chunk.size}}")
    .bean(InitialItemImport.class, "createItemTransferRequest")
    .to("cxf:bean:itemTransfer?dataFormat=POJO")
    .bean(InitialItemImport.class, "itemTransferResponseToList")
    .split(body()).parallelProcessing()
        .bean(InitialItemImport.class, "convertItemToUpsert")
        .to("mongodb:mongo?database={{mongo.database}}&collection=articles&operation=update")
    .end()
    .choice()
        .when(method(InitialItemImport.class, "shouldTriggerNext"))
            .bean(InitialItemImport.class, "createNextFilter")
            .to(ACTIVEMQ_UPDATE_ITEMS)
        .otherwise()
            .log(LoggingLevel.INFO, logger, "Finished Full-Update of Items")
    .end();

和定义服务的 WSDL:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions name="OutboundItemTransferIISWebService"
    targetNamespace="http://tempuri.org/OutboundItemTransferIISWebService/"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex"
    xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://tempuri.org/OutboundItemTransferIISWebService/"
    xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
    xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy"
    xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract"
    xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
    xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
    <wsp:Policy wsu:Id="WSHttpBinding_OutboundItemTransferIISWebService_policy">
        <wsp:ExactlyOne>
            <wsp:All>
                <wsaw:UsingAddressing />
            </wsp:All>
        </wsp:ExactlyOne>
    </wsp:Policy>
    <wsdl:types>
        <xsd:schema elementFormDefault="qualified"
            targetNamespace="http://tempuri.org/OutboundItemTransferIISWebService/">
            <xsd:element name="ItemTransfer">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element minOccurs="0" maxOccurs="1" name="p_OutboundItem"
                            type="q1:ItemData" xmlns:q1="urn:microsoft-dynamics-nav/xmlports/x60780" />
                        <xsd:element minOccurs="0" maxOccurs="1" name="p_ItemFilter"
                            type="xsd:string" />
                        <xsd:element minOccurs="1" maxOccurs="1" name="p_ItemMaxFilter"
                            type="xsd:int" />
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="ItemTransferResponse">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element minOccurs="0" maxOccurs="1"
                            name="ItemTransferResult" type="q2:ItemData"
                            xmlns:q2="urn:microsoft-dynamics-nav/xmlports/x60780" />
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:schema>
        <xsd:schema elementFormDefault="qualified"
            targetNamespace="urn:microsoft-dynamics-nav/xmlports/x60780">
            <xsd:complexType name="ItemData" mixed="true">
                <xsd:sequence>
                    <xsd:element minOccurs="0" maxOccurs="unbounded" name="Item"
                        type="q3:Item" xmlns:q3="urn:microsoft-dynamics-nav/xmlports/x60780" />
                </xsd:sequence>
            </xsd:complexType>
            <xsd:complexType name="Item">
                <xsd:sequence>
                    <xsd:element minOccurs="0" maxOccurs="1" name="No"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="No_2"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Description"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="Search_Description" type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Description_2"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="Base_Unit_of_Measure" type="xsd:string" />
                    <xsd:element minOccurs="1" maxOccurs="1"
                        name="Price_Unit_Conversion" type="xsd:int" />
                    <xsd:element minOccurs="1" maxOccurs="1" name="Unit_Price"
                        type="xsd:decimal" />
                    <xsd:element minOccurs="1" maxOccurs="1" name="Duty_Due_Percent"
                        type="xsd:decimal" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Duty_Code"
                        type="xsd:string" />
                    <xsd:element minOccurs="1" maxOccurs="1" name="Gross_Weight"
                        type="xsd:decimal" />
                    <xsd:element minOccurs="1" maxOccurs="1" name="Net_Weight"
                        type="xsd:decimal" />
                    <xsd:element minOccurs="1" maxOccurs="1" name="Unit_Volume"
                        type="xsd:decimal" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Freight_Type"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Tariff_No"
                        type="xsd:string" />
                    <xsd:element minOccurs="1" maxOccurs="1"
                        name="Duty_Unit_Conversion" type="xsd:decimal" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="Country_Region_Purchased_Code" type="xsd:string" />
                    <xsd:element minOccurs="1" maxOccurs="1" name="Blocked"
                        type="xsd:boolean" />
                    <xsd:element minOccurs="1" maxOccurs="1"
                        name="Price_Includes_VAT" type="xsd:boolean" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="VAT_Bus_Posting_Gr_Price" type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="Gen_Prod_Posting_Group" type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="Country_Region_of_Origin_Code" type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Tax_Group_Code"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="VAT_Prod_Posting_Group" type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="Manufacturer_Code" type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="Item_Category_Code" type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="Product_Group_Code" type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="Expiration_Calculation" type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Common_Item_No"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="Last_Date_Modified" type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="Recency_From_Date" type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Recency_To_Date"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Status_Code"
                        type="xsd:string" />
                    <xsd:element minOccurs="1" maxOccurs="1"
                        name="Rock_Bottom_Price" type="xsd:boolean" />
                    <xsd:element minOccurs="1" maxOccurs="1" name="Buy_Hit"
                        type="xsd:boolean" />
                    <xsd:element minOccurs="1" maxOccurs="1" name="Test_Winner"
                        type="xsd:boolean" />
                    <xsd:element minOccurs="1" maxOccurs="1" name="Inventory"
                        type="xsd:decimal" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="Item_Status_Display_Text" type="xsd:string" />
                    <xsd:element minOccurs="1" maxOccurs="1" name="Not_Homologated"
                        type="xsd:boolean" />
                    <xsd:element minOccurs="1" maxOccurs="1" name="Last_Direct_Cost"
                        type="xsd:decimal" />
                    <xsd:element minOccurs="1" maxOccurs="1" name="Unit_List_Price"
                        type="xsd:decimal" />
                    <xsd:element minOccurs="0" maxOccurs="unbounded" name="ItemVariant"
                        type="q4:ItemVariant" xmlns:q4="urn:microsoft-dynamics-nav/xmlports/x60780" />
                    <xsd:element minOccurs="0" maxOccurs="unbounded" name="ItemVendor"
                        type="q5:ItemVendor" xmlns:q5="urn:microsoft-dynamics-nav/xmlports/x60780" />
                    <xsd:element minOccurs="0" maxOccurs="unbounded" name="ItemSalesPrice"
                        type="q6:ItemSalesPrice" xmlns:q6="urn:microsoft-dynamics-nav/xmlports/x60780" />
                    <xsd:element minOccurs="0" maxOccurs="unbounded" name="ItemTranslation"
                        type="q7:ItemTranslation" xmlns:q7="urn:microsoft-dynamics-nav/xmlports/x60780" />
                    <xsd:element minOccurs="0" maxOccurs="unbounded"
                        name="ItemDistributionChannel" type="q8:ItemDistributionChannel"
                        xmlns:q8="urn:microsoft-dynamics-nav/xmlports/x60780" />
                </xsd:sequence>
            </xsd:complexType>
            <xsd:complexType name="ItemVariant">
                <xsd:sequence>
                    <xsd:element minOccurs="0" maxOccurs="1" name="Code"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Description"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Description_2"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Variant_Promo"
                        type="xsd:string" />
                    <xsd:element minOccurs="1" maxOccurs="1"
                        name="Variant_Inventory" type="xsd:decimal" />
                </xsd:sequence>
            </xsd:complexType>
            <xsd:complexType name="ItemVendor">
                <xsd:sequence>
                    <xsd:element minOccurs="0" maxOccurs="1" name="Vendor_No"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="Lead_Time_Calculation" type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Vendor_Item_No"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Variant_Code"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" default="false"
                        name="Primary_Vendor" type="xsd:boolean" />
                </xsd:sequence>
            </xsd:complexType>
            <xsd:complexType name="ItemSalesPrice">
                <xsd:sequence>
                    <xsd:element minOccurs="0" maxOccurs="1" name="Sales_Type"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Sales_Code"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Starting_Date"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Currency_Code"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Variant_Code"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="Unit_Of_Measure_Code" type="xsd:string" />
                    <xsd:element minOccurs="1" maxOccurs="1" name="Minimum_Quantity"
                        type="xsd:decimal" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Ending_Date"
                        type="xsd:string" />
                    <xsd:element minOccurs="1" maxOccurs="1" name="Unit_Price"
                        type="xsd:decimal" />
                    <xsd:element minOccurs="1" maxOccurs="1"
                        name="Price_Includes_VAT" type="xsd:boolean" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="VAT_Bus_Posting_Grp_Price" type="xsd:string" />
                    <xsd:element minOccurs="1" maxOccurs="1" name="Action_Price"
                        type="xsd:boolean" />
                </xsd:sequence>
            </xsd:complexType>
            <xsd:complexType name="ItemTranslation">
                <xsd:sequence>
                    <xsd:element minOccurs="0" maxOccurs="1" name="Variant_Code"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Language_Code"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Description"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Description_2"
                        type="xsd:string" />
                </xsd:sequence>
            </xsd:complexType>
            <xsd:complexType name="ItemDistributionChannel">
                <xsd:sequence>
                    <xsd:element minOccurs="0" maxOccurs="1" name="Item_No"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Variant_Code"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="Responsibility_Center" type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Start_Date"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="Distribution_Channel_Code" type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Item_Description"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="Item_Description_2" type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Language_Code"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Promo_From_Date"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1" name="Promo_Until_Date"
                        type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="Recency_From_Date_Distr" type="xsd:string" />
                    <xsd:element minOccurs="0" maxOccurs="1"
                        name="Recency_To_Date_Distr" type="xsd:string" />
                </xsd:sequence>
            </xsd:complexType>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message
        name="OutboundItemTransferIISWebService_ItemTransfer_InputMessage">
        <wsdl:part name="parameters" element="tns:ItemTransfer" />
    </wsdl:message>
    <wsdl:message
        name="OutboundItemTransferIISWebService_ItemTransfer_OutputMessage">
        <wsdl:part name="parameters" element="tns:ItemTransferResponse" />
    </wsdl:message>
    <wsdl:portType name="OutboundItemTransferIISWebService">
        <wsdl:operation name="ItemTransfer">
            <wsdl:input
                wsaw:Action="http://tempuri.org/OutboundItemTransferIISWebService/OutboundItemTransferIISWebService/ItemTransfer"
                message="tns:OutboundItemTransferIISWebService_ItemTransfer_InputMessage" />
            <wsdl:output
                wsaw:Action="http://tempuri.org/OutboundItemTransferIISWebService/OutboundItemTransferIISWebService/ItemTransferResponse"
                message="tns:OutboundItemTransferIISWebService_ItemTransfer_OutputMessage" />
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="WSHttpBinding_OutboundItemTransferIISWebService"
        type="tns:OutboundItemTransferIISWebService">
        <wsp:PolicyReference
            URI="#WSHttpBinding_OutboundItemTransferIISWebService_policy" />
        <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="ItemTransfer">
            <soap12:operation
                soapAction="http://tempuri.org/OutboundItemTransferIISWebService/OutboundItemTransferIISWebService/ItemTransfer"
                style="document" />
            <wsdl:input>
                <soap12:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="OutboundItemTransferIISWebService">
        <wsdl:port name="WSHttpBinding_OutboundItemTransferIISWebService"
            binding="tns:WSHttpBinding_OutboundItemTransferIISWebService">
            <soap12:address
                location="http://mdnmt2.ms.local/wc3/entw/OutboundItemTransferIISWebService.svc" />
            <wsa10:EndpointReference>
                <wsa10:Address>http://mdnmt2.ms.local/wc3/entw/OutboundItemTransferIISWebService.svc</wsa10:Address>
            </wsa10:EndpointReference>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

解决方案

在 Karaf 中安装 cxf-ws-addr (feature:install cxf-ws-addr)。

这似乎是 apache karaf 的 camel-cxf 功能中缺失或有问题的依赖项。

从头开始:

就像我之前提到的,我添加了一个应该添加操作 header 的拦截器,但这没有用。所以我调试了我的请求的整个 Interceptor-Chain 并检查了每个拦截器在做什么(是的,每个拦截器)。为了找到差异,我已经为独立的和远程调试 karaf 做了这个。

我发现,前面提到的拦截器没有做任何有用的事情(所以不要使用它)并且在 karaf 内部拦截器 org.apache.cxf.ws.addressing.impl.MAPAggregatorImpl 不是完全用过。我检查了已安装的包和 maven 的依赖关系树,实际上,maven 依赖关系 camel-cxf 引用 cxf-rt-ws-addr (其中包含拦截器)。但是karaf中的功能没有。

这真的很讨厌,因为(在我看来)bundle 特性的好处之一是,它们代表了 Maven 依赖层次结构,我不必自己管理它们!