1 28 29 package com.caucho.ejb.hessian; 30 31 import com.caucho.ejb.protocol.Skeleton; 32 import com.caucho.ejb.xa.EjbTransactionManager; 33 import com.caucho.hessian.io.HessianInput; 34 import com.caucho.hessian.io.HessianOutput; 35 import com.caucho.hessian.io.HessianProtocolException; 36 37 import javax.transaction.xa.XAResource ; 38 import java.io.InputStream ; 39 import java.io.OutputStream ; 40 import java.util.logging.Level ; 41 import java.util.logging.Logger ; 42 43 46 public class XAResourceSkeleton extends Skeleton { 47 protected static final Logger log 48 = Logger.getLogger(XAResourceSkeleton.class.getName()); 49 50 private EjbTransactionManager _tm; 51 52 XAResourceSkeleton(EjbTransactionManager tm) 53 { 54 _tm = tm; 55 } 56 57 60 public void _service(InputStream is, OutputStream os) 61 throws Exception 62 { 63 HessianInput in = new HessianReader(is); 64 HessianOutput out = new HessianWriter(os); 65 66 in.startCall(); 67 68 String method = in.getMethod(); 69 70 try { 71 if (method.equals("commitOnePhase") || 72 method.equals("commitOnePhase_string") || 73 method.equals("commitOnePhase_1")) { 74 executeCommitOnePhase(in, out); 75 } 76 else if (method.equals("commit") || 77 method.equals("commit_string") || 78 method.equals("commit_1")) { 79 executeCommit(in, out); 80 } 81 else if (method.equals("rollback") || 82 method.equals("rollback_string") || 83 method.equals("rollback_1")) { 84 executeRollback(in, out); 85 } 86 else if (method.equals("prepare") || 87 method.equals("prepare_string") || 88 method.equals("prepare_1")) { 89 executePrepare(in, out); 90 } 91 else 92 executeUnknown(method, in, out); 93 } catch (HessianProtocolException e) { 94 throw e; 95 } catch (Throwable e) { 96 log.log(Level.WARNING, e.toString(), e); 97 98 out.startReply(); 99 out.writeFault("ServiceException", e.getMessage(), e); 100 out.completeReply(); 101 } 102 } 103 104 private void executeCommitOnePhase(HessianInput in, HessianOutput out) 105 throws Throwable 106 { 107 String xid = in.readString(); 108 in.completeCall(); 109 110 _tm.commitTransaction(xid); 111 112 out.startReply(); 113 out.writeNull(); 114 out.completeReply(); 115 } 116 117 private void executeCommit(HessianInput in, HessianOutput out) 118 throws Throwable 119 { 120 String xid = in.readString(); 121 in.completeCall(); 122 123 _tm.commitTransaction(xid); 124 125 out.startReply(); 126 out.writeNull(); 127 out.completeReply(); 128 } 129 130 private void executePrepare(HessianInput in, HessianOutput out) 131 throws Throwable 132 { 133 String xid = in.readString(); 134 in.completeCall(); 135 136 138 out.startReply(); 139 out.writeInt(XAResource.XA_OK); 140 out.completeReply(); 141 } 142 143 private void executeRollback(HessianInput in, HessianOutput out) 144 throws Throwable 145 { 146 String xid = in.readString(); 147 in.completeCall(); 148 149 _tm.rollbackTransaction(xid); 150 151 out.startReply(); 152 out.writeNull(); 153 out.completeReply(); 154 } 155 156 163 protected void executeUnknown(String method, 164 HessianInput in, HessianOutput out) 165 throws Exception 166 { 167 if (method.equals("_hessian_getAttribute")) { 168 String key = in.readString(); 169 in.completeCall(); 170 171 out.startReply(); 172 173 187 out.writeNull(); 188 189 out.completeReply(); 190 } 191 else { 192 out.startReply(); 193 out.writeFault("NoMethod", "no such method: " + method, null); 194 out.completeReply(); 195 } 196 } 197 } 198 | Popular Tags |