Wso2Dss Box_Carring not working in WSO2esb4.8.0

后端 未结 2 1660
臣服心动
臣服心动 2021-01-23 01:17

I am working with wso2dss3.0.1 and wso2esb4.8.0.I wish to work with Transactions for that i enabled box_carying in wso2dss and its working fine.Means i wish insert the data into

相关标签:
2条回答
  • 2021-01-23 02:04

    There is a workaround, use request_box to wrap multiple sql non-query operation in a single request to avoid using session. If any sql in the request fails, the whole request will be rollback.

    First you need a mysql database named MyDB with a user named root whose password is root and a Postgresql database also named MyDB with a user named postgres whose password is root. Then create a table named customer in both databases:

        CREATE TABLE customer (
            cust_id int(11) NOT NULL,
            name varchar(255) NOT NULL,
            PRIMARY KEY (`cust_id`)
        );
    

    The sample inserts a record into mysql, then inserts two records with the same cust_id into postgres which causes an error, so the whole transaction will be rolled back and you will not see the record inserted into mysql.

    Below is my proxy service definition:

        <?xml version="1.0" encoding="UTF-8"?>
        <proxy xmlns="http://ws.apache.org/ns/synapse" name="MyTransactionProxy" 
            startOnLoad="true" statistics="disable" trace="disable" transports="http,https">
            <target>
                <inSequence>
                    <property expression="//id/text()" name="id"/>
                    <property expression="//name/text()" name="name"/>
                    <payloadFactory media-type="xml">
                        <format>
                            <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
                              xmlns:dat="http://ws.wso2.org/dataservice">
                                <soapenv:Header/>
                                <soapenv:Body>
                                    <dat:request_box>
                                        <dat:my_insert>
                                            <dat:id>$1</dat:id>
                                            <dat:name>$2</dat:name>
                                        </dat:my_insert>
                                        <dat:pos_insert>
                                            <dat:id>$1</dat:id>
                                            <dat:name>$2</dat:name>
                                        </dat:pos_insert>
                                        <dat:pos_insert>
                                            <dat:id>$1</dat:id>
                                            <dat:name>$2</dat:name>
                                        </dat:pos_insert>
                                    </dat:request_box>
                                </soapenv:Body>
                            </soapenv:Envelope>
                        </format>
                        <args>
                            <arg evaluator="xml" expression="get-property('id')"/>
                            <arg evaluator="xml" expression="get-property('name')"/>
                        </args>
                    </payloadFactory>
                    <callout action="urn:request_box" serviceURL="http://longqinsi:8280/services/DTPDS">
                        <source xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" 
                            xmlns:s12="http://www.w3.org/2003/05/soap-envelope" 
                            xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/>
                        <target xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" 
                            xmlns:s12="http://www.w3.org/2003/05/soap-envelope" 
                            xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/>
                    </callout>
                </inSequence>
                <outSequence>
                    <send/>
                </outSequence>
            </target>
            <description/>
        </proxy>
    

    My data service is defined as below:

        <?xml version="1.0" encoding="UTF-8"?>
        <data disableStreaming="true" enableBoxcarring="true" enableDTP="true" name="DTPDS">
            <config id="pos_ds">
                <property name="org.wso2.ws.dataservice.xa_datasource_class">org.postgresql.xa.PGXADataSource</property>
                <property name="org.wso2.ws.dataservice.xa_datasource_properties">
                    <property name="ServerName">localhost</property>
                    <property name="PortNumber">5432</property>
                    <property name="DatabaseName">MyDB</property>
                    <property name="User">postgres</property>
                    <property name="Password">root</property>
                </property>
            </config>
            <config id="my_ds">
                <property name="org.wso2.ws.dataservice.xa_datasource_class">com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</property>
                <property name="org.wso2.ws.dataservice.xa_datasource_properties">
                    <property name="URL">jdbc:mysql://localhost:3306/MyDB</property>
                    <property name="User">root</property>
                    <property name="Password">root</property>
                </property>
            </config>
            <query id="pos_q" useConfig="pos_ds">
                <sql>INSERT INTO customer VALUES(?,?)</sql>
                <param name="id" sqlType="INTEGER"/>
                <param name="name" sqlType="STRING"/>
            </query>
            <query id="my_q" useConfig="my_ds">
                <sql>INSERT INTO customer VALUES(?,?)</sql>
                <param name="id" sqlType="INTEGER"/>
                <param name="name" sqlType="STRING"/>
            </query>
            <operation disableStreaming="true" name="pos_insert" returnRequestStatus="true">
                <call-query href="pos_q">
                    <with-param name="id" query-param="id"/>
                    <with-param name="name" query-param="name"/>
                </call-query>
            </operation>
            <operation disableStreaming="true" name="my_insert" returnRequestStatus="true">
                <call-query href="my_q">
                    <with-param name="id" query-param="id"/>
                    <with-param name="name" query-param="name"/>
                </call-query>
            </operation>
        </data>
    
    0 讨论(0)
  • 2021-01-23 02:17

    Your you are not doing your DSS operations in the same session.

    DSS uses the JSESSIONID cookie to identify sessions. You need to grab that cookie from the begin_boxcar call and in turn send the cookie along with the rest of the DSS calls that you wish to perform in the same transaction.

    Finally you will need to send the same cookie in the call to end_boxcar or abort_boxcar, whichever you end up calling.

    After your call to a begin_boxcar operation in a DSS service you can access the cookies set by the service through transport properties:

    <property name="setCookieHeader" expression="$trp:Set-Cookie" action="set"/>
    

    After you have the cookie in a Synapse message context property you can use a scripting language such as Groovy or JavaScript to parse the actual value from the cookie.

    Any subsequent DSS calls that should be in the same boxcarring session must send the cookie to the DSS service. You can have Axis2 send the cookie by setting it to a transport property (analogous to HTTP headers in this case):

    <property name="Cookie" expression="$ctx:jsessionIdCookie" action="set" scope="transport" />
    
    0 讨论(0)
提交回复
热议问题