Dynamic DataSource Configuration in DBReport/DBlookup mediator in wso2ei Esb profile - wso2-esb

In DBReport/DBLookup mediator,is it possible to pass dynamic datasource?
I want to pass datasource name from property mediator,something like this:
<property name="dsName" value="sample_dbname">
<dbreport><connection><dsName>get-property('dsName')<dsName></connection></dbreport>

Related

How can we inject properties into wso2 Micro Integrator and Enterprise Integrator using file.properties?

I want to use the .car file on another server without using integration studio. So I want to be able to change the hostname and port dynamically using a configuration file. My endpoint URL has variables in it {uri.var.x} that's why I can't use $FILE:x to get the complete URL from file.properties.
I have already tried How to read a property injected from file.properties in WSO2 - micro integrator? but it did not work.
You can simply read the Property from the file and assign it to the variable you desire. Then use it in your Endpoint configurations.
<property expression="get-property('file', 'x')" name="uri.var.x"/>
You can store the values in a properties file called file.properties in the MI_HOME/conf folder and it will be loaded automatically. If you are using a different fileName you can pass it to the server startup script like -Dproperties.file.path=/home/dev/dev.properties. Then you can read them through a Property Mediator.
Further, if you want to construct the full URL from multiple properties you can use Xpath functions.
<property expression="concat('https://', get-property('file', 'host'), ':', get-property('file', 'port'))" name="uri.var.x" scope="default" type="STRING" />
If the properties are not picked from the default file, pass the file path like below.
sh micro-integrator.sh -Dproperties.file.path=./conf/file.properties
Update on WSO2 EI
It seems file scope is not supported in EI. But instead, you can read variables from Environment variables with get-property('env', 'NAME_OF_VARIABLE')
<property expression="concat('https://', get-property('env', 'host'), ':', get-property('env', 'port'))" name="uri.var.x" scope="default" type="STRING"/>
If you want to read them from a properties file, you can do something like the below. Assuming you have a properties file like below.
stockQuoteEP=http://localhost:9000/services/SimpleStockQuoteService
ycr=test1234
host=localycr
port=6676
Add the following script to integrator.sh to export the properties as environment variables. You can improve the script as you require.
while read line; do
echo "Exporting $line"
export $line
done < /home/wso2/wso2ei-6.6.0/conf/file.properties
Then in your integration read them as below.
<property expression="concat('https://', get-property('env', 'host'), ':', get-property('env', 'port'))" name="uri.var.x" scope="default" type="STRING"/>
Update 2 on File Scope in Property mediator
As Sanoj mentioned, file scope in the property mediator is only available from MI 4.0 onward vanilla packs. If you have a WSO2 subscription you can get it as an update for both MI and EI.

Apache camel how insert property in SetBody

I am creating a message in my route, using:
<setBody id="_setBody1">
<constant>
<![CDATA[
<?xml version="1.0" encoding="UTF-8"?&>
..........
<mes:CalendarView MaxEntriesReturned="5" StartDate="(property.DateStart)" EndDate="(property.EndDate)"/>
But property doesn't work. In log I see:
<mes:CalendarView MaxEntriesReturned="5" StartDate="(property.DateStart)" EndDate="(property.EndDate)"/>
How I can insert property in message?
It looks like you want to set some properties inside a static content of XML. I suggest using one of the templates.. such as velocity. It will allow you to do property replacement and manage the static content outside of the route (which is handy for testing and other maintenance)
Yes, i created property before:
<setProperty id="_setProperty1" propertyName="DateStart">
<groovy>new java.text.SimpleDateFormat('yyyy-MM-dd').format(request.body.getStartDate())</groovy>
</setProperty>
But i want to insert this property in content of xml, inside Apache Camel route.

How to access property mediator outside iterator which is defined inside iterator?

I have treed as below
<iterate xmlns:oag="http://www.openapplications.org/oagis/10" xmlns:fn="http://www.w3.org/2005/xpath-functions" continueParent="true" preservePayload="true" attachPath="//ProcessCredit/DataArea" expression="//ProcessCredit/DataArea/Credit sequential="true">
.....
<property xmlns:ns="http://org.apache.synapse/xsd"
xmlns:oa="http://www.openapplications.org/oagis/10"
name="ChargeTransactionKey"
expression="concat(get-property('operation','ChargeTransactionKey'),//Extension/ValueText[#typeCode='Charge Transaction Key'],':')"
scope="operation"
type="STRING"
description="ChargeTransactionKey"/>
...........
</iterate >
<log level="full">
<property name="requestIdChargeTransactionKey"
expression="get-property('operation','ChargeTransactionKey')"/>
</log>
but value in property "requestIdChargeTransactionKey" is null, it means I'm unable to capture the property which is defined inside iterator.
can anybody help on syntax?
The mediation inside iterate works with clones of MessageContext. If you continue parent mediation (set continueParent attribute to true), you work with the initial MessageContext and therefore all the properties you have set with scope 'default' inside iterate are lost
But there is a scope named 'operation' used to retrieve a property in the operation context level and if you set a property with this scope inside iterate, you can get it's value in the parent mediation
Inside iterate :
<property name="ChargeTransactionKey" value="xxx" scope="operation"/>
In parent mediation :
get-property('operation','ChargeTransactionKey')
WSO2 Documentation, You can fetch the property in the operation context level from the operation scope.
The properties within iterated/cloned message with the operation scope are preserved in the sequence even if you have configured your API resources to be sent through the fault sequence when faults exist.
get-property('operation', String propertyName)
A given property with the operation scope only exists in a single request and can be accessed by a single resource. The properties in this scope are passed to the error handler when the FORCE_ERROR_ON_SOAP_FAULT property is set to true

NHibernate mapping customization

I'm using Nhibernate 3.3.1 and I need to ensure that none of my string columns would have lengths smaller than 15 i.e.
I'm trying to check it no AfterMapProperty/BeforeMapProperty events of ModelMapper, but as I know Length property is private of PropertyMapper class or some base class of it.
I'm tryign to avoid to use Reflection to access private property to get Length and check it.
Can you help me?
You can use the check attribute to achieve this.. In your mapping file you need to define something like this:
<property name="Foo" type="string">
<column name="foo" check="DATALENGTH(foo) > 15"/>
</property>
This will create a check constraint.. I am not too sure about the DATALENGTH method but you can confirm that..
Refer section 20.1.1 of NH docs here: http://nhibernate.info/doc/nh/en/index.html

What is the significane of bean id activemqTx?

I've been having trouble with Camel transactions and after some great help from the camel list I eventually tracked it down to using org.apache.activemq.camel.component.ActiveMQComponent in a bean with id 'activemq'. If I use an id of 'activemqTx' it works. But I can't seem to find any documentation on the significance of 'activemqTx' as a bean id.
only one message gets through the route with this:
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
everything works with this:
<bean id="activemqTx" class="org.apache.activemq.camel.component.ActiveMQComponent">
Must have been a bean name clash