2017-09-06 107 views
2

我在我的應用程序上下文駱駝路線定義爲阿帕奇駱駝的XPath條件路由

<camelContext xmlns="http://camel.apache.org/schema/spring" 
    trace="true" id="camel"> 

    <route id="wsProxyRedirection"> 
     <from uri="cxf:bean:cdcPocProxyWebServiceStartPoint" /> 
     <choice> 
      <when> 
       <xpath>//soapenv:Envelope/soapenv:Body/hel:sayHello/toWhom = 'normal'</xpath> 
       <to uri="jms:queue:normalQueue" /> 
      </when> 
      <when> 
       <xpath>//soapenv:Envelope/soapenv:Body/hel:sayHello/toWhom = 'urgent'</xpath> 
       <to uri="jms:queue:urgentQueue" /> 
      </when> 
      <when> 
       <xpath>//soapenv:Envelope/soapenv:Body/hel:sayHello/toWhom = 'veryUrgent'</xpath> 
       <to uri="jms:queue:veryUrgentQueue" /> 
      </when> 
     </choice> 
    </route> 
</camelContext> 

,我發送請求爲:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hel="http://cxf.apache.org/wsse/handler/helloworld"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <hel:sayHello> 
     <toWhom>normal</toWhom> 
     </hel:sayHello> 
    </soapenv:Body> 
</soapenv:Envelope> 

但我得到的迴應是:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
     <soap:Fault> 
     <faultcode>soap:Server</faultcode> 
     <faultstring>Error during type conversion from type: java.lang.String to the required type: org.w3c.dom.Document with value test due org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.</faultstring> 
     </soap:Fault> 
    </soap:Body> 
</soap:Envelope> 

這只是一個簡單的選擇POC,但我不能使它的工作......我有什麼需要改變我的xpath條件?

謝謝

回答

1

你的第一個例子似乎是正確的。問題在於你如何發送消息,導致cxf收到的數據對xml無效,所以你收到SAXParseException。 當然,你不應該使用「$ {simple} contains」,因爲你使用xml,而apache camel提供了很多工具來處理它。 我按照您的要求創建測試示例。

CXF端點:主體內容和u不必XPath中使用SOAP代碼:當您使用的有效載荷DATAFORMAT你會用肥皂工作完全

<camelcxf:cxfEndpoint 
     id="cdcPocProxyWebServiceStartPoint" 
     wsdlURL="etc/Test.WSDL" 
     address="/services/request"> 
    <camelcxf:properties> 
     <entry key="dataFormat" value="PAYLOAD"/> 
    </camelcxf:properties> 
</camelcxf:cxfEndpoint> 

路線:

<camelContext id="incomingRequestsProcessing" xmlns="http://camel.apache.org/schema/spring"> 
    <route id="wsProxyRedirection" xmlns:hel="http://cxf.apache.org/wsse/handler/helloworld"> 
     <from uri="cxf:bean:cdcPocProxyWebServiceStartPoint?loggingFeatureEnabled=true"/> 
     <choice> 
      <when> 
       <xpath>//hel:sayHello/toWhom = 'normal'</xpath> 
       <log message="Receive average hello status"/> 
      </when> 
      <when> 
       <xpath>//hel:sayHello/toWhom = 'urgent'</xpath> 
       <log message="Receive urgent hello status"/> 
      </when> 
      <when> 
       <xpath>//hel:sayHello/toWhom = 'veryUrgent'</xpath> 
       <log message="Receive very urgent hello status"/> 
      </when> 
     </choice> 
    </route> 
</camelContext> 

我使用了SoapUI進行測試。併發送您的請求的結果是:

2017-10-13 17:19:37,745 | INFO | tp1048175215-590 | wsProxyRedirection    | 178 - org.apache.camel.camel-core - 2.16.3 | Receive average hello status 

我試圖設置大部分日誌,但我不能。編輯說,「您的文章似乎包含代碼格式不正確的代碼」。可悲的是我不知道該怎麼做。 希望我的文章能幫到你。

+0

感謝它的工作! – ggwtf

0

在「when」條件中,而不是「xpath」,請嘗試使用「simple」。替換這些詞。

<的XPath> - > <簡單>

1

它與<simple>${body} contains 'normal'</simple>

改變<xpath>//soapenv:Envelope/soapenv:Body/hel:sayHello/toWhom = 'normal'</xpath>的時候,但我想提出它的工作原理與XPath的工作..

0

嘗試設置不同的參數dataFormat到消費者端點。試着用CXF_MESSAGE

<from uri="cxf:bean:cdcPocProxyWebServiceStartPoint?dataFormat=CXF_MESSAGE" /> 

此外,試圖改變你的<xpath ... />使用以下格式:

<xpath>//soapenv:Envelope/soapenv:Body/hel:sayHello[toWhom='normal']</xpath>

+0

如果您將'dataFormat'設置爲'MESSAGE',是否有任何更改? – mgyongyosi

+0

消息未被佔用,並且出現超時錯誤 – ggwtf

+0

嘗試將'?exchangePattern = InOnly'參數添加到jms端點。 (例如:''。 – mgyongyosi