Java Apache条件路由
我的应用程序上下文中有一个驼峰路由,定义为Java Apache条件路由,java,xpath,soap,apache-camel,cxf,Java,Xpath,Soap,Apache Camel,Cxf,我的应用程序上下文中有一个驼峰路由,定义为 <camelContext xmlns="http://camel.apache.org/schema/spring" trace="true" id="camel"> <route id="wsProxyRedirection"> <from uri="cxf:bean:cdcPocProxyWebServiceStartPoint" /> <choice&g
<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/soapenv:Body/hel:sayHello/toWhom='normal'
//soapenv:Envelope/soapenv:Body/hel:sayHello/toWhom='紧急'
//soapenv:Envelope/soapenv:Body/hel:sayHello/toWhom='veryUrgent'
我发送的请求是:
<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>
soap:服务器
从类型:java.lang.String转换为所需类型:org.w3c.dom.Document时出错,测试值为org.xml.sax.SAXParseException;行号:1;列数:1;prolog中不允许包含内容。
这只是一个简单的选择,但我不能让它工作。。。在xpath条件中我必须更改什么
谢谢在“when”条件下,尝试使用“simple”代替“xpath”。替换这些单词
//soapenv:Envelope/soapenv:Body/hel:sayHello/toWhom='normal'
时起作用,${Body}包含'normal'
但是我想让它与xpath一起工作。尝试为使用者端点设置不同的
dataFormat
参数。尝试使用CXF\u消息
:
<from uri="cxf:bean:cdcPocProxyWebServiceStartPoint?dataFormat=CXF_MESSAGE" />
另外,请尝试更改
以使用以下格式:
//soapenv:Envelope/soapenv:Body/hel:sayHello[toWhom='normal']
您的第一个示例似乎是正确的。问题是如何发送消息,因为cxf接收的数据对xml无效,所以您会收到SAXParseException。
当然,您不应该使用“${simple}contains”,因为您使用的是xml,而ApacheCamel提供了很多工具来使用它。
我根据您的需求创建测试示例
Cxf端点:
<camelcxf:cxfEndpoint
id="cdcPocProxyWebServiceStartPoint"
wsdlURL="etc/Test.WSDL"
address="/services/request">
<camelcxf:properties>
<entry key="dataFormat" value="PAYLOAD"/>
</camelcxf:properties>
</camelcxf:cxfEndpoint>
我试着设置大部分日志,但我做不到。编辑说“您的文章似乎包含未正确格式化为代码的代码”。遗憾的是,我不知道该怎么做。
希望我的帖子能对您有所帮助。如果您将
dataFormat
设置为MESSAGE
,是否有任何更改?消息未被使用,并且我遇到了超时错误尝试将?exchangePattern=InOnly
参数添加到jms端点。(例如,
。同样的问题,我尝试了有效载荷
数据格式(因为消息
已被弃用)。我得到了一个响应(不再超时),但我无法做出条件选择(字段未被提取)。如果有效载荷
,请尝试将xpath更改为/hel:sayHello[toWhom='normal']
,因为正文的内容是soap:body!()
<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>
2017-10-13 17:19:37,745 | INFO | tp1048175215-590 | wsProxyRedirection | 178 - org.apache.camel.camel-core - 2.16.3 | Receive average hello status