I have made a web app which call mule server which is listening to http inbound point at 8081 for accessing the database.I am accessing the database successfully and getting a message. But I want to access the other rest services after I get the object from the database and run some operations.
I don't know how to achieve this.
Please give me example. I am posting my flow.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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.5.1"
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/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.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/jersey http://www.mulesoft.org/schema/mule/jersey/current/mule-jersey.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
<http:endpoint exchange-pattern="request-response" host="localhost" port="8081" method="POST" name="HTTP" doc:name="HTTP"/>
<db:mysql-config name="MySQL_Configuration" host="localhost" port="3306" user="root" password="123456" database="Customer" doc:name="MySQL Configuration"/>
<flow name="muleesbintegrationFlow1" doc:name="muleesbintegrationFlow1">
<http:inbound-endpoint exchange-pattern="request-response" path="crud" doc:name="HTTP" ref="HTTP"/>
<set-session-variable variableName="input" value="#[message.inboundProperties.'http.query.params'.input]" doc:name="input"/>
<set-session-variable variableName="cid" value="#[message.inboundProperties.'http.query.params'.cid]" doc:name="cid"/>
<set-session-variable variableName="fname" value="#[message.inboundProperties.'http.query.params'.fname]" doc:name="fname"/>
<set-session-variable variableName="lname" value="#[message.inboundProperties.'http.query.params'.fname]" doc:name="lname"/>
<choice doc:name="ChoicerOfCrud">
<when expression="#[sessionVars['input']== "insert"]">
<db:insert config-ref="MySQL_Configuration" doc:name="insert">
<db:parameterized-query><![CDATA[INSERT INTO `Customer`.`customer` (`customer_id`, `fname`, `lname`) VALUES (#[sessionVars['cid']], #[sessionVars['fname']], #[sessionVars['lname']]);]]></db:parameterized-query>
</db:insert>
</when>
<when expression="#[sessionVars['input']]=="update"]">
<db:update config-ref="MySQL_Configuration" doc:name="update">
<db:parameterized-query><![CDATA[UPDATE `Customer`.`customer` set
fname = #[sessionVars['fname']],
lname= #[sessionVars['lname']]
where customer_id = #[sessionVars['cid']];]]></db:parameterized-query>
</db:update>
</when>
<when expression="#[sessionVars['input']=="select"]">
<db:select config-ref="MySQL_Configuration" doc:name="selected">
<db:parameterized-query><![CDATA[SELECT * FROM Customer.customer where customer_id =#[sessionVars['cid']];]]></db:parameterized-query>
</db:select>
</when>
<otherwise>
<db:delete config-ref="MySQL_Configuration" doc:name="delete">
<db:dynamic-query><![CDATA[DELETE FROM `Customer`.`customer` WHERE `customer_id`=#[sessionVars['cid']];]]></db:dynamic-query>
</db:delete>
</otherwise>
</choice>
</flow>
</mule>
I recommend to use http:outbound-endpoint to consume a REST service (GET,POST, PUT or DELETE). In this example you can see a flow to invoke a services GET:
<flow name="invoke-ws" doc:name="invoke-ws">
<vm:inbound-endpoint exchange-pattern="request-response" path="vm-ws" doc:name="VM"/>
<logger message="payload is: #[payload]" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" method="GET" address="http://ip:port/service/#[payload]" doc:name="HTTP">
<set-property propertyName="Accept" value="application/json"/>
</http:outbound-endpoint>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<logger message="payload is: #[payload]" level="INFO" doc:name="Logger"/>
</flow>
If the service is SOAP over HTTP, I recommend using http://www.mulesoft.org/documentation/display/current/Web+Service+Consumer
Related
I'm not able to refer the query from flowVariable inside database connector. I have read that it was a known issue in mule 3.5. I'm not sure if it is still an open issue in 3.8. Do any one know about it ?
Below is the flow -
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:db="http://www.mulesoft.org/schema/mule/db" 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://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/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.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="8081" doc:name="HTTP Listener Configuration"/>
<db:mysql-config name="MySQL_Configuration5" host="localhost" port="3306" user="root" password="root" database="world" doc:name="MySQL Configuration"/>
<flow name="selectFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/db/select" allowedMethods="GET" doc:name="HTTP"/>
<db:select config-ref="MySQL_Configuration5" doc:name="local mysql database">
<db:parameterized-query><![CDATA[select * from country where code='IND']]></db:parameterized-query>
</db:select>
<json:object-to-json-transformer doc:name="Object to JSON"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>
<flow name="deleteFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/db/delete" allowedMethods="DELETE" doc:name="HTTP"/>
<db:delete config-ref="MySQL_Configuration5" doc:name="local mysql database">
<db:parameterized-query><![CDATA[delete from countrylanguage where countrycode='PAK']]></db:parameterized-query>
</db:delete>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
<flow name="postFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/db/insert" allowedMethods="POST" doc:name="HTTP"/>
<set-variable variableName="jsonString" value="#[payload]" doc:name="Variable"/>
<flow-ref name="cleanUpBeforeInserting" doc:name="cleanUpBeforeInserting"/>
<json:json-to-object-transformer doc:name="JSON to Object" returnClass="java.util.Collection"/>
<flow-ref name="InsertEachRecord" doc:name="Flow Reference"/>
</flow>
<flow name="cleanUpBeforeInserting">
<db:delete config-ref="MySQL_Configuration5" doc:name="Database">
<db:parameterized-query><![CDATA[delete from countrylanguage where countrycode='PAK']]></db:parameterized-query>
</db:delete>
<set-payload value="#[flowVars.jsonString]" doc:name="Set Payload"/>
<logger message="************* cleaned up data **************** " level="INFO" doc:name="Logger"/>
</flow>
<sub-flow name="InsertEachRecord">
<foreach doc:name="For Each">
<set-variable variableName="sqlStatement" value="Insert into countrylanguage (countrycode, language, percentage, isofficial) values(#[payload.CountryCode], #[payload.Language],#[payload.Percentage], #[payload.IsOfficial])" doc:name="Variable"/>
<logger message="#[flowVars.sqlStatement]" level="INFO" doc:name="Logger"/>
<db:insert config-ref="MySQL_Configuration5" doc:name="Database">
<db:parameterized-query><![CDATA[#[flowVars.sqlStatement]]]></db:parameterized-query>
</db:insert>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</foreach>
</sub-flow>
</mule>
It works fine if I replace the #[flowVars.sqlStatement] with Insert into countrylanguage (countrycode, language, percentage, isofficial) values(#[payload.CountryCode], #[payload.Language],#[payload.Percentage], #[payload.IsOfficial])
Any pointers would be helpful. Thanks in advance.
Instead using <db:parameterized-query> try with <db:dynamic-query> like following
<db:insert config-ref="MySQL_Configuration5" doc:name="Database">
<db:dynamic-query><![CDATA[#[flowVars.sqlStatement]]]></db:dynamic-query>
</db:insert>
In Mulesoft, How can I manage multiple twitter user accounts dynamically because at present it requires consumerkey, consumersecret, accesskey and accesstoken in connector configuration for an application which can own only one user.
Please anyone can explain?
<twitter:config name="Twitter__Configuration" accessKey="#[flowVars.accessToken]" consumerKey="#[flowVars.consumerKey]" consumerSecret="#[flowVars.consumerSecret]" doc:name="Twitter: Configuration" accessSecret="#[flowVars.accessTokenSecret]"/>
<flow name="twitterFlow1">
<db:select config-ref="MySQL_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[select * from twittercredentials;]]></db:parameterized-query>
</db:select>
<set-variable variableName="consumerKey" value="#[message.payload[0]['consumerkey']]" doc:name="Variable" />
<set-variable variableName="consumerSecret" value="#[message.payload[0]['consumersecret']]" doc:name="Variable" />
<set-variable variableName="accessToken" value="#[message.payload[0]['accesstoken']]" doc:name="Variable" />
<set-variable variableName="accessTokenSecret" value="#[message.payload[0]['accesstokensecret']]" doc:name="Variable" />
</flow>
<flow name="twitterFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/twitterconnect" doc:name="HTTP"/>
<flow-ref name="twitterFlow1" />
<twitter:show-user config-ref="Twitter__Configuration" doc:name="Twitter"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
assigned the values in variables and accessed as flowvars in the global element which fails.
I think in this post from mule community forum you can find the answer to your question.
Basically you can use mule expression language in twitter globalk connector in this way:
<twitter:config name="Twitter" accessKey="#[flowVars.accessKey]"
accessSecret="#[flowVars.accessSecret]" consumerKey="#
[flowVars.consumerKey]" consumerSecret="#[flowVars.consumerSecret]"/>
Hope this helps
Full example:
This is an example flow:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:twitter="http://www.mulesoft.org/schema/mule/twitter" 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://www.mulesoft.org/schema/mule/twitter http://www.mulesoft.org/schema/mule/twitter/current/mule-twitter.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<twitter:config name="Twitter" accessKey="#[flowVars['accessKey']]" accessSecret="#[flowVars['accessSecret']]" consumerKey="Cannot be parametrized" consumerSecret="Cannot be parametrized" useSSL="false" doc:name="Twitter"/>
<flow name="twitterFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<logger level="INFO" doc:name="Logger"/>
<message-properties-transformer scope="invocation" doc:name="Message Properties">
<add-message-property key="accessKey" value="#['myVarAccessKey']"/>
<add-message-property key="accessSecret" value="#['myVarAccessSecret']"/>
</message-properties-transformer>
<twitter:update-status config-ref="Twitter" status="ciao" doc:name="Twitter"/>
</flow>
</mule>
Here also a screenshot of a wireshark capture using IP filtering (twitter ip families) for debug the http call:
I have a very simple flow where im trying to do comparision of inbound property and payload which are integers inside a choice component, inspite of the values being the same the choice component routes its to the default section.
I would like to get some help to make this work
Thank you in advance
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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.4.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/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<flow name="flow_testFlow1" doc:name="flow_testFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<set-payload value="#[12]" doc:name="Set Payload"/>
<set-property propertyName="trial" value="#[12]" doc:name="Property"/>
<choice doc:name="Choice">
<when expression="#[payload == message.inboundProperties['trial']]">
<logger level="INFO" doc:name="Logger" message="Success"/>
</when>
<otherwise>
<logger level="INFO" doc:name="Logger" message="error"/>
</otherwise>
</choice>
</flow>
</mule>
set-property sets properties in the outbound scope, the inbound scope is read-only (created by the inbound endpoint).
So you need to fix your choice route expression like this:
<when expression="#[payload == message.outboundProperties['trial']]">
And then it works.
I'm completely new to Mule and I'm trying to put together a system to retrieve an XML file from a remote server and either display it as is or to convert it to JSON and then display it like that. What I have at the moment is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json" 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.4.1" 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/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
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/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
<flow name="TestFlow1" doc:name="TestFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<set-variable variableName="type" value="#[message.inboundProperties['type']]" doc:name="Set type variable"/>
<http:outbound-endpoint exchange-pattern="request-response" host="[URL REMOVED]" port="80" path="#[message.inboundProperties['feed']].php" method="GET" doc:name="HTTP" ><response><object-to-string-transformer /></response></http:outbound-endpoint>
<logger level="INFO" doc:name="Logger"/>
<choice doc:name="Choice">
<when expression="#[flowVars['type']=='JSON']">
<json:object-to-json-transformer doc:name="Object to JSON"/>
</when>
<when expression="#[flowVars['type']=='xml']">
<mulexml:object-to-xml-transformer acceptMuleMessage="true" doc:name="Object to XML"/>
<logger level="INFO" doc:name="XML"/>
</when>
<otherwise>
<set-payload value="Type not set" doc:name="Error message"/>
</otherwise>
</choice>
<logger level="INFO" doc:name="Logger"/>
</flow>
</mule>
Retrieving the XML and displaying it as-is works just fine. I just need to figure out the JSON conversion.
I tried putting in an HTTP-to-Object transformer before the Object-to-JSON transformer, but that throws an illegal argument exception because the http:outbound-endpoint returns a response of class ReleasingInputStream. I've tried converting the response to a string and work with that, but that didn't work either.
What is the best way to go about doing this?
Check this out. This explains who to transform the XML to JSON.
Mule: Is there simple way of converting XML to JSON
I am trying to select data from database using mule studio i have done all the jdbc connection and getting data from database.But unable to respond to client with JSON
my client is CURL client sending data to mule in JSON like this
curl -H "Content-Type: application/json" -d '{"id":"1"}' http://localhost:8081/selectdb
and created flow with below configuration i am getting response from database in my esb log but unable to pass the client my config is like this
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" 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.4.1" 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/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.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/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.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/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd">
<jdbc-ee:postgresql-data-source name="PostgreSQL_Data_Source" user="youtilitydba" password="Youtility11" url="jdbc:postgresql://localhost:5432/sample" transactionIsolation="UNSPECIFIED" doc:name="PostgreSQL Data Source"/>
<jdbc-ee:connector name="Database" dataSource-ref="PostgreSQL_Data_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"/>
<flow name="selectfromdbFlow1" doc:name="selectfromdbFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="selectdb" doc:name="HTTP"/>
<json:json-to-object-transformer returnClass="java.util.Map" doc:name="JSON to Object"/>
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryKey="SELECT" queryTimeout="-1" connector-ref="Database" doc:name="Database">
<jdbc-ee:query key="SELECT" value="select firstname,lastname,id from users where id =#[message.payload.id]"/>
</jdbc-ee:outbound-endpoint>
<logger message="message before set httpresponse #[payload]" level="INFO" doc:name="Logger"/>
<response>
<logger message="after expression #[payload]" level="INFO" doc:name="Logger"/>
</response>
<response>
<expression-transformer expression="#[payload]" doc:name="Expression"/>
</response>
</flow></mule>
and i logged it twice but same message logging but unable to send to client my logs like this
INFO 2013-11-29 12:57:12,589 [[selectfromdb].connector.http.mule.default.receiver.02] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'Database.dispatcher.1260873373'. Object is: EEJdbcMessageDispatcher
INFO 2013-11-29 12:57:12,589 [[selectfromdb].connector.http.mule.default.receiver.02] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'Database.dispatcher.1260873373'. Object is: EEJdbcMessageDispatcher
INFO 2013-11-29 12:57:12,637 [[selectfromdb].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: message before set httpresponse [{lastname=ff, firstname=ff, id=5}]
INFO 2013-11-29 12:57:12,639 [[selectfromdb].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: after expression [{lastname=ff, firstname=ff, id=5}]
but not geting from client side
tried with setpayload,echo,httpresponsebuilder,expression-transfomer also but i am unable to get this
After the query you have to use an Object to JSON Transformer then add an HTTP Response Builder with the following properties: contentType=application/json and status=200.
Here is an example:
<flow name="DB-Read-TestFlow1" doc:name="DB-Read-TestFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="selectdb" doc:name="HTTP"/>
<json:json-to-object-transformer returnClass="java.util.Map" doc:name="JSON to Object"/>
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryKey="SELECT" queryTimeout="-1" connector-ref="Database" doc:name="Database">
<jdbc-ee:query key="SELECT" value="select firstname,lastname,id from users where id =#[message.payload.id]"/>
</jdbc-ee:outbound-endpoint>
<logger message="message before set httpresponse #[payload]" level="INFO" doc:name="Logger"/>
<response>
<logger message="after expression #[payload]" level="INFO" doc:name="Logger"/>
</response>
<json:object-to-json-transformer doc:name="Object to JSON"/>
<response>
<http:response-builder status="200" contentType="application/json" doc:name="HTTP Response Builder"/>
</response>
</flow>
You can directly use <http:response-builder/> at the end with your status code and set you message as payload
Something like the following :-
<http:response-builder status="200" contentType="application/json" doc:name="HTTP Response Builder">
<set-payload value="Your Message" />
</http:response-builder>