Reputation: 710
I have this mule flow
:
<?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:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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/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/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd">
<spring:beans>
<spring:bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<spring:property name="locations">
<spring:list>
<spring:value>configSQL.properties</spring:value>
</spring:list>
</spring:property>
</spring:bean>
</spring:beans>
<db:generic-config name="BBDD_USER" doc:name="Generic Database Configuration" driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="${sql.url}/${sql.database};user=${sql.username};password=${sql.password}"/>
<flow name="sincro-sql" doc:name="sincro-sql">
<http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8042" doc:name="HTTP"/>
<logger message="#[message.payloadAs(java.lang.String)]" level="INFO" doc:name="JSON"/>
<json:json-to-object-transformer doc:name="JSON to Object" returnClass="json.database.object.Data"/>
<db:stored-procedure config-ref="BBDD_USER" doc:name="Data" source="json.database.object.Data" streaming="true">
<db:parameterized-query><![CDATA[{ CALL dbo.ExecSQL(:table_name, :field_name) }]]></db:parameterized-query>
<db:in-param name="field_name" type="VARCHAR" value="field_test"/>
<db:in-param name="table_name" type="VARCHAR" value="table_test"/>
</db:stored-procedure>
</flow>
</mule>
It receives a JSON that I transform to object with a class that contains:
@JsonAutoDetect
public class Data{
private String table_name;
private String field_name;
public void setTableName(String table_name) {
this.table_name= table_name;
}
public String getTableName() {
return table_name;
}
public void setFieldName(String field_name) {
this.field_name= field_name;
}
public String getFieldName() {
return field_name;
}
}
And finally, I call to my database. How can I assign, for example, the property about the table name from the class to the parameter in the database element?
For example,
<db:in-param name="table_name" type="VARCHAR" value="PROPERTY OF CLASS"/>
Upvotes: 0
Views: 260
Reputation: 11606
Use MEL(Mule Expression Langauge) and standard Java method invocation. As Data is you payload, use #[payload.table_name] MEL will automatically use the getter for that field.
Upvotes: 1