I'm using wso2esb 4.7.0 and postgresql and inserting values in two different tables of same database through proxy service.This insertion operation in working properly.Now my scenario is if my second insertion fails,first insertion should rollback.for that i have use transaction mediator(rollback transaction) but it is not working properly.
proxy configuration and fault sequence as follows:
<target >
<inSequence onError="myFaultHandler">
<transaction action="new"/>
<dbreport>
<connection>
<pool>
<password>Youtility11</password>
<user>youtilitydba</user>
<url>jdbx:postgresql://localhost:5432/DB2</url>
<driver>org.postgresql.Driver</driver>
</pool>
</connection>
<statement>
<sql>
insert into table1(name,id) values(?,?)</sql>
<parameter xmlns:ns="http://org.apache.synapse/xsd"
expression="//name/text()"
type="VARCHAR"/>
<parameter xmlns:ns="http://org.apache.synapse/xsd"
expression="//id/text()"
type="VARCHAR"/>
</statement>
</dbreport>
<log level="full">
<property name="name" expression="get-property('name')"/>
<property name="id" expression="get-property('id')"/>
</log>
<log level="full">
<property name="text" value="Reporting to the DB2"/>
</log>
<dbreport>
<connection>
<pool>
<password>Youtility11</password>
<user>youtilitydba</user>
<url>jdbx:postgresql://localhost:5432/DB2</url>
<driver>org.postgresql.Driver</driver>
</pool>
</connection>
<statement>
<sql>
insert into table2(firstname,lastname) values(?,?)</sql>
<parameter xmlns:ns="http://org.apache.synapse/xsd"
expression="//firstname/text()"
type="VARCHAR"/>
<parameter xmlns:ns="http://org.apache.synapse/xsd"
expression="//lastname/text()"
type="VARCHAR"/>
</statement>
</dbreport>
</inSequence>
</target>
and sequence is:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="myFaultHandler">
<log level="full">
<property name="message" value="**ROLLBACK**"/>
</log>
<transaction action="rollback"/>
</sequence>
here when i'm inserting wrong record in second table it shows error but first table insertion is done.why rollback is not working? let me know..
thanks in advance
Related
I send Mail with WSO2 ESB 5.0.0
1. I have uncommented the following line in Axis2.xml file
<transportSender name="mailto" class="org.apache.axis2.transport.mail.MailTransportSender">
<parameter name="mail.smtp.host">smtp.gmail.com</parameter>
<parameter name="mail.smtp.port">587</parameter>
<parameter name="mail.smtp.starttls.enable">true</parameter>
<parameter name="mail.smtp.auth">true</parameter>
<parameter name="mail.smtp.user">lmphuong</parameter>
<parameter name="mail.smtp.password">password</parameter>
<parameter name="mail.smtp.from">lmphuong#gmail.com</parameter>
</transportSender>
<transportReceiver name="mailto" class="org.apache.axis2.transport.mail.MailTransportListener">
<!-- configure any optional POP3/IMAP properties
check com.sun.mail.pop3 and com.sun.mail.imap package documentation for more details-->
</transportReceiver>
2. Add content at messageFormatters in axis2.xml
<messageFormatter contentType="text/html" class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>
3. I have create Proxy Service in WSO2 ESB
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="EmailSender"
transports="http https"
startOnLoad="true">
<description/>
<target>
<inSequence>
<log/>
<property name="messageType"
value="text/html"
scope="axis2"
type="STRING"/>
<property name="ContentType" value="text/html" scope="axis2"/>
<property name="Subject" value="Testing ESB" scope="transport"/>
<property name="OUT_ONLY" value="true"/>
<property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
<payloadFactory media-type="xml">
<format>
<ns:text xmlns:ns="http://ws.apache.org/commons/ns/payload">$1</ns:text>
</format>
<args>
<arg value="Hello WSO2 ESB.....!"/>
</args>
</payloadFactory>
<log level="full"/>
<send>
<endpoint>
<address uri="mailto:ledung123#gmail.com"/>
</endpoint>
</send>
</inSequence>
<outSequence/>
</target>
</proxy>
4. I recieved error
ERROR - MailTransportSender Error creating mail message or sending it to the configured server
javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:306)
...
[2017-09-15 08:04:05,945] ERROR - MailTransportSender Error generating mail message
...
Please help me out how to soved this error
Looks like thereĀ“s something wrong with your credentials (AuthenticationFailedException). Do you have any special chracters in your credentials? Or is there are proxy server between esb and gmail?
What you could do is start esb in debug/enable wire log to see the complete traffic. More info can be found here.
https://docs.wso2.com/display/ESB500/Debugging+Mediation#DebuggingMediation-Viewingwirelogs
Another option might be to use the GMail connector which can be found here.
https://docs.wso2.com/display/ESBCONNECTORS/Gmail+Connector
https://store.wso2.com/store/pages/top-assets?q=%22_default%22%3A%22gmail%22
I would like to create a Dynamic HTTP Endpoint in WSO2. I have a sequence (Tconf) which contains all the property values. I am deriving them, using the Property Mediator. Once I get the variables, I am using the SendMediator to send an rest request. Unfortunately it does not seem to be working. Not sure what I am doing wrong, but none of the properties are getting appended. I can see all the properties when I log them.
<api xmlns="http://ws.apache.org/ns/synapse" name="TririgaApi" context="/tririga">
<resource methods="GET" url-mapping="/employee">
<inSequence>
<sequence key="Tconf"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="uri.var.service.user" expression="get-property('tri.service.user')"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="uri.var.service.pass" expression="get-property('tri.service.pass')"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="uri.var.service.host" expression="get-property('tri.service.host')"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="uri.var.service.path" expression="get-property('tri.service.path')"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="uri.var.service.wfName" expression="get-property('triPeople.database.employee.wfName')"/>
<send>
<endpoint>
<http method="GET" uri-template="http://host:port/{uri.service.host}{uri.var.service.path}?USERNAME={uri.var.service.user}&PASSWORD={uri.var.service.pass}&ioName={uri.var.service.wfName}"/>
</endpoint>
</send>
</inSequence>
</resource>
</api>
You can configure your sequence and API like below to acheive your requirnment.
Sequence Config:
<sequence xmlns="http://ws.apache.org/ns/synapse">
<property name="uri.var.service.user" scope="default" type="STRING" value="testuser"/>
<property name="uri.var.service.pass" scope="default" type="STRING" value="testpasswd"/>
<property name="uri.var.service.host" scope="default" type="STRING" value="testhost"/>
<property name="uri.var.service.path" scope="default" type="STRING" value="testpath"/>
<property name="uri.var.service.wfName" scope="default"
type="STRING" value="testwfName"/>
</sequence>
API Config:
<api xmlns="http://ws.apache.org/ns/synapse" name="TririgaApi" context="/tririga">
<resource methods="GET" url-mapping="/employee">
<inSequence>
<log>
<property name="====== API IN =====" value="==== INSEQ ===="/>
</log>
<sequence key="conf:/Tconf"/>
<property name="POST_TO_URI" value="true" scope="axis2"/>
<send>
<endpoint>
<http method="GET" uri-template="http://localhost:9000/{uri.var.service.host}/{uri.var.service.path}?USERNAME={uri.var.service.user}&PASSWORD={uri.var.service.pass}&ioName={uri.var.service.wfName}"/>
</endpoint>
</send>
</inSequence>
</resource>
</api>
Thanks.
How can i determine that a message contains a specific element? i want to enrich the message if it does not contain specific element, but i do not know how to determine it?
thank you.
You can use the filter mediator to perform content based mediation. Following sample shows your usecase. (1) The filtering was done using the xpath matching. It searches for NOT occurrence of XPath //p:echoString/test, and performs enrich mediation based on that. Following soap body will match the filter. (2)
(1)
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="messageFilter" transports="http https" startOnLoad="true" trace="disable">
<target>
<inSequence>
<log level="full" separator=","/>
<filter xpath="not(//p:echoString/test)" xmlns:p="http://echo.services.core.carbon.wso2.org" >
<then>
<log separator=",">
<property name="XPath Matched" value="true"/>
</log>
<enrich>
<source clone="true" xpath="//p:echoString/in"/>
<target type="property" property="ORIGINAL_REQ"/>
</enrich>
<log separator=",">
<property name="ORIGINAL_REQ" expression="get-property('ORIGINAL_REQ')"/>
</log>
</then>
<else>
<log separator=",">
<property name="XPath Matched" value="false"/>
</log>
</else>
</filter>
<send>
<endpoint>
<address uri="http://localhost:9763/services/echo"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full" separator=",">
<property name="OUT-SEQUENCE" value="property_value"/>
</log>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
(2)
<body>
<p:echoString xmlns:p="http://echo.services.core.carbon.wso2.org">
<in>123</in>
<test>testing-node</test>
</p:echoString>
</body>
I'm working with wso2esb 4.8.0 and i go through this scenario which is given in wso2esb documentation.I want to copy the records from first database to second database as soon as i delete them from first database.but when i put the duplicate record it should neither delete from first nor insert into second.
my proxy service :
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="Transaction_mediator"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="name"
expression="//name/text()"
scope="default"
type="STRING"/>
<property name="id"
expression="//id/text()"
scope="default"
type="STRING"/>
<property name="price"
expression="//price/text()"
scope="default"
type="STRING"/>
<transaction action="new"/>
<log level="full">
<property name="text" value="Reporting to the DB1"/>
</log>
<dbreport useTransaction="true">
<connection>
<pool>
<dsName>DS1</dsName>
</pool>
</connection>
<statement>
<sql>
delete from c1 where name=?</sql>
<parameter expression="get-property('name')" type="VARCHAR"/>
</statement>
</dbreport>
<log level="full">
<property name="text" value="Reporting to the DB2"/>
</log>
<dbreport useTransaction="true">
<connection>
<pool>
<dsName>DS2</dsName>
</pool>
</connection>
<statement>
<sql>
INSERT into c1 values (?,?,?)</sql>
<parameter expression="get-property('name')" type="VARCHAR"/>
<parameter expression="get-property('id')" type="INTEGER"/>
<parameter expression="get-property('price')" type="INTEGER"/>
</statement>
</dbreport>
<transaction action="commit"/>
<send/>
</inSequence>
<outSequence>
<log level="full"/>
<send/>
</outSequence>
</target>
<description/>
</proxy>
It's working but error occurred when i put duplicate records.At that time It deleting records from first but not inserting into second database.What should i do?is their any solution?let me know.
There is an issue with transaction mediator with JDBC and it has been reported in the wso2 esb issue tracker. Therefore, this may be fixed in feature releases.
I am relatively new to WSO2 ESB,
Trying to invoke a REST Web service with GET parameter which is hosted on WSO2 ESB through another REST API.
This is a simple Web service(SampleREST) which replies with welcome messsage in XML format,
When i am invoking this service directly; i can see the correct response on browser, shown below
<Message xmlns="http://ws.apache.org/ns/synapse">WelcomeRanjan</Message>
Now i created another REST web service(InvokeSampleRest) which in turn invokes SampleREST web service with the parametrized GET,
the Invoke WebService Client returns me the XML response wrapped inside the mediator xml tag and other malformed tags, shown below
<mediate><<Message xmlns>"http://ws.apache.org/ns/synapse">WelcomeRanjan</Message></<Message xmlns></mediate>
Here is my Code for the SampleREST API
<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse" name="SampleREST" context="/SampleRest" hostname="10.203.245.47">
<resource methods="GET" uri-template="/{str1}">
<inSequence>
<header name="To" action="remove"/>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<payloadFactory>
<format>
<Message>$1</Message>
</format>
<args>
<arg expression="get-property('uri.var.str1')"/>
</args>
</payloadFactory>
<log level="full" separator=",">
<property name="sequence" value="*** Got Request ***"/>
</log>
<send/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
The code for the InvokeSampleREST code is as shown below( i am calling SampleREST service from here )
<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse" name="InvokeSampleREST" context="/InvokeSampleREST" hostname="10.203.245.47">
<resource methods="GET" uri-template="/{str1}">
<inSequence>
<log level="full" separator=","/>
<property name="REST_URL_POSTFIX" expression="fn:concat('/Welcome',get-property('uri.var.str1'))" scope="axis2" type="STRING"/>
<log level="full">
<property name="sequence" value="****Message Sent *** "/>
</log>
<send>
<endpoint>
<address uri="http://10.203.245.47:8280/SampleRest/"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full" separator=",">
<property name="out" value="** Ouput of Rest call ***"/>
</log>
<property name="ContentType" value="application/xml" scope="axis2" type="STRING"/>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
Appreciate any help.
Thanks,
Ranjan
Why are you using two APIs? You can design your flow, in a single API. I mean you can merge them together.
BTW, you need to set the contentType property in your backend API(ie:At SampleREST API)
Because, when you send back the response to "InvokeSampleREST" API, System doesnt know the content-type of the incoming response and try to handle it as text message.
Eg:
<api name="SampleREST" context="/SampleRest" hostname="localhost">
<resource methods="GET" uri-template="/{str1}">
<inSequence>
<header name="To" action="remove"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<payloadFactory>
<format>
<Message>$1</Message>
</format>
<args>
<arg expression="get-property('uri.var.str1')"/>
</args>
</payloadFactory>
<log level="full" separator=",">
<property name="sequence" value="*** Got Request ***"/>
</log>
<property name="Content-Type"
value="application/xml"
scope="transport"
type="STRING"/>
<send/>
</inSequence>
<faultSequence/>
</resource>
Try doing the following change at the InvokeSampleREST API.
At the outSequence, set the messageType as follows before the <send> mediator.
<property name="messageType" value="application/xml" scope="axis2"/>