【发布时间】:2015-01-20 00:12:12
【问题描述】:
我正在使用 mule 来公开 Web 服务。我已经构建了一个 WSDL 文件,我正在尝试从消息中获取文本以加载到数据库中,但我不知道如何获取文本。我正在使用 Logger 来记录我的有效负载,如下所示。
INFO 2015-01-20 11:00:54,470 [[ws-mule-cxf].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tra="http://training/">
<soapenv:Header/>
<soapenv:Body>
<tra:sayHi>
<!--Optional:-->
<ID>111</ID>
<!--Optional:-->
<name>John</name>
<!--Optional:-->
<industry>IT</industry>
<!--Optional:-->
<REF/>
</tra:sayHi>
</soapenv:Body>
</soapenv:Envelope>
所以基本上我想获取 ID、名称和行业节点中的文本值,并将它们映射到数据库表。任何人都请让我知道如何编写代码来获取这些信息?谢谢!
现在我已经删除了数据库连接器部分,只放置了一个有效负载组件来从标题和正文中提取数据以检查 xpath 是否正常工作,但它不能。
配置 XML 在这里:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd">
<db:mysql-config name="MySQL_Configuration" host="localhost" port="3306" user="admin" password="pontiac" database="sqwarepeg" doc:name="MySQL Configuration"/>
<file:connector name="File" writeToDirectory="C:\Testing" autoDelete="false" streaming="true" validateConnections="true" doc:name="File"/>
<flow name="sf2dbtestFlow1" doc:name="sf2dbtestFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<cxf:proxy-service port="SF2DBPort" namespace="http://training/" service="SF2DBService" payload="envelope" wsdlLocation="src/test/resources/SF2DB.wsdl" doc:name="CXF"/>
<mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
<set-payload value="#[xpath('//soapenv:Envelope/soapenv:Body/*')]" doc:name="Set Payload"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
错误信息是:
表达式“xpath('//soapenv:Envelope/soapenv:Body/*')”的执行失败。 (org.mule.api.expression.ExpressionRuntimeException)。消息负载的类型:字符串
**更新:我添加了
<mulexml:namespace-manager includeConfigNamespaces="true">
<mulexml:namespace prefix="soapenv" uri="http://schemas.xmlsoap.org/soap/envelope/"/>
<mulexml:namespace prefix="tra" uri="http://training/"/>
</mulexml:namespace-manager>
在xml中,现在它报告另一个错误: 信息 2015-01-22 12:22:39,847 [[ws-mule-cxf].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: org.dom4j.tree.DefaultElement@ 4586a9c5 [元素:http://training/ 属性:[]/>] WARN 2015-01-22 12:22:39,850 [[ws-mule-cxf].connector.http.mule.default.receiver.03] org.apache.cxf.phase.PhaseInterceptorChain:{http://training/}SF2DBService 的拦截器已抛出异常,现在展开 org.apache.cxf.interceptor.Fault:无法将类 org.dom4j.tree.DefaultElement 转换为 XMLStreamReader。
有人可以帮忙吗?谢谢! **
【问题讨论】:
-
您似乎在使用 Mule 来使用远程 Web 服务,而不是公开 Web 服务。对吗?
-
显示帮助流程。
-
谢谢,但是我要暴露一个web服务,而不是消费
标签: mule