Get Return value from stored procedure call in Mule 3.5.0 ESB - sql-server-2005

Using Mule CE 3.5.0 & SQL Server 2005.
I'm trying to call a stored procedure using the new Mule connectors db:generic-config & db:stored-procedure and then retrieve the return value from the stored procedure.
For some reason I can't get Mule to retrieve the return value from the stored procedure.
Here is sample stored procedure code,
CREATE PROCEDURE dbo.sp_AddConnection (#pUserName varchar(30),
#pPassword varchar(30),
#opConnectionID bigint OUTPUT)
AS
BEGIN
SET NOCOUNT ON;
DECLARE #rc int;
SET #opConnectionID = 0;
....
--If login is good then
--SET #rc = 0
--SET #opConnectionID = new ConnectionID from Connection table
--If login is bad then
--SET #rc = 1
--SET #opConnectionID = 0
....
SET NOCOUNT OFF;
RETURN(#rc);
END;
The following Mule code works to retrieve the ConnectionID output parameter.
<db:generic-config name="MSSQL"
url="jdbc:sqlserver://local:1433;user=username;password=password;applicationName=Mule-ESB;databaseName=db1;"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
doc:name="Generic Database Configuration"/>
<flow name="jdbctestFlow1" doc:name="jdbctestFlow1">
<quartz:inbound-endpoint jobName="CronJobSchedule"
doc:name="Quartz"
repeatInterval="0"
responseTimeout="10000"
cronExpression="00 29 01 ? * *"> <!-- Change as necessary --->
<quartz:event-generator-job/>
</quartz:inbound-endpoint>
<db:stored-procedure config-ref="MSSQL" doc:name="Database">
<db:parameterized-query><![CDATA[{ CALL dbo.sp_Add_Connection(:pUserName, :pPassword, :opConnectionID) }]]></db:parameterized-query>
<db:in-param name="pEmail" type="VARCHAR" value="user1"/>
<db:in-param name="pPassword" type="VARCHAR" value="1234"/>
<db:inout-param name="opConnectionID" type="BIGINT" value="0"/>
</db:stored-procedure>
<logger message="opConnectionID = #[message.payload['opConnectionID']]" level="INFO" doc:name="Logger"/>
</flow>
The above Mule flow works and I can
I can get the ConnectionID output variable with #[message.payload['opConnectionID']].
Next I changed db:stored-procedure element to try and get the return value.
<flow name="jdbctestFlow1" doc:name="jdbctestFlow1">
<quartz:inbound-endpoint jobName="CronJobSchedule"
doc:name="Quartz"
repeatInterval="0"
responseTimeout="10000"
cronExpression="00 29 01 ? * *"> <!-- Change as necessary --->
<quartz:event-generator-job/>
</quartz:inbound-endpoint>
<db:stored-procedure config-ref="MSSQL" doc:name="Database">
<db:parameterized-query><![CDATA[{ CALL :returnValue = dbo.sp_Add_Connection(:pUserName, :pPassword, :opConnectionID) }]]></db:parameterized-query>
<db:out-param name="returnValue" type="INTEGER"/>
<db:in-param name="pEmail" type="VARCHAR" value="user1"/>
<db:in-param name="pPassword" type="VARCHAR" value="1234"/>
<db:inout-param name="opConnectionID" type="BIGINT" value="0"/>
</db:stored-procedure>
<logger message="Finish SP call" level="INFO" doc:name="Logger"/> <!-- doens't make it here -->
<logger message="opConnectionID = #[message.payload['opConnectionID']]" level="INFO" doc:name="Logger"/>
<logger message="returnValue = #[message.payload['returnValue']]" level="INFO" doc:name="Logger"/>
</flow>
Mule throws the following error,
********************************************************************************
Message : Index: 5, Size: 5 (java.lang.IndexOutOfBoundsException). Message payload is of type: NullPayload
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Index: 5, Size: 5 (java.lang.IndexOutOfBoundsException)
java.util.LinkedList:-1 (null)
2. Index: 5, Size: 5 (java.lang.IndexOutOfBoundsException). Message payload is of type: NullPayload (org.mule.api.MessagingException)
org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.IndexOutOfBoundsException: Index: 5, Size: 5
at java.util.LinkedList.checkElementIndex(Unknown Source)
at java.util.LinkedList.get(Unknown Source)
at org.mule.module.db.internal.domain.executor.AbstractExecutor.doProcessParameters(AbstractExecutor.java:51)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
I'm thinking it may be a Mule CE vs Mule EE thing but I don't see anything in the reference docs saying this functionality is only available in Mule EE.
It may also be that I'm just calling the db:stored-procedure incorrectly.
Any clues to point me in the right direction would be appreciated.
Thanks in advance.

I think the problem is that you don't have the parameter returnValue defined in you stored procedure.
you should have something like this:
CREATE PROCEDURE dbo.sp_AddConnection (#pUserName varchar(30),
#pPassword varchar(30),
#opConnectionID bigint OUTPUT,
#returnValue int OUTPUT)
and also de parametrized query:
<db:parameterized-query><![CDATA[{ CALL :returnValue = dbo.sp_Add_Connection(:pUserName, :pPassword, :opConnectionID, :returnValue) }]]></db:parameterized-query>

Related

Json to object and Mule expression

I have a json file which the link is https://gist.githubusercontent.com/Rajeun/b550fe17181610f5c0f0/raw/7ba82c6c1135d474e0bedc8b203d3cf16e196038/file.json
i want to do a test on the boolean "sent". there is my xml file.
<http:request-config name="HTTP_Request_Configuration"
host="gist.githubusercontent.com" port="443" protocol="HTTPS"
doc:name="HTTP Request Configuration" />
<flow name="testFlow">
<poll doc:name="Poll">
<http:request config-ref="HTTP_Request_Configuration"
path="Rajeun/b550fe17181610f5c0f0/raw/7ba82c6c1135d474e0bedc8b203d3cf16e196038/file.json"
method="GET" doc:name="HTTP" />
</poll>
<json:json-to-object-transformer
returnClass="java.lang.Object" doc:name="JSON to Object" />
<choice doc:name="Choice">
<when expression="#[payload.sent] == true )">
<logger message="its ok" level="INFO" doc:name="Logger"/>
</when>
<otherwise>
<logger message="Error" level="INFO" doc:name="Logger"/>
</otherwise>
</choice>
</flow>
errors:
ERROR 2015-03-25 16:29:59,871 [[push1].testFlow.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Failed to transform from "json" to "java.lang.Object"
Code : MULE_ERROR-109
--------------------------------------------------------------------------------
Exception stack is:
1. Unexpected character ('"' (code 34)): was expecting comma to separate OBJECT entries
at [Source: java.io.InputStreamReader#1a09a5b; line: 5, column: 4] (org.codehaus.jackson.JsonParseException)
org.codehaus.jackson.JsonParser:1433 (null)
2. Failed to transform from "json" to "java.lang.Object" (org.mule.api.transformer.TransformerException)
org.mule.module.json.transformers.JsonToObject:132 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.codehaus.jackson.JsonParseException: Unexpected character ('"' (code 34)): was expecting comma to separate OBJECT entries
at [Source: java.io.InputStreamReader#1a09a5b; line: 5, column: 4]
at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1433)
at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:521)
at org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:442)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
i don't know what is the problem please any help !!
The expression should be <when expression="#[payload.sent == true ]"> and this is working for me ..
also as afelisatti mentioned, there should be a comma after email attribute in JSON payload
There's is no comma after the "email" in that JSON file so the transformation fails, that's what the error message is saying. I believe the correct format would be
{
"token" : 123,
"tel" : 456,
"email" : "Rm9vYmFyIQ==",
"sent" : true
}
Remove
<json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object" />
and use an json based mule expression #[json:sent]

Scatter gather routing error. Message payload is of type: String

I'm new to Mule and while working on a fairly simple Hello World example on Anypoint Studio to test out the Scatter/Gather flow control element, I'm getting the following error, without much else in the way of information:
ERROR 2014-12-19 22:00:30,172 [[unifinesb].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Exception was found for route(s): 0. Message payload is of type: String
Type : org.mule.routing.CompositeRoutingException
Code : MULE_ERROR--2
JavaDoc : http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/routing/CompositeRoutingException.html
Payload : /Waldo
********************************************************************************
Exception stack is:
1. Exception was found for route(s): 0. Message payload is of type: String (org.mule.routing.CompositeRoutingException)
org.mule.routing.CollectAllAggregationStrategy:51 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/routing/CompositeRoutingException.html)
********************************************************************************
Root Exception stack trace:
org.mule.routing.CompositeRoutingException: Exception was found for route(s): 0. Message payload is of type: String
at org.mule.routing.CollectAllAggregationStrategy.aggregateWithFailedRoutes(CollectAllAggregationStrategy.java:51)
at org.mule.routing.CollectAllAggregationStrategy.aggregate(CollectAllAggregationStrategy.java:38)
at org.mule.routing.ScatterGatherRouter.processResponses(ScatterGatherRouter.java:207)
at org.mule.routing.ScatterGatherRouter.process(ScatterGatherRouter.java:135)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at ...
Judging from the top description of the error, I understand the problem to be that Scatter gather does not receive String payloads, even though the current documentation for the component mentions nothing of the sort. Is this correct?
The flow I'm running is fairly simple, receiving a String from an inbound http and trying to route it to a REST service that will use the String to print something (returning text/plain) and to a DB to store the String in a table. Relevant code follows:
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8084" doc:name="HTTP"/>
<expression-filter expression="#[payload != '/favicon.ico']" doc:name="Filter browser icon padding"/>
<logger message="current payload is #[payload]" level="INFO" doc:name="Startup log - to stdout"/>
<scatter-gather doc:name="Scatter-Gather">
<processor-chain>
<logger message="#['Rest branch msg input :' + payload]" level="DEBUG" doc:name="File Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" method="POST" address="http://localhost:8080/application/rest/mensaje?givenName=#[payload]" doc:name="REST Service"/>
<logger message="#['Rest msg output :' + payload]" level="DEBUG" doc:name="File Logger"/>
</processor-chain>
<processor-chain>
<logger message="#['Database msg input :' + payload]" level="DEBUG" doc:name="File Logger"/>
<db:insert config-ref="MySQL_VestaLocal" doc:name="Application Postgress">
<db:parameterized-query><![CDATA[insert into http_user_info (first_name) values ('#[payload]');]]></db:parameterized-query>
</db:insert>
<logger message="#['Database msg output :' + payload]" level="DEBUG" doc:name="File Logger"/>
</processor-chain>
</scatter-gather>
<set-payload value="#['REST DB Success!']" doc:name="Set Payload"/>
Trawling through the net I found this old Mule JIRA issue with an exception similar to what I'm getting, but trying out the suggested solution (workaround?) didn't do anything for me: https://www.mulesoft.org/jira/browse/MULE-7594
Something wrong is happening in your route 0.
You are getting a composite routing exception as per documentation:
The CompositeRoutingException is new to the 3.5.0 Runtime. It extends
the Mule MessagingException to aggregate exceptions from different
routes in the context of a single message router. Exceptions are
correlated to each route through a sequential ID.
This exception exposes two methods which allow you to obtain the IDs
of failed routes and the exceptions returned by each route.
The getExceptions method returns a map where the key is an integer
that identifies the index of the failed route, and the value is the
exception itself. The getExceptionForRouteIndex(int) method returns
the exception of the requested route ID.
As you don't have an execption strategy, the toString is call to that exception and that only prints the route failing (that has nothing to do with the fact that the payload is String)
Please use the following exeption strategy to find out exactly what's wrong:
<catch-exception-strategy doc:name="Catch Exception Strategy">
<logger level="ERROR" message="#[exception.exceptions]"/>
</catch-exception-strategy>

How to get the SOAP request from an ActiveMQ queue and implement it in the webservice

I have a requirement in Mule in which I need to expose a SOAP web service ..
Now I am implementing it in 2 flows :-
<flow name="ServiceFlow" doc:name="ServiceFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="mainData" doc:name="HTTP" />
<cxf:jaxws-service serviceClass="com.test.services.schema.maindata.v1.MainData" doc:name="SOAP" />
<object-to-string-transformer doc:name="Object to String"/>
<jms:outbound-endpoint queue="NewQueue" connector-ref="Active_MQ" doc:name="JMS"/>
</flow>
<flow name="Flow2" doc:name="Flow2" >
<jms:inbound-endpoint connector-ref="Active_MQ" address="jms://tcp:NewQueue" doc:name="JMS" exchange-pattern="request-response"/>
<component class="com.test.services.schema.maindata.v1.Impl.MainDataImpl" doc:name="JavaMain_ServiceImpl" >
<method-entry-point-resolver>
<include-entry-point method="retrieveDataOperation"/>
<include-entry-point method="insertDataOperation"/>
<include-entry-point method="updateDataOperation"/>
<include-entry-point method="deleteDataOperation"/>
</method-entry-point-resolver>
</component>
<logger level="INFO" message="payload :-#[message.payload]" doc:name="Logger"/>
</flow>
In the first flow (ServiceFlow) I am trying to send the SOAP request in an ActiveMQ queue and in second flow (Flow2) ..I am trying to consume the request in MainDataImpl class .. But I am getting an exception while consuming the request :-
Exception stack is:
1. "Message with id "ID:ANIRBAN-PC-49419-1407595657591-1:1:6:1:1" has been redelivered 1 times on endpoint "jms://tcp:NewQueue", which exceeds the maxRedelivery setting of 0 on the connector "Active_MQ". Message payload is of type: ActiveMQTextMessage (org.mule.transport.jms.redelivery.MessageRedeliveredException)
org.mule.transport.jms.redelivery.JmsXRedeliveryHandler:81 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/transport/jms/redelivery/MessageRedeliveredException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.transport.jms.redelivery.MessageRedeliveredException: "Message with id "ID:ANIRBAN-PC-49419-1407595657591-1:1:6:1:1" has been redelivered 1 times on endpoint "jms://tcp:NewQueue", which exceeds the maxRedelivery setting of 0 on the connector "Active_MQ". Message payload is of type: ActiveMQTextMessage
at org.mule.transport.jms.redelivery.JmsXRedeliveryHandler.handleRedelivery(JmsXRedeliveryHandler.java:81)
at org.mule.transport.jms.MultiConsumerJmsMessageReceiver$JmsWorker.preProcessMessage(MultiConsumerJmsMessageReceiver.java:512)
at org.mule.transport.AbstractReceiverWorker$1$1.process(AbstractReceiverWorker.java:117)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
Now I want to know how can I resolve the issue as I guess MainDataImpl is expecting the message as object type .. but there is no way to convert the String message into Object ... Any solution for the above issue ??? Please Help
UPDATE AFTER ADDING OBJECT TO XML:-
<jms:activemq-connector name="Active_MQ" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>
<flow name="ServiceFlow" doc:name="ServiceFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" path="mainData" doc:name="HTTP" />
<cxf:jaxws-service serviceClass="com.test.services.schema.maindata.v1.MainData" doc:name="SOAP" />
<mulexml:object-to-xml-transformer doc:name="Object to XML"/>
<!-- <vm:outbound-endpoint exchange-pattern="request-response" path="Flow1-WT-Main" doc:name="VM"/> -->
<jms:outbound-endpoint queue="NewQueue" connector-ref="Active_MQ" doc:name="JMS"/>
</flow>
<flow name="Flow2" doc:name="Flow2" >
<!-- <vm:inbound-endpoint exchange-pattern="request-response" path="Flow1-WT-Main" doc:name="VM"/> -->
<jms:inbound-endpoint connector-ref="Active_MQ" address="jms://tcp:NewQueue" doc:name="JMS" exchange-pattern="request-response"/>
<mulexml:xml-to-object-transformer doc:name="XML to Object"/>
<async doc:name="Async">
<logger message="Payload :-#[message.payload]" level="INFO" doc:name="Logger"/>
</async>
<component class="com.test.services.schema.maindata.v1.Impl.MainDataImpl" doc:name="JavaMain_ServiceImpl" >
<method-entry-point-resolver>
<include-entry-point method="retrieveDataOperation"/>
<include-entry-point method="insertDataOperation"/>
<include-entry-point method="updateDataOperation"/>
<include-entry-point method="deleteDataOperation"/>
</method-entry-point-resolver>
</component>
<logger level="INFO" message="ccccccc :-#[message.payload]" doc:name="Logger"/>
</flow>
Now the exception is :-
INFO 2014-08-09 21:10:33,426 [ActiveMQ Session Task-1] org.mule.api.processor.LoggerMessageProcessor: ccccccc :-com.test.services.schema.maindata.v1.DataResponse#1ca5a88a
INFO 2014-08-09 21:10:33,426 [[Dummysimpleclientwebservice].Flow2.1.02] org.mule.api.processor.LoggerMessageProcessor: Payload :-com.test.services.schema.maindata.v1.DataRequest#3fdc0ab7
ERROR 2014-08-09 21:10:33,433 [ActiveMQ Session Task-1] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Source was not of a supported type. Valid types are Message, String, Map, InputStream, List, byte[], Serializable or OutputHandler, but was DataResponse (javax.jms.JMSException)
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Source was not of a supported type. Valid types are Message, String, Map, InputStream, List, byte[], Serializable or OutputHandler, but was DataResponse(JMS Code: null) (javax.jms.JMSException)
org.mule.transport.jms.JmsMessageUtils:144 (http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/jms/JMSException.html)
2. Source was not of a supported type. Valid types are Message, String, Map, InputStream, List, byte[], Serializable or OutputHandler, but was DataResponse (javax.jms.JMSException) (org.mule.api.transformer.TransformerException)
org.mule.transport.jms.transformers.AbstractJmsTransformer:79 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
javax.jms.JMSException: Source was not of a supported type. Valid types are Message, String, Map, InputStream, List, byte[], Serializable or OutputHandler, but was DataResponse
at org.mule.transport.jms.JmsMessageUtils.toMessage(JmsMessageUtils.java:144)
at org.mule.transport.jms.transformers.AbstractJmsTransformer.transformToMessage(AbstractJmsTransformer.java:66)
at org.mule.transport.jms.transformers.ObjectToJMSMessage.transformMessage(ObjectToJMSMessage.java:54)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
ERROR 2014-08-09 21:10:34,488 [ActiveMQ Session Task-2] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : "Message with id "ID:ANIRBAN-PC-49768-1407598818233-1:1:6:1:1" has been redelivered 1 times on endpoint "jms://tcp:NewQueue", which exceeds the maxRedelivery setting of 0 on the connector "Active_MQ". Message payload is of type: ActiveMQTextMessage
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. "Message with id "ID:ANIRBAN-PC-49768-1407598818233-1:1:6:1:1" has been redelivered 1 times on endpoint "jms://tcp:NewQueue", which exceeds the maxRedelivery setting of 0 on the connector "Active_MQ". Message payload is of type: ActiveMQTextMessage (org.mule.transport.jms.redelivery.MessageRedeliveredException)
org.mule.transport.jms.redelivery.JmsXRedeliveryHandler:81 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/transport/jms/redelivery/MessageRedeliveredException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.transport.jms.redelivery.MessageRedeliveredException: "Message with id "ID:ANIRBAN-PC-49768-1407598818233-1:1:6:1:1" has been redelivered 1 times on endpoint "jms://tcp:NewQueue", which exceeds the maxRedelivery setting of 0 on the connector "Active_MQ". Message payload is of type: ActiveMQTextMessage
at org.mule.transport.jms.redelivery.JmsXRedeliveryHandler.handleRedelivery(JmsXRedeliveryHandler.java:81)
at org.mule.transport.jms.MultiConsumerJmsMessageReceiver$JmsWorker.preProcessMessage(MultiConsumerJmsMessageReceiver.java:512)
at org.mule.transport.AbstractReceiverWorker$1$1.process(AbstractReceiverWorker.java:117)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
As you guessed it, the problem is that you serialize the inbound message object to a String with object-to-string-transformer and, via a JMS queue, try to feed it to the MainDataImpl object, which takes objects as input parameters for its different operations.
The solution is to simply serialize the inbound object to XML, send it via JMS then deserialize it back to an object.
For this replace the object-to-string-transformer with an object-to-xml-transformer and add a xml-to-object-transformer right after the jms:inbound-endpoint.
EDIT
I didn't realize you're using NewQueue in request-response fashion, because you actually inconsistently declare it. On the jms:outbound-endpoint you do not provide an exchange-pattern which makes it one-way by default ; while on the jms:inbound-endpoint your set the exchange-pattern to request-response, which triggers the execution of the response phase of Flow2.
So: be consistent, use the same exchange-pattern on both JMS endpoints or, even better, declare a global JMS endpoint with the right exchange-pattern and ref-it from the jms:inbound and outbound endpoints.
If you decide to stay with request-response, then you need to do the same for the response, ie. serialize the result of calling MainDataImpl (a DataResponse object) back to XML and in ServiceFlow deserialize it back to object.
So, the working solution is (as per David's suggestion)
1. Need to add <mulexml:object-to-xml-transformer doc:name="Object to XML"/> before JMS outbound and <mulexml:xml-to-object-transformer doc:name="XML to Object"/> after JMS inbound
2. Need to use the same exchange-pattern on both JMS endpoints

How to access flow vars in jdbc end point in mule studio application

<jdbc-ee:mysql-data-source name="MySQL_Data_Source" user="root" password="root" url="jdbc:mysql://localhost:3306/test" transactionIsolation="UNSPECIFIED" doc:name="MySQL Data Source"/>
<jdbc-ee:connector name="test" dataSource-ref="MySQL_Data_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"/>
<data-mapper:config name="DataMapper" transformationGraphPath="mapper.grf" doc:name="DataMapper"/>
<flow name="EmployeeListFlow1" doc:name="EmployeeListFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP" path="employeelist"/>
<json:json-to-object-transformer doc:name="JSON to Object" returnClass="java.util.Map"/>
<choice doc:name="Choice">
<when expression="payload.storeId == null || payload.storeId <= 0 ">
<set-variable variableName="query" value="select e.employeeid,e.companyid,e.firstName,e.lastName from employees e where companyid = #[message.payload.companyId]" doc:name="CompanyId"/>
</when>
<otherwise>
<set-variable variableName="query" value="select e.employeeid,e.companyid,e.firstName,e.lastName from employees e where employeeid in (select employeeid from employeestores where storeid =#[message.payload.storeId] )" doc:name="StoreId"/>
</otherwise>
</choice>
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryTimeout="-1" doc:name="EmployeeListFetch" connector-ref="Theatro" queryKey="employees_list">
<jdbc-ee:query key="employees_list" value="#[flowVars['query']]"/>
</jdbc-ee:outbound-endpoint>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
Exception :
Root Exception stack trace:
java.lang.IllegalArgumentException: No SQL Strategy found for SQL statement: #[flowVars['query']]
at com.mulesoft.mule.transport.jdbc.sqlstrategy.EESqlStatementStrategyFactory.create(EESqlStatementStrategyFactory.java:109)
at org.mule.transport.jdbc.JdbcMessageDispatcher.doSend(JdbcMessageDispatcher.java:69)
at org.mule.transport.AbstractMessageDispatcher.process(AbstractMessageDispatcher.java:81)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
Here I want to build dynamically jdbc query based on input.
json data {"companyId":"1","storeId":"1"}
Please help me.
try using something like the following for jdbc dynamic outbound endpoints:
<outbound-endpoint address="jdbc://select * from ${datasource.table} #[variable:where-statement]" exchange-pattern="request-response"/>
HTH
There are 2 mistakes here,
In Choice the expression is missing []
Something like <when expression="[payload.storeId == null || payload.storeId <= 0] ">
and next your query should be something like this :-
select e.employeeid,e.companyid,e.firstName,e.lastName from employees e where employeeid in (select employeeid from employeestores where storeid ='#[message.payload.storeId]' )
Where #[message.payload.storeId] should be inside '' as storeId is a String

Mule: transform the results of outbound-endpoint

The following flow transforms incoming an JSON payload into a SOAP message which is used in a subflow to make a webservice request. Everything works fine -- i'm able to send a response back for the original (incoming) request, but I want to add a final step to transform the SOAP result into JSON before sending it back to the client.
Here is the flow:
<mule ...>
<data-mapper:config name="json2xml_grf" transformationGraphPath="json2xml.grf" doc:name="DataMapper"/>
<flow name="simpleFlow" doc:name="simpleFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<set-property propertyName="Access-Control-Allow-Origin" value="*" doc:name="Property"/>
<choice doc:name="Choice">
<when expression="#[message.inboundProperties['http.method'] != 'OPTIONS']">
<data-mapper:transform config-ref="json2xml_grf" doc:name="DataMapper"/>
<flow-ref name="invokeCalculatorService" doc:name="invokeCalculator"/>
</when>
<otherwise>
<http:response-builder status="200" doc:name="HTTP Response Builder">
...
</http:response-builder>
</otherwise>
</choice>
</flow>
<flow name="invokeService" doc:name="invokeService">
<cxf:proxy-client payload="body" enableMuleSoapHeaders="true" doc:name="Proxy Client">
</cxf:proxy-client>
<mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" xsl-file="/Users/jsleeuw/MuleStudio/workspace/calc/src/main/resources/transformsoap.xslt" doc:name="XSLT"/>
<http:outbound-endpoint exchange-pattern="request-response" doc:name="CalculatorService" method="POST" host="service-host" port="30001"/>
</flow>
</mule>
Putting a DataMapper at the end of the subflow like this:
...
<flow-ref name="invokeCalculatorService" doc:name="invokeCalculator"/>
<data-mapper:transform config-ref="xml2json_grf" doc:name="DataMapper"/>
...
Results in this error:
********************************************************************************
Message : Error executing graph: ERROR (com.mulesoft.mule.module.datamapper.api.exception.DataMapperExecutionException). Message payload is of type: DepthXMLStreamReader
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Content is not allowed in prolog. (org.xml.sax.SAXParseException)
org.apache.xerces.util.ErrorHandlerWrapper:-1 (null)
2. org.xml.sax.SAXParseException: Content is not allowed in prolog. (net.sf.saxon.trans.DynamicError)
net.sf.saxon.event.Sender:308 (null)
3. XPath evaluation failed (org.jetel.exception.JetelRuntimeException)
org.jetel.component.tree.reader.xml.XmlXPathEvaluator:81 (null)
4. Error executing graph: ERROR (com.mulesoft.mule.module.datamapper.api.exception.DataMapperExecutionException)
com.mulesoft.mule.module.datamapper.impl.DefaultGraphExecutor:83 (null)
5. Error executing graph: ERROR (com.mulesoft.mule.module.datamapper.api.exception.DataMapperExecutionException). Message payload is of type: DepthXMLStreamReader (com.mulesoft.mule.module.datamapper.processors.DataMapperMessageExecutionException)
com.mulesoft.mule.module.datamapper.processors.DataMapperMessageProcessor:135 (null)
--------------------------------------------------------------------------------
Whereas putting the datamapper at the end of the subflow ends up blocking the response.
How should I go about transforming my response?
From the Content is not allowed in prolog exception it seems that <flow-ref name="invokeCalculatorService" /> doesn't return a payload that is parseable as XML.
This sub-flow returns a org.apache.cxf.staxutils.DepthXMLStreamReader, which is an javax.xml.stream.XMLStreamReader. The only transformer I know of that can deserialize this type to an XML string is: <mulexml:dom-to-xml-transformer />.
Can you add one just before the data-mapper element?