why dbreport mediator gets an exception if userTransction is true - wso2

When I use dbreport mediator using transaction, it went wrong which says:
java.lang.ClassCastException: org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to javax.sql.PooledConnection
but if i don't the property of useTransaction of dbreport mediator is false, it works fine, I don't konw why this happens, maybe a bug?
below is my configuration:
<api context="/transaction" name="TransactionAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET">
<inSequence>
<transaction action="use-existing-or-new"/>
<dbreport useTransaction="true">
<connection>
<pool>
<password>1</password>
<driver>oracle.jdbc.OracleDriver</driver>
<url>jdbc:oracle:thin:#10.10.90.241:1522:orcl</url>
<user>bap_sr</user>
</pool>
</connection>
<statement>
<sql><![CDATA[insert into action_view values('c','s','a')]]></sql>
</statement>
</dbreport>
<send>
<endpoint key="FormEp"/>
</send>
</inSequence>
<outSequence>
<transaction action="commit"/>
<send/>
</outSequence>
<faultSequence/>
</resource>

It's a bug https://github.com/wso2/product-ei/issues/1176.
You can define the datasource in the master-datasource.xml.

Related

Iterate mediator doesn't send response to aggregate mediator

Based on WSO2 documentation, we can use Aggregate mediator to collect responses from Iterate mediator and send back the aggregated data to as response to client, but for some reason, I can't use Aggregate mediator out side the Iterate to get the expected results, the following code stucks in Iterate mediator for ever
<api context="/test" name="test" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST GET">
<inSequence>
<iterate description="Students Loop" expression="json-eval($.students)" id="create_students" sequential="true">
<target>
<sequence>
<call blocking="true">
<endpoint key="CreateStudent"/>
</call>
</sequence>
</target>
</iterate>
<aggregate id="create_students">
<completeCondition>
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete aggregateElementType="root" expression="json-eval($)"/>
</aggregate>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
but the following code is working fine:
<api context="/test" name="test" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST GET">
<inSequence>
<iterate description="Students Loop" expression="json-eval($.students)" id="create_students" sequential="true">
<target>
<sequence>
<call blocking="true">
<endpoint key="CreateStudent"/>
</call>
<property name="RESULTS" scope="default">
<students xmlns=""/>
</property>
<aggregate id="create_students">
<completeCondition>
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete aggregateElementType="root" enclosingElementProperty="RESULTS" expression="json-eval($)">
<log level="full"/>
</onComplete>
</aggregate>
<respond/>
</sequence>
</target>
</iterate>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Is that means, I have to put Aggregate inside Iterate?
The first approach is correct, but as I know, the calls should be non-blocking, while we use the aggregate mediator. Otherwise the aggregation does not proceed.

How do i use wso2 dblookup mediator with mysql? i tried this code on micro integrator

<?xml version="1.0" encoding="UTF-8"?>
<api context="/database" name="databaseApi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST GET">
<inSequence>
<log level="full"/>
<dblookup>
<connection>
<pool>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3307/api</url>
<user>root</user>
<password>1234</password>
</pool>
</connection>
<statement>
<sql><![CDATA[select * from api.userlist where api.userlist.id = ?]]></sql>
<parameter expression="$url:id" type="NUMERIC"/>
<result column="id" name="UserId"/>
<result column="name" name="UserName"/>
<result column="role" name="UserRole"/>
</statement>
</dblookup>
<log level="full"/>
<log level="custom">
<property expression="get-property('UserId')" name="UserId"/>
<property expression="get-property('UserName')" name="UserName"/>
<property expression="get-property('UserRole')" name="UserRole"/>
</log>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
this error shows up whenever i send a request even though the connection works
[2022-05-03 11:44:34,477] ERROR {DBLookupMediator} - {api:databaseApi} SQL
Exception occurred while executing statement : select * from
api.userlist where api.userlist.id = ? against DataSource :
jdbc:mysql://localhost:3307/api
org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver
class 'com.mysql.jdbc.Driver'
If you are using ESB server, you need to add the mysql driver to the <PRODUCT_HOME>/repository/components/lib location and restart the server [1].
[1]-https://docs.wso2.com/display/ESB481/Setting+up+MySQL#SettingupMySQL-Settingupthedrivers

The system cannot infer the transport information from URL WSO2EI

Please, I have this error with my WSO2EI API definitions, it worked for me many times but no I don't know what is happening.
My Configuration is as following :
<resource methods="PUT DELETE GET" uri-template="/{appointmentId}">
<inSequence>
<log description="" level="custom">
<property expression="uri.var.appointmentId" name="property_name"/>
</log>
<switch description="" source="$axis2:HTTP_METHOD">
<case regex="GET">
<sequence key="appointmentGet"/>
</case>
<default>
<sequence key="errorSequence"/>
</default>
</switch>
<respond/>
</inSequence>
<outSequence/>
<faultSequence>
<sequence key="errorSequence"/>
<send/>
</faultSequence>
</resource>
Thank you very much
I forgot to use get-property('uri.var.appointmentId')

Guaranteed Delivery of Messages with Active MQ and WSO2 EI

Issue: i have a proxy service which consumes only XML message, but sometimes if we are getting XML message with not proper format,just syntax error,our proxy should send that message to a different queue,the message should not loss.
i have followed the below link but unable to get the expected output
https://www.yenlo.com/blog/guaranteed-message-deliveries-part-3-monitoring-the-redelivery-policy
Below is my proxy:
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="RollbackProxy" startOnLoad="true" transports="jms" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<log description="" level="full">
<property name="****************" value="******************************"/>
</log>
</inSequence>
<outSequence/>
<faultSequence>
<property name="SET_ROLLBACK_ONLY" scope="axis2" type="STRING" value="true"/>
<log category="ERROR" level="full">
<property expression="$ctx:ERROR_CODE" name="error_code"/>
<property expression="$ctx:ERROR_MESSAGE" name="error_message"/>
<property expression="$ctx:ERROR_DETAIL" name="error_detail"/>
</log>
</faultSequence>
</target>
<parameter name="transport.jms.Destination">QueueName</parameter>
<parameter name="transport.jms.ContentType">
<rules xmlns="">
<jmsProperty>contentType</jmsProperty>
<default>application/xml</default>
</rules>
</parameter>
<parameter name="transport.jms.ConnectionFactory">myQueueConnectionFactory</parameter>
</proxy>
axis2.xml and activemq.xml i have properly updated.
we are using active MQ.
Can somebody guide me on this?
Thanks in Advance

How do I return a response in an wso2 esb proxy with vfs JMS Sender?

I have a proxy service in WSO2 ESB 4.5.0 that is supposed to handle a SOAP-request from a webclient, send information to a JMS-topic and then respond to the the webclient.
The problem is that when I use the JMS-sender it by default waits for a response on a temporary queue.
To change the behavior of the JMS-Sender I can set OUT_ONLY to true, but then the webclient does not get a response at all.
Is there a way to return a response even if I set OUT_ONLY to true?
OR
Can I set JMS-Sender not to expect a reply without sending OUT_ONLY to true?
According to your requirement you may need to use a Messagestore, please refer the following configuration, which stores the message in JMSStore and sending the acknowledgement back to the client (success or failed),followed by ESB uses the forward schedul processor which guarantees that the store message in the JMSStore will be delivered to the backend, and in the case of the real BE (may be JMS) failed it retires thus util the message is delivered thus it wont be removed from the Message store, this a part how the DEAD LATTER CHANNELING has been accomplished using WSO2 ESB
<proxy xmlns="http://ws.apache.org/ns/synapse" name="StockQuoteProxy" transports="http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="OUT_ONLY" value="true"/>
<property name="target.endpoint" value="JMSEP"/>
<property name="enableREST" value="true"/>
<store messageStore="JMSMS"/>
<payloadFactory>
<format>
<esbResponse xmlns="">
<text> added sccuessfully </text>
</esbResponse>
</format>
</payloadFactory>
<header name="To" action="remove"/>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<send/>
</inSequence>
<faultSequence>
<makefault version="soap11">
<code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/" value="soap11Env:VersionMismatch"/>
<reason value="test"/>
<role>MessageStoreFault</role>
<detail>MessageStoreFault</detail>
</makefault>
<send/>
</faultSequence>
</target>
<publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
<description></description>
</proxy>
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="JMSEP">
<address uri="jms:/SimpleStockQuoteService?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616" format="pox">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
<timeout>
<duration>1000</duration>
<responseAction>fault</responseAction>
</timeout>
</address>
</endpoint>
<messageStore name="JMSMS" class="org.wso2.carbon.message.store.persistence.jms.JMSMessageStore" xmlns="http://ws.apache.org/ns/synapse">
<parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
<parameter name="java.naming.provider.url">tcp://localhost:61616</parameter>
<parameter name="store.jms.destination">JMSMS</parameter>
<parameter name="store.jms.JMSSpecVersion">1.1</parameter>
<parameter name="store.jms.cache.connection">false</parameter>
</messageStore>
<messageProcessor name="Processor1" class="org.apache.synapse.message.processors.forward.ScheduledMessageForwardingProcessor" messageStore="JMSMS" xmlns="http://ws.apache.org/ns/synapse">
<parameter name="interval">4000</parameter>
</messageProcessor>