This is my mule flow:
HTTP Listener -> Logger -> WS:Consumer -> Logger
<flow name="ClientFlow" >
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<logger level="INFO" doc:name="Logger" message="#[message.payloadAs(java.lang.String)]"/>
<ws:consumer config-ref="Web_Service_Consumer" doc:name="Web Service Consumer" operation="NewRequestTest"/>
<logger message="#[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
</flow>
I send a SOAP message to my mule flow with SOAPUI:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<NewRequestTest xmlns="urn:microsoft-dynamics-schemas/codeunit/Requests">
<xmlEntry>
<NewRequestTest>
<hiMessage>Hi</hiMessage>
<NewRequestTest>
</xmlEntry>
</NewRequestTest>
</soapenv:Body>
</soapenv:Envelope>
I want to do the operation from the ws:consumer dynamically getting from the SOAP header with a MEL expression.
In what way it would be possible to obtain that information?
You can just use the xpath3 function if your operation is specified somewhere in the body of the request, in this way:
<set-variable variableName="operation" value="#[xpath('//theTagcontainingwhatyouwant')]" doc:name="Variable"/>
<ws:consumer config-ref="Web_Service_Consumer" doc:name="Web Service Consumer" operation="#[flowVars['operation']]"/>
Please note that in theory you could take the operation also from the SOAP-Action header that normally comes along with a soap request, you can access it via inboundProperties
#[message.inboundProperties['SOAPAction']]
Hope this helps
Related
I have an endpoint accepting Soap Requests, after this endpoint, it goes to a Transform Message which generates the appropriate request to an external web service.
What I want to do is to use the Choice Pattern to decide to which external web service I must redirect.
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<cxf:configuration name="CXF_Configuration" enableMuleSoapHeaders="true" initializeStaticBusInstance="true" doc:name="CXF Configuration"/>
<ws:consumer-config name="Web_Service_Consumer" service="KarmaService" port="KarmaPort" serviceAddress="http://localhost:8080/TestingWS/Karma" wsdlLocation="http://localhost:8080/TestingWS/Karma?wsdl" doc:name="Web Service Consumer"/>
<flow name="testingChoice">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<cxf:proxy-service configuration-ref="CXF_Configuration" payload="body" doc:name="CXF"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace ns0 http://karmapackage/
---
{
ns0#sayHello: {
arg0: payload.invoke.arg0
}
}]]></dw:set-payload>
</dw:transform-message>
<choice doc:name="Choice">
<when expression="#[payload]">
<logger message="Info1" level="INFO" doc:name="Logger"/>
</when>
<otherwise>
<logger message="Default" level="INFO" doc:name="Logger"/>
</otherwise>
</choice>
<ws:consumer config-ref="Web_Service_Consumer" operation="sayHello" doc:name="Web Service Consumer"/>
<logger message="Andando" level="INFO" doc:name="Logger"/>
</flow>
Right now, Choice is redirecting to Logger info, just to know what it is doing.
I don't know how to set the expression on the when condition to check if arg0 has the value choosePath1 for example.
I would appreciate any help,
Thanks in advance
Check this post, write xpath expression based on your transformed xml. Mule 3.4.0 Choice router based on presence of a node in payload using Xpath
Also check how to build xml xpath on mule documents
https://docs.mulesoft.com/mule-user-guide/v/3.8/xpath
I want to write a mule application which will read the database for unprocessed records, club them in JSON payload format and then hit a REST webservice.
I am able to read the records from the database and able to convert the database records in JSON. However, whenever I run the application I am getting following exception
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
Here is my Mule configuration XML
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" 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"
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/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<db:mysql-config name="MySQL_Configuration" host="localhost" port="3306" user="root" database="my_database_name" doc:name="MySQL Configuration"/>
<http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="example.net" port="8000" basePath="API" doc:name="HTTP Request Configuration"/>
<flow name="cwg_clientFlow">
<poll doc:name="Poll">
<db:select config-ref="MySQL_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[SELECT * FROM cwg_ws_data WHERE SyncFlag = 0]]></db:parameterized-query>
</db:select>
</poll>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<json:object-to-json-transformer doc:name="Object to JSON" />
<logger message="JSON Payload is #[payload]" level="INFO" doc:name="Logger"/>
<http:request config-ref="HTTP_Request_Configuration" path="/cwg" method="POST" doc:name="HTTP">
<http:request-builder>
<http:query-params expression="#[payload]"/>
<http:header headerName="access_token" value="MQTgpMUmyQLt134maB6vPp6oWFgMtGsqzIlpCN74"/>
</http:request-builder>
</http:request>
<logger message="webservice response #[payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
I am unable to understand where it is going wrong
Please help me, I am trying this since last 2 days.
Thanks in advance
-Paresh (kendreparesh#gmail.com)
Try removing this line.
<http:query-params expression="#[payload]"/>
It should work. As your payload is Json String and you are trying to map it to Query params which expects Map. Also for POST your payload will converted to body.
expression in query-params must be a map. If you are going to pass data as query-params, why are you doing object to json? Try removing below two lines -
<json:object-to-json-transformer doc:name="Object to JSON" />
<logger message="JSON Payload is #[payload]" level="INFO" doc:name="Logger"/>
I have the following Mule flow. What I'm trying to achieve is simply to put the SOAP message into the JMS queue.
The content of the message in the JMS queue is
org.mule.module.xml.stax.ReversibleXMLStreamReader#3c7e9afa
What am I missing in the transformer?
<object-to-string-transformer name="Object_to_String" doc:name="Object to String"/>
<flow name="soapServiceFlow">
<http:listener config-ref="SOAP_JMS_HTTP_Listener_Configuration" path="/soap" doc:name="HTTP"/>
<cxf:proxy-service
configuration-ref="CXF_Configuration"
doc:name="CXF"
payload="envelope"
wsdlLocation="service.wsdl"
namespace="http://www.examples.com/wsdl/ReportService"
port="ReportPort"
service="ReportService" />
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<jms:outbound-endpoint queue="my.requests" connector-ref="Active_MQ" doc:name="JMS" transformer-refs="Object_to_String">
<jms:transaction action="NONE"/>
</jms:outbound-endpoint>
</flow>
This is a transformation error and you can simply use object-to-string-transformer to make it work:-
<object-to-string-transformer doc:name="Object to String"/>
before your JMS outbound
Before the logger, add <object-to-string-transformer doc:name="Object to String"/> for you to see the string content of the class org.mule.module.xml.stax.ReversibleXMLStreamReader#3c7e9afa
I'm trying to configure a flow in mule studio using the Web Services Connector. The SOAP body the endpoint is expecting looks like:
<soapenv:Body>
<v4:readFields>
<filter>
<type>?</type>
<id>?</id>
<name>
<operator>?</operator>
<value>?</value>
</name>
</filter>
<pageNumber>?</pageNumber>
</v4:readFields>
</soapenv:Body>
The <filter> node itself is required, but the contents are optional, so I'd like to get my flow to send a body like:
<soapenv:Body>
<v4:readFields>
<filter />
<pageNumber>1</pageNumber>
</v4:readFields>
</soapenv:Body>
Is there a way to set up the message payload to send this request?
Running Anypoint Studio 5.1.0, Mule ESB 3.6.
My current flow config:
<flow name="GetFieldInfo">
<http:listener config-ref="localhost" path="/fields" doc:name="HTTP"/>
<enricher source="#[payload]" target="#[flowVars.sessionId]" doc:name="GetSessionId">
<flow-ref name="GetSessionId" doc:name="Login"/>
</enricher>
<data-mapper:transform config-ref="Xml_loginResponse__To_Xml_sessionHeader_" input-ref="#[flowVars["sessionId"]]" target="#[message.outboundProperties["soap.sessionHeader"]]" doc:name="Set Session Header"/>
<ws:consumer config-ref="BrontoAPI" operation="readFields" doc:name="Web Service Consumer"/>
<echo-component doc:name="Echo"/>
</flow>
you can make use of mule parse template to send static xml with variable data
sample :
<soapenv:Body>
<v4:readFields>
<filter />
<pageNumber>#[payload]</pageNumber>
</v4:readFields>
</soapenv:Body>
you can find the documentation here https://developer.mulesoft.com/docs/display/current/Parse+Template+Reference
I am new to Mule and just trying to use mule to expose SOAP webservice. I used following example from mule soft http://www.mulesoft.org/documentation/display/current/XML-only+SOAP+Web+Service+Example. I am able to expose the webservice but getting error when DataMapper component tries to map Data from one request to another. Attached files contains required configurations. When I run the test xml on mapper using preview tab in Mule Studio it returns just: and says Your XML is not valid. Error: Premature End of File.
Please suggest.
Following is the configuration:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:http="http://www.mulesoft.org/schema/mule/http" 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.3.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
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/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd
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/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd ">
<data-mapper:config name="admitToUpsert" transformationGraphPath="admittoupsert.grf" doc:name="DataMapper"/>
<flow name="admitPatientService" doc:name="admitPatientService">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8080" doc:name="AdmissionService"/>
<cxf:proxy-service port="AdmissionPort" namespace="http://www.mule-health.com/SOA/service/admission/1.0" service="AdmissionService" payload="body" doc:name="Proxy Service" wsdlLocation="service/AdmissionService.wsdl"/>
<logger message="First request: #[message.payload]" level="INFO" doc:name="Logger"/>
<mulexml:dom-to-xml-transformer doc:name="Object to XML" returnClass="java.lang.String"/>
<logger message="Before hiting transfomer: #[message.payload]" level="INFO" doc:name="Logger"/>
<data-mapper:transform config-ref="admitToUpsert" doc:name="DataMapper"/>
<byte-array-to-string-transformer returnClass="java.lang.String" mimeType="text/plain" doc:name="Byte Array to String"/>
<logger message="Upsert Request is: #[message]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
Following is the Test xml:
<ns0:admitSubject xmlns:ns0="http://www.mule-health.com/SOA/service/admission/1.0" xmlns:ns1="http://www.mule-health.com/SOA/model/1.0">
<ns1:Referer>
<ns1:clientId>7899</ns1:clientId>
</ns1:Referer>
<ns1:Referral>
<ns1:procedure>
<ns1:code>In-patient</ns1:code>
<ns1:admission>Elective</ns1:admission>
<ns1:department>CARDIOLOGY</ns1:department>
</ns1:procedure>
</ns1:Referral>
<ns1:Subject>
<ns1:nationalId>4657</ns1:nationalId>
<ns1:firstName>Charles</ns1:firstName>
<ns1:lastName>Brown</ns1:lastName>
<ns1:address1>Any Street</ns1:address1>
<ns1:address2>?</ns1:address2>
<ns1:address3>?</ns1:address3>
<ns1:nationality>American</ns1:nationality>
<ns1:gender>Male</ns1:gender>
<ns1:dateOfBirth>1987-01-19</ns1:dateOfBirth>
</ns1:Subject>
</ns0:admitSubject>
WSDL and XSD can be pulled from https://github.com/mulesoft/Pre-sales-hospital-admission/tree/master/src/main/resources/service. Apologies for not pasting it here as it would have caused to much data on page but I can add them if requested
I am able to resolve this. It seems some special character got creeped in while copy pasting the xml. When I generated the XML from XSD in Mule studio it worked fine.