1 7 8 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 ; 17 import javax.naming.NamingException ; 18 import javax.transaction.HeuristicMixedException ; 19 import javax.transaction.HeuristicRollbackException ; 20 import javax.transaction.RollbackException ; 21 import javax.transaction.SystemException ; 22 import javax.transaction.UserTransaction ; 23 24 34 35 public class TransactionResponseHandler extends BasicHandler 36 { 37 38 final protected UserTransaction userTransaction; 39 40 public TransactionResponseHandler() throws NamingException 41 { 42 userTransaction = 43 (UserTransaction )new InitialContext (). 44 lookup(Constants.USER_TRANSACTION_JNDI_NAME); 45 } 46 47 51 protected void endTransaction(MessageContext msgContext, boolean commit) 52 throws AxisFault 53 { 54 Object 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 e) 70 { 71 throw new AxisFault("Could not rollback tx.", e); 72 } 73 catch (SystemException e) 74 { 75 throw new AxisFault("Could not influence tx setting.", e); 76 } 77 catch (HeuristicMixedException e) 78 { 79 throw new AxisFault("Could not commit tx.", e); 80 } 81 catch (HeuristicRollbackException 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 96 99 public void invoke(MessageContext msgContext) throws AxisFault 100 { 101 endTransaction(msgContext, true); 102 } 103 104 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 |