This project has retired. For details please refer to its
Attic page.
EntryPointSingleNode xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.samples;
17
18 import java.util.List;
19 import org.apache.juddi.api_v3.Node;
20 import org.apache.juddi.v3.client.UDDIConstants;
21 import org.apache.juddi.v3.client.config.UDDIClient;
22 import org.apache.juddi.v3.client.config.UDDINode;
23 import org.apache.juddi.v3.client.transport.Transport;
24 import org.uddi.api_v3.BusinessList;
25 import org.uddi.api_v3.DiscardAuthToken;
26 import org.uddi.api_v3.FindBusiness;
27 import org.uddi.api_v3.FindQualifiers;
28 import org.uddi.api_v3.FindService;
29 import org.uddi.api_v3.GetAuthToken;
30 import org.uddi.api_v3.Name;
31 import org.uddi.api_v3.ServiceList;
32 import org.uddi.v3_service.UDDIInquiryPortType;
33 import org.uddi.v3_service.UDDISecurityPortType;
34
35
36
37
38
39 public class EntryPointSingleNode {
40
41 static void goSingleNode() throws Exception {
42 String currentNode = "default";
43 UDDIClient clerkManager = new UDDIClient("META-INF/simple-publish-uddi.xml");
44
45 List<Node> uddiNodeList = clerkManager.getClientConfig().getUDDINodeList();
46 System.out.println();
47
48 System.out.println("Nodes:");
49 for (int i = 0; i < uddiNodeList.size(); i++) {
50 System.out.println((i + 1) + ") Node name: " + uddiNodeList.get(i).getName());
51 }
52 System.out.print("Destination Node: ");
53 int index = Integer.parseInt(System.console().readLine()) - 1;
54
55 currentNode = uddiNodeList.get(index).getName();
56 Transport transport = clerkManager.getTransport(currentNode);
57 authtoken = login(currentNode, transport);
58 String input = null;
59 do {
60 System.out.println(" 1) Login");
61 System.out.println(" 2) Print auth token");
62 System.out.println(" 3) Logout (discard auth token)");
63
64 System.out.println(" 4) Find Binding by QOS Parameters (Binding/tModelInstanceInfo)");
65 System.out.println(" 5) Find Business by QOS Parameters (Binding/tModelInstanceInfo)");
66 System.out.println(" 6) Find Service by QOS Parameters (Binding/tModelInstanceInfo)");
67 System.out.println(" 7) UDDI Create Bulk (makes N business/services");
68
69 System.out.println(" 8) UDDI Custody Transfer (within a single node)");
70 System.out.println(" 9) UDDI Digital Signatures - Sign a Business");
71 System.out.println("10) UDDI Digital Signatures - Sign a Service");
72 System.out.println("11) UDDI Digital Signatures - Sign a tModel");
73 System.out.println("12) UDDI Digital Signatures - Search for Signed Items");
74 System.out.println("13) Find a Binding, lists all bindings for all services");
75 System.out.println("14) Find Endpoints of a service (given the key)");
76 System.out.println("15) Get the details of a service");
77 System.out.println("16) Make a Key Generator tModel");
78 System.out.println("17) Create a Business Relationship Between two users and two Businesses(Publisher Assertion)");
79 System.out.println("18) Subscriptions - Asynchronous, listens for all changes");
80 System.out.println("19) Subscriptions - Synchronous");
81 System.out.println("20) WSDL2UDDI - Register a service from a WSDL document");
82 System.out.println("21) WADL2UDDI - Register a service from a WADL document");
83
84 System.out.println("22) Print Subscriptions");
85 System.out.println("23) Delete a subscription");
86 System.out.println("24) Delete all subscriptions");
87 System.out.println("25) Subscriptions - Asynchronous, publisher assertion subscriptions");
88 System.out.println("26) Replication - do_ping");
89 System.out.println("27) Replication - get high watermarks");
90 System.out.println("28) Replication - get change records");
91 System.out.println("29) Replication - get failed change records (jUDDI only)");
92
93
94 System.out.println("31) Quick add the jUDDI cloud node to *this's configuration file");
95 System.out.println("32) Add a node to *this's configuration file");
96 System.out.println("35) View all registered nodes for this client");
97
98
99 System.out.println("33) Register a *this node to a jUDDI server");
100 System.out.println("34) View all registered remote nodes on a jUDDI server");
101 System.out.println("35) UnRegister a node on a jUDDI server");
102
103
104 System.out.println("37) View the replication config from the current jUDDI server");
105 System.out.println("38) Set the replication config on a remote jUDDI server");
106 System.out.println("39) Prints the current replication status of a given node");
107 System.out.println("40) Periodic publisher, 1biz+1svc every 5 seconds");
108
109
110 System.out.println("q) quit");
111 System.out.print(username + "@" + currentNode + "# ");
112 input = System.console().readLine();
113 try {
114 processInput(input, currentNode, transport, clerkManager);
115 } catch (Exception ex) {
116 ex.printStackTrace();
117 }
118 } while (!input.equalsIgnoreCase("q"));
119 }
120 private static String authtoken = null;
121 static String password;
122 static String username;
123
124 private static String login(String currentNode, Transport transport) throws Exception {
125 System.out.println("Options:");
126 System.out.println("1) Enter a username/password for auth token");
127 System.out.println("2) Enter a username/password for HTTP based logins");
128 System.out.println("3) Enter a username/password for use stored credentials");
129 System.out.print("Login Method: ");
130 String input = System.console().readLine();
131 if ("1".equalsIgnoreCase(input)) {
132 UDDISecurityPortType security = null;
133 security = transport.getUDDISecurityService();
134 System.out.print(currentNode + "# username: ");
135 username = System.console().readLine();
136 char passwordArray[] = System.console().readPassword(currentNode + "# password: ");
137 GetAuthToken getAuthTokenRoot = new GetAuthToken();
138 getAuthTokenRoot.setUserID(username);
139 password = new String(passwordArray);
140 getAuthTokenRoot.setCred((password));
141 String lauthtoken = security.getAuthToken(getAuthTokenRoot).getAuthInfo();
142 System.out.println("Success!");
143 return lauthtoken;
144 } else if ("2".equalsIgnoreCase(input)) {
145 System.out.println("not implemented yet!");
146
147 } else if ("3".equalsIgnoreCase(input)) {
148 System.out.println("not implemented yet!");
149 } else {
150 System.out.println("Aborted!");
151 }
152 return null;
153
154 }
155
156 private static void processInput(final String input, final String currentNode, final Transport transport, UDDIClient client) throws Exception {
157 if (input == null) {
158 return;
159 }
160 if (input.equals("1")) {
161 login(currentNode, transport);
162 }
163
164 if (input.equals("2")) {
165 System.out.println("Token info: " + authtoken);
166 }
167 if (input.equals("3")) {
168 if (authtoken != null) {
169 UDDISecurityPortType security = null;
170 security = transport.getUDDISecurityService();
171 DiscardAuthToken getAuthTokenRoot = new DiscardAuthToken();
172 getAuthTokenRoot.setAuthInfo(authtoken);
173 security.discardAuthToken(getAuthTokenRoot);
174 System.out.println("Success!");
175 }
176 }
177
178 if (input.equals("4")) {
179 SearchByQos.doFindBinding(authtoken);
180 }
181 if (input.equals("5")) {
182 SearchByQos.doFindBusiness(authtoken);
183 }
184 if (input.equals("6")) {
185 SearchByQos.doFindService(authtoken);
186 }
187 if (input.equals("7")) {
188
189 System.out.print("businesses: ");
190 int biz = Integer.parseInt(System.console().readLine());
191 System.out.print("servicesPerBusiness: ");
192 int svc = Integer.parseInt(System.console().readLine());
193 new UddiCreatebulk(transport, false, currentNode).publishBusiness(authtoken, biz, svc, username);
194 }
195 if (input.equals("8")) {
196 UDDISecurityPortType security = null;
197 security = transport.getUDDISecurityService();
198
199 System.out.print("Transfer from username: ");
200 String uname = (System.console().readLine());
201 char passwordArray[] = System.console().readPassword("password: ");
202 GetAuthToken getAuthTokenRoot = new GetAuthToken();
203 getAuthTokenRoot.setUserID(uname);
204 getAuthTokenRoot.setCred(new String(passwordArray));
205 String authtokenFrom = security.getAuthToken(getAuthTokenRoot).getAuthInfo();
206 System.out.println("Success!");
207
208 System.out.print("Transfer to username: ");
209 String uname2 = (System.console().readLine());
210 char passwordArray2[] = System.console().readPassword("password: ");
211 getAuthTokenRoot = new GetAuthToken();
212 getAuthTokenRoot.setUserID(uname2);
213 getAuthTokenRoot.setCred(new String(passwordArray2));
214 String authtokenFrom2 = security.getAuthToken(getAuthTokenRoot).getAuthInfo();
215 System.out.println("Success!");
216 System.out.print("business/tModel key to transfer: ");
217 String key = (System.console().readLine());
218 new UddiCustodyTransfer().TransferBusiness(uname, authtokenFrom, uname2, authtokenFrom2, key);
219 }
220 if (input.equals("9")) {
221 System.out.print("Business key to sign: ");
222 String key = (System.console().readLine());
223 new UddiDigitalSignatureBusiness().fire(authtoken, key);
224 }
225 if (input.equals("10")) {
226 System.out.print("Service key to sign: ");
227 String key = (System.console().readLine());
228 new UddiDigitalSignatureService().fire(authtoken, key);
229 }
230 if (input.equals("11")) {
231 System.out.print("tModel key to sign: ");
232 String key = (System.console().readLine());
233 new UddiDigitalSignatureTmodel().fire(authtoken, key);
234 }
235 if (input.equals("12")) {
236 new UddiDigitalSignatureSearch().fire(authtoken);
237 }
238 if (input.equals("13")) {
239 new UddiFindBinding().fire(authtoken);
240 }
241 if (input.equals("14")) {
242 System.out.print("Service key to parse the endpoints: ");
243 String key = (System.console().readLine());
244 new UddiFindEndpoints().fire(authtoken, key);
245 }
246 if (input.equals("15")) {
247 System.out.print("Service key: ");
248 String key = (System.console().readLine());
249 new UddiGetServiceDetails().fire(authtoken, key);
250 }
251 if (input.equals("16")) {
252 System.out.print("Get FQDN: ");
253 String key = (System.console().readLine());
254 new UddiKeyGenerator().fire(authtoken, key);
255 }
256 if (input.equals("17")) {
257 UDDISecurityPortType security = null;
258
259 security = transport.getUDDISecurityService();
260
261 System.out.print("1st Business username: ");
262 String uname = (System.console().readLine());
263 char passwordArray[] = System.console().readPassword("password: ");
264 GetAuthToken getAuthTokenRoot = new GetAuthToken();
265 getAuthTokenRoot.setUserID(uname);
266 getAuthTokenRoot.setCred(new String(passwordArray));
267 String authtokenFrom = security.getAuthToken(getAuthTokenRoot).getAuthInfo();
268 System.out.println("Success!");
269
270 System.out.print(uname + "'s business : ");
271 String key = (System.console().readLine());
272
273 System.out.print("2st Business username: ");
274 String uname2 = (System.console().readLine());
275 char passwordArray2[] = System.console().readPassword("password: ");
276 getAuthTokenRoot = new GetAuthToken();
277 getAuthTokenRoot.setUserID(uname2);
278 getAuthTokenRoot.setCred(new String(passwordArray2));
279 String authtokenFrom2 = security.getAuthToken(getAuthTokenRoot).getAuthInfo();
280 System.out.println("Success!");
281
282 System.out.print(uname2 + "'s business : ");
283 String key2 = (System.console().readLine());
284
285 System.out.print("relationship (parent-child, peer-peer,or identity) : ");
286 String relationship = (System.console().readLine());
287 new UddiRelatedBusinesses().fire(key, authtokenFrom, key2, authtokenFrom2, relationship);
288 }
289 if (input.equals("18")) {
290 new UddiSubscribe(client, currentNode, transport).fire();
291
292 }
293 if (input.equals("19")) {
294 System.out.print("Subscription key: ");
295 String key = (System.console().readLine());
296 System.out.println("Fetching results for the past 30 days...");
297 new UddiSubscribeValidate(transport).go(authtoken, input);
298 }
299
300 if (input.equals("20")) {
301 System.out.print("Path or URL to WSDL file: ");
302 String url = (System.console().readLine());
303 System.out.print("Business key to attach to: ");
304 String key = (System.console().readLine());
305 new WsdlImport().fire(url, key, authtoken, transport);
306 }
307 if (input.equals("21")) {
308 System.out.print("Path or URL to WADL file: ");
309 String url = (System.console().readLine());
310 System.out.print("Business key to attach to: ");
311 String key = (System.console().readLine());
312 new WadlImport().fire(url, key, authtoken, transport);
313 }
314
315 if (input.equals("22")) {
316 new UddiSubscriptionManagement(transport).printSubscriptions(authtoken);
317 }
318 if (input.equals("23")) {
319 System.out.print("Subscription key: ");
320 String key2 = (System.console().readLine());
321 new UddiSubscriptionManagement(transport).deleteSubscription(authtoken, key2);
322 }
323 if (input.equals("24")) {
324 new UddiSubscriptionManagement(transport).deleteAllSubscriptions(authtoken);
325 }
326 if (input.equals("25")) {
327 new UddiSubscribeAssertionStatus().fire(currentNode);
328
329 }
330 if (input.equals("26")) {
331
332
333 new UddiReplication(client, currentNode).doPing();
334
335 }
336 if (input.equals("27")) {
337
338 new UddiReplication(client, currentNode).getHighWatermarks();
339
340 }
341 if (input.equals("28")) {
342
343
344 System.out.print("Change ID to fetch: ");
345 String id = (System.console().readLine());
346
347 System.out.print("Node id of something in the replication graph: ");
348 String src = (System.console().readLine());
349
350 new UddiReplication(client, currentNode).getChangeRecords(Long.parseLong(id), src);
351
352 }
353 if ("29".equals(input)) {
354 new JuddiAdminService(client, transport).dumpFailedReplicationRecords(authtoken);
355 }
356 if (input.equals("31")) {
357
358 new JuddiAdminService(client, transport).quickRegisterRemoteCloud(authtoken);
359 }
360 if (input.equals("31")) {
361
362 new JuddiAdminService(client, transport).quickRegisterLocalCloud();
363 }
364 if (input.equals("32")) {
365
366 UDDIClient clerkManager = new UDDIClient("META-INF/simple-publish-uddi.xml");
367 UDDINode node = new UDDINode();
368 System.out.print("Name (must be unique: ");
369 node.setClientName(System.console().readLine());
370 node.setName(node.getClientName());
371 System.out.print("Description: ");
372 node.setDescription(System.console().readLine());
373
374 node.setHomeJUDDI(false);
375 System.out.print("Inquiry URL: ");
376 node.setInquiryUrl(System.console().readLine());
377
378 System.out.print("Inquiry REST URL (optional): ");
379 node.setInquiryRESTUrl(System.console().readLine());
380
381 System.out.print("jUDDI API URL (optional): ");
382 node.setJuddiApiUrl(System.console().readLine());
383 System.out.print("Custody Transfer URL: ");
384 node.setCustodyTransferUrl(System.console().readLine());
385 System.out.print("Publish URL: ");
386 node.setPublishUrl(System.console().readLine());
387 System.out.print("Replication URL: ");
388 node.setReplicationUrl(System.console().readLine());
389 System.out.print("Security URL: ");
390 node.setSecurityUrl(System.console().readLine());
391 System.out.print("Subscription URL: ");
392 node.setSubscriptionUrl(System.console().readLine());
393
394 System.out.print("Subscription Listener URL: ");
395 node.setSubscriptionListenerUrl(System.console().readLine());
396
397 System.out.print("Transport (defaults to JAXWS): ");
398 node.setProxyTransport(System.console().readLine());
399 if (node.getProxyTransport() == null || node.getProxyTransport().trim().equalsIgnoreCase("")) {
400 node.setProxyTransport(org.apache.juddi.v3.client.transport.JAXWSTransport.class.getCanonicalName());
401 }
402 System.out.print("Factory Initial (optional): ");
403 node.setFactoryInitial(System.console().readLine());
404 System.out.print("Factory Naming Provider (optional): ");
405 node.setFactoryNamingProvider(System.console().readLine());
406 System.out.print("Factory URL Packages (optional): ");
407 node.setFactoryURLPkgs(System.console().readLine());
408
409 clerkManager.getClientConfig().addUDDINode(node);
410 clerkManager.getClientConfig().saveConfig();
411 System.out.println("Saved.");
412 }
413 if (input.equals("33")) {
414
415
416 UDDIClient clerkManager = new UDDIClient("META-INF/simple-publish-uddi.xml");
417 List<Node> uddiNodeList = clerkManager.getClientConfig().getUDDINodeList();
418 System.out.println();
419
420 System.out.println("Locally defined nodes:");
421 for (int i = 0; i < uddiNodeList.size(); i++) {
422 System.out.println("________________________________________________________________________________");
423 System.out.println((i + 1) + ") Node name: " + uddiNodeList.get(i).getName());
424 System.out.println((i + 1) + ") Node description: " + uddiNodeList.get(i).getDescription());
425 System.out.println((i + 1) + ") Transport: " + uddiNodeList.get(i).getProxyTransport());
426 System.out.println((i + 1) + ") jUDDI URL: " + uddiNodeList.get(i).getJuddiApiUrl());
427 }
428 System.out.println("Local Source Node: ");
429 int index = Integer.parseInt(System.console().readLine()) - 1;
430
431 System.out.println("Remote Destination(s):");
432 for (int i = 0; i < uddiNodeList.size(); i++) {
433 System.out.println("________________________________________________________________________________");
434 System.out.println((i + 1) + ") Node name: " + uddiNodeList.get(i).getName());
435 System.out.println((i + 1) + ") Node description: " + uddiNodeList.get(i).getDescription());
436 System.out.println((i + 1) + ") Transport: " + uddiNodeList.get(i).getProxyTransport());
437 System.out.println((i + 1) + ") jUDDI URL: " + uddiNodeList.get(i).getJuddiApiUrl());
438 }
439 System.out.println("Remote Destination Node to publish to: ");
440 int index2 = Integer.parseInt(System.console().readLine()) - 1;
441
442 new JuddiAdminService(client, transport).registerLocalNodeToRemoteNode(authtoken, uddiNodeList.get(index), uddiNodeList.get(index2));
443
444 }
445 if (input.equals("34")) {
446
447
448 new JuddiAdminService(client, transport).viewRemoteNodes(authtoken);
449 }
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465 if (input.equals("35")) {
466
467 new JuddiAdminService(client, transport).viewRemoveRemoteNode(authtoken);
468
469 }
470 if (input.equals("37")) {
471 new JuddiAdminService(client, transport).viewReplicationConfig(authtoken, currentNode);
472 }
473 if (input.equals("38")) {
474 new JuddiAdminService(client, transport).setReplicationConfig(authtoken);
475 }
476
477 if (input.equals("39")) {
478 new JuddiAdminService(client, transport).printStatus(transport, authtoken);
479 }
480 if (input.equals("40")) {
481
482 UDDIInquiryPortType uddiInquiryService = transport.getUDDIInquiryService();
483 FindBusiness fb = new FindBusiness();
484 fb.setAuthInfo(authtoken);
485 fb.getName().add(new Name(UDDIConstants.WILDCARD, null));
486 fb.setFindQualifiers(new FindQualifiers());
487 fb.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
488 fb.setMaxRows(1);
489 fb.setListHead(0);
490 BusinessList findBusiness = uddiInquiryService.findBusiness(fb);
491 System.out.println("current business counts "
492 + findBusiness.getListDescription().getActualCount() + " "
493 + findBusiness.getListDescription().getIncludeCount() + " "
494 + findBusiness.getListDescription().getListHead());
495 FindService fs = new FindService();
496 fs.setAuthInfo(authtoken);
497 fs.getName().add(new Name(UDDIConstants.WILDCARD, null));
498 fs.setFindQualifiers(new FindQualifiers());
499 fs.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
500 fs.setMaxRows(1);
501 fs.setListHead(0);
502 ServiceList findService = uddiInquiryService.findService(fs);
503 System.out.println("current service counts "
504 + findService.getListDescription().getActualCount() + " "
505 + findService.getListDescription().getIncludeCount() + " "
506 + findService.getListDescription().getListHead());
507
508 running = true;
509 createdServices = 0;
510 createdBusinesses = 0;
511
512 new Thread(new Runnable() {
513 @Override
514 public void run() {
515 UddiCreatebulk uddiCreatebulk = new UddiCreatebulk(transport, false, currentNode);
516 while (running) {
517 try {
518 uddiCreatebulk.publishBusiness(authtoken, 1, 1, username);
519 createdBusinesses++;
520 createdServices++;
521 Thread.sleep(5000);
522 } catch (Exception ex) {
523 System.out.println("eception caught, assuming it's an expired token, attempting to reauthenticate " + ex.getMessage());
524
525 try {
526 UDDISecurityPortType security = null;
527 security = transport.getUDDISecurityService();
528
529 GetAuthToken getAuthTokenRoot = new GetAuthToken();
530 getAuthTokenRoot.setUserID(username);
531 getAuthTokenRoot.setCred((password));
532 authtoken = security.getAuthToken(getAuthTokenRoot).getAuthInfo();
533 } catch (Exception x) {
534 System.out.println("unable to reauthenticate, aborting!");
535 ex.printStackTrace();
536 running = false;
537 }
538
539 }
540 }
541 }
542 }).start();
543 System.out.println("Started, press <Enter> to stop!");
544 System.console().readLine();
545 running = false;
546
547 System.out.println("before business counts "
548 + findBusiness.getListDescription().getActualCount());
549
550 fb.setAuthInfo(authtoken);
551 BusinessList afterfindBusiness = uddiInquiryService.findBusiness(fb);
552 System.out.println("after business counts "
553 + afterfindBusiness.getListDescription().getActualCount());
554 System.out.println("actual created " + createdBusinesses);
555 System.out.println("Delta = " + (afterfindBusiness.getListDescription().getActualCount() - findBusiness.getListDescription().getActualCount()));
556
557 System.out.println("before service counts "
558 + findService.getListDescription().getActualCount());
559
560 fs.setAuthInfo(authtoken);
561 ServiceList afterfindService = uddiInquiryService.findService(fs);
562 System.out.println("after service counts "
563 + afterfindService.getListDescription().getActualCount());
564 System.out.println("actual created " + createdServices);
565 System.out.println("delta = " + (afterfindService.getListDescription().getActualCount() - findService.getListDescription().getActualCount()));
566 if ((afterfindService.getListDescription().getActualCount() - findService.getListDescription().getActualCount()) == createdServices) {
567 System.out.println("success");
568 } else {
569 System.out.println("failure!");
570 }
571
572 }
573
574 }
575 static boolean running = true;
576 static int createdServices = 0;
577 static int createdBusinesses = 0;
578
579 }