This project has retired. For details please refer to its
Attic page.
BPEL2UDDI xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juddi.v3.client.mapping.wsdl;
18
19 import org.apache.juddi.v3.client.mapping.Common2UDDI;
20 import java.net.MalformedURLException;
21 import java.net.URL;
22 import java.rmi.RemoteException;
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Properties;
27 import java.util.Set;
28
29 import javax.wsdl.Binding;
30 import javax.wsdl.Definition;
31 import javax.wsdl.Port;
32 import javax.wsdl.PortType;
33 import javax.wsdl.Service;
34 import javax.wsdl.WSDLException;
35 import javax.xml.namespace.QName;
36
37 import org.apache.commons.configuration.ConfigurationException;
38 import org.apache.commons.logging.Log;
39 import org.apache.commons.logging.LogFactory;
40 import org.apache.juddi.api_v3.AccessPointType;
41 import org.apache.juddi.jaxb.PrintUDDI;
42 import org.apache.juddi.v3.annotations.AnnotationProcessor;
43 import org.apache.juddi.v3.client.config.Property;
44 import org.apache.juddi.v3.client.config.UDDIClerk;
45 import org.apache.juddi.v3.client.config.UDDIKeyConvention;
46 import org.apache.juddi.v3.client.mapping.URLLocalizer;
47 import org.apache.juddi.v3.client.transport.TransportException;
48 import org.uddi.api_v3.AccessPoint;
49 import org.uddi.api_v3.BindingTemplate;
50 import org.uddi.api_v3.BusinessService;
51 import org.uddi.api_v3.CategoryBag;
52 import org.uddi.api_v3.FindBinding;
53 import org.uddi.api_v3.FindTModel;
54 import org.uddi.api_v3.GetTModelDetail;
55 import org.uddi.api_v3.InstanceDetails;
56 import org.uddi.api_v3.KeyedReference;
57 import org.uddi.api_v3.Name;
58 import org.uddi.api_v3.OverviewDoc;
59 import org.uddi.api_v3.OverviewURL;
60 import org.uddi.api_v3.TModel;
61 import org.uddi.api_v3.TModelBag;
62 import org.uddi.api_v3.TModelDetail;
63 import org.uddi.api_v3.TModelInfo;
64 import org.uddi.api_v3.TModelInstanceDetails;
65 import org.uddi.api_v3.TModelInstanceInfo;
66 import org.uddi.api_v3.TModelList;
67 import org.w3c.dom.Element;
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82 public class BPEL2UDDI extends AnnotationProcessor {
83
84 private Log log = LogFactory.getLog(this.getClass());
85
86 private String keyDomainURI;
87 private UDDIClerk clerk;
88 private String lang;
89 private URLLocalizer urlLocalizer;
90 private String businessKey;
91 private Properties properties = new Properties();
92
93 private WSDL2UDDI wsdl2UDDI;
94
95 public BPEL2UDDI(UDDIClerk clerk, URLLocalizer urlLocalizer, Properties properties) throws ConfigurationException {
96 super();
97
98 this.clerk = clerk;
99 this.urlLocalizer = urlLocalizer;
100 this.properties = properties;
101
102
103 this.keyDomainURI = "uddi:" + properties.getProperty("keyDomain") + ":";
104 this.businessKey = UDDIKeyConvention.getBusinessKey(properties);
105 this.lang = properties.getProperty(Property.LANG,Property.DEFAULT_LANG);
106
107 this.wsdl2UDDI = new WSDL2UDDI(clerk, urlLocalizer, properties);
108 }
109
110 public String getKeyDomainURI() {
111 return keyDomainURI;
112 }
113
114 public void setKeyDomainURI(String keyDomainURI) {
115 this.keyDomainURI = keyDomainURI;
116 }
117
118 public UDDIClerk getClerk() {
119 return clerk;
120 }
121
122 public void setClerk(UDDIClerk clerk) {
123 this.clerk = clerk;
124 }
125
126 public String getLang() {
127 return lang;
128 }
129
130 public void setLang(String lang) {
131 this.lang = lang;
132 }
133
134 public URLLocalizer getUrlLocalizer() {
135 return urlLocalizer;
136 }
137
138 public void setUrlLocalizer(URLLocalizer urlLocalizer) {
139 this.urlLocalizer = urlLocalizer;
140 }
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 @SuppressWarnings("unchecked")
161 public BindingTemplate register(QName serviceName, String portName, URL serviceUrl, Definition wsdlDefinition)
162 throws WSDLException, MalformedURLException, RemoteException, ConfigurationException, TransportException
163 {
164 String targetNamespace = wsdlDefinition.getTargetNamespace();
165 String genericWSDLURL = wsdlDefinition.getDocumentBaseURI();
166 String bpelOverviewURL = "http://localhost:8080/bpel-console/"; //TODO maybe point to bpel in console
167
168 String serviceKey = UDDIKeyConvention.getServiceKey(properties, serviceName.getLocalPart());
169 BusinessService service = lookupService(serviceKey);
170 if (service==null) {
171 List<TModel> tModels = new ArrayList<TModel>();
172
173 Map<QName,PortType> portTypes = (Map<QName,PortType>) wsdlDefinition.getAllPortTypes();
174 tModels.addAll(createWSDLPortTypeTModels(genericWSDLURL, portTypes));
175
176 Map<QName,Binding> bindings = (Map<QName,Binding>) wsdlDefinition.getAllBindings();
177 tModels.addAll(createWSDLBindingTModels(genericWSDLURL, bindings));
178
179 TModel bpel4WSTModel = createBPEL4WSProcessTModel(serviceName, targetNamespace, portTypes, bpelOverviewURL);
180 tModels.add(bpel4WSTModel);
181
182 for (TModel tModel : tModels) {
183 clerk.register(tModel);
184 }
185
186 service = createBusinessService(serviceName, wsdlDefinition);
187
188 clerk.register(service);
189 }
190
191 BindingTemplate binding = createBPELBinding(serviceName, portName, serviceUrl, wsdlDefinition);
192
193 clerk.register(binding);
194 return binding;
195 }
196
197 public String unRegister(QName serviceName, String portName, URL serviceUrl) throws RemoteException, ConfigurationException, TransportException {
198
199 String serviceKey = UDDIKeyConvention.getServiceKey(properties, serviceName.getLocalPart());
200 BusinessService service = lookupService(serviceKey);
201 boolean isRemoveServiceIfNoTemplates = true;
202 String bindingKey = UDDIKeyConvention.getBindingKey(properties, serviceName, portName, serviceUrl);
203
204 for (BindingTemplate bindingTemplate : service.getBindingTemplates().getBindingTemplate()) {
205 if (bindingKey.equals(bindingTemplate.getBindingKey())) {
206 clerk.unRegisterBinding(bindingKey);
207
208 if (service.getBindingTemplates().getBindingTemplate().size()==1 && isRemoveServiceIfNoTemplates) {
209 clerk.unRegisterService(serviceKey);
210
211 FindTModel findTmodelForProcessName = createFindTModelForProcessName(serviceName);
212 TModelList tModelList = clerk.findTModel(findTmodelForProcessName);
213 if (tModelList!=null && tModelList.getTModelInfos()!=null && tModelList.getTModelInfos().getTModelInfo()!=null) {
214 TModelInfo tModelInfo = tModelList.getTModelInfos().getTModelInfo().get(0);
215 String bpel4WSTModelKey = tModelInfo.getTModelKey();
216 clerk.unRegisterTModel(bpel4WSTModelKey);
217
218 GetTModelDetail findAllPortTypesForProcess = createFindAllPortTypesForProcess_1(bpel4WSTModelKey);
219 TModelDetail tModelDetail = clerk.getTModelDetail(findAllPortTypesForProcess);
220 if (tModelDetail!=null) {
221 List<TModel> tModelPortTypeList = tModelDetail.getTModel();
222 if (tModelPortTypeList!=null && tModelPortTypeList.size()>0) {
223 TModel bpel4WSTModel = tModelPortTypeList.get(0);
224 CategoryBag categoryBag = bpel4WSTModel.getCategoryBag();
225 if (categoryBag!=null && categoryBag.getKeyedReference()!=null) {
226 List<KeyedReference> portTypeTModelKeys = new ArrayList<KeyedReference>();
227 KeyedReference namespaceRef = null;
228 for (KeyedReference keyedReference : categoryBag.getKeyedReference()) {
229 if ("uddi:uddi.org:wsdl:porttypereference".equals(keyedReference.getTModelKey()) ) {
230 portTypeTModelKeys.add(keyedReference);
231 }
232 if ("uddi:uddi.org:xml:namespace".equals(keyedReference.getTModelKey()) ) {
233 namespaceRef = keyedReference;
234 }
235 }
236 String namespace = null;
237 if (namespaceRef!=null) namespace = namespaceRef.getKeyValue();
238
239 for (KeyedReference keyedReference : portTypeTModelKeys) {
240 FindTModel findBindingTModel = WSDL2UDDI.createFindBindingTModelForPortType(keyedReference.getKeyValue(), namespace);
241 TModelList bindingTmodels = clerk.findTModel(findBindingTModel);
242 if (bindingTmodels!=null && bindingTmodels.getTModelInfos()!=null && bindingTmodels.getTModelInfos().getTModelInfo()!=null) {
243 for (TModelInfo bindingTModelInfo : bindingTmodels.getTModelInfos().getTModelInfo()) {
244
245 clerk.unRegisterTModel(bindingTModelInfo.getTModelKey());
246 }
247 }
248
249 clerk.unRegisterTModel(keyedReference.getKeyValue());
250 }
251 }
252 }
253 }
254 }
255 }
256 break;
257 }
258 }
259 return service.getServiceKey();
260 }
261
262
263
264
265
266
267
268
269 public BusinessService lookupService(String serviceKey) throws RemoteException, ConfigurationException, TransportException {
270
271
272 BusinessService service = clerk.getServiceDetail(serviceKey);
273 return service;
274 }
275
276
277
278
279
280
281
282 public BusinessService createBusinessService(QName serviceName, Definition wsdlDefinition) {
283
284 log.debug("Constructing Service UDDI Information for " + serviceName);
285 BusinessService service = new BusinessService();
286
287 service.setBusinessKey(businessKey);
288
289 service.setServiceKey(UDDIKeyConvention.getServiceKey(properties, serviceName.getLocalPart()));
290
291 String serviceDescription = properties.getProperty(Property.SERVICE_DESCRIPTION, Property.DEFAULT_SERVICE_DESCRIPTION);
292 if (wsdlDefinition.getService(serviceName) !=null) {
293
294 Element docElement = wsdlDefinition.getService(serviceName).getDocumentationElement();
295 if (docElement!=null && docElement.getTextContent()!=null) {
296 serviceDescription = docElement.getTextContent();
297 }
298 }
299
300 service.getDescription().addAll(Common2UDDI.mapDescription(serviceDescription, lang));
301
302 Name sName = new Name();
303 sName.setLang(lang);
304 sName.setValue(serviceName.getLocalPart());
305 service.getName().add(sName);
306
307
308 if (properties.containsKey(Property.SERVICE_CATEGORY_BAG)) {
309 String serviceCategoryBag = properties.getProperty(Property.SERVICE_CATEGORY_BAG);
310 log.debug("Adding KeyedReferences '" + serviceCategoryBag + "' to service " + serviceName.getLocalPart());
311 CategoryBag categoryBag = parseCategoryBag(serviceCategoryBag);
312 service.setCategoryBag(categoryBag);
313 }
314
315 return service;
316 }
317
318 public Set<TModel> createWSDLPortTypeTModels(String wsdlURL, Map<QName,PortType> portTypes) throws WSDLException
319 {
320 return wsdl2UDDI.createWSDLPortTypeTModels(wsdlURL, portTypes);
321 }
322
323 public Set<TModel> createWSDLBindingTModels(String wsdlURL, Map<QName,Binding> bindings) throws WSDLException
324 {
325 return wsdl2UDDI.createWSDLBindingTModels(wsdlURL, bindings);
326 }
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347 public TModel createBPEL4WSProcessTModel(QName serviceName, String targetNamespace, Map<QName,PortType> portTypes, String bpelOverviewURL) {
348 TModel tModel = new TModel();
349
350 tModel.setTModelKey(keyDomainURI + serviceName.getLocalPart() + "Process");
351
352 Name name = new Name();
353 name.setLang("en");
354 name.setValue(serviceName.getLocalPart());
355 tModel.setName(name);
356
357 OverviewURL overviewURL = new OverviewURL();
358 overviewURL.setValue("http://localhost:8080/bpel-console/"); //should point to the bpel of this process, maybe in guvnor
359 OverviewDoc overviewDoc = new OverviewDoc();
360 overviewDoc.setOverviewURL(overviewURL);
361 tModel.getOverviewDoc().add(overviewDoc);
362
363 CategoryBag categoryBag = new CategoryBag();
364
365 if (targetNamespace!=null) {
366 KeyedReference namespaceReference = WSDL2UDDI.newKeyedReference(
367 "uddi:uddi.org:xml:namespace", "uddi-org:xml:namespace", targetNamespace);
368 categoryBag.getKeyedReference().add(namespaceReference);
369 }
370 KeyedReference typesReference = WSDL2UDDI.newKeyedReference(
371 "uddi:uddi.org:bpel:types", "uddi-org:bpel:types", "process");
372 categoryBag.getKeyedReference().add(typesReference);
373 for (QName qName : portTypes.keySet()) {
374 String portTypeKey = keyDomainURI + qName.getLocalPart();
375 KeyedReference portTypeReference = WSDL2UDDI.newKeyedReference(
376 "uddi:uddi.org:wsdl:porttypereference", "uddi-org:wsdl:portTypeReference", portTypeKey);
377 categoryBag.getKeyedReference().add(portTypeReference);
378 }
379
380 tModel.setCategoryBag(categoryBag);
381
382 if (log.isDebugEnabled()) {
383 log.debug(new PrintUDDI<TModel>().print(tModel));
384 }
385
386 return tModel;
387 }
388
389 public BindingTemplate createBPELBinding(QName serviceName, String portName, URL serviceUrl, Definition wsdlDefinition) {
390
391 BindingTemplate bindingTemplate = new BindingTemplate();
392
393 bindingTemplate.setServiceKey(UDDIKeyConvention.getServiceKey(properties, serviceName.getLocalPart()));
394
395 String bindingKey = UDDIKeyConvention.getBindingKey(properties, serviceName, portName, serviceUrl);
396 bindingTemplate.setBindingKey(bindingKey);
397
398 AccessPoint accessPoint = new AccessPoint();
399 accessPoint.setUseType(AccessPointType.END_POINT.toString());
400 accessPoint.setValue(urlLocalizer.rewrite(serviceUrl));
401 bindingTemplate.setAccessPoint(accessPoint);
402
403 Service service = wsdlDefinition.getService(serviceName);
404
405 if (service!=null) {
406 TModelInstanceDetails tModelInstanceDetails = new TModelInstanceDetails();
407
408 Port port = service.getPort(portName);
409 if (port!=null) {
410 Binding binding = port.getBinding();
411
412 String bindingDescription = properties.getProperty(Property.BINDING_DESCRIPTION, Property.DEFAULT_BINDING_DESCRIPTION);
413
414 Element docElement = binding.getDocumentationElement();
415 if (docElement!=null && docElement.getTextContent()!=null) {
416 bindingDescription = docElement.getTextContent();
417 }
418
419 bindingTemplate.getDescription().addAll(Common2UDDI.mapDescription(bindingDescription, lang));
420
421
422 TModelInstanceInfo tModelInstanceInfoBinding = new TModelInstanceInfo();
423 tModelInstanceInfoBinding.setTModelKey(keyDomainURI + binding.getQName().getLocalPart());
424 InstanceDetails instanceDetails = new InstanceDetails();
425 instanceDetails.setInstanceParms(portName);
426 tModelInstanceInfoBinding.setInstanceDetails(instanceDetails);
427
428 tModelInstanceInfoBinding.getDescription().addAll(Common2UDDI.mapDescription("The wsdl:binding that this wsdl:port implements. " + bindingDescription +
429 " The instanceParms specifies the port local name.", lang));
430 tModelInstanceDetails.getTModelInstanceInfo().add(tModelInstanceInfoBinding);
431
432
433 PortType portType = binding.getPortType();
434 TModelInstanceInfo tModelInstanceInfoPortType = new TModelInstanceInfo();
435 tModelInstanceInfoPortType.setTModelKey(keyDomainURI + portType.getQName().getLocalPart());
436 String portTypeDescription = "";
437 docElement = portType.getDocumentationElement();
438 if (docElement!=null && docElement.getTextContent()!=null) {
439 portTypeDescription = docElement.getTextContent();
440 }
441
442 tModelInstanceInfoPortType.getDescription().addAll(Common2UDDI.mapDescription("The wsdl:portType that this wsdl:port implements." + portTypeDescription, lang));
443 tModelInstanceDetails.getTModelInstanceInfo().add(tModelInstanceInfoPortType);
444
445
446 TModelInstanceInfo tModelInstanceInfoBPEL = new TModelInstanceInfo();
447 tModelInstanceInfoBPEL.setTModelKey(keyDomainURI + service.getQName().getLocalPart() + "Process");
448
449
450 String serviceDescription = properties.getProperty(Property.SERVICE_DESCRIPTION, Property.DEFAULT_SERVICE_DESCRIPTION);
451
452 docElement = wsdlDefinition.getService(serviceName).getDocumentationElement();
453 if (docElement!=null && docElement.getTextContent()!=null) {
454 serviceDescription = docElement.getTextContent();
455 }
456
457 tModelInstanceInfoBPEL.getDescription().addAll(Common2UDDI.mapDescription("The bpel:process this wsdl:port supports." + serviceDescription, lang));
458 tModelInstanceDetails.getTModelInstanceInfo().add(tModelInstanceInfoBPEL);
459
460 bindingTemplate.setTModelInstanceDetails(tModelInstanceDetails);
461 } else {
462 log.error("Could not find Port with portName: " + portName);
463 }
464 } else {
465 log.error("Could not find Service with serviceName: " + serviceName.getLocalPart());
466 }
467
468 if (log.isDebugEnabled()) {
469 log.debug(new PrintUDDI<BindingTemplate>().print(bindingTemplate));
470 }
471
472 return bindingTemplate;
473 }
474
475
476
477
478
479
480
481 public FindTModel createFindTModelForProcessName (QName serviceName) {
482
483 FindTModel findTModel = new FindTModel();
484 Name name = new Name();
485
486 name.setValue(serviceName.getLocalPart());
487 findTModel.setName(name);
488 CategoryBag categoryBag = new CategoryBag();
489
490 String namespace = serviceName.getNamespaceURI();
491 if (namespace!=null && namespace.length()!=0) {
492 KeyedReference namespaceReference = WSDL2UDDI.newKeyedReference(
493 "uddi:uddi.org:xml:namespace", "uddi-org:xml:namespace", namespace);
494 categoryBag.getKeyedReference().add(namespaceReference);
495 }
496 KeyedReference typesReference = WSDL2UDDI.newKeyedReference(
497 "uddi:uddi.org:bpel:types", "uddi-org:bpel:types", "process");
498 categoryBag.getKeyedReference().add(typesReference);
499 findTModel.setCategoryBag(categoryBag);
500
501 if (log.isDebugEnabled()) {
502 log.debug(new PrintUDDI<FindTModel>().print(findTModel));
503 }
504 return findTModel;
505 }
506
507
508
509
510
511
512 public FindTModel createFindProcessesForPortTypes(String portTypeKey) {
513 FindTModel findTModel = new FindTModel();
514 CategoryBag categoryBag = new CategoryBag();
515
516 KeyedReference typesReference = WSDL2UDDI.newKeyedReference(
517 "uddi:uddi.org:bpel:types", "uddi-org:bpel:types", "process");
518 categoryBag.getKeyedReference().add(typesReference);
519
520 KeyedReference portTypeReference = WSDL2UDDI.newKeyedReference(
521 "uddi:uddi.org:wsdl:porttypereference", "uddi-org:wsdl:portTypeReference", portTypeKey);
522 categoryBag.getKeyedReference().add(portTypeReference);
523
524 findTModel.setCategoryBag(categoryBag);
525
526 return findTModel;
527 }
528
529
530
531
532
533
534
535
536
537 public GetTModelDetail createFindAllPortTypesForProcess_1(String processKey) {
538 GetTModelDetail getTModelDetail = new GetTModelDetail();
539 getTModelDetail.getTModelKey().add(processKey);
540 return getTModelDetail;
541 }
542
543
544
545
546
547
548
549 public GetTModelDetail createFindAllPortTypesForProcess_2(List<String> portTypeTModelKeys) {
550 GetTModelDetail getTModelDetail = new GetTModelDetail();
551 for (String tModelKey : portTypeTModelKeys) {
552 getTModelDetail.getTModelKey().add(tModelKey);
553 }
554 return getTModelDetail;
555 }
556
557
558
559
560
561 public FindBinding createFindImplementationsForProcess(String processKey) {
562 FindBinding findBinding = new FindBinding();
563 TModelBag tModelBag = new TModelBag();
564 tModelBag.getTModelKey().add(processKey);
565 return findBinding;
566 }
567
568 }