I'm using mule to expose a Web service. I have built a WSDL file and I'm trying to get the text from the message to load into a database but I don't know how to get the text. I'm using a Logger to record my payload as below.
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>
So basically I want to get to text values in ID, Name and industry nodes and map them to a database table. Anyone please let me know how to write the code to get these information? Thanks!
Now I've remove the Database connector part and only put a set payload component to extract data from header and body to check if xpath is working, but it can't.
The configuration XML is here:
<?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>
The error message is:
Execution of the expression "xpath('//soapenv:Envelope/soapenv:Body/*')" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String
**Update: I added
<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>
in the xml and now it reports another error: INFO 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 [Element: http://training/ attributes: []/>] WARN 2015-01-22 12:22:39,850 [[ws-mule-cxf].connector.http.mule.default.receiver.03] org.apache.cxf.phase.PhaseInterceptorChain: Interceptor for {http://training/}SF2DBService has thrown exception, unwinding now org.apache.cxf.interceptor.Fault: Unable to convert class org.dom4j.tree.DefaultElement to XMLStreamReader.
Anyone can help?Thank you! **