2013-10-25 21 views
0

我试图创建,它发送一个RESTful HTTP POST和插入这个数据到表中的交易单元。2阶段提交POX/REST端点+数据库的插入

虽然我对本地序列的的onError处理程序,当我禁用连接到我的终点,而不是失败的“发送”调停使端点处于暂停状态。然后它继续跳过发送并只插入数据。此外,我的自定义失败序列抱怨说我没有进行交易,即使它在'我调用<transaction action="new"/>

'后调用'虽然我已阅读文档并理解进入SUSPEND是默认行为失败的端点,我实际上想要更多的控制。我想触发我自己在失败(或收据的一些特定的HTTP响应代码)序列,并调用<transaction action="rollback"/>

为了清楚起见,我的序列的相关部分如下所示:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="csvToDatabaseRollback"> 
    <log level="custom"> 
     <property name="text" value="Rolling back transaction"/> 
    </log> 
    <transaction action="rollback"/> 
    <!-- rollback any other state, here --> 
</sequence> 

<sequence xmlns="http://ws.apache.org/ns/synapse" name="csvRow2Pc" onError="csvToDatabaseRollback"> 
    <transaction action="new"/> 
    <log level="full"> 
     <property name="State" value="Iteration"/> 
    </log> 
    <property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/> 
    <log level="custom"> 
     <property name="text" value="Calling rest-endpoint"/> 
    </log> 
    <send> 
     <endpoint> 
     <address uri="http://localhost:80/spotify" format="pox"/> 
     </endpoint> 
    </send> 
    <log level="custom"> 
     <property name="text" value="After HTTP POST"/> 
    </log> 
    <dbreport useTransaction="true"> 
     <connection> 
     .... 
     </connection> 
     <statement> 
     <sql> 
      <![CDATA[ insert into file values (?, ?, ?)]]></sql>                                                         
      <parameter xmlns:ns2="http://org.apache.synapse/xsd" xmlns:ns="http://org.apache.synapse/xsd" xmlns:sec="http://secservice.samples.esb.wso2.org" expression="//line/col_one/text()" type="VARCHAR"/> 
      <parameter xmlns:ns2="http://org.apache.synapse/xsd" xmlns:ns="http://org.apache.synapse/xsd" xmlns:sec="http://secservice.samples.esb.wso2.org" expression="//line/col_two/text()" type="VARCHAR"/> 
      <parameter xmlns:ns2="http://org.apache.synapse/xsd" xmlns:ns="http://org.apache.synapse/xsd" xmlns:sec="http://secservice.samples.esb.wso2.org" expression="//line/col_three/text()" type="VARCHAR"/> 
     </statement> 
     </dbreport> 
     <log level="custom"> 
     <property name="text" value="Before tx commit"/> 
     </log> 
     <transaction action="commit"/> 
</sequence> 

日志包含:

[2013-10-25 15:09:40,117] WARN - ConnectCallback Connection refused or failed for : localhost/127.0.0.1:80 
[2013-10-25 15:09:40,116] INFO - LogMediator text = After HTTP POST 
[2013-10-25 15:09:40,129] INFO - LogMediator text = Rolling back transaction 
[2013-10-25 15:09:40,129] WARN - EndpointContext Suspending endpoint : endpoint_f2e0b5550f82db317194145cb24b59f38a63ab610d8a994c - last suspend duration was : 30000ms and current suspend duration is : 30000ms - Next retry after : Fri Oct 25 15:10:10 NZDT 2013 
[2013-10-25 15:09:40,121] INFO - LogMediator text = Before tx commit 
[2013-10-25 15:09:40,131] INFO - LogMediator text = Rolling back transaction 
[2013-10-25 15:09:40,131] ERROR - TransactionMediator Unable to rollback transaction 
java.lang.IllegalStateException: This method needs a transaction for the calling thread and none exists. 
Possible causes: either you didn't start a transaction, 
it rolledback due to timeout, or it was committed already. 
ACTIONS: You can try one of the following: 
1. Make sure you started a transaction for the thread. 

如果我托运的行已提交到数据库中。随后的尝试将愉快地跳过'发送'中介,因为它已被暂停。

理想情况下,我想发送HTTP POST和定制的路由规则基于REST的反应,而不是暂停。我怎样才能做到这一点?

回答

0

当端点ESB暂停会调用faultsequence。在故障序列中,您可以调用您的任何序列。因此它可以让你控制你的自定义代码。

+0

感谢。我已经证明了上述情况。问题不在于我的故障序列没有被调用;它是:ⅰ)当我故障序列内回滚,它不能识别外部事务;看到上面的错误。 ii)端点被暂停,并在下次调用时被忽略。 –