KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > net > axis > server > TransactionResponseHandler


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 // $Id: TransactionResponseHandler.java,v 1.5.6.1 2005/03/02 14:19:51 tdiesler Exp $
9

10 package org.jboss.net.axis.server;
11
12 import org.jboss.axis.AxisFault;
13 import org.jboss.axis.MessageContext;
14 import org.jboss.axis.handlers.BasicHandler;
15
16 import javax.naming.InitialContext JavaDoc;
17 import javax.naming.NamingException JavaDoc;
18 import javax.transaction.HeuristicMixedException JavaDoc;
19 import javax.transaction.HeuristicRollbackException JavaDoc;
20 import javax.transaction.RollbackException JavaDoc;
21 import javax.transaction.SystemException JavaDoc;
22 import javax.transaction.UserTransaction JavaDoc;
23
24 /**
25  * This handler is to finish a previously opened client-side transaction.
26  * <br>
27  * <h3>Change notes</h3>
28  * <ul>
29  * </ul>
30  * @created 22.03.2002
31  * @author <a HREF="mailto:Christoph.Jung@infor.de">Christoph G. Jung</a>
32  * @version $Revision: 1.5.6.1 $
33  */

34
35 public class TransactionResponseHandler extends BasicHandler
36 {
37
38    final protected UserTransaction JavaDoc userTransaction;
39
40    public TransactionResponseHandler() throws NamingException JavaDoc
41    {
42       userTransaction =
43               (UserTransaction JavaDoc)new InitialContext JavaDoc().
44               lookup(Constants.USER_TRANSACTION_JNDI_NAME);
45    }
46    
47    //
48
// Protected Helpers
49
//
50

51    protected void endTransaction(MessageContext msgContext, boolean commit)
52            throws AxisFault
53    {
54       Object JavaDoc tx =
55               msgContext.getProperty(Constants.TRANSACTION_PROPERTY);
56       if (tx != null)
57       {
58          try
59          {
60             if (commit)
61             {
62                userTransaction.commit();
63             }
64             else
65             {
66                userTransaction.rollback();
67             }
68          }
69          catch (RollbackException JavaDoc e)
70          {
71             throw new AxisFault("Could not rollback tx.", e);
72          }
73          catch (SystemException JavaDoc e)
74          {
75             throw new AxisFault("Could not influence tx setting.", e);
76          }
77          catch (HeuristicMixedException JavaDoc e)
78          {
79             throw new AxisFault("Could not commit tx.", e);
80          }
81          catch (HeuristicRollbackException JavaDoc e)
82          {
83             throw new AxisFault("Could not commit tx.", e);
84          }
85          finally
86          {
87             msgContext.setProperty(Constants.TRANSACTION_PROPERTY, null);
88          }
89       }
90    }
91
92    //
93
// API
94
//
95

96    /*
97     * @see Handler#invoke(MessageContext)
98     */

99    public void invoke(MessageContext msgContext) throws AxisFault
100    {
101       endTransaction(msgContext, true);
102    }
103
104    /*
105     * @see Handler#onFault(MessageContext)
106     */

107    public void onFault(MessageContext msgContext)
108    {
109       try
110       {
111          endTransaction(msgContext, false);
112       }
113       catch (AxisFault e)
114       {
115       }
116    }
117
118 }
Popular Tags