1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.kandula.wsat.twopc;
18
19 import org.apache.axiom.om.OMElement;
20 import org.apache.axis2.AxisFault;
21 import org.apache.axis2.context.OperationContext;
22 import org.apache.axis2.wsdl.WSDLConstants;
23 import org.apache.kandula.Constants;
24 import org.apache.kandula.coordinator.at.ATCoordinator;
25 import org.apache.kandula.faults.AbstractKandulaException;
26 import org.apache.kandula.participant.Vote;
27 import org.apache.kandula.storage.StorageFactory;
28
29 /***
30 * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
31 */
32 public class CoordinatorPortTypeRawXMLSkeleton {
33 private OperationContext opContext;
34
35 public void setOperationContext(OperationContext opContext) {
36 this.opContext = opContext;
37 }
38
39 /***
40 * @param requestElement
41 * @throws AbstractKandulaException
42 */
43 public OMElement preparedOperation(OMElement requestElement)
44 throws AxisFault {
45 StorageFactory.getInstance().setConfigurationContext(
46 opContext.getServiceContext().getConfigurationContext());
47 OMElement header = opContext.getMessageContext(
48 WSDLConstants.MESSAGE_LABEL_IN_VALUE).getEnvelope().getHeader();
49 String activityId = header.getFirstChildWithName(
50 Constants.TRANSACTION_ID_PARAMETER).getText();
51 String enlistmentId = header.getFirstChildWithName(
52 Constants.ENLISTMENT_ID_PARAMETER).getText();
53 ATCoordinator coordinator = new ATCoordinator();
54 try {
55 coordinator.countVote(activityId, Vote.PREPARED, enlistmentId);
56 } catch (AbstractKandulaException e) {
57 AxisFault fault = new AxisFault(e);
58 fault.setFaultCode(e.getFaultCode());
59 throw fault;
60 }
61 return null;
62 }
63
64 /***
65 * @param requestElement
66 * @throws AbstractKandulaException
67 */
68 public OMElement abortedOperation(OMElement requestElement)
69 throws AxisFault {
70 StorageFactory.getInstance().setConfigurationContext(
71 opContext.getServiceContext().getConfigurationContext());
72 OMElement header = opContext.getMessageContext(
73 WSDLConstants.MESSAGE_LABEL_IN_VALUE).getEnvelope().getHeader();
74 String activityId = header.getFirstChildWithName(
75 Constants.TRANSACTION_ID_PARAMETER).getText();
76 String enlistmentId = header.getFirstChildWithName(
77 Constants.ENLISTMENT_ID_PARAMETER).getText();
78 ATCoordinator coordinator = new ATCoordinator();
79 try {
80 coordinator.abortedOperation(activityId, enlistmentId);
81 } catch (AbstractKandulaException e) {
82 AxisFault fault = new AxisFault(e);
83 fault.setFaultCode(e.getFaultCode());
84 throw fault;
85 }
86 return null;
87 }
88
89 /***
90 * @param requestElement
91 * @throws AbstractKandulaException
92 */
93 public OMElement readOnlyOperation(OMElement requestElement)
94 throws AxisFault {
95 StorageFactory.getInstance().setConfigurationContext(
96 opContext.getServiceContext().getConfigurationContext());
97 OMElement header = opContext.getMessageContext(
98 WSDLConstants.MESSAGE_LABEL_IN_VALUE).getEnvelope().getHeader();
99 String activityId = header.getFirstChildWithName(
100 Constants.TRANSACTION_ID_PARAMETER).getText();
101 String enlistmentId = header.getFirstChildWithName(
102 Constants.ENLISTMENT_ID_PARAMETER).getText();
103 ATCoordinator coordinator = new ATCoordinator();
104 try {
105 coordinator.countVote(activityId, Vote.READ_ONLY, enlistmentId);
106 } catch (AbstractKandulaException e) {
107 AxisFault fault = new AxisFault(e);
108 fault.setFaultCode(e.getFaultCode());
109 throw fault;
110 }
111 return null;
112 }
113
114 /***
115 * @param requestElement
116 * @throws AbstractKandulaException
117 */
118 public OMElement committedOperation(OMElement requestElement)
119 throws AxisFault {
120 StorageFactory.getInstance().setConfigurationContext(
121 opContext.getServiceContext().getConfigurationContext());
122 OMElement header = opContext.getMessageContext(
123 WSDLConstants.MESSAGE_LABEL_IN_VALUE).getEnvelope().getHeader();
124 String activityId = header.getFirstChildWithName(
125 Constants.TRANSACTION_ID_PARAMETER).getText();
126 String enlistmentId = header.getFirstChildWithName(
127 Constants.ENLISTMENT_ID_PARAMETER).getText();
128 ATCoordinator coordinator = new ATCoordinator();
129 try {
130 coordinator.countParticipantOutcome(activityId, enlistmentId);
131 } catch (AbstractKandulaException e) {
132 AxisFault fault = new AxisFault(e);
133 fault.setFaultCode(e.getFaultCode());
134 throw fault;
135 }
136 return null;
137 }
138
139 /***
140 * @param requestElement
141 * @throws AbstractKandulaException
142 */
143 public OMElement replayOperation(OMElement requestElement) throws AxisFault {
144 StorageFactory.getInstance().setConfigurationContext(
145 opContext.getServiceContext().getConfigurationContext());
146 System.out.println("Visited Replay operation");
147 return null;
148 }
149
150 }