1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.jboss.as.quickstarts.wsba.coordinatorcompletion.simple;
18
19 import com.arjuna.mw.wst11.BusinessActivityManager;
20 import com.arjuna.mw.wst11.BusinessActivityManagerFactory;
21 import com.arjuna.wst.SystemException;
22 import org.jboss.as.quickstarts.wsba.coordinatorcompletion.simple.jaxws.SetServiceBA;
23 import javax.jws.HandlerChain;
24 import javax.jws.WebMethod;
25 import javax.jws.WebService;
26 import javax.jws.soap.SOAPBinding;
27 import javax.servlet.annotation.WebServlet;
28 import java.util.UUID;
29
30
31
32
33
34
35 @WebService(serviceName = "SetServiceBAService", portName = "SetServiceBA", name = "SetServiceBA", targetNamespace = "http://www.jboss.org/jboss-jdf/jboss-as-quickstart/helloworld/wsba/coordinatorcompletion/set")
36 @HandlerChain(file = "/context-handlers.xml", name = "Context Handlers")
37 @SOAPBinding(style = SOAPBinding.Style.RPC)
38 @WebServlet("/SetServiceBA")
39 public class SetServiceBAImpl implements SetServiceBA {
40
41
42
43
44
45
46
47 @WebMethod
48 public void addValueToSet(String value) throws AlreadyInSetException, SetServiceException {
49
50 System.out.println("[SERVICE] invoked addValueToSet('" + value + "')");
51
52 BusinessActivityManager activityManager = BusinessActivityManagerFactory.businessActivityManager();
53
54
55
56
57 String transactionId;
58 try {
59 transactionId = activityManager.currentTransaction().toString();
60 } catch (SystemException e) {
61 throw new SetServiceException("Unable to lookup existing BusinesActivity", e);
62 }
63
64
65
66
67 SetParticipantBA participantBA = SetParticipantBA.getParticipant(transactionId);
68
69 if (participantBA == null) {
70 try {
71
72 SetParticipantBA participant = new SetParticipantBA(transactionId, value);
73 SetParticipantBA.recordParticipant(transactionId, participant);
74
75 System.out.println("[SERVICE] Enlisting a participant into the BA");
76 activityManager.enlistForBusinessAgreementWithCoordinatorCompletion(participant, "SetServiceBAImpl:"
77 + UUID.randomUUID());
78 } catch (Exception e) {
79 System.err.println("Participant enlistment failed");
80 throw new SetServiceException("Error enlisting participant", e);
81 }
82 } else {
83 System.out.println("[SERVICE] Re-using the existing participant, already registered for this BA");
84 participantBA.addValue(value);
85 }
86
87
88 System.out.println("[SERVICE] Invoking the back-end business logic");
89 MockSetManager.add(value);
90 }
91
92
93
94
95
96
97
98 @WebMethod
99 public boolean isInSet(String value) {
100 return MockSetManager.isInSet(value);
101 }
102
103
104
105
106
107
108
109 @WebMethod
110 public void clear() {
111 MockSetManager.clear();
112 }
113 }