1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.jboss.as.quickstarts.wsba.participantcompletion.simple;
18
19 import com.arjuna.mw.wst11.BusinessActivityManager;
20 import com.arjuna.mw.wst11.BusinessActivityManagerFactory;
21 import com.arjuna.wst11.BAParticipantManager;
22 import org.jboss.as.quickstarts.wsba.participantcompletion.simple.jaxws.SetServiceBA;
23
24 import javax.jws.HandlerChain;
25 import javax.jws.WebMethod;
26 import javax.jws.WebService;
27 import javax.jws.soap.SOAPBinding;
28 import javax.servlet.annotation.WebServlet;
29 import java.util.UUID;
30
31
32
33
34
35
36 @WebService(serviceName = "SetServiceBAService", portName = "SetServiceBA", name = "SetServiceBA", targetNamespace = "http://www.jboss.org/jboss-jdf/jboss-as-quickstart/helloworld/wsba/participantcompletion/set")
37 @HandlerChain(file = "/context-handlers.xml", name = "Context Handlers")
38 @SOAPBinding(style = SOAPBinding.Style.RPC)
39 @WebServlet("/SetServiceBA")
40 public class SetServiceBAImpl implements SetServiceBA {
41
42
43
44
45
46
47
48 @WebMethod
49 public void addValueToSet(String value) throws AlreadyInSetException, SetServiceException {
50
51 System.out.println("[SERVICE] invoked addValueToSet('" + value + "')");
52
53 BAParticipantManager participantManager;
54
55 try {
56
57 SetParticipantBA participant = new SetParticipantBA(value);
58 BusinessActivityManager activityManager = BusinessActivityManagerFactory.businessActivityManager();
59 System.out.println("[SERVICE] Enlisting a participant into the BA");
60 participantManager = activityManager.enlistForBusinessAgreementWithParticipantCompletion(participant,
61 "SetServiceBAImpl:" + UUID.randomUUID());
62 } catch (Exception e) {
63 System.err.println("Participant enlistment failed");
64 e.printStackTrace(System.err);
65 throw new SetServiceException("Error enlisting participant", e);
66 }
67
68
69 System.out.println("[SERVICE] Invoking the back-end business logic");
70 MockSetManager.add(value);
71
72
73
74
75
76
77
78 System.out
79 .println("[SERVICE] Prepare the backend resource and if successful notify the coordinator that we have completed our work");
80 if (MockSetManager.prepare()) {
81 try {
82
83 System.out.println("[SERVICE] Prepare successful, notifying coordinator of completion");
84 participantManager.completed();
85 } catch (Exception e) {
86
87
88
89
90 MockSetManager.rollback(value);
91
92 System.err.println("[SERVICE] 'completed' callback failed");
93 throw new SetServiceException("Error when notifying the coordinator that the work is completed", e);
94 }
95 } else {
96 try {
97
98
99
100 System.out.println("[SERVICE] Prepare failed, notifying coordinator that we cannot complete");
101 participantManager.cannotComplete();
102 } catch (Exception e) {
103 System.err.println("'cannotComplete' callback failed");
104 throw new SetServiceException("Error when notifying the coordinator that the work is cannot be completed", e);
105 }
106 throw new SetServiceException("Unable to prepare the back-end resource");
107 }
108
109 }
110
111
112
113
114
115
116
117 @WebMethod
118 public boolean isInSet(String value) {
119 return MockSetManager.isInSet(value);
120 }
121
122
123
124
125
126
127
128 @WebMethod
129 public void clear() {
130 MockSetManager.clear();
131 }
132 }