This project has retired. For details please refer to its
Attic page.
RequestHandler xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.v3.client.transport.wrapper;
17
18 import java.io.StringWriter;
19 import java.lang.reflect.Method;
20 import java.rmi.Remote;
21 import java.util.List;
22 import javax.xml.XMLConstants;
23
24 import javax.xml.parsers.DocumentBuilder;
25 import javax.xml.parsers.DocumentBuilderFactory;
26 import javax.xml.parsers.ParserConfigurationException;
27 import javax.xml.transform.Transformer;
28 import javax.xml.transform.TransformerException;
29 import javax.xml.transform.TransformerFactory;
30 import javax.xml.transform.dom.DOMSource;
31 import javax.xml.transform.stream.StreamResult;
32 import javax.xml.ws.Holder;
33
34 import org.apache.juddi.jaxb.JAXBMarshaller;
35 import org.uddi.api_v3.AssertionStatusItem;
36 import org.uddi.api_v3.AssertionStatusReport;
37 import org.uddi.api_v3.CompletionStatus;
38 import org.uddi.api_v3.DispositionReport;
39 import org.uddi.api_v3.GetAssertionStatusReport;
40 import org.uddi.api_v3.GetPublisherAssertions;
41 import org.uddi.api_v3.PublisherAssertion;
42 import org.uddi.api_v3.PublisherAssertions;
43 import org.uddi.api_v3.PublisherAssertionsResponse;
44 import org.uddi.api_v3.SetPublisherAssertions;
45 import org.uddi.v3_service.DispositionReportFaultMessage;
46 import org.w3c.dom.Document;
47 import org.w3c.dom.Element;
48 import org.w3c.dom.Node;
49
50
51
52
53
54 public class RequestHandler {
55
56
57
58
59 private static DocumentBuilder docBuilder = null;
60
61 private volatile String version;
62 private volatile String operation;
63
64 private volatile Remote portType;
65 private volatile String methodName;
66 private volatile Class<?> operationClass;
67 private static TransformerFactory transFactory = null;
68
69
70
71
72
73
74
75
76
77
78
79 public String getOperation(Element uddiReq) throws Exception {
80 if (uddiReq == null) {
81 throw new UnsupportedOperationException("UDDI Request is null");
82 }
83
84 String operation = uddiReq.getLocalName();
85 if ((operation == null) || (operation.trim().length() == 0)) {
86 throw new UnsupportedOperationException("operation " + operation + " not supported");
87 }
88 setOperation(operation);
89 return operation;
90 }
91
92
93
94
95
96
97
98
99
100
101
102 public String getVersion(Element uddiReq, String operation) throws Exception {
103 String version = uddiReq.getAttribute("generic");
104 if ((version == null) || ("".equals(version))) {
105 if ("urn:uddi-org:api_v3".equals(uddiReq.getNamespaceURI())) {
106 version = "3.0";
107 }
108 }
109 if (!"3.0".equals(version)) {
110 throw new UnsupportedOperationException("version needs to be 3.0");
111 }
112 setVersion(version);
113 return version;
114 }
115
116 public static synchronized String getText(Element element) throws TransformerException {
117 if (transFactory == null) {
118 transFactory = TransformerFactory.newInstance();
119 transFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
120 transFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
121 }
122 Transformer trans = transFactory.newTransformer();
123 StringWriter sw = new StringWriter();
124 trans.transform(new DOMSource(element), new StreamResult(sw));
125 return sw.toString();
126 }
127
128 @SuppressWarnings("unchecked")
129 public Node invoke(Element uddiReq) throws Exception {
130 Node response = null;
131
132
133 DocumentBuilder docBuilder = getDocumentBuilder();
134 Document document = docBuilder.newDocument();
135 Element element = document.createElement("temp");
136 try {
137
138
139
140
141 Object uddiReqObj = JAXBMarshaller.unmarshallFromElement(uddiReq, "org.uddi.api_v3");
142 Object result = null;
143 if (operationClass.equals(GetAssertionStatusReport.class)) {
144 GetAssertionStatusReport getAssertionStatusReport = (GetAssertionStatusReport) uddiReqObj;
145 Method method = portType.getClass().getMethod(methodName, String.class, CompletionStatus.class);
146 result = method.invoke(portType, getAssertionStatusReport.getAuthInfo(), getAssertionStatusReport.getCompletionStatus());
147 AssertionStatusReport assertionStatusReport = new AssertionStatusReport();
148 assertionStatusReport.getAssertionStatusItem().addAll((List<AssertionStatusItem>) result);
149 result = assertionStatusReport;
150 } else if (operationClass.equals(SetPublisherAssertions.class)) {
151 SetPublisherAssertions setPublisherAssertions = (SetPublisherAssertions) uddiReqObj;
152 Method method = portType.getClass().getMethod(methodName, String.class, Holder.class);
153 Holder<List<PublisherAssertion>> holder = new Holder<List<PublisherAssertion>>(setPublisherAssertions.getPublisherAssertion());
154 result = method.invoke(portType, setPublisherAssertions.getAuthInfo(), holder);
155 PublisherAssertions assertions = new PublisherAssertions();
156 if (holder.value != null) {
157 assertions.getPublisherAssertion().addAll(holder.value);
158 }
159 result = assertions;
160 } else if (operationClass.equals(GetPublisherAssertions.class)) {
161 GetPublisherAssertions getPublisherAssertions = (GetPublisherAssertions) uddiReqObj;
162 Method method = portType.getClass().getMethod(methodName, String.class);
163 result = method.invoke(portType, getPublisherAssertions.getAuthInfo());
164 List<PublisherAssertion> assertionList = (List<PublisherAssertion>) result;
165 PublisherAssertionsResponse publisherAssertionsResponse = new PublisherAssertionsResponse();
166 if (assertionList != null) {
167 publisherAssertionsResponse.getPublisherAssertion().addAll(assertionList);
168 }
169 result = publisherAssertionsResponse;
170 } else {
171 Method method = portType.getClass().getMethod(methodName, operationClass);
172 result = method.invoke(portType, (Object) uddiReqObj);
173 }
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188 if (result != null) {
189 JAXBMarshaller.marshallToElement(result, "org.uddi.api_v3", element);
190
191
192
193
194 document.appendChild(element.getFirstChild());
195 }
196 response = document;
197 } catch (Exception e) {
198 DispositionReport dr = DispositionReportFaultMessage.getDispositionReport(e);
199 if (dr != null) {
200 JAXBMarshaller.marshallToElement(dr, "org.uddi.api_v3", element);
201 document.appendChild(element.getFirstChild());
202 response = document;
203 } else {
204 throw e;
205 }
206
207 }
208 return response;
209 }
210
211
212
213
214 private DocumentBuilder getDocumentBuilder() {
215 if (docBuilder == null) {
216 docBuilder = createDocumentBuilder();
217 }
218 return docBuilder;
219 }
220
221
222
223
224 private synchronized DocumentBuilder createDocumentBuilder() {
225 if (docBuilder != null) {
226 return docBuilder;
227 }
228
229 try {
230 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
231 factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
232 factory.setNamespaceAware(true);
233
234
235 docBuilder = factory.newDocumentBuilder();
236 } catch (ParserConfigurationException pcex) {
237 pcex.printStackTrace();
238 }
239
240 return docBuilder;
241 }
242
243 public String getOperation() {
244 return operation;
245 }
246
247 public void setOperation(String operation) {
248 this.operation = operation;
249 }
250
251 public Remote getPortType() {
252 return portType;
253 }
254
255 public void setPortType(Remote portType) {
256 this.portType = portType;
257 }
258
259 public String getMethodName() {
260 return methodName;
261 }
262
263 public void setMethodName(String methodName) {
264 this.methodName = methodName;
265 }
266
267 public Class<?> getOperationClass() {
268 return operationClass;
269 }
270
271 public void setOperationClass(Class<?> operationClass) {
272 this.operationClass = operationClass;
273 }
274
275 public String getVersion() {
276 return version;
277 }
278
279 public void setVersion(String version) {
280 this.version = version;
281 }
282
283 }