简体   繁体   English

Camel-CXF在Apache Karaf中运行时不添加soap:Header to Request

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

I'm using Camel (2.16.3) to call a Webservice (see WSDL below). 我使用Camel(2.16.3)来调用Webservice(参见下面的WSDL)。 If I run my Route Standalone with the camel:run maven command, everything works fine and the Request is like so: 如果我使用camel:run maven命令运行我的Route Standalone,一切正常,请求就像这样:

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

But if I deploy my Project to a Karaf (4.0.4) Installation and trigger the Request, the soap:Header is missing: 但是,如果我将我的项目部署到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>

Because for the Server, which is called, the Header is required I get an SOAP Fault back. 因为对于被调用的服务器,需要Header,所以我得到了SOAP Fault。


Attachments 附件

Following the Spring configuration which defines the CXF Endpoint: 遵循定义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>

and the Route (in Java DSL) which trigger the request: 以及触发请求的Route(在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();

and the WSDL which defines the Service: 以及定义服务的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>

Solution

Install cxf-ws-addr ( feature:install cxf-ws-addr ) in Karaf. 在Karaf中安装cxf-ws-addrfeature:install cxf-ws-addr )。

This seems to be a missing or buggy dependency in the camel-cxf feature of apache karaf. 这似乎是apache karaf的camel-cxf功能中的缺失或错误依赖。

From the beginning : 从一开始

Like I mentioned before, I added an Interceptor which should add the action header and this didn't worked. 就像我之前提到的那样,我添加了一个拦截器,它应该添加动作头,这没有用。 So I debugged the whole Interceptor-Chain of my Request and checked what every Interceptor is doing (yes, every Interceptor). 所以我调试了我的Request的整个Interceptor-Chain并检查了每个Interceptor正在做什么(是的,每个Interceptor)。 To find the differences I have done this for standalone and with remote debugging for karaf. 为了找到差异,我已经为独立和karaf的远程调试做了这个。

I found out, that the Interceptor mentioned before is not doing anything usefull (so don't use it) and inside karaf the Interceptor org.apache.cxf.ws.addressing.impl.MAPAggregatorImpl isn't used at all. 我发现,前面提到的Interceptor没有做任何有用的事情(所以不要使用它),而在karaf中,根本没有使用Interceptor org.apache.cxf.ws.addressing.impl.MAPAggregatorImpl I have checked the installed bundle's and the dependency tree of maven and indeed, the maven dependency camel-cxf references cxf-rt-ws-addr (which contains the Interceptor). 我检查了已安装的bundle和maven的依赖树,实际上,maven依赖camel-cxf引用了cxf-rt-ws-addr (包含Interceptor)。 But the feature in karaf does not. 但卡拉夫的功能却没有。

This is really nasty, because (in my opinion) one of the benefits of the bundle features is, that they represent the maven dependency hierarchy and I don't have to manage them myself! 这真的很讨厌,因为(在我看来)捆绑功能的一个好处是,它们代表了maven依赖层次结构,我不需要自己管理它们!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM