1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.kandula.wscoor;
18
19 import javax.xml.namespace.QName;
20
21 import org.apache.axiom.om.OMAbstractFactory;
22 import org.apache.axiom.om.OMElement;
23 import org.apache.axiom.om.OMNamespace;
24 import org.apache.axiom.soap.SOAPFactory;
25 import org.apache.axis2.AxisFault;
26 import org.apache.axis2.addressing.EndpointReference;
27 import org.apache.axis2.context.OperationContext;
28 import org.apache.axis2.wsdl.WSDLConstants;
29 import org.apache.kandula.Constants;
30 import org.apache.kandula.coordinator.Coordinator;
31 import org.apache.kandula.faults.AbstractKandulaException;
32 import org.apache.kandula.storage.StorageFactory;
33 import org.apache.kandula.utility.EndpointReferenceFactory;
34
35 /***
36 * @author <a href="mailto:thilina@apache.org"> Thilina Gunarathne </a>
37 */
38
39 public class RegistrationPortTypeRawXMLSkeleton {
40 private OperationContext opContext;
41
42 public void setOperationContext(OperationContext opContext) {
43 this.opContext = opContext;
44 }
45
46 public OMElement registerOperation(OMElement request) throws AxisFault {
47
48 String protocolIdentifier;
49 EndpointReference participantEPR;
50 String activityId;
51 StorageFactory.getInstance().setConfigurationContext(
52 opContext.getServiceContext().getConfigurationContext());
53
54
55
56 protocolIdentifier = request.getFirstChildWithName(
57 new QName("ProtocolIdentifier")).getText();
58 OMElement participantEPRElement = request
59 .getFirstChildWithName(new QName("ParticipantProtocolService"));
60
61 participantEPR = EndpointReferenceFactory
62 .endpointFromOM(participantEPRElement);
63
64 OMElement header = opContext.getMessageContext(
65 WSDLConstants.MESSAGE_LABEL_IN_VALUE).getEnvelope().getHeader();
66 activityId = header.getFirstChildWithName(
67 Constants.TRANSACTION_ID_PARAMETER).getText();
68
69
70
71 try {
72 Coordinator coordinator = new Coordinator();
73 EndpointReference epr = coordinator.registerParticipant(activityId,
74 protocolIdentifier, participantEPR);
75 SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
76 OMNamespace wsCoor = factory.createOMNamespace(Constants.WS_COOR,
77 "wscoor");
78 OMElement responseEle = factory.createOMElement("RegisterResponse",
79 wsCoor);
80 responseEle.addChild(toOM(epr));
81 return responseEle;
82 } catch (AbstractKandulaException e) {
83 AxisFault fault = new AxisFault(e);
84 fault.setFaultCode(e.getFaultCode());
85 throw fault;
86 }
87 }
88
89 /***
90 * Serializes an EndpointRefrence to OM Nodes
91 */
92 private OMElement toOM(EndpointReference epr) {
93 SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
94 OMNamespace wsCoor = factory.createOMNamespace(
95 org.apache.kandula.Constants.WS_COOR, "wscoor");
96 OMElement protocolService = factory.createOMElement(
97 "CoordinatorProtocolService", wsCoor);
98 OMElement coordinatorProtocolService = factory.createOMElement(
99 "CoordinatorProtocolService", wsCoor);
100 EndpointReferenceFactory.endpointToOM(epr, coordinatorProtocolService,
101 factory);
102 protocolService.addChild(coordinatorProtocolService);
103 return protocolService;
104 }
105 }