I need to get value from input html FORM to using as query in database using by Mule studio - mule-studio

enter image description here
How can I get the value from html input from to use as query in my database in mule studio .
<http:listener-config name="HTTP_Listener_Configuration" host="localhost"
port="8081" doc:name="HTTP Listener Configuration"/>
<db:mysql-config name="MySQL_Configuration" host="localhost" port="3306"
user="root" password="Blue1234" database="news" doc:name="MySQL Configuration"/>
<flow name="searchhtmlFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/web" doc:name="HTTP"/>
<db:select config-ref="MySQL_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[select txt from news.nws where sub=#[message.inboundProperties[q]]]]></db:parameterized-query>
</db:select>
<parse-template location="C:\Users\Hersh\Desktop\attach\index.html" doc:name="Parse Template"/>
<set-property propertyName="content" value="#[message.inboundProperties.'http.query.params'.q]" doc:name="Property"/>
</flow>

Try this out :-
<http:listener-config name="HTTP_Listener_Configuration" host="localhost"
port="8081" doc:name="HTTP Listener Configuration"/>
<db:mysql-config name="MySQL_Configuration" host="localhost" port="3306"
user="root" password="Blue1234" database="news" doc:name="MySQL Configuration"/>
<flow name="searchhtmlFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/web" doc:name="HTTP"/>
<parse-template location="C:\Users\Hersh\Desktop\attach\index.html" doc:name="Parse Template"/>
<logger message="Value from DB :- #[message.inboundProperties.'http.query.params'.q]" level="INFO" doc:name="Logger"/>
<db:select config-ref="MySQL_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[select txt from news.nws where sub=#[message.inboundProperties[q]]]]></db:parameterized-query>
</db:select>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>

Related

How to use Choice Pattern over Soap Request in Mule ESB?

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

Error while consuming REST service over HTTPs

I have a simple REST HTTPS POST, the uri of it is like that: https://paymentservicestest.informa.com/mcas_services.asp?
which works perfectly to run in a browser, Postman, etc. With Mule 3.8 HTTP I select the uri from the RAML generataed specification, set uri-param and still I am getting an exception and Code below.
ERROR 2016-10-11 16:16:52,944 [[tstconnection].HTTP_Listener_Configuration.worker.01] org.mule.module.http.internal.request.DefaultHttpRequester: Remote host closed connection. Possible SSL/TLS handshake issue. Check protocols, cipher suites and certificate set up. Use -Djavax.net.debug=handshake for further debugging.
ERROR 2016-10-11 16:16:53,025 [[tstconnection].HTTP_Listener_Configuration.worker.01] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Error sending HTTP request.
Payload : {NullPayload}
Payload Type : org.mule.transport.NullPayload
Element : /tstconnectionFlow/processors/1 # tstconnection:tstconnection.xml:14 (HTTP)
Element XML : <http:request config-ref="HTTP_Request_Configuration" path="/mcas_services.asp" method="POST" doc:name="HTTP">
<http:request-builder>
<http:query-param paramName="username" value="XXXXX"></http:query-param>
<http:query-param paramName="password" value="XXXXX"></http:query-param>
<http:query-param paramName="method" value="XXXXX"></http:query-param>
<http:query-param paramName="source" value="XXXXX"></http:query-param>
<http:query-param paramName="cardtype" value="XXXXX"></http:query-param>
<http:query-param paramName="currency" value="XXXXX"></http:query-param>
</http:request-builder>
</http:request>
--------------------------------------------------------------------------------
Root Exception stack trace:
java.io.IOException: Remotely closed
My sample Code is :
<?xml version="1.0" encoding="UTF-8"?>
<mule 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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="2020" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="paymentservice.informa.com" port="443" connectionIdleTimeout="300000" responseTimeout="300000" doc:name="HTTP Request Configuration" />
<flow name="tstconnectionFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<logger message="sampleTest" level="INFO" doc:name="Logger"/>
<http:request config-ref="HTTP_Request_Configuration" path="/mcas_services.asp" method="GET" doc:name="HTTP">
<!-- <http:request-builder>
<http:query-param paramName="qParams1" value="#[flowVars.qParams]"/>
</http:request-builder> -->
<http:request-builder>
<http:query-param paramName="username" value="XXXXXX"/>
<http:query-param paramName="password" value="XXXXXX"/>
<http:query-param paramName="method" value="XXXXXXX"/>
<http:query-param paramName="source" value="XXXXX"/>
<http:query-param paramName="cardtype" value="XXXX"/>
<http:query-param paramName="currency" value="XXX"/>
</http:request-builder>
</http:request>
<logger level="INFO" doc:name="blankResponse"/>
<logger message="Reponse: #[payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
It looks like you have a typo in your URI
I can see from your post that the actual URI should be:
https://paymentservices.informa.com/
whilst in your config you are calling the following URI:
https://paymentservice.informa.com/
make sure you include the 's' in "services", this should at least make a successful request to the correct server.
Change your HTTP_Request_Configuration to:
<?xml version="1.0" encoding="UTF-8"?>
<mule
...
<http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="paymentservices.informa.com" port="443" connectionIdleTimeout="300000" responseTimeout="300000" doc:name="HTTP Request Configuration" />
...
</mule>

Mule - java.lang.String cannot be cast to java.util.Map

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"/>

How to call a REST service using PUT method in Mule?

Below is my flow. I need to call a REST service using PUT method. Using the same json request and the same service url it is working fine from Postman, but from Mule I am getting the error: "Cannot PUT /api/sms/send". Can someone please tell me what is wrong ?
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" 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" version="EE-3.7.0"
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/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8093" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="api.example.com" port="443" doc:name="HTTP Request Configuration"/>
<flow name="testprojectFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" allowedMethods="GET" doc:name="HTTP"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
message_id: "d5c9af23-f1b2-4d5e-9d6b-439371e0009a",
dst_number: "1234567890",
src_number: "1234567891",
message_type: "SMS:TEXT",
message_data: "TEST MESSAGE SMS API",
submit_date: now
}]]></dw:set-payload>
</dw:transform-message>
<http:request config-ref="HTTP_Request_Configuration" path="/api/sms/send" method="PUT" doc:name="HTTP"/>
<logger level="INFO" doc:name="Logger"/>
</flow>
</mule>

Controlling number of threads in Mule

I'm using Mule 3.3.1 Community Edition.
I have a flow that accepts HTTP requests. This runs successfully.
<flow name="TestFlow">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8088" path="test" doc:name="HTTP" mimeType="text/plain"
encoding="UTF-8"/>
<logger level="INFO" category="hello" doc:name="Logger"/>
</flow>
The service needs to be single-threaded so that messages are handled strictly in the order in which they are received. My thought was to set maxThreadsActive=1 and maxBufferSize=100 to get my desired behavior. However, I can't get any control over threads to work.
At this point I'm just trying to get a thread profile working, regardless of the number of threads. I added a threading-profile exactly out of the current version of the Manning book Mule in Action, but Mule rejects it as "Invalid content" and won't run.
<flow name="TestFlow">
<threading-profile maxBufferSize="100" maxThreadsActive="20" maxThreadsIdle="10"
threadTTL="60000" poolExhaustedAction="RUN" />
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8088" path="test" doc:name="HTTP" mimeType="text/plain"
encoding="UTF-8"/>
<logger level="INFO" category="hello" doc:name="Logger"/>
</flow>
I commented that out and moved up to a configuration block.
<configuration>
<default-threading-profile maxThreadsActive="20" maxBufferSize="100"
poolExhaustedAction="RUN" />
</configuration>
<flow name="TestFlow">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8088" path="test" doc:name="HTTP" mimeType="text/plain"
encoding="UTF-8"/>
<logger level="INFO" category="hello" doc:name="Logger"/>
</flow>
Mule accepts this, but the service no longer returns; the client simply hangs waiting for a response.
How do I configure my flow so that I can control thread pool size and, once that's done, so that only one thread is available in the pool?
You need to configure the receiver-threading-profile of the HTTP connector:
<http:connector name="httpConnector">
<receiver-threading-profile maxThreadsActive="1" />
</http:connector>