This project has retired. For details please refer to its
Attic page.
UDDIClient xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juddi.v3.client.config;
18
19 import java.util.Collection;
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23 import java.util.Properties;
24 import java.util.Set;
25 import org.apache.commons.configuration.ConfigurationException;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.juddi.api_v3.Node;
29 import org.apache.juddi.v3.annotations.AnnotationProcessor;
30 import org.apache.juddi.v3.client.ClassUtil;
31 import org.apache.juddi.v3.client.Release;
32 import org.apache.juddi.v3.client.UDDIConstants;
33 import org.apache.juddi.v3.client.embed.EmbeddedRegistry;
34 import org.apache.juddi.v3.client.mapping.ServiceLocator;
35 import org.apache.juddi.v3.client.mapping.URLLocalizerDefaultImpl;
36 import org.apache.juddi.v3.client.subscription.SubscriptionCallbackListener;
37 import org.apache.juddi.v3.client.transport.InVMTransport;
38 import org.apache.juddi.v3.client.transport.Transport;
39 import org.uddi.api_v3.BindingTemplate;
40 import org.uddi.api_v3.BusinessService;
41 import org.uddi.api_v3.CategoryBag;
42 import org.uddi.api_v3.KeyedReference;
43 import org.uddi.api_v3.TModelInstanceDetails;
44 import org.uddi.api_v3.TModelInstanceInfo;
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 public class UDDIClient {
73
74 private static Log log = LogFactory.getLog(UDDIClient.class);
75 private ClientConfig clientConfig = null;
76 private String CONFIG_FILE = "META-INF/uddi.xml";
77 private Properties properties = null;
78 private static Map<String, ServiceLocator> serviceLocators = new HashMap<String, ServiceLocator>();
79
80
81 public static void clearServiceLocatorCaches(){
82 serviceLocators.clear();
83 }
84
85
86
87
88
89 public UDDIClient() throws ConfigurationException {
90 super();
91 log.info("jUDDI Client version - " + Release.getjUDDIClientVersion());
92 clientConfig = new ClientConfig(CONFIG_FILE, properties);
93 UDDIClientContainer.addClient(this);
94 }
95
96
97
98
99
100
101
102 public UDDIClient(String configurationFile) throws ConfigurationException {
103 super();
104 log.info("jUDDI Client version - " + Release.getjUDDIClientVersion());
105 clientConfig = new ClientConfig(configurationFile);
106 UDDIClientContainer.addClient(this);
107 }
108
109
110
111
112
113
114
115
116
117 public UDDIClient(String configurationFile, Properties properties) throws ConfigurationException {
118 super();
119 log.info("jUDDI Client version - " + Release.getjUDDIClientVersion());
120 clientConfig = new ClientConfig(configurationFile, properties);
121 UDDIClientContainer.addClient(this);
122 }
123
124
125
126
127
128
129
130 public synchronized ServiceLocator getServiceLocator() throws ConfigurationException {
131 return getServiceLocator(null);
132 }
133
134
135
136
137
138
139 public synchronized ServiceLocator getServiceLocator(String clerkName) throws ConfigurationException {
140 UDDIClerk clerk = getClerk(clerkName);
141 if (clerk==null){
142 throw new ConfigurationException("could not locate the UDDI Clerk '" + clerkName +"'.");
143 }
144 if (!serviceLocators.containsKey(clerk.getName())) {
145 ServiceLocator serviceLocator = new ServiceLocator(clerk, new URLLocalizerDefaultImpl(), properties);
146 serviceLocators.put(clerk.getName(), serviceLocator);
147 }
148 return serviceLocators.get(clerk.getName());
149 }
150
151
152
153
154
155
156
157
158 public void stop() throws ConfigurationException {
159 log.info("Stopping UDDI Client " + clientConfig.getClientName());
160 releaseResources();
161
162 if (UDDIClientContainer.contains(getName())) {
163 UDDIClientContainer.removeClerkManager(getName());
164 }
165
166
167 if (InVMTransport.class.getCanonicalName().equals(getClientConfig().getHomeNode().getProxyTransport())) {
168 log.info("Shutting down embedded Server");
169 stopEmbeddedServer();
170 }
171 log.info("UDDI Clerks shutdown completed for manager " + clientConfig.getClientName());
172 }
173
174 private void releaseResources() {
175 if (this.clientConfig.isRegisterOnStartup()) {
176 unRegisterWSDLs();
177 unRegisterBindingsOfAnnotatedServices(true);
178 }
179 }
180
181
182
183
184
185
186
187
188 public void start() throws ConfigurationException {
189
190 if (UDDIClientContainer.addClient(this)) {
191
192 if (InVMTransport.class.getCanonicalName().equals(getClientConfig().getHomeNode().getProxyTransport())) {
193 log.info("Starting embedded Server");
194 startEmbeddedServer();
195 }
196 if (this.clientConfig.isRegisterOnStartup()) {
197 Runnable runnable = new BackGroundRegistration(this);
198 Thread thread = new Thread(runnable);
199 thread.setName("juddi background registration");
200 thread.setDaemon(true);
201 thread.start();
202 }
203 }
204 }
205
206 protected void startEmbeddedServer() throws ConfigurationException {
207
208 try {
209 String embeddedServerClass = getClientConfig().getHomeNode().getProperties().getProperty("embeddedServer", "org.apache.juddi.v3.client.embed.JUDDIRegistry");
210 Class<?> clazz = ClassUtil.forName(embeddedServerClass, this.getClass());
211 EmbeddedRegistry embeddedRegistry = (EmbeddedRegistry) clazz.newInstance();
212 embeddedRegistry.start();
213 } catch (Exception e) {
214 throw new ConfigurationException(e.getMessage(), e);
215 }
216 }
217
218 protected void stopEmbeddedServer() throws ConfigurationException {
219
220 try {
221 String embeddedServerClass = getClientConfig().getHomeNode().getProperties().getProperty("embeddedServer", "org.apache.juddi.v3.client.embed.JUDDIRegistry");
222 Class<?> clazz = ClassUtil.forName(embeddedServerClass, this.getClass());
223 EmbeddedRegistry embeddedRegistry = (EmbeddedRegistry) clazz.newInstance();
224 embeddedRegistry.stop();
225 } catch (Exception e) {
226 throw new ConfigurationException(e.getMessage(), e);
227 }
228 }
229
230
231
232
233
234
235 public void restart() throws ConfigurationException {
236 stop();
237 start();
238 }
239
240
241
242
243
244
245 public void saveClerkAndNodeInfo() {
246
247 Map<String, UDDIClerk> uddiClerks = clientConfig.getUDDIClerks();
248
249 if (uddiClerks.size() > 0) {
250
251
252 UDDIClerk homeClerk = null;
253 for (UDDIClerk clerk : uddiClerks.values()) {
254 if (clerk.getUDDINode().isHomeJUDDI()) {
255 homeClerk = clerk;
256 }
257 }
258
259 if (homeClerk != null) {
260 int numberOfHomeJUDDIs = 0;
261 for (UDDINode uddiNode : clientConfig.getUDDINodes().values()) {
262 if (uddiNode.isHomeJUDDI()) {
263 numberOfHomeJUDDIs++;
264 }
265 homeClerk.saveNode(uddiNode.getApiNode());
266 }
267 if (numberOfHomeJUDDIs == 1) {
268 for (UDDIClerk clerk : clientConfig.getUDDIClerks().values()) {
269 homeClerk.saveClerk(clerk);
270 }
271 } else {
272 log.error("The client config needs to have one homeJUDDI node and found " + numberOfHomeJUDDIs);
273 }
274 } else {
275 log.debug("No home clerk found.");
276 }
277 }
278 }
279
280
281
282
283 public void xRegister() {
284 log.debug("Starting cross registration...");
285
286 Set<XRegistration> xBusinessRegistrations = clientConfig.getXBusinessRegistrations();
287 for (XRegistration xRegistration : xBusinessRegistrations) {
288 xRegistration.xRegisterBusiness();
289 }
290
291 Set<XRegistration> xServiceBindingRegistrations = clientConfig.getXServiceBindingRegistrations();
292 for (XRegistration xRegistration : xServiceBindingRegistrations) {
293 xRegistration.xRegisterServiceBinding();
294 }
295 log.debug("Cross registration completed");
296 }
297
298
299
300
301
302 public void registerAnnotatedServices() {
303 Map<String, UDDIClerk> uddiClerks = clientConfig.getUDDIClerks();
304 if (uddiClerks.size() > 0) {
305 AnnotationProcessor ap = new AnnotationProcessor();
306 for (UDDIClerk uddiClerk : uddiClerks.values()) {
307 Collection<BusinessService> services = ap.readServiceAnnotations(
308 uddiClerk.getClassWithAnnotations(), uddiClerk.getUDDINode().getProperties());
309 for (BusinessService businessService : services) {
310 log.info("Node=" + uddiClerk.getUDDINode().getApiNode().getName());
311 uddiClerk.register(businessService, uddiClerk.getUDDINode().getApiNode());
312 }
313 }
314 }
315 }
316
317
318
319
320
321
322 public void unRegisterAnnotatedServices() {
323 Map<String, UDDIClerk> clerks = clientConfig.getUDDIClerks();
324 if (clerks.size() > 0) {
325 AnnotationProcessor ap = new AnnotationProcessor();
326 for (UDDIClerk clerk : clerks.values()) {
327 Collection<BusinessService> services = ap.readServiceAnnotations(
328 clerk.getClassWithAnnotations(), clerk.getUDDINode().getProperties());
329 for (BusinessService businessService : services) {
330 clerk.unRegisterService(businessService.getServiceKey(), clerk.getUDDINode().getApiNode());
331 }
332 }
333 }
334 }
335
336
337
338
339
340
341
342
343
344
345 public void unRegisterBindingsOfAnnotatedServices(boolean removeServiceWithNoBindingTemplates) {
346
347 Map<String, UDDIClerk> clerks = clientConfig.getUDDIClerks();
348 if (clerks.size() > 0) {
349 AnnotationProcessor ap = new AnnotationProcessor();
350 for (UDDIClerk clerk : clerks.values()) {
351 Collection<BusinessService> services = ap.readServiceAnnotations(
352 clerk.getClassWithAnnotations(), clerk.getUDDINode().getProperties());
353 for (BusinessService businessService : services) {
354 if (businessService.getBindingTemplates() != null) {
355 List<BindingTemplate> bindingTemplates = businessService.getBindingTemplates().getBindingTemplate();
356 for (BindingTemplate bindingTemplate : bindingTemplates) {
357 clerk.unRegisterBinding(bindingTemplate.getBindingKey(), clerk.getUDDINode().getApiNode());
358 }
359 }
360 if (removeServiceWithNoBindingTemplates) {
361 try {
362 BusinessService existingService = clerk.getServiceDetail(businessService.getServiceKey(), clerk.getUDDINode().getApiNode());
363 if (existingService.getBindingTemplates() == null || existingService.getBindingTemplates().getBindingTemplate().size() == 0) {
364 clerk.unRegisterService(businessService.getServiceKey(), clerk.getUDDINode().getApiNode());
365 }
366 } catch (Exception e) {
367 log.error(e.getMessage(), e);
368 }
369 }
370 }
371 }
372 }
373
374 }
375
376
377
378
379
380
381 public ClientConfig getClientConfig() {
382 return clientConfig;
383 }
384
385
386
387
388
389
390 public String getName() {
391 return clientConfig.getClientName();
392 }
393
394
395
396
397
398
399
400
401 @Deprecated
402 public String getClientCallbackUrl() {
403 return clientConfig.getClientCallbackUrl();
404 }
405
406
407
408
409
410
411
412
413
414
415
416 public Transport getTransport() throws ConfigurationException {
417 return getTransport("default");
418 }
419
420
421
422
423
424
425
426
427
428 public Transport getTransport(String nodeName) throws ConfigurationException {
429 try {
430 String clazz = clientConfig.getUDDINode(nodeName).getProxyTransport();
431 String managerName = clientConfig.getClientName();
432 Class<?> transportClass = ClassUtil.forName(clazz, UDDIClient.class);
433 if (transportClass != null) {
434 Transport transport = (Transport) transportClass.getConstructor(String.class, String.class).newInstance(managerName, nodeName);
435 return transport;
436 } else {
437 throw new ConfigurationException("ProxyTransport was not defined in the " + clientConfig.getConfigurationFile());
438 }
439 } catch (Exception e) {
440 throw new ConfigurationException(e.getMessage(), e);
441 }
442 }
443
444
445
446
447
448
449
450
451
452
453
454
455 public UDDIClerk getClerk(String clerkName) {
456 if (clerkName == null || clerkName.length() == 0) {
457 return getClientConfig().getUDDIClerks().get("default");
458 }
459 return getClientConfig().getUDDIClerks().get(clerkName);
460 }
461
462
463
464
465
466
467 public void registerWSDLs() {
468 Map<String, UDDIClerk> uddiClerks = clientConfig.getUDDIClerks();
469 if (uddiClerks.size() > 0) {
470 for (UDDIClerk uddiClerk : uddiClerks.values()) {
471 uddiClerk.registerWsdls();
472 }
473 }
474 }
475
476
477
478
479 public void unRegisterWSDLs() {
480 Map<String, UDDIClerk> uddiClerks = clientConfig.getUDDIClerks();
481 if (uddiClerks.size() > 0) {
482 for (UDDIClerk uddiClerk : uddiClerks.values()) {
483 uddiClerk.unRegisterWsdls();
484 }
485 }
486 }
487
488
489
490
491
492
493
494
495 public static BindingTemplate addSOAPtModels(BindingTemplate bt) {
496 if (bt.getCategoryBag() == null) {
497 bt.setCategoryBag(new CategoryBag());
498 }
499 boolean found = false;
500 for (int i = 0; i < bt.getCategoryBag().getKeyedReference().size(); i++) {
501 if (bt.getCategoryBag().getKeyedReference().get(i).getTModelKey() != null
502 && bt.getCategoryBag().getKeyedReference().get(i).getTModelKey().equalsIgnoreCase("uddi:uddi.org:categorization:types")) {
503 if (bt.getCategoryBag().getKeyedReference().get(i).getKeyName() != null
504 && bt.getCategoryBag().getKeyedReference().get(i).getKeyName().equalsIgnoreCase("uddi-org:types:wsdl")) {
505 found = true;
506 }
507 }
508 }
509 if (!found) {
510 bt.getCategoryBag().getKeyedReference().add(new KeyedReference("uddi:uddi.org:categorization:types", "uddi-org:types:wsdl", "wsdlDeployment"));
511 }
512 if (bt.getCategoryBag().getKeyedReference().isEmpty() && bt.getCategoryBag().getKeyedReferenceGroup().isEmpty()) {
513 bt.setCategoryBag(null);
514 }
515 if (bt.getTModelInstanceDetails() == null) {
516 bt.setTModelInstanceDetails(new TModelInstanceDetails());
517 }
518 TModelInstanceInfo tModelInstanceInfo;
519 if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.PROTOCOL_SOAP)) {
520 tModelInstanceInfo = new TModelInstanceInfo();
521 tModelInstanceInfo.setTModelKey(UDDIConstants.PROTOCOL_SOAP);
522 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
523 }
524
525 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("http:")) {
526 if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.TRANSPORT_HTTP)) {
527 tModelInstanceInfo = new TModelInstanceInfo();
528 tModelInstanceInfo.setTModelKey(UDDIConstants.TRANSPORT_HTTP);
529 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
530 }
531 }
532 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("jms:")) {
533 if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.TRANSPORT_JMS)) {
534 tModelInstanceInfo = new TModelInstanceInfo();
535 tModelInstanceInfo.setTModelKey(UDDIConstants.TRANSPORT_JMS);
536 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
537 }
538 }
539 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("rmi:")) {
540 if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.TRANSPORT_RMI)) {
541 tModelInstanceInfo = new TModelInstanceInfo();
542 tModelInstanceInfo.setTModelKey(UDDIConstants.TRANSPORT_RMI);
543 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
544 }
545 }
546 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("udp:")) {
547 if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.TRANSPORT_UDP)) {
548 tModelInstanceInfo = new TModelInstanceInfo();
549 tModelInstanceInfo.setTModelKey(UDDIConstants.TRANSPORT_UDP);
550 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
551 }
552 }
553 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("amqp:")) {
554 if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.TRANSPORT_AMQP)) {
555 tModelInstanceInfo = new TModelInstanceInfo();
556 tModelInstanceInfo.setTModelKey(UDDIConstants.TRANSPORT_AMQP);
557 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
558 }
559 }
560 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("mailto:")) {
561 if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.TRANSPORT_EMAIL)) {
562 tModelInstanceInfo = new TModelInstanceInfo();
563 tModelInstanceInfo.setTModelKey(UDDIConstants.TRANSPORT_EMAIL);
564 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
565 }
566 }
567 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("ftp:")) {
568 if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.TRANSPORT_FTP)) {
569 tModelInstanceInfo = new TModelInstanceInfo();
570 tModelInstanceInfo.setTModelKey(UDDIConstants.TRANSPORT_FTP);
571 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
572 }
573 }
574 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("https:")) {
575 if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.PROTOCOL_SSLv3)) {
576 tModelInstanceInfo = new TModelInstanceInfo();
577 tModelInstanceInfo.setTModelKey(UDDIConstants.PROTOCOL_SSLv3);
578 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
579 }
580 }
581 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("ftps:")) {
582 if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.PROTOCOL_SSLv3)) {
583 tModelInstanceInfo = new TModelInstanceInfo();
584 tModelInstanceInfo.setTModelKey(UDDIConstants.PROTOCOL_SSLv3);
585 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
586 }
587 }
588 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("jndi:")) {
589 if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.TRANSPORT_JNDI_RMI)) {
590 tModelInstanceInfo = new TModelInstanceInfo();
591 tModelInstanceInfo.setTModelKey(UDDIConstants.TRANSPORT_JNDI_RMI);
592 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
593 }
594 }
595 return bt;
596 }
597
598
599
600
601
602
603
604
605 public static BindingTemplate addRESTtModels(BindingTemplate bt) {
606 if (bt.getTModelInstanceDetails() == null) {
607 bt.setTModelInstanceDetails(new TModelInstanceDetails());
608 }
609 TModelInstanceInfo tModelInstanceInfo;
610 if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.PROTOCOL_REST)) {
611 tModelInstanceInfo = new TModelInstanceInfo();
612 tModelInstanceInfo.setTModelKey(UDDIConstants.PROTOCOL_REST);
613 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
614 }
615
616 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("http:")) {
617 if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.TRANSPORT_HTTP)) {
618 tModelInstanceInfo = new TModelInstanceInfo();
619 tModelInstanceInfo.setTModelKey(UDDIConstants.TRANSPORT_HTTP);
620 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
621 }
622 }
623 if (bt.getAccessPoint() != null && bt.getAccessPoint().getValue().startsWith("https:")) {
624 if (!exists(bt.getTModelInstanceDetails().getTModelInstanceInfo(), UDDIConstants.PROTOCOL_SSLv3)) {
625 tModelInstanceInfo = new TModelInstanceInfo();
626 tModelInstanceInfo.setTModelKey(UDDIConstants.PROTOCOL_SSLv3);
627 bt.getTModelInstanceDetails().getTModelInstanceInfo().add(tModelInstanceInfo);
628 }
629 }
630 return bt;
631 }
632
633 private static boolean exists(List<TModelInstanceInfo> items, String key) {
634 for (int i = 0; i < items.size(); i++) {
635 if (items.get(i).getTModelKey() != null
636 && items.get(i).getTModelKey().equalsIgnoreCase(key)) {
637 return true;
638 }
639 }
640 return false;
641 }
642 }