This project has retired. For details please refer to its
Attic page.
JuddiAdminService 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.io.FileInputStream;
19 import java.math.BigInteger;
20 import java.rmi.RemoteException;
21 import java.security.KeyStore;
22 import java.util.List;
23 import javax.net.ssl.KeyManagerFactory;
24 import javax.net.ssl.SSLContext;
25 import javax.xml.bind.JAXB;
26 import javax.xml.ws.BindingProvider;
27 import org.apache.commons.configuration.ConfigurationException;
28 import org.apache.juddi.api_v3.DeleteNode;
29 import org.apache.juddi.api_v3.GetFailedReplicationChangeRecordsMessageRequest;
30 import org.apache.juddi.api_v3.GetFailedReplicationChangeRecordsMessageResponse;
31 import org.apache.juddi.api_v3.Node;
32 import org.apache.juddi.api_v3.NodeDetail;
33 import org.apache.juddi.api_v3.NodeList;
34 import org.apache.juddi.api_v3.SaveNode;
35 import org.apache.juddi.jaxb.PrintJUDDI;
36 import org.apache.juddi.v3.client.UDDIService;
37 import org.apache.juddi.v3.client.config.UDDIClient;
38 import org.apache.juddi.v3.client.config.UDDINode;
39 import org.apache.juddi.v3.client.cryptor.TransportSecurityHelper;
40 import org.apache.juddi.v3.client.transport.Transport;
41 import org.apache.juddi.v3.client.transport.TransportException;
42 import org.apache.juddi.v3_service.JUDDIApiPortType;
43 import org.uddi.api_v3.Contact;
44 import org.uddi.api_v3.Description;
45 import org.uddi.api_v3.Email;
46 import org.uddi.api_v3.GetAuthToken;
47 import org.uddi.api_v3.PersonName;
48 import org.uddi.api_v3.Phone;
49 import org.uddi.repl_v3.ChangeRecordIDType;
50 import org.uddi.repl_v3.CommunicationGraph;
51 import org.uddi.repl_v3.CommunicationGraph.Edge;
52 import org.uddi.repl_v3.DoPing;
53 import org.uddi.repl_v3.Operator;
54 import org.uddi.repl_v3.OperatorStatusType;
55 import org.uddi.repl_v3.ReplicationConfiguration;
56 import org.uddi.v3_service.UDDIReplicationPortType;
57 import org.uddi.v3_service.UDDISecurityPortType;
58
59
60
61
62
63 public class JuddiAdminService {
64
65 private JUDDIApiPortType juddi = null;
66 private UDDIClient clerkManager = null;
67
68 public JuddiAdminService(UDDIClient client, Transport transport) {
69 try {
70 clerkManager = client;
71 if (transport != null)
72
73
74
75
76 {
77 transport = clerkManager.getTransport();
78 juddi = transport.getJUDDIApiService();
79 }
80
81
82
83
84 } catch (Exception e) {
85 e.printStackTrace();
86 }
87 }
88
89 static Node getCloudInstance() {
90 Node n = new Node();
91 n.setClientName("juddicloud");
92 n.setName("juddicloud");
93 n.setCustodyTransferUrl("http://uddi-jbossoverlord.rhcloud.com/services/custody-transfer");
94 n.setDescription("juddicloud");
95 n.setProxyTransport("org.apache.juddi.v3.client.transport.JAXWSTransport");
96 n.setInquiryUrl("http://uddi-jbossoverlord.rhcloud.com/services/inquiry");
97 n.setJuddiApiUrl("http://uddi-jbossoverlord.rhcloud.com/services/juddi-api");
98 n.setPublishUrl("http://uddi-jbossoverlord.rhcloud.com/services/publish");
99 n.setSecurityUrl("http://uddi-jbossoverlord.rhcloud.com/services/security");
100 n.setSubscriptionListenerUrl("http://uddi-jbossoverlord.rhcloud.com/services/subscription-listener");
101 n.setSubscriptionUrl("http://uddi-jbossoverlord.rhcloud.com/services/subscription");
102 n.setReplicationUrl("uddi-jbossoverlord.rhcloud.com/services/replication");
103 return n;
104 }
105
106 JuddiAdminService(UDDIClient client, Transport transport, String currentNode) {
107 curentnode = currentNode;
108 try {
109 clerkManager = client;
110 if (transport == null)
111
112
113
114
115 {
116 transport = clerkManager.getTransport();
117 }
118
119
120
121 juddi = transport.getJUDDIApiService();
122 } catch (Exception e) {
123 e.printStackTrace();
124 }
125 }
126
127 String curentnode = "default";
128
129 public void quickRegisterRemoteCloud(String token) {
130 try {
131
132
133 SaveNode node = new SaveNode();
134 node.setAuthInfo(token);
135
136 node.getNode().add(getCloudInstance());
137
138 PrintJUDDI<SaveNode> p = new PrintJUDDI<SaveNode>();
139 System.out.println("Before sending");
140 System.out.println(p.print(node));
141 juddi.saveNode(node);
142 System.out.println("Saved");
143
144 } catch (Exception e) {
145 e.printStackTrace();
146 }
147 }
148
149 void setupReplication() {
150 throw new UnsupportedOperationException("Not supported yet.");
151 }
152
153 void viewRemoteNodes(String authtoken) throws ConfigurationException, TransportException, RemoteException {
154
155 List<Node> uddiNodeList = clerkManager.getClientConfig().getUDDINodeList();
156 System.out.println();
157 System.out.println("Select a node (from *this config)");
158 for (int i = 0; i < uddiNodeList.size(); i++) {
159 System.out.print(i + 1);
160 System.out.println(") " + uddiNodeList.get(i).getName() + uddiNodeList.get(i).getDescription());
161 }
162 System.out.println("Node #: ");
163 int index = Integer.parseInt(System.console().readLine()) - 1;
164 String node = uddiNodeList.get(index).getName();
165 Transport transport = clerkManager.getTransport(node);
166
167 JUDDIApiPortType juddiApiService = transport.getJUDDIApiService();
168
169 NodeList allNodes = juddiApiService.getAllNodes(authtoken);
170 if (allNodes == null || allNodes.getNode().isEmpty()) {
171 System.out.println("No nodes registered!");
172 } else {
173 for (int i = 0; i < allNodes.getNode().size(); i++) {
174 System.out.println("_______________________________________________________________________________");
175 System.out.println("Name :" + allNodes.getNode().get(i).getName());
176 System.out.println("Inquiry :" + allNodes.getNode().get(i).getInquiryUrl());
177 System.out.println("Publish :" + allNodes.getNode().get(i).getPublishUrl());
178 System.out.println("Securit :" + allNodes.getNode().get(i).getSecurityUrl());
179 System.out.println("Replication :" + allNodes.getNode().get(i).getReplicationUrl());
180 System.out.println("Subscription :" + allNodes.getNode().get(i).getSubscriptionUrl());
181 System.out.println("Custody Xfer :" + allNodes.getNode().get(i).getCustodyTransferUrl());
182
183 }
184 }
185
186 }
187
188 void quickRegisterLocalCloud() throws ConfigurationException {
189 UDDINode node = new UDDINode(getCloudInstance());
190 clerkManager.getClientConfig().addUDDINode(node);
191 clerkManager.getClientConfig().saveConfig();
192 System.out.println();
193 System.out.println("Added and saved.");
194 }
195
196 void registerLocalNodeToRemoteNode(String authtoken, Node cfg, Node publishTo) throws Exception {
197
198 Transport transport = clerkManager.getTransport(publishTo.getName());
199
200 UDDISecurityPortType security2 = transport.getUDDISecurityService();
201 System.out.print("username: ");
202 String uname = System.console().readLine();
203 char passwordArray[] = System.console().readPassword("password: ");
204 GetAuthToken getAuthTokenRoot = new GetAuthToken();
205 getAuthTokenRoot.setUserID(uname);
206 getAuthTokenRoot.setCred(new String(passwordArray));
207 authtoken = security2.getAuthToken(getAuthTokenRoot).getAuthInfo();
208 System.out.println("Success!");
209
210 JUDDIApiPortType juddiApiService = transport.getJUDDIApiService();
211 SaveNode sn = new SaveNode();
212 sn.setAuthInfo(authtoken);
213 sn.getNode().add(cfg);
214 NodeDetail saveNode = juddiApiService.saveNode(sn);
215 JAXB.marshal(saveNode, System.out);
216 System.out.println("Success.");
217
218 }
219
220 void viewReplicationConfig(String authtoken, String node) throws Exception {
221
222 Transport transport = clerkManager.getTransport(node);
223
224 JUDDIApiPortType juddiApiService = transport.getJUDDIApiService();
225 ReplicationConfiguration replicationNodes = juddiApiService.getReplicationNodes(authtoken);
226
227 System.out.println("Current Config:");
228 JAXB.marshal(replicationNodes, System.out);
229
230 }
231
232 void setReplicationConfig(String authtoken) throws Exception {
233 List<Node> uddiNodeList = clerkManager.getClientConfig().getUDDINodeList();
234 System.out.println();
235 System.out.println("Select a node (from *this config)");
236 for (int i = 0; i < uddiNodeList.size(); i++) {
237 System.out.print(i + 1);
238 System.out.println(") " + uddiNodeList.get(i).getName() + uddiNodeList.get(i).getDescription());
239 }
240 System.out.println("Node #: ");
241 int index = Integer.parseInt(System.console().readLine()) - 1;
242 String node = uddiNodeList.get(index).getName();
243 Transport transport = clerkManager.getTransport(node);
244
245 JUDDIApiPortType juddiApiService = transport.getJUDDIApiService();
246 System.out.println("fetching...");
247
248 ReplicationConfiguration replicationNodes = null;
249 try {
250 replicationNodes = juddiApiService.getReplicationNodes(authtoken);
251 } catch (Exception ex) {
252 System.out.println("Error getting replication config");
253 ex.printStackTrace();
254 replicationNodes = new ReplicationConfiguration();
255
256 }
257 String input = "";
258 while (!"d".equalsIgnoreCase(input) && !"q".equalsIgnoreCase(input)) {
259 System.out.println("Current Config:");
260 JAXB.marshal(replicationNodes, System.out);
261 System.out.println("1) Remove a replication node");
262 System.out.println("2) Add a replication node");
263 System.out.println("3) Remove an Edge");
264 System.out.println("4) Add an Edge");
265 System.out.println("5) Set Registry Contact");
266 System.out.println("6) Add Operator info");
267 System.out.println("7) Remove Operator info");
268 System.out.println("d) Done, save changes");
269 System.out.println("q) Quit and abandon changes");
270
271 input = System.console().readLine();
272 if (input.equalsIgnoreCase("1")) {
273 menu_RemoveReplicationNode(replicationNodes);
274 } else if (input.equalsIgnoreCase("2")) {
275 menu_AddReplicationNode(replicationNodes, juddiApiService, authtoken);
276 } else if (input.equalsIgnoreCase("d")) {
277 if (replicationNodes.getCommunicationGraph() == null) {
278 replicationNodes.setCommunicationGraph(new CommunicationGraph());
279 }
280 if (replicationNodes.getRegistryContact() == null) {
281 replicationNodes.setRegistryContact(new ReplicationConfiguration.RegistryContact());
282 }
283 if (replicationNodes.getRegistryContact().getContact() == null) {
284 replicationNodes.getRegistryContact().setContact(new Contact());
285 replicationNodes.getRegistryContact().getContact().getPersonName().add(new PersonName("unknown", null));
286 }
287
288 replicationNodes.setSerialNumber(0L);
289 replicationNodes.setTimeOfConfigurationUpdate("");
290 replicationNodes.setMaximumTimeToGetChanges(BigInteger.ONE);
291 replicationNodes.setMaximumTimeToSyncRegistry(BigInteger.ONE);
292
293 JAXB.marshal(replicationNodes, System.out);
294 juddiApiService.setReplicationNodes(authtoken, replicationNodes);
295 }
296
297 }
298 if (input.equalsIgnoreCase("d")) {
299
300 juddiApiService.setReplicationNodes(authtoken, replicationNodes);
301 System.out.println("Saved!, dumping config from the server");
302 replicationNodes = juddiApiService.getReplicationNodes(authtoken);
303 JAXB.marshal(replicationNodes, System.out);
304
305 } else {
306
307 System.out.println("aborting!");
308 }
309
310 }
311
312 void viewRemoveRemoteNode(String authtoken) throws Exception {
313 List<Node> uddiNodeList = clerkManager.getClientConfig().getUDDINodeList();
314 System.out.println();
315 System.out.println("Select a node (from *this config)");
316 for (int i = 0; i < uddiNodeList.size(); i++) {
317 System.out.print(i + 1);
318 System.out.println(") " + uddiNodeList.get(i).getName() + uddiNodeList.get(i).getDescription());
319 }
320 System.out.println("Node #: ");
321 int index = Integer.parseInt(System.console().readLine()) - 1;
322 String node = uddiNodeList.get(index).getName();
323 Transport transport = clerkManager.getTransport(node);
324
325 JUDDIApiPortType juddiApiService = transport.getJUDDIApiService();
326
327 NodeList allNodes = juddiApiService.getAllNodes(authtoken);
328 if (allNodes == null || allNodes.getNode().isEmpty()) {
329 System.out.println("No nodes registered!");
330 } else {
331 for (int i = 0; i < allNodes.getNode().size(); i++) {
332 System.out.println("_______________________________________________________________________________");
333 System.out.println("(" + i + ") Name :" + allNodes.getNode().get(i).getName());
334 System.out.println("(" + i + ") Inquiry :" + allNodes.getNode().get(i).getInquiryUrl());
335
336 }
337
338 System.out.println("Node to remove from : ");
339 int nodenum = Integer.parseInt(System.console().readLine());
340 juddiApiService.deleteNode(new DeleteNode(authtoken, allNodes.getNode().get(nodenum).getName()));
341
342 }
343 }
344
345 private void menu_RemoveReplicationNode(ReplicationConfiguration replicationNodes) {
346 if (replicationNodes.getCommunicationGraph() == null) {
347 replicationNodes.setCommunicationGraph(new CommunicationGraph());
348 }
349 for (int i = 0; i < replicationNodes.getCommunicationGraph().getNode().size(); i++) {
350 System.out.println((i + 1) + ") " + replicationNodes.getCommunicationGraph().getNode().get(i));
351 }
352 System.out.println("Node #: ");
353 int index = Integer.parseInt(System.console().readLine()) - 1;
354 replicationNodes.getCommunicationGraph().getNode().remove(index);
355
356 }
357
358 private void menu_AddReplicationNode(ReplicationConfiguration replicationNodes, JUDDIApiPortType juddiApiService, String authtoken) throws Exception {
359
360 if (replicationNodes.getCommunicationGraph() == null) {
361 replicationNodes.setCommunicationGraph(new CommunicationGraph());
362 }
363
364 Operator op = new Operator();
365 System.out.println("The Operator Node id should be the UDDI Node ID of the new node to replicate with. It should also match the root business key in"
366 + " the new registry.");
367 System.out.print("Operator Node id: ");
368 op.setOperatorNodeID(System.console().readLine().trim());
369
370 System.out.print("Replication URL: ");
371 op.setSoapReplicationURL(System.console().readLine().trim());
372 op.setOperatorStatus(OperatorStatusType.NEW);
373 System.out.println("The replication node requires at least one point of contact");
374 System.out.print("Number of contacts: ");
375 int index = Integer.parseInt(System.console().readLine());
376 for (int i = 0; i < index; i++) {
377 System.out.println("_______________________");
378 System.out.println("Info for contact # " + (i + 1));
379 op.getContact().add(getContactInfo());
380 }
381 System.out.println("_______________________");
382 System.out.println("Current Operator:");
383 System.out.println("_______________________");
384 JAXB.marshal(op, System.out);
385
386 System.out.print("Confirm adding? (y/n) :");
387 if (System.console().readLine().trim().equalsIgnoreCase("y")) {
388 replicationNodes.getOperator().add(op);
389 replicationNodes.getCommunicationGraph().getNode().add(op.getOperatorNodeID());
390
391 }
392 }
393
394 private Contact getContactInfo() {
395 Contact c = new Contact();
396 System.out.print("Use Type (i.e. primary): ");
397 c.setUseType(System.console().readLine().trim());
398 if (c.getUseType().trim().equalsIgnoreCase("")) {
399 c.setUseType("primary");
400 }
401
402 c.getPersonName().add(getPersonName());
403
404 while (true) {
405 System.out.println("Thus far:");
406 JAXB.marshal(c, System.out);
407 System.out.println("Options:");
408 System.out.println("\t1) Add PersonName");
409 System.out.println("\t2) Add Email address");
410 System.out.println("\t3) Add Phone number");
411 System.out.println("\t4) Add Description");
412 System.out.println("\t<enter> Finish and return");
413
414 System.out.print("> ");
415 String input = System.console().readLine();
416 if (input.trim().equalsIgnoreCase("")) {
417 break;
418 } else if (input.trim().equalsIgnoreCase("1")) {
419 c.getPersonName().add(getPersonName());
420 } else if (input.trim().equalsIgnoreCase("2")) {
421 c.getEmail().add(getEmail());
422 } else if (input.trim().equalsIgnoreCase("3")) {
423 c.getPhone().add(getPhoneNumber());
424 } else if (input.trim().equalsIgnoreCase("4")) {
425 c.getDescription().add(getDescription());
426 }
427 }
428 return c;
429 }
430
431 private PersonName getPersonName() {
432 PersonName pn = new PersonName();
433 System.out.print("Name: ");
434 pn.setValue(System.console().readLine().trim());
435 System.out.print("Language (en): ");
436 pn.setLang(System.console().readLine().trim());
437 if (pn.getLang().equalsIgnoreCase("")) {
438 pn.setLang("en");
439 }
440
441 return pn;
442 }
443
444 private Email getEmail() {
445 Email pn = new Email();
446 System.out.print("Email address Value: ");
447
448 pn.setValue(System.console().readLine().trim());
449 System.out.print("Use type (i.e. primary): ");
450 pn.setUseType(System.console().readLine().trim());
451 return pn;
452 }
453
454 private Phone getPhoneNumber() {
455
456 Phone pn = new Phone();
457 System.out.print("Phone Value: ");
458
459 pn.setValue(System.console().readLine().trim());
460 System.out.print("Use type (i.e. primary): ");
461 pn.setUseType(System.console().readLine().trim());
462 return pn;
463 }
464
465 private Description getDescription() {
466 Description pn = new Description();
467 System.out.print("Value: ");
468
469 pn.setValue(System.console().readLine().trim());
470 System.out.print("Language (en): ");
471 pn.setLang(System.console().readLine().trim());
472 if (pn.getLang().equalsIgnoreCase("")) {
473 pn.setLang("en");
474 }
475 return pn;
476 }
477
478 void autoMagic123() throws Exception {
479
480
481 Transport transport = clerkManager.getTransport("default");
482 String authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")).getAuthInfo();
483
484 JUDDIApiPortType juddiApiService = transport.getJUDDIApiService();
485 System.out.println("fetching...");
486
487 ReplicationConfiguration replicationNodes = null;
488 try {
489 replicationNodes = juddiApiService.getReplicationNodes(authtoken);
490 } catch (Exception ex) {
491 System.out.println("Error getting replication config");
492 ex.printStackTrace();
493 replicationNodes = new ReplicationConfiguration();
494
495 }
496 if (replicationNodes.getCommunicationGraph() == null) {
497 replicationNodes.setCommunicationGraph(new CommunicationGraph());
498 }
499 Operator op = new Operator();
500 op.setOperatorNodeID("uddi:juddi.apache.org:node1");
501 op.setSoapReplicationURL(clerkManager.getClientConfig().getUDDINode("default").getReplicationUrl());
502 op.setOperatorStatus(OperatorStatusType.NORMAL);
503 op.getContact().add(new Contact());
504 op.getContact().get(0).getPersonName().add(new PersonName("bob", "en"));
505 op.getContact().get(0).setUseType("admin");
506 replicationNodes.getOperator().clear();
507 replicationNodes.getOperator().add(op);
508
509 op = new Operator();
510 op.setOperatorNodeID("uddi:another.juddi.apache.org:node2");
511 op.setSoapReplicationURL(clerkManager.getClientConfig().getUDDINode("uddi:another.juddi.apache.org:node2").getReplicationUrl());
512 op.setOperatorStatus(OperatorStatusType.NORMAL);
513 op.getContact().add(new Contact());
514 op.getContact().get(0).getPersonName().add(new PersonName("mary", "en"));
515 op.getContact().get(0).setUseType("admin");
516 replicationNodes.getOperator().add(op);
517 op = new Operator();
518
519 op.setOperatorNodeID("uddi:yet.another.juddi.apache.org:node3");
520 op.setSoapReplicationURL(clerkManager.getClientConfig().getUDDINode("uddi:yet.another.juddi.apache.org:node3").getReplicationUrl());
521 op.setOperatorStatus(OperatorStatusType.NORMAL);
522 op.getContact().add(new Contact());
523 op.getContact().get(0).getPersonName().add(new PersonName("mary", "en"));
524 op.getContact().get(0).setUseType("admin");
525 replicationNodes.getOperator().add(op);
526
527 replicationNodes.getCommunicationGraph().getNode().add("uddi:another.juddi.apache.org:node2");
528 replicationNodes.getCommunicationGraph().getNode().add("uddi:juddi.apache.org:node1");
529 replicationNodes.getCommunicationGraph().getNode().add("uddi:yet.another.juddi.apache.org:node3");
530 replicationNodes.setSerialNumber(0L);
531 replicationNodes.setTimeOfConfigurationUpdate("");
532 replicationNodes.setMaximumTimeToGetChanges(BigInteger.ONE);
533 replicationNodes.setMaximumTimeToSyncRegistry(BigInteger.ONE);
534
535 if (replicationNodes.getRegistryContact().getContact() == null) {
536 replicationNodes.getRegistryContact().setContact(new Contact());
537 replicationNodes.getRegistryContact().getContact().getPersonName().add(new PersonName("unknown", null));
538 }
539
540 JAXB.marshal(replicationNodes, System.out);
541 juddiApiService.setReplicationNodes(authtoken, replicationNodes);
542
543 transport = clerkManager.getTransport("uddi:another.juddi.apache.org:node2");
544 authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")).getAuthInfo();
545
546 juddiApiService = transport.getJUDDIApiService();
547 juddiApiService.setReplicationNodes(authtoken, replicationNodes);
548
549 transport = clerkManager.getTransport("uddi:yet.another.juddi.apache.org:node3");
550 authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")).getAuthInfo();
551
552 juddiApiService = transport.getJUDDIApiService();
553 juddiApiService.setReplicationNodes(authtoken, replicationNodes);
554
555 }
556
557 void autoMagicDirected() throws Exception {
558
559
560 Transport transport = clerkManager.getTransport("default");
561 String authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")).getAuthInfo();
562
563 JUDDIApiPortType juddiApiService = transport.getJUDDIApiService();
564 System.out.println("fetching...");
565
566 ReplicationConfiguration replicationNodes = null;
567 try {
568 replicationNodes = juddiApiService.getReplicationNodes(authtoken);
569 } catch (Exception ex) {
570 System.out.println("Error getting replication config");
571 ex.printStackTrace();
572 replicationNodes = new ReplicationConfiguration();
573
574 }
575 if (replicationNodes.getCommunicationGraph() == null) {
576 replicationNodes.setCommunicationGraph(new CommunicationGraph());
577 }
578 Operator op = new Operator();
579 op.setOperatorNodeID("uddi:juddi.apache.org:node1");
580 op.setSoapReplicationURL(clerkManager.getClientConfig().getUDDINode("default").getReplicationUrl());
581 op.setOperatorStatus(OperatorStatusType.NORMAL);
582 op.getContact().add(new Contact());
583 op.getContact().get(0).getPersonName().add(new PersonName("bob", "en"));
584 op.getContact().get(0).setUseType("admin");
585 replicationNodes.getOperator().clear();
586 replicationNodes.getOperator().add(op);
587
588 op = new Operator();
589 op.setOperatorNodeID("uddi:another.juddi.apache.org:node2");
590 op.setSoapReplicationURL(clerkManager.getClientConfig().getUDDINode("uddi:another.juddi.apache.org:node2").getReplicationUrl());
591 op.setOperatorStatus(OperatorStatusType.NORMAL);
592 op.getContact().add(new Contact());
593 op.getContact().get(0).getPersonName().add(new PersonName("mary", "en"));
594 op.getContact().get(0).setUseType("admin");
595 replicationNodes.getOperator().add(op);
596 op = new Operator();
597
598 op.setOperatorNodeID("uddi:yet.another.juddi.apache.org:node3");
599 op.setSoapReplicationURL(clerkManager.getClientConfig().getUDDINode("uddi:yet.another.juddi.apache.org:node3").getReplicationUrl());
600 op.setOperatorStatus(OperatorStatusType.NORMAL);
601 op.getContact().add(new Contact());
602 op.getContact().get(0).getPersonName().add(new PersonName("mary", "en"));
603 op.getContact().get(0).setUseType("admin");
604 replicationNodes.getOperator().add(op);
605 replicationNodes.getCommunicationGraph().getNode().clear();
606 replicationNodes.getCommunicationGraph().getNode().add("uddi:another.juddi.apache.org:node2");
607 replicationNodes.getCommunicationGraph().getNode().add("uddi:juddi.apache.org:node1");
608 replicationNodes.getCommunicationGraph().getNode().add("uddi:yet.another.juddi.apache.org:node3");
609 replicationNodes.getCommunicationGraph().getEdge().clear();
610 Edge e = new CommunicationGraph.Edge();
611 e.setMessageSender("uddi:juddi.apache.org:node1");
612 e.setMessageReceiver("uddi:another.juddi.apache.org:node2");
613 replicationNodes.getCommunicationGraph().getEdge().add(e);
614
615 e = new CommunicationGraph.Edge();
616 e.setMessageSender("uddi:another.juddi.apache.org:node2");
617 e.setMessageReceiver("uddi:yet.another.juddi.apache.org:node3");
618 replicationNodes.getCommunicationGraph().getEdge().add(e);
619
620 e = new CommunicationGraph.Edge();
621 e.setMessageSender("uddi:yet.another.juddi.apache.org:node3");
622 e.setMessageReceiver("uddi:juddi.apache.org:node1");
623 replicationNodes.getCommunicationGraph().getEdge().add(e);
624
625 replicationNodes.setSerialNumber(0L);
626 replicationNodes.setTimeOfConfigurationUpdate("");
627 replicationNodes.setMaximumTimeToGetChanges(BigInteger.ONE);
628 replicationNodes.setMaximumTimeToSyncRegistry(BigInteger.ONE);
629
630 if (replicationNodes.getRegistryContact().getContact() == null) {
631 replicationNodes.getRegistryContact().setContact(new Contact());
632 replicationNodes.getRegistryContact().getContact().getPersonName().add(new PersonName("unknown", null));
633 }
634
635 JAXB.marshal(replicationNodes, System.out);
636
637 juddiApiService.setReplicationNodes(authtoken, replicationNodes);
638 System.out.println("Saved to node1");
639 TestEquals(replicationNodes, juddiApiService.getReplicationNodes(authtoken));
640
641 transport = clerkManager.getTransport("uddi:another.juddi.apache.org:node2");
642 authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")).getAuthInfo();
643 juddiApiService = transport.getJUDDIApiService();
644 juddiApiService.setReplicationNodes(authtoken, replicationNodes);
645 System.out.println("Saved to node2");
646 TestEquals(replicationNodes, juddiApiService.getReplicationNodes(authtoken));
647
648 transport = clerkManager.getTransport("uddi:yet.another.juddi.apache.org:node3");
649 authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")).getAuthInfo();
650 juddiApiService = transport.getJUDDIApiService();
651 juddiApiService.setReplicationNodes(authtoken, replicationNodes);
652 System.out.println("Saved to node3");
653 TestEquals(replicationNodes, juddiApiService.getReplicationNodes(authtoken));
654
655 }
656
657 void autoMagic() throws Exception {
658
659 Transport transport = clerkManager.getTransport("default");
660 String authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")).getAuthInfo();
661
662 JUDDIApiPortType juddiApiService = transport.getJUDDIApiService();
663 System.out.println("fetching...");
664
665 ReplicationConfiguration replicationNodes = null;
666 try {
667 replicationNodes = juddiApiService.getReplicationNodes(authtoken);
668 } catch (Exception ex) {
669 System.out.println("Error getting replication config");
670 ex.printStackTrace();
671 replicationNodes = new ReplicationConfiguration();
672
673 }
674
675 replicationNodes.setCommunicationGraph(new CommunicationGraph());
676
677 Operator op = new Operator();
678 op.setOperatorNodeID("uddi:juddi.apache.org:node1");
679 op.setSoapReplicationURL(clerkManager.getClientConfig().getUDDINode("default").getReplicationUrl());
680 op.setOperatorStatus(OperatorStatusType.NORMAL);
681 op.getContact().add(new Contact());
682 op.getContact().get(0).getPersonName().add(new PersonName("bob", "en"));
683 op.getContact().get(0).setUseType("admin");
684 replicationNodes.getOperator().clear();
685 replicationNodes.getOperator().add(op);
686
687 op = new Operator();
688 op.setOperatorNodeID("uddi:another.juddi.apache.org:node2");
689 op.setSoapReplicationURL(clerkManager.getClientConfig().getUDDINode("uddi:another.juddi.apache.org:node2").getReplicationUrl());
690 op.setOperatorStatus(OperatorStatusType.NORMAL);
691 op.getContact().add(new Contact());
692 op.getContact().get(0).getPersonName().add(new PersonName("mary", "en"));
693 op.getContact().get(0).setUseType("admin");
694 replicationNodes.getOperator().add(op);
695 replicationNodes.getCommunicationGraph().getNode().add("uddi:another.juddi.apache.org:node2");
696 replicationNodes.getCommunicationGraph().getNode().add("uddi:juddi.apache.org:node1");
697 replicationNodes.setSerialNumber(0L);
698 replicationNodes.setTimeOfConfigurationUpdate("");
699 replicationNodes.setMaximumTimeToGetChanges(BigInteger.ONE);
700 replicationNodes.setMaximumTimeToSyncRegistry(BigInteger.ONE);
701
702 if (replicationNodes.getRegistryContact().getContact() == null) {
703 replicationNodes.getRegistryContact().setContact(new Contact());
704 replicationNodes.getRegistryContact().getContact().getPersonName().add(new PersonName("unknown", null));
705 }
706
707 JAXB.marshal(replicationNodes, System.out);
708 juddiApiService.setReplicationNodes(authtoken, replicationNodes);
709
710 transport = clerkManager.getTransport("uddi:another.juddi.apache.org:node2");
711 authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")).getAuthInfo();
712
713 juddiApiService = transport.getJUDDIApiService();
714 juddiApiService.setReplicationNodes(authtoken, replicationNodes);
715
716 }
717
718 void autoMagic3() throws Exception {
719
720 Transport transport = clerkManager.getTransport("default");
721 String authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")).getAuthInfo();
722
723 JUDDIApiPortType juddiApiService = transport.getJUDDIApiService();
724 System.out.println("fetching...");
725
726 ReplicationConfiguration replicationNodes = null;
727 try {
728 replicationNodes = juddiApiService.getReplicationNodes(authtoken);
729 } catch (Exception ex) {
730 System.out.println("Error getting replication config");
731 ex.printStackTrace();
732 replicationNodes = new ReplicationConfiguration();
733
734 }
735 if (replicationNodes.getCommunicationGraph() == null) {
736 replicationNodes.setCommunicationGraph(new CommunicationGraph());
737 }
738 Operator op = new Operator();
739 op.setOperatorNodeID("uddi:juddi.apache.org:node1");
740 op.setSoapReplicationURL(clerkManager.getClientConfig().getUDDINode("default").getReplicationUrl());
741 op.setOperatorStatus(OperatorStatusType.NORMAL);
742 op.getContact().add(new Contact());
743 op.getContact().get(0).getPersonName().add(new PersonName("bob", "en"));
744 op.getContact().get(0).setUseType("admin");
745 replicationNodes.getOperator().clear();
746 replicationNodes.getOperator().add(op);
747
748 op = new Operator();
749 op.setOperatorNodeID("uddi:another.juddi.apache.org:node2");
750 op.setSoapReplicationURL(clerkManager.getClientConfig().getUDDINode("uddi:another.juddi.apache.org:node2").getReplicationUrl());
751 op.setOperatorStatus(OperatorStatusType.NORMAL);
752 op.getContact().add(new Contact());
753 op.getContact().get(0).getPersonName().add(new PersonName("mary", "en"));
754 op.getContact().get(0).setUseType("admin");
755 replicationNodes.getOperator().add(op);
756
757 op = new Operator();
758 op.setOperatorNodeID("uddi:yet.another.juddi.apache.org:node3");
759 op.setSoapReplicationURL(clerkManager.getClientConfig().getUDDINode("uddi:yet.another.juddi.apache.org:node3").getReplicationUrl());
760 op.setOperatorStatus(OperatorStatusType.NORMAL);
761 op.getContact().add(new Contact());
762 op.getContact().get(0).getPersonName().add(new PersonName("mary", "en"));
763 op.getContact().get(0).setUseType("admin");
764 replicationNodes.getOperator().add(op);
765
766 replicationNodes.getCommunicationGraph().getNode().add("uddi:another.juddi.apache.org:node2");
767 replicationNodes.getCommunicationGraph().getNode().add("uddi:yet.another.juddi.apache.org:node3");
768 replicationNodes.getCommunicationGraph().getNode().add("uddi:juddi.apache.org:node1");
769 replicationNodes.setSerialNumber(0L);
770 replicationNodes.setTimeOfConfigurationUpdate("");
771 replicationNodes.setMaximumTimeToGetChanges(BigInteger.ONE);
772 replicationNodes.setMaximumTimeToSyncRegistry(BigInteger.ONE);
773
774 if (replicationNodes.getRegistryContact().getContact() == null) {
775 replicationNodes.getRegistryContact().setContact(new Contact());
776 replicationNodes.getRegistryContact().getContact().getPersonName().add(new PersonName("unknown", null));
777 }
778
779 JAXB.marshal(replicationNodes, System.out);
780 juddiApiService.setReplicationNodes(authtoken, replicationNodes);
781
782 transport = clerkManager.getTransport("uddi:another.juddi.apache.org:node2");
783 authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")).getAuthInfo();
784
785 juddiApiService = transport.getJUDDIApiService();
786 juddiApiService.setReplicationNodes(authtoken, replicationNodes);
787
788 transport = clerkManager.getTransport("uddi:yet.another.juddi.apache.org:node3");
789 authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")).getAuthInfo();
790
791 juddiApiService = transport.getJUDDIApiService();
792 juddiApiService.setReplicationNodes(authtoken, replicationNodes);
793
794 }
795
796 void printStatus(Transport transport, String authtoken) throws Exception {
797
798 JUDDIApiPortType juddiApiService = transport.getJUDDIApiService();
799 System.out.println("fetching...");
800
801 ReplicationConfiguration replicationNodes = null;
802 try {
803 replicationNodes = juddiApiService.getReplicationNodes(authtoken);
804 } catch (Exception ex) {
805 System.out.println("Error getting replication config");
806 ex.printStackTrace();
807 replicationNodes = new ReplicationConfiguration();
808
809 }
810 UDDIReplicationPortType uddiReplicationPort = new UDDIService().getUDDIReplicationPort();
811
812 for (Operator o : replicationNodes.getOperator()) {
813 System.out.println("*******************\n\rstats for node " + o.getOperatorNodeID());
814 ((BindingProvider) uddiReplicationPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, o.getSoapReplicationURL());
815
816 List<ChangeRecordIDType> highWaterMarks = uddiReplicationPort.getHighWaterMarks();
817 for (ChangeRecordIDType cr : highWaterMarks) {
818 JAXB.marshal(cr, System.out);
819 }
820 }
821 }
822
823 void printStatus() throws Exception {
824
825
826 Transport transport = clerkManager.getTransport("default");
827 String authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")).getAuthInfo();
828
829 JUDDIApiPortType juddiApiService = transport.getJUDDIApiService();
830 System.out.println("fetching...");
831
832 ReplicationConfiguration replicationNodes = null;
833 try {
834 replicationNodes = juddiApiService.getReplicationNodes(authtoken);
835 } catch (Exception ex) {
836 System.out.println("Error getting replication config");
837 ex.printStackTrace();
838 replicationNodes = new ReplicationConfiguration();
839
840 }
841 UDDIReplicationPortType uddiReplicationPort = new UDDIService().getUDDIReplicationPort();
842
843 for (Operator o : replicationNodes.getOperator()) {
844 System.out.println("*******************\n\rstats for node " + o.getOperatorNodeID());
845 ((BindingProvider) uddiReplicationPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, o.getSoapReplicationURL());
846
847 List<ChangeRecordIDType> highWaterMarks = uddiReplicationPort.getHighWaterMarks();
848 for (ChangeRecordIDType cr : highWaterMarks) {
849 JAXB.marshal(cr, System.out);
850 }
851 }
852
853 }
854
855 private void TestEquals(ReplicationConfiguration setter, ReplicationConfiguration getter) {
856 if (getter == null) {
857 l("null getter");
858 return;
859 }
860 if (setter == null) {
861 l("null setter");
862 return;
863 }
864 if (getter.getOperator().size() != setter.getOperator().size()) {
865 l("operator size mismatch");
866 return;
867 }
868 if (getter.getCommunicationGraph().getNode().size() != setter.getCommunicationGraph().getNode().size()) {
869 l("comm/node size mismatch");
870 return;
871 }
872 if (getter.getCommunicationGraph().getEdge().size() != setter.getCommunicationGraph().getEdge().size()) {
873 l("comm/node size mismatch");
874 return;
875 }
876
877 }
878
879 private void l(String msg) {
880 System.out.println(msg);
881 }
882
883 void dumpFailedReplicationRecords(String authtoken) throws Exception {
884 GetFailedReplicationChangeRecordsMessageRequest req = new GetFailedReplicationChangeRecordsMessageRequest();
885 req.setAuthInfo(authtoken);
886 req.setMaxRecords(20);
887 req.setOffset(0);
888 GetFailedReplicationChangeRecordsMessageResponse failedReplicationChangeRecords = juddi.getFailedReplicationChangeRecords(req);
889 while (failedReplicationChangeRecords != null
890 && failedReplicationChangeRecords.getChangeRecords() != null
891 && !failedReplicationChangeRecords.getChangeRecords().getChangeRecord().isEmpty()) {
892 for (int i = 0; i < failedReplicationChangeRecords.getChangeRecords().getChangeRecord().size(); i++) {
893 JAXB.marshal(failedReplicationChangeRecords.getChangeRecords().getChangeRecord().get(i), System.out);
894 }
895 req.setOffset(req.getOffset() + failedReplicationChangeRecords.getChangeRecords().getChangeRecord().size());
896 failedReplicationChangeRecords = juddi.getFailedReplicationChangeRecords(req);
897 }
898 }
899
900 void printStatusSingleNode(Transport transport, String authtoken) throws Exception {
901 String replicationUrl = clerkManager.getClientConfig().getUDDINode(curentnode).getReplicationUrl();
902
903 SSLContext sc = SSLContext.getInstance("SSLv3");
904
905 KeyManagerFactory kmf
906 = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
907
908 KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
909 FileInputStream fis = null;
910 try {
911 fis = new FileInputStream(System.getProperty("javax.net.ssl.keyStore"));
912 ks.load(fis, System.getProperty("javax.net.ssl.keyStorePassword").toCharArray());
913 } catch (Exception ex) {
914
915 } finally {
916 if (fis != null) {
917 fis.close();
918 }
919 }
920
921 kmf.init(ks, System.getProperty("javax.net.ssl.keyStorePassword").toCharArray());
922
923 sc.init(kmf.getKeyManagers(), null, null);
924
925 UDDIReplicationPortType uddiReplicationPort = new UDDIService().getUDDIReplicationPort();
926 ((BindingProvider) uddiReplicationPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, replicationUrl);
927 ((BindingProvider) uddiReplicationPort).getRequestContext()
928 .put(
929 "com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory",
930 sc.getSocketFactory());
931
932
933
934
935
936 String doPing = uddiReplicationPort.doPing(new DoPing());
937 System.out.println(doPing + ".., success");
938
939 }
940
941 void autoMagicDirectedSSL() throws Exception {
942
943
944 Transport transport = clerkManager.getTransport("default");
945 String authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")).getAuthInfo();
946
947 JUDDIApiPortType juddiApiService = transport.getJUDDIApiService();
948 System.out.println("fetching...");
949
950 ReplicationConfiguration replicationNodes = null;
951 try {
952 replicationNodes = juddiApiService.getReplicationNodes(authtoken);
953 } catch (Exception ex) {
954 System.out.println("Error getting replication config");
955 ex.printStackTrace();
956 replicationNodes = new ReplicationConfiguration();
957
958 }
959
960 replicationNodes.setCommunicationGraph(new CommunicationGraph());
961
962 Operator op = new Operator();
963 op.setOperatorNodeID("uddi:juddi.apache.org:node1");
964 op.setSoapReplicationURL(clerkManager.getClientConfig().getUDDINode("default").getReplicationUrl());
965 op.setOperatorStatus(OperatorStatusType.NORMAL);
966 op.getContact().add(new Contact());
967 op.getContact().get(0).getPersonName().add(new PersonName("bob", "en"));
968 op.getContact().get(0).setUseType("admin");
969 replicationNodes.getOperator().clear();
970 replicationNodes.getOperator().add(op);
971
972 op = new Operator();
973 op.setOperatorNodeID("uddi:another.juddi.apache.org:node2");
974 op.setSoapReplicationURL(clerkManager.getClientConfig().getUDDINode("uddi:another.juddi.apache.org:node2").getReplicationUrl());
975 op.setOperatorStatus(OperatorStatusType.NORMAL);
976 op.getContact().add(new Contact());
977 op.getContact().get(0).getPersonName().add(new PersonName("mary", "en"));
978 op.getContact().get(0).setUseType("admin");
979 replicationNodes.getOperator().add(op);
980 op = new Operator();
981
982 op.setOperatorNodeID("uddi:yet.another.juddi.apache.org:node3");
983 op.setSoapReplicationURL(clerkManager.getClientConfig().getUDDINode("uddi:yet.another.juddi.apache.org:node3").getReplicationUrl());
984 op.setOperatorStatus(OperatorStatusType.NORMAL);
985 op.getContact().add(new Contact());
986 op.getContact().get(0).getPersonName().add(new PersonName("mary", "en"));
987 op.getContact().get(0).setUseType("admin");
988 replicationNodes.getOperator().add(op);
989 replicationNodes.getCommunicationGraph().getNode().clear();
990 replicationNodes.getCommunicationGraph().getNode().add("uddi:another.juddi.apache.org:node2");
991 replicationNodes.getCommunicationGraph().getNode().add("uddi:juddi.apache.org:node1");
992 replicationNodes.getCommunicationGraph().getNode().add("uddi:yet.another.juddi.apache.org:node3");
993 replicationNodes.getCommunicationGraph().getEdge().clear();
994 Edge e = new CommunicationGraph.Edge();
995 e.setMessageSender("uddi:juddi.apache.org:node1");
996 e.setMessageReceiver("uddi:another.juddi.apache.org:node2");
997 replicationNodes.getCommunicationGraph().getEdge().add(e);
998
999 e = new CommunicationGraph.Edge();
1000 e.setMessageSender("uddi:another.juddi.apache.org:node2");
1001 e.setMessageReceiver("uddi:yet.another.juddi.apache.org:node3");
1002 replicationNodes.getCommunicationGraph().getEdge().add(e);
1003
1004 e = new CommunicationGraph.Edge();
1005 e.setMessageSender("uddi:yet.another.juddi.apache.org:node3");
1006 e.setMessageReceiver("uddi:juddi.apache.org:node1");
1007 replicationNodes.getCommunicationGraph().getEdge().add(e);
1008
1009 replicationNodes.setSerialNumber(0L);
1010 replicationNodes.setTimeOfConfigurationUpdate("");
1011 replicationNodes.setMaximumTimeToGetChanges(BigInteger.ONE);
1012 replicationNodes.setMaximumTimeToSyncRegistry(BigInteger.ONE);
1013
1014 if (replicationNodes.getRegistryContact().getContact() == null) {
1015 replicationNodes.getRegistryContact().setContact(new Contact());
1016 replicationNodes.getRegistryContact().getContact().getPersonName().add(new PersonName("unknown", null));
1017 }
1018
1019 JAXB.marshal(replicationNodes, System.out);
1020
1021 juddiApiService.setReplicationNodes(authtoken, replicationNodes);
1022 System.out.println("Saved to node1");
1023 TestEquals(replicationNodes, juddiApiService.getReplicationNodes(authtoken));
1024
1025 transport = clerkManager.getTransport("uddi:another.juddi.apache.org:node2");
1026 authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")).getAuthInfo();
1027 juddiApiService = transport.getJUDDIApiService();
1028 juddiApiService.setReplicationNodes(authtoken, replicationNodes);
1029 System.out.println("Saved to node2");
1030 TestEquals(replicationNodes, juddiApiService.getReplicationNodes(authtoken));
1031
1032 transport = clerkManager.getTransport("uddi:yet.another.juddi.apache.org:node3");
1033 authtoken = transport.getUDDISecurityService().getAuthToken(new GetAuthToken("root", "root")).getAuthInfo();
1034 juddiApiService = transport.getJUDDIApiService();
1035 juddiApiService.setReplicationNodes(authtoken, replicationNodes);
1036 System.out.println("Saved to node3");
1037 TestEquals(replicationNodes, juddiApiService.getReplicationNodes(authtoken));
1038 }
1039
1040 void pingAll() throws Exception {
1041 List<Node> uddiNodeList = clerkManager.getClientConfig().getUDDINodeList();
1042
1043 UDDIReplicationPortType uddiReplicationPort = new UDDIService().getUDDIReplicationPort();
1044 TransportSecurityHelper.applyTransportSecurity((BindingProvider) uddiReplicationPort);
1045
1046 for (Node currenteNode : uddiNodeList) {
1047 try {
1048 String replicationUrl = clerkManager.getClientConfig().getUDDINode(currenteNode.getName()).getReplicationUrl();
1049 ((BindingProvider) uddiReplicationPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, replicationUrl);
1050 long now = System.currentTimeMillis();
1051 String doPing = uddiReplicationPort.doPing(new DoPing());
1052 System.out.println(replicationUrl + " " + currenteNode.getName() + " says it's node id is " + doPing + " (took " + (System.currentTimeMillis() - now) + "ms)");
1053 } catch (Exception ex) {
1054 System.out.println("Error! " + currenteNode.getName() + " " + currenteNode.getReplicationUrl());
1055 ex.printStackTrace();
1056 }
1057
1058 }
1059
1060 }
1061
1062 }