This project has retired. For details please refer to its
Attic page.
UddiAdminHub xref
1 package org.apache.juddi.adminconsole.hub;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.io.InputStream;
20 import java.io.StringReader;
21 import java.io.StringWriter;
22 import java.math.BigInteger;
23 import java.net.URL;
24 import java.rmi.RemoteException;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Properties;
29 import javax.persistence.EntityManager;
30 import javax.persistence.EntityTransaction;
31 import javax.persistence.Query;
32 import javax.servlet.ServletContext;
33 import javax.servlet.http.HttpServletRequest;
34 import javax.servlet.http.HttpSession;
35 import javax.xml.XMLConstants;
36 import javax.xml.bind.JAXB;
37 import javax.xml.datatype.DatatypeConfigurationException;
38 import javax.xml.parsers.DocumentBuilder;
39 import javax.xml.parsers.DocumentBuilderFactory;
40 import javax.xml.transform.OutputKeys;
41 import javax.xml.transform.Transformer;
42 import javax.xml.transform.TransformerFactory;
43 import javax.xml.transform.dom.DOMSource;
44 import javax.xml.transform.stream.StreamResult;
45 import javax.xml.transform.stream.StreamSource;
46 import javax.xml.ws.BindingProvider;
47 import javax.xml.ws.Holder;
48 import org.apache.commons.configuration.Configuration;
49 import org.apache.commons.configuration.ConfigurationException;
50 import org.apache.commons.lang.StringEscapeUtils;
51 import org.apache.commons.logging.Log;
52 import org.apache.commons.logging.LogFactory;
53 import org.apache.juddi.api_v3.Clerk;
54 import org.apache.juddi.api_v3.ClientSubscriptionInfoDetail;
55 import org.apache.juddi.api_v3.DeleteClientSubscriptionInfo;
56 import org.apache.juddi.api_v3.DeletePublisher;
57 import org.apache.juddi.api_v3.GetAllPublisherDetail;
58 import org.apache.juddi.api_v3.GetPublisherDetail;
59 import org.apache.juddi.api_v3.Node;
60 import org.apache.juddi.api_v3.Publisher;
61 import org.apache.juddi.api_v3.PublisherDetail;
62 import org.apache.juddi.api_v3.SaveClerk;
63 import org.apache.juddi.api_v3.SaveClientSubscriptionInfo;
64 import org.apache.juddi.api_v3.SaveNode;
65 import org.apache.juddi.api_v3.SavePublisher;
66 import org.apache.juddi.api_v3.SyncSubscription;
67 import org.apache.juddi.api_v3.SyncSubscriptionDetail;
68 import org.apache.juddi.v3.client.UDDIConstants;
69 import org.apache.juddi.v3.client.config.ClientConfig;
70 import org.apache.juddi.v3.client.config.UDDIClient;
71 import org.apache.juddi.v3.client.config.UDDINode;
72 import org.apache.juddi.v3.client.transport.Transport;
73 import org.apache.juddi.v3_service.JUDDIApiPortType;
74 import org.apache.juddi.adminconsole.AES;
75 import org.apache.juddi.adminconsole.resources.ResourceLoader;
76 import org.apache.juddi.api.impl.JUDDIApiImpl;
77 import org.apache.juddi.api.impl.UDDIInquiryImpl;
78 import org.apache.juddi.api.impl.UDDIPublicationImpl;
79 import org.apache.juddi.api.impl.UDDIReplicationImpl;
80 import org.apache.juddi.api_v3.AdminSaveBusiness;
81 import org.apache.juddi.api_v3.AdminSaveSubscriptionRequest;
82 import org.apache.juddi.api_v3.AdminSaveSubscriptionResponse;
83 import org.apache.juddi.api_v3.AdminSaveTModel;
84 import org.apache.juddi.api_v3.ClerkList;
85 import org.apache.juddi.api_v3.ClientSubscriptionInfo;
86 import org.apache.juddi.api_v3.DeleteClerk;
87 import org.apache.juddi.api_v3.DeleteNode;
88 import org.apache.juddi.api_v3.GetEntityHistoryMessageRequest;
89 import org.apache.juddi.api_v3.GetEntityHistoryMessageResponse;
90 import org.apache.juddi.api_v3.GetFailedReplicationChangeRecordsMessageRequest;
91 import org.apache.juddi.api_v3.GetFailedReplicationChangeRecordsMessageResponse;
92 import org.apache.juddi.api_v3.NodeList;
93 import org.apache.juddi.api_v3.SubscriptionWrapper;
94 import org.apache.juddi.config.AppConfig;
95 import org.apache.juddi.config.PersistenceManager;
96 import org.apache.juddi.config.Property;
97 import org.apache.juddi.model.BindingTemplate;
98 import org.apache.juddi.subscription.notify.SMTPNotifier;
99 import org.uddi.api_v3.AuthToken;
100 import org.uddi.api_v3.BusinessDetail;
101 import org.uddi.api_v3.BusinessEntity;
102 import org.uddi.api_v3.BusinessService;
103 import org.uddi.api_v3.DeleteBusiness;
104 import org.uddi.api_v3.DeleteTModel;
105 import org.uddi.api_v3.DiscardAuthToken;
106 import org.uddi.api_v3.DispositionReport;
107 import org.uddi.api_v3.FindBusiness;
108 import org.uddi.api_v3.FindQualifiers;
109 import org.uddi.api_v3.GetAuthToken;
110 import org.uddi.api_v3.GetBusinessDetail;
111 import org.uddi.api_v3.Name;
112 import org.uddi.api_v3.SaveBusiness;
113 import org.uddi.repl_v3.ChangeRecordIDType;
114 import org.uddi.repl_v3.ChangeRecords;
115 import org.uddi.repl_v3.GetChangeRecords;
116 import org.uddi.repl_v3.HighWaterMarkVectorType;
117 import org.uddi.repl_v3.ReplicationConfiguration;
118 import org.uddi.sub_v3.Subscription;
119 import org.uddi.sub_v3.SubscriptionResultsList;
120 import org.uddi.subr_v3.NotifySubscriptionListener;
121
122 import org.uddi.v3_service.DispositionReportFaultMessage;
123 import org.uddi.v3_service.UDDISecurityPortType;
124 import org.w3c.dom.Document;
125 import org.xml.sax.InputSource;
126
127
128
129
130
131
132
133
134
135 public class UddiAdminHub {
136
137
138
139
140 public static final String LOGGER_NAME = "org.apache.juddi";
141 transient AuthStyle style = null;
142 Properties properties = null;
143
144
145
146
147 public static final Log log = LogFactory.getLog(LOGGER_NAME);
148
149 private UddiAdminHub() throws DatatypeConfigurationException {
150
151 }
152
153
154
155
156
157
158 public static void reset(HttpSession _session) {
159 _session.removeAttribute("hub");
160
161 }
162
163
164
165
166
167 public void die() {
168 if (token != null && security != null) {
169 DiscardAuthToken da = new DiscardAuthToken();
170 da.setAuthInfo(token);
171 try {
172 security.discardAuthToken(da);
173 } catch (Exception ex) {
174 HandleException(ex);
175 }
176 }
177 token = null;
178 security = null;
179 juddi = null;
180 }
181
182
183
184 public static final String PROP_CONFIG_NODE = "config.props.node";
185
186
187
188 public static final String PROP_AUTH_TYPE = "config.props.authtype";
189
190
191
192 public static final String PROP_AUTO_LOGOUT = "config.props.automaticLogouts.enable";
193
194
195
196 public static final String PROP_AUTO_LOGOUT_TIMER = "config.props.automaticLogouts.duration";
197
198
199
200 public static final String PROP_PREFIX = "config.props.";
201
202
203
204
205 public static final String PROP_ADMIN_LOCALHOST_ONLY = "config.props.configLocalHostOnly";
206
207 private transient UDDISecurityPortType security = null;
208 private transient JUDDIApiPortType juddi = null;
209 private transient String token = null;
210 private transient HttpSession session;
211 private transient Transport transport = null;
212 private transient ClientConfig clientConfig;
213 private static final long serialVersionUID = 1L;
214 private String nodename = "default";
215 private final String clientName = "juddigui";
216 private boolean WS_Transport = false;
217 private boolean WS_securePorts = false;
218
219
220
221
222
223
224
225
226
227
228 public static UddiAdminHub getInstance(ServletContext application, HttpSession _session) throws Exception {
229 Object j = _session.getAttribute("hub");
230 if (j == null) {
231 UddiAdminHub hub = new UddiAdminHub(application, _session);
232 _session.setAttribute("hub", hub);
233 return hub;
234 }
235
236 return (UddiAdminHub) j;
237 }
238 String locale = "en";
239
240 private UddiAdminHub(ServletContext application, HttpSession _session) throws Exception {
241 URL prop = application.getResource("/WEB-INF/config.properties");
242 if (prop == null) {
243 application.getResource("WEB-INF/config.properties");
244 }
245 if (prop == null) {
246 throw new Exception("Cannot locate the configuration file.");
247 }
248 session = _session;
249
250 InputStream in = prop.openStream();
251 Properties p = new Properties();
252 p.load(in);
253 in.close();
254 session = _session;
255 properties = p;
256 EnsureConfig();
257 }
258
259 private void EnsureConfig() {
260 if (clientConfig == null) {
261 try {
262 UDDIClient client = new UDDIClient();
263
264 clientConfig = client.getClientConfig();
265 try {
266 style = AuthStyle.valueOf(clientConfig.getConfiguration().getString(PROP_AUTH_TYPE));
267 } catch (Exception ex) {
268 log.warn("'UDDI_AUTH' is not defined in the config (" + PROP_AUTH_TYPE + ")! defaulting to UDDI_AUTH");
269 style = AuthStyle.UDDI_AUTH;
270 }
271
272 nodename = clientConfig.getConfiguration().getString(PROP_CONFIG_NODE);
273 if (nodename == null || nodename.equals("")) {
274 log.warn("'node' is not defined in the config! defaulting to 'default'");
275 nodename = "default";
276 }
277 UDDINode uddiNode = clientConfig.getUDDINode(nodename);
278
279 String clazz = uddiNode.getProxyTransport();
280 if (clazz.contains("JAXWSTransport")) {
281 WS_Transport = true;
282 }
283
284 transport = client.getTransport(nodename);
285 security = transport.getUDDISecurityService();
286 juddi = transport.getJUDDIApiService();
287 if (WS_Transport) {
288 if (uddiNode.getJuddiApiUrl().toLowerCase().startsWith("https://")
289 && (uddiNode.getSecurityUrl() != null && uddiNode.getSecurityUrl().toLowerCase().startsWith("https://"))) {
290 WS_securePorts = true;
291 }
292 }
293
294 } catch (Exception ex) {
295 HandleException(ex);
296 }
297 }
298
299 }
300
301
302
303
304
305
306
307
308
309 private String HandleException(Exception ex) {
310 if (ex instanceof DispositionReportFaultMessage) {
311 DispositionReportFaultMessage f = (DispositionReportFaultMessage) ex;
312 log.error(ex.getMessage() + (f.detail != null && f.detail.getMessage() != null ? StringEscapeUtils.escapeHtml(f.detail.getMessage()) : ""));
313 log.debug(ex.getMessage(), ex);
314 return ResourceLoader.GetResource(session, "errors.generic") + " " + StringEscapeUtils.escapeHtml(ex.getMessage()) + " " + (f.detail != null && f.detail.getMessage() != null ? StringEscapeUtils.escapeHtml(f.detail.getMessage()) : "");
315 } else if (ex instanceof RemoteException) {
316 RemoteException f = (RemoteException) ex;
317 log.error("RemoteException " + ex.getMessage());
318 log.debug("RemoteException " + ex.getMessage(), ex);
319 return ResourceLoader.GetResource(session, "errors.generic") + " " + StringEscapeUtils.escapeHtml(ex.getMessage()) + " " + (f.detail != null && f.detail.getMessage() != null ? StringEscapeUtils.escapeHtml(f.detail.getMessage()) : "");
320 } else if (ex instanceof NullPointerException) {
321 log.error("NPE! Please report! " + ex.getMessage(), ex);
322 log.debug("NPE! Please report! " + ex.getMessage(), ex);
323 return ResourceLoader.GetResource(session, "errors.generic") + " " + StringEscapeUtils.escapeHtml(ex.getMessage());
324 } else {
325 log.error("Unexpected error " + ex.getMessage(), ex);
326
327 return ResourceLoader.GetResource(session, "errors.generic") + " " + StringEscapeUtils.escapeHtml(ex.getMessage());
328 }
329 }
330
331
332
333
334
335
336
337 public boolean isSecure() {
338
339 EnsureConfig();
340 return WS_securePorts;
341 }
342
343
344
345
346
347
348
349
350 public ClientConfig GetJuddiClientConfig() throws ConfigurationException {
351 EnsureConfig();
352 return clientConfig;
353 }
354
355
356
357
358
359
360
361 public String go(HttpServletRequest parameters) {
362 try {
363 String action = parameters.getParameter("soapaction");
364 if (action.equalsIgnoreCase("adminDelete_tmodel")) {
365 return adminDelete_tmodel(parameters);
366 } else if (action.equalsIgnoreCase("delete_ClientSubscriptionInfo")) {
367 return delete_ClientSubscriptionInfo(parameters);
368 } else if (action.equalsIgnoreCase("delete_publisher")) {
369 return delete_publisher(parameters);
370 } else if (action.equalsIgnoreCase("getAllPublisherDetail")) {
371 return getAllPublisherDetail(parameters);
372 } else if (action.equalsIgnoreCase("get_publisherDetail")) {
373 return get_publisherDetail(parameters);
374 } else if (action.equalsIgnoreCase("invoke_SyncSubscription")) {
375 return invoke_SyncSubscription(parameters);
376 } else if (action.equalsIgnoreCase("save_Clerk")) {
377 return save_Clerk(parameters);
378 } else if (action.equalsIgnoreCase("save_ClientSubscriptionInfo")) {
379 return save_ClientSubscriptionInfo(parameters);
380 } else if (action.equalsIgnoreCase("save_Node")) {
381 return save_Node(parameters);
382 } else if (action.equalsIgnoreCase("save_publisher")) {
383 return save_publisher(parameters);
384 } else if (action.equalsIgnoreCase("send_EmailTest")) {
385 return sendTestEmail(parameters);
386 } else if (action.equalsIgnoreCase("get_AllNodes")) {
387 return getAllNodes(parameters);
388 } else if (action.equalsIgnoreCase("get_AllClerks")) {
389 return getAllClerks(parameters);
390 } else if (action.equalsIgnoreCase("delete_Node")) {
391 return deleteNode(parameters);
392 } else if (action.equalsIgnoreCase("delete_Clerk")) {
393 return deleteClerk(parameters);
394 } else if (action.equalsIgnoreCase("admin_DeleteSubscription")) {
395 return deleteSubscription(parameters);
396 } else if (action.equalsIgnoreCase("admin_SaveBusiness")) {
397 return adminSaveBusiness(parameters);
398 } else if (action.equalsIgnoreCase("admin_SaveTModel")) {
399 return adminSaveTmodel(parameters);
400 } else if (action.equalsIgnoreCase("get_AllClientSubscriptionInfo")) {
401 return getAllClientSubscriptionInfo(parameters);
402 } else if (action.equalsIgnoreCase("set_ReplicationNodes")) {
403 return setReplicationConfig(parameters);
404 } else if (action.equalsIgnoreCase("get_ReplicationNodes")) {
405 return getReplicationNodes(parameters);
406 } else if (action.equalsIgnoreCase("admin_SaveSubscription")) {
407 return adminSaveSubscription(parameters);
408 } else if (action.equalsIgnoreCase("get_EntityHistory")) {
409 return getEntityHistory(parameters);
410 } else if (action.equalsIgnoreCase("change_NodeID")) {
411 return change_NodeID(parameters);
412 } else if (action.equalsIgnoreCase("changeRecord")) {
413 return getChangeRecord(parameters);
414 } else if (action.equalsIgnoreCase("getFailedReplicationChangeRecords")) {
415 return getFailedReplicationChangeRecords(parameters);
416 }
417
418 } catch (Exception ex) {
419 return "Error!" + HandleException(ex);
420 }
421 return "not yet implemented!";
422 }
423
424 private String save_Clerk(HttpServletRequest parameters) {
425 SaveClerk sc = new SaveClerk();
426 sc.setAuthInfo(GetToken());
427 Clerk c = new Clerk();
428 c.setName(parameters.getParameter("CLERKsetName"));
429 Node node = new Node();
430 node.setClientName(parameters.getParameter("CLERKNODEsetClientName"));
431 node.setCustodyTransferUrl(parameters.getParameter("CLERKNODEsetCustodyTransferUrl"));
432 node.setDescription(parameters.getParameter("CLERKNODEsetDescription"));
433 node.setFactoryInitial(parameters.getParameter("CLERKNODEsetFactoryInitial"));
434 node.setFactoryNamingProvider(parameters.getParameter("CLERKNODEsetFactoryNamingProvider"));
435 node.setFactoryURLPkgs(parameters.getParameter("CLERKNODEsetFactoryURLPkgs"));
436 node.setInquiryUrl(parameters.getParameter("CLERKNODEsetInquiryUrl"));
437 node.setJuddiApiUrl(parameters.getParameter("CLERKNODEsetJuddiApiUrl"));
438 node.setName(parameters.getParameter("CLERKNODEsetName"));
439 node.setProxyTransport(parameters.getParameter("CLERKNODEsetProxyTransport"));
440 node.setPublishUrl(parameters.getParameter("CLERKNODEsetPublishUrl"));
441 node.setReplicationUrl(parameters.getParameter("CLERKNODEsetReplicationUrl"));
442 node.setSecurityUrl(parameters.getParameter("CLERKNODEsetSecurityUrl"));
443 node.setSubscriptionListenerUrl(parameters.getParameter("CLERKNODEsetSubscriptionListenerUrl"));
444 node.setSubscriptionUrl(parameters.getParameter("CLERKNODEsetSubscriptionUrl"));
445 c.setNode(node);
446 c.setPassword(parameters.getParameter("CLERKsetPassword"));
447 c.setPublisher(parameters.getParameter("CLERKsetPublisher"));
448
449 sc.getClerk().add(c);
450 try {
451 juddi.saveClerk(sc);
452 } catch (Exception ex) {
453 if (isExceptionExpiration(ex)) {
454 token = null;
455 sc.setAuthInfo(GetToken());
456 try {
457 juddi.saveClerk(sc);
458 } catch (Exception ex1) {
459 return "Error!" + HandleException(ex1);
460 }
461
462 } else {
463 return "Error!" + HandleException(ex);
464 }
465 }
466 return "Success";
467 }
468
469 private String save_Node(HttpServletRequest parameters) {
470 SaveNode sn = new SaveNode();
471 sn.setAuthInfo(GetToken());
472 Node node = new Node();
473 node.setClientName(parameters.getParameter("NODEsetClientName"));
474 node.setCustodyTransferUrl(parameters.getParameter("NODEsetCustodyTransferUrl"));
475 node.setDescription(parameters.getParameter("NODEsetDescription"));
476 node.setFactoryInitial(parameters.getParameter("NODEsetFactoryInitial"));
477 node.setFactoryNamingProvider(parameters.getParameter("NODEsetFactoryNamingProvider"));
478 node.setFactoryURLPkgs(parameters.getParameter("NODEsetFactoryURLPkgs"));
479 node.setInquiryUrl(parameters.getParameter("NODEsetInquiryUrl"));
480 node.setJuddiApiUrl(parameters.getParameter("NODEsetJuddiApiUrl"));
481 node.setName(parameters.getParameter("NODEsetName"));
482 node.setProxyTransport(parameters.getParameter("NODEsetProxyTransport"));
483 node.setPublishUrl(parameters.getParameter("NODEsetPublishUrl"));
484 node.setReplicationUrl(parameters.getParameter("NODEsetReplicationUrl"));
485 node.setSecurityUrl(parameters.getParameter("NODEsetSecurityUrl"));
486 node.setSubscriptionListenerUrl(parameters.getParameter("NODEsetSubscriptionListenerUrl"));
487 node.setSubscriptionUrl(parameters.getParameter("NODEsetSubscriptionUrl"));
488 sn.getNode().add(node);
489
490 try {
491 juddi.saveNode(sn);
492 } catch (Exception ex) {
493 if (isExceptionExpiration(ex)) {
494 token = null;
495 sn.setAuthInfo(GetToken());
496 try {
497 juddi.saveNode(sn);
498 } catch (Exception ex1) {
499 return "Error!" + HandleException(ex1);
500 }
501
502 } else {
503 return "Error!" + HandleException(ex);
504 }
505 }
506 return "Success";
507 }
508
509 private String sendTestEmail(HttpServletRequest parameters) {
510 try {
511
512 String to = parameters.getParameter("send_EmailTestEMAIL");
513 if (!to.startsWith("mailto:")) {
514 to = "mailto:" + to;
515 }
516 BindingTemplate modellbt = new BindingTemplate("test", null, "endpoint", to, null, null, null, null, null);
517 org.apache.juddi.subscription.notify.SMTPNotifier smtp = new SMTPNotifier(modellbt);
518 NotifySubscriptionListener body = new NotifySubscriptionListener();
519
520 body.setSubscriptionResultsList(new SubscriptionResultsList());
521 body.getSubscriptionResultsList().setSubscription(new Subscription());
522 body.getSubscriptionResultsList().getSubscription().setSubscriptionKey("TEST");
523 smtp.notifySubscriptionListener(body);
524 return "Success";
525 } catch (Exception ex) {
526 return "Failure!" + HandleException(ex);
527 }
528 }
529
530 private String getAllNodes(HttpServletRequest parameters) {
531 NodeList allNodes = null;
532 try {
533
534 allNodes = juddi.getAllNodes(GetToken());
535 } catch (Exception ex) {
536
537 if (isExceptionExpiration(ex)) {
538 token = null;
539 try {
540 allNodes = juddi.getAllNodes(GetToken());
541 } catch (Exception ex1) {
542 return HandleException(ex1);
543 }
544 } else {
545 return HandleException(ex);
546 }
547 }
548 try {
549 return PrettyPrintJaxbObject(allNodes);
550 } catch (Exception ex) {
551 return HandleException(ex);
552 }
553
554 }
555
556 private String getAllClerks(HttpServletRequest parameters) {
557 ClerkList allNodes = null;
558 try {
559
560 allNodes = juddi.getAllClerks(GetToken());
561 } catch (Exception ex) {
562
563 if (isExceptionExpiration(ex)) {
564 token = null;
565 try {
566 allNodes = juddi.getAllClerks(GetToken());
567 } catch (Exception ex1) {
568 return HandleException(ex1);
569 }
570 } else {
571 return HandleException(ex);
572 }
573 }
574 try {
575 return PrettyPrintJaxbObject(allNodes);
576 } catch (Exception ex) {
577 return HandleException(ex);
578 }
579 }
580
581 private String getAllClientSubscriptionInfo(HttpServletRequest parameters) {
582 List<SubscriptionWrapper> allClientSubscriptionInfo = null;
583 try {
584
585 allClientSubscriptionInfo = juddi.getAllClientSubscriptionInfo(GetToken());
586 } catch (Exception ex) {
587
588 if (isExceptionExpiration(ex)) {
589 token = null;
590 try {
591 allClientSubscriptionInfo = juddi.getAllClientSubscriptionInfo(GetToken());
592 } catch (Exception ex1) {
593 return HandleException(ex1);
594 }
595 } else {
596 return HandleException(ex);
597 }
598 }
599 try {
600 return PrettyPrintJaxbObject(allClientSubscriptionInfo);
601 } catch (Exception ex) {
602 return HandleException(ex);
603 }
604 }
605
606 private String getReplicationNodes(HttpServletRequest parameters) {
607 ReplicationConfiguration cfg = null;
608 try {
609
610 cfg = juddi.getReplicationNodes(GetToken());
611 } catch (Exception ex) {
612
613 if (isExceptionExpiration(ex)) {
614 token = null;
615 try {
616 cfg = juddi.getReplicationNodes(GetToken());
617 } catch (Exception ex1) {
618 return HandleException(ex1);
619 }
620 } else {
621 return HandleException(ex);
622 }
623 }
624 try {
625 return PrettyPrintJaxbObject(cfg);
626 } catch (Exception ex) {
627 return HandleException(ex);
628 }
629 }
630
631 private String deleteNode(HttpServletRequest parameters) {
632 DeleteNode cfg = new DeleteNode();
633 cfg.setAuthInfo(GetToken());
634 cfg.setNodeID(parameters.getParameter("delete_NodeName"));
635 try {
636
637 juddi.deleteNode(cfg);
638 } catch (Exception ex) {
639
640 if (isExceptionExpiration(ex)) {
641 token = null;
642 try {
643 cfg.setAuthInfo(GetToken());
644 juddi.deleteNode(cfg);
645 } catch (Exception ex1) {
646 return HandleException(ex1);
647 }
648 } else {
649 return HandleException(ex);
650 }
651 }
652
653 return "Success";
654 }
655
656 private String deleteSubscription(HttpServletRequest parameters) {
657 List<String> keys = new ArrayList<String>();
658 keys.add(parameters.getParameter("admin_DeleteSubscriptionKey"));
659 try {
660
661 juddi.adminDeleteSubscription(GetToken(), keys);
662 } catch (Exception ex) {
663
664 if (isExceptionExpiration(ex)) {
665 token = null;
666 try {
667 juddi.adminDeleteSubscription(GetToken(), keys);
668 } catch (Exception ex1) {
669 return HandleException(ex1);
670 }
671 } else {
672 return HandleException(ex);
673 }
674 }
675
676 return "Success";
677 }
678
679 private String deleteClerk(HttpServletRequest parameters) {
680 DeleteClerk cfg = new DeleteClerk();
681 cfg.setAuthInfo(GetToken());
682 cfg.setClerkID(parameters.getParameter("delete_ClerkName"));
683 try {
684
685 juddi.deleteClerk(cfg);
686 } catch (Exception ex) {
687
688 if (isExceptionExpiration(ex)) {
689 token = null;
690 try {
691 cfg.setAuthInfo(GetToken());
692 juddi.deleteClerk(cfg);
693 } catch (Exception ex1) {
694 return HandleException(ex1);
695 }
696 } else {
697 return HandleException(ex);
698 }
699 }
700
701 return "Success";
702 }
703
704 private String setReplicationConfig(HttpServletRequest parameters) {
705 ReplicationConfiguration cfg = (ReplicationConfiguration) JUDDIRequestsAsXML.getObjectJuddi("set_ReplicationNodes", parameters.getParameter("set_ReplicationNodesXML"));
706 DispositionReport setReplicationNodes = null;
707 try {
708
709 setReplicationNodes = juddi.setReplicationNodes(GetToken(), cfg);
710 } catch (Exception ex) {
711
712 if (isExceptionExpiration(ex)) {
713 token = null;
714 try {
715 setReplicationNodes = juddi.setReplicationNodes(GetToken(), cfg);
716 } catch (Exception ex1) {
717 return HandleException(ex1);
718 }
719 } else {
720 return HandleException(ex);
721 }
722 }
723 try {
724 return PrettyPrintJaxbObject(setReplicationNodes);
725 } catch (Exception ex) {
726 return HandleException(ex);
727 }
728 }
729
730 private String adminSaveBusiness(HttpServletRequest parameters) {
731
732 AdminSaveBusiness cfg = (AdminSaveBusiness) JUDDIRequestsAsXML.getObjectJuddi("admin_SaveBusiness", parameters.getParameter("admin_SaveBusinessXML"));
733 DispositionReport setReplicationNodes = null;
734 try {
735
736 setReplicationNodes = juddi.adminSaveBusiness(GetToken(), cfg.getValues());
737 } catch (Exception ex) {
738
739 if (isExceptionExpiration(ex)) {
740 token = null;
741 try {
742 setReplicationNodes = juddi.adminSaveBusiness(GetToken(), cfg.getValues());
743 } catch (Exception ex1) {
744 return HandleException(ex1);
745 }
746 } else {
747 return HandleException(ex);
748 }
749 }
750 try {
751 return PrettyPrintJaxbObject(setReplicationNodes);
752 } catch (Exception ex) {
753 return HandleException(ex);
754 }
755 }
756
757 private String adminSaveTmodel(HttpServletRequest parameters) {
758
759 AdminSaveTModel cfg = (AdminSaveTModel) JUDDIRequestsAsXML.getObjectJuddi("admin_SaveTModel", parameters.getParameter("admin_SaveTModelXML"));
760
761 DispositionReport setReplicationNodes = null;
762 try {
763
764 setReplicationNodes = juddi.adminSaveTModel(GetToken(), cfg.getValues());
765 } catch (Exception ex) {
766
767 if (isExceptionExpiration(ex)) {
768 token = null;
769 try {
770 setReplicationNodes = juddi.adminSaveTModel(GetToken(), cfg.getValues());
771 } catch (Exception ex1) {
772 return HandleException(ex1);
773 }
774 } else {
775 return HandleException(ex);
776 }
777 }
778 try {
779 return PrettyPrintJaxbObject(setReplicationNodes);
780 } catch (Exception ex) {
781 return HandleException(ex);
782 }
783 }
784
785 private String adminSaveSubscription(HttpServletRequest parameters) {
786
787 AdminSaveSubscriptionRequest cfg = (AdminSaveSubscriptionRequest) JUDDIRequestsAsXML.getObjectJuddi("admin_SaveSubscription", parameters.getParameter("admin_SaveSubscriptionXML"));
788
789 Holder<List<Subscription>> holder = new Holder<List<Subscription>>(cfg.getSubscriptions());
790 try {
791
792 juddi.adminSaveSubscription(GetToken(), cfg.getPublisherOrUsername(), holder);
793 } catch (Exception ex) {
794
795 if (isExceptionExpiration(ex)) {
796 token = null;
797 try {
798 juddi.adminSaveSubscription(GetToken(), cfg.getPublisherOrUsername(), holder);
799 } catch (Exception ex1) {
800 return HandleException(ex1);
801 }
802 } else {
803 return HandleException(ex);
804 }
805 }
806 AdminSaveSubscriptionResponse res = new AdminSaveSubscriptionResponse();
807 res.getSubscriptions().addAll(holder.value);
808 try {
809 return PrettyPrintJaxbObject(res);
810 } catch (Exception ex) {
811 return HandleException(ex);
812 }
813 }
814
815 private String getEntityHistory(HttpServletRequest parameters) {
816 GetEntityHistoryMessageRequest sn = new GetEntityHistoryMessageRequest();
817 sn.setAuthInfo(GetToken());
818 sn.setEntityKey(parameters.getParameter("get_EntityHistoryKey"));
819 GetEntityHistoryMessageResponse entityHistory = null;
820 try {
821 sn.setMaxRecords(Long.parseLong(parameters.getParameter("get_EntityHistoryMaxCount")));
822 sn.setOffset(Long.parseLong(parameters.getParameter("get_EntityHistoryOffset")));
823 entityHistory = juddi.getEntityHistory(sn);
824 } catch (Exception ex) {
825 if (isExceptionExpiration(ex)) {
826 token = null;
827 sn.setAuthInfo(GetToken());
828 try {
829 entityHistory = juddi.getEntityHistory(sn);
830 } catch (Exception ex1) {
831 return "Error!" + HandleException(ex1);
832 }
833
834 } else {
835 return "Error!" + HandleException(ex);
836 }
837 }
838 if (entityHistory == null) {
839 return "Something went wrong!";
840 }
841 try {
842 return PrettyPrintJaxbObject(entityHistory);
843 } catch (Exception ex) {
844 return HandleException(ex);
845 }
846
847 }
848
849 private String change_NodeID(HttpServletRequest parameters) {
850
851
852 EntityManager em = PersistenceManager.getEntityManager();
853 EntityTransaction tx = em.getTransaction();
854
855 try {
856
857 ReplicationConfiguration replicationNodes = new JUDDIApiImpl().getReplicationNodes(GetToken());
858 if (replicationNodes.getOperator().size() > 1) {
859 throw new Exception("Replication is configured with " + replicationNodes.getOperator() + " nodes. Node rename aborted");
860 }
861 Configuration configuration = AppConfig.getConfiguration();
862
863 String currentnode = configuration.getString(Property.JUDDI_NODE_ID);
864 String newnode = parameters.getParameter("change_NodeIDKey");
865 if (newnode == null) {
866 throw new Exception("The new node id was not specified");
867 }
868 newnode = newnode.trim();
869 newnode = newnode.toLowerCase();
870 log.warn("AUDIT - Renaming Node ID from " + currentnode + " to " + newnode);
871
872 UDDIPublicationImpl pub = new UDDIPublicationImpl();
873 UDDIInquiryImpl inquire = new UDDIInquiryImpl();
874
875 GetBusinessDetail gbd = new GetBusinessDetail();
876 gbd.setAuthInfo(GetToken());
877 gbd.getBusinessKey().add(newnode);
878 BusinessDetail businessDetail = null;
879 try {
880 businessDetail = inquire.getBusinessDetail(gbd);
881 } catch (Exception ex) {
882
883 }
884 if (businessDetail == null || businessDetail.getBusinessEntity().isEmpty()) {
885
886
887 gbd.getBusinessKey().clear();
888 gbd.getBusinessKey().add(AppConfig.getConfiguration().getString(Property.JUDDI_NODE_ROOT_BUSINESS));
889 businessDetail = inquire.getBusinessDetail(gbd);
890 BusinessEntity get = businessDetail.getBusinessEntity().get(0);
891 get.setBusinessKey(newnode);
892 get.getSignature().clear();
893 if (get.getBusinessServices() != null) {
894 for (BusinessService bs : get.getBusinessServices().getBusinessService()) {
895 bs.setBusinessKey(newnode);
896 bs.getSignature().clear();
897
898
899 }
900 }
901 SaveBusiness sb = new SaveBusiness();
902 sb.setAuthInfo(GetToken());
903 sb.getBusinessEntity().add(get);
904
905 BusinessDetail saveBusiness = pub.saveBusiness(sb);
906 newnode = saveBusiness.getBusinessEntity().get(0).getBusinessKey();
907 }
908
909 tx.begin();
910
911 Query createQuery = em.createQuery("Update UddiEntity ue set ue.nodeId=:node where ue.nodeId=:oldnode");
912 createQuery.setParameter("node", newnode);
913 createQuery.setParameter("oldnode", currentnode);
914 int records = createQuery.executeUpdate();
915
916 createQuery = em.createQuery("Update ChangeRecord ue set ue.nodeID=:node where ue.nodeID=:oldnode");
917 createQuery.setParameter("node", newnode);
918 createQuery.setParameter("oldnode", currentnode);
919 records += createQuery.executeUpdate();
920
921
922 tx.commit();
923 try {
924 DeleteBusiness db = new DeleteBusiness();
925 db.setAuthInfo(GetToken());
926 db.getBusinessKey().add(currentnode);
927 pub.deleteBusiness(db);
928 } catch (Exception ex) {
929 log.warn("Node id change error: ", ex);
930 }
931
932
933 AppConfig.setJuddiProperty(Property.JUDDI_NODE_ID, newnode);
934 AppConfig.setJuddiProperty(Property.JUDDI_NODE_ROOT_BUSINESS, newnode);
935
936 return "Sucess, Records update: " + records + " current node id is now " + AppConfig.getConfiguration().getString(Property.JUDDI_NODE_ID);
937 } catch (Exception ex) {
938 return HandleException(ex);
939 } finally {
940 if (tx.isActive()) {
941 tx.rollback();
942 }
943 em.close();
944 }
945 }
946
947 private String getChangeRecord(HttpServletRequest parameters) {
948 try {
949 GetChangeRecords req = new GetChangeRecords();
950
951 req.setRequestingNode(AppConfig.getConfiguration().getString(Property.JUDDI_NODE_ID));
952
953 req.setResponseLimitCount(BigInteger.ONE);
954 req.setChangesAlreadySeen(new HighWaterMarkVectorType());
955 req.getChangesAlreadySeen().getHighWaterMark().add(
956 new ChangeRecordIDType(parameters.getParameter("nodeid"),
957 Long.parseLong(parameters.getParameter("recordid"))));
958 ChangeRecords changeRecords = new UDDIReplicationImpl().getChangeRecords(req);
959 return PrettyPrintJaxbObject(changeRecords);
960
961 } catch (Exception ex) {
962 return HandleException(ex);
963 }
964 }
965
966
967
968
969
970
971
972
973 private String PrettyPrintJaxbObject(Object jaxb) throws Exception {
974 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
975 dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
976 DocumentBuilder db = dbf.newDocumentBuilder();
977 StringWriter sw = new StringWriter();
978 JAXB.marshal(jaxb, sw);
979 InputSource is = new InputSource(new StringReader(sw.toString()));
980
981 TransformerFactory transFactory = TransformerFactory.newInstance();
982 transFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
983 transFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
984 Transformer transformer = transFactory.newTransformer();
985 transformer.setOutputProperty(OutputKeys.INDENT, "yes");
986
987 StreamResult result = new StreamResult(new StringWriter());
988 Document document = db.parse(is);
989 DOMSource source = new DOMSource(document);
990 transformer.transform(source, result);
991 String xmlString = result.getWriter().toString();
992
993 return "<pre>" + StringEscapeUtils.escapeXml(xmlString) + "</pre>";
994 }
995
996 private String getFailedReplicationChangeRecords(HttpServletRequest parameters) {
997 try {
998
999 GetFailedReplicationChangeRecordsMessageRequest req = new GetFailedReplicationChangeRecordsMessageRequest();
1000 req.setAuthInfo(GetToken());
1001 req.setMaxRecords(Integer.parseInt(parameters.getParameter("getFailedReplicationChangeRecordsMaxCount")));
1002 req.setOffset(0);
1003 req.setOffset(Integer.parseInt(parameters.getParameter("getFailedReplicationChangeRecordsOffset")));
1004 GetFailedReplicationChangeRecordsMessageResponse failedReplicationChangeRecords = null;
1005 try {
1006 failedReplicationChangeRecords = juddi.getFailedReplicationChangeRecords(req);
1007 } catch (Exception ex) {
1008 if (isExceptionExpiration(ex)) {
1009 token = null;
1010 req.setAuthInfo(GetToken());
1011 try {
1012 failedReplicationChangeRecords = juddi.getFailedReplicationChangeRecords(req);
1013 } catch (Exception ex1) {
1014 return "Error!" + HandleException(ex1);
1015 }
1016
1017 } else {
1018 return "Error!" + HandleException(ex);
1019 }
1020 }
1021
1022 return PrettyPrintJaxbObject(failedReplicationChangeRecords);
1023 } catch (Exception ex) {
1024 return HandleException(ex);
1025 }
1026 }
1027
1028 public enum AuthStyle {
1029
1030
1031
1032
1033 HTTP,
1034
1035
1036
1037 UDDI_AUTH
1038 }
1039
1040 private String GetToken() {
1041 EnsureConfig();
1042 if (style != AuthStyle.UDDI_AUTH) {
1043 BindingProvider bp = null;
1044 if (WS_Transport) {
1045 Map<String, Object> context = null;
1046 bp = (BindingProvider) juddi;
1047 context = bp.getRequestContext();
1048 context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
1049 context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));
1050 }
1051 return null;
1052 } else {
1053 if (token != null) {
1054 return token;
1055 }
1056 GetAuthToken req = new GetAuthToken();
1057 if (session.getAttribute("username") != null
1058 && session.getAttribute("password") != null) {
1059 req.setUserID((String) session.getAttribute("username"));
1060 req.setCred(AES.Decrypt((String) session.getAttribute("password"), (String) properties.get("key")));
1061 try {
1062 AuthToken authToken = security.getAuthToken(req);
1063 token = authToken.getAuthInfo();
1064 } catch (Exception ex) {
1065 return HandleException(ex);
1066 }
1067 }
1068 }
1069 return token;
1070 }
1071
1072 private String delete_publisher(HttpServletRequest parameters) {
1073 DeletePublisher sb = new DeletePublisher();
1074 sb.setAuthInfo(GetToken());
1075 sb.getPublisherId().add(parameters.getParameter("delete_publisherKEY"));
1076 try {
1077 juddi.deletePublisher(sb);
1078 } catch (Exception ex) {
1079 if (isExceptionExpiration(ex)) {
1080 token = null;
1081 sb.setAuthInfo(GetToken());
1082 try {
1083 juddi.deletePublisher(sb);
1084 } catch (Exception e) {
1085 return HandleException(e);
1086 }
1087
1088 } else {
1089 return HandleException(ex);
1090 }
1091 }
1092 return "Success";
1093 }
1094
1095 private String getAllPublisherDetail(HttpServletRequest parameters) {
1096 StringBuilder ret = new StringBuilder();
1097 GetAllPublisherDetail sb = new GetAllPublisherDetail();
1098 sb.setAuthInfo(GetToken());
1099 PublisherDetail d = null;
1100 try {
1101 d = juddi.getAllPublisherDetail(sb);
1102 } catch (Exception ex) {
1103 if (isExceptionExpiration(ex)) {
1104 token = null;
1105 sb.setAuthInfo(GetToken());
1106 try {
1107 d = juddi.getAllPublisherDetail(sb);
1108 } catch (Exception ex1) {
1109 return HandleException(ex1);
1110 }
1111
1112 } else {
1113 return HandleException(ex);
1114 }
1115 }
1116 if (d != null) {
1117 ret.append("<table class=\"table table-hover\"><tr><th>Name</th><th>Info</th></tr>");
1118 for (int i = 0; i < d.getPublisher().size(); i++) {
1119 ret.append("<tr><td>").append(StringEscapeUtils.escapeHtml(d.getPublisher().get(i).getPublisherName()))
1120 .append("</td><td>");
1121 ret.append(PrintPublisherDetail(d.getPublisher().get(i)))
1122 .append("</td></tr>");
1123 }
1124 ret.append("</table>");
1125 } else {
1126 ret.append("No data returned");
1127 }
1128 return ret.toString();
1129 }
1130
1131 private String PrintPublisherDetail(Publisher p) {
1132 StringBuilder ret = new StringBuilder();
1133
1134 ret.append("Authorized Name = ").append(StringEscapeUtils.escapeHtml(p.getAuthorizedName()))
1135 .append("<br>")
1136 .append("Publisher Name = ").append(StringEscapeUtils.escapeHtml(p.getPublisherName()))
1137 .append("<br>")
1138 .append("Email = ")
1139 .append(StringEscapeUtils.escapeHtml(p.getEmailAddress()))
1140 .append("<br>")
1141 .append("Administrator = ")
1142 .append((p.isIsAdmin()))
1143 .append("<br>")
1144 .append("Enabled = ")
1145 .append((p.isIsEnabled()))
1146 .append("<br>")
1147 .append("Max Bindings per = ")
1148 .append(p.getMaxBindingsPerService())
1149 .append("<br>")
1150 .append("Max Businesses = ")
1151 .append(p.getMaxBusinesses())
1152 .append("<br>")
1153 .append("Max Services per = ")
1154 .append(p.getMaxServicePerBusiness())
1155 .append("<br>")
1156 .append("Max tModels = ")
1157 .append(p.getMaxTModels())
1158 .append("");
1159 return ret.toString();
1160 }
1161
1162 private String get_publisherDetail(HttpServletRequest parameters) {
1163 StringBuilder ret = new StringBuilder();
1164 GetPublisherDetail sb = new GetPublisherDetail();
1165 sb.getPublisherId().add(parameters.getParameter("get_publisherDetailKEY"));
1166 sb.setAuthInfo(GetToken());
1167 PublisherDetail d = null;
1168 try {
1169 d = juddi.getPublisherDetail(sb);
1170 } catch (Exception ex) {
1171 if (isExceptionExpiration(ex)) {
1172 token = null;
1173 sb.setAuthInfo(GetToken());
1174 try {
1175 d = juddi.getPublisherDetail(sb);
1176 } catch (Exception ex1) {
1177 return HandleException(ex1);
1178 }
1179
1180 } else {
1181 return HandleException(ex);
1182 }
1183 }
1184 if (d != null) {
1185 ret.append("<table class=\"table table-hover\"><tr><th>Name</th><th>Info</th></tr>");
1186 for (int i = 0; i < d.getPublisher().size(); i++) {
1187 ret.append("<tr><td>").append(StringEscapeUtils.escapeHtml(d.getPublisher().get(i).getPublisherName()))
1188 .append("</td><td>");
1189 ret.append(PrintPublisherDetail(d.getPublisher().get(i)))
1190 .append("</td></tr>");
1191 }
1192 ret.append("</table>");
1193 } else {
1194 ret.append("No data returned");
1195 }
1196 return ret.toString();
1197 }
1198
1199 private String invoke_SyncSubscription(HttpServletRequest parameters) {
1200 StringBuilder ret = new StringBuilder();
1201 SyncSubscription sb = new SyncSubscription();
1202
1203 SyncSubscriptionDetail d = null;
1204 try {
1205 StringReader sr = new StringReader(parameters.getParameter("invoke_SyncSubscriptionXML").trim());
1206 sb = (JAXB.unmarshal(sr, SyncSubscription.class));
1207 sb.setAuthInfo(GetToken());
1208 d = juddi.invokeSyncSubscription(sb);
1209 } catch (Exception ex) {
1210 if (isExceptionExpiration(ex)) {
1211 token = null;
1212 sb.setAuthInfo(GetToken());
1213 try {
1214 d = juddi.invokeSyncSubscription(sb);
1215 } catch (Exception ex1) {
1216 return HandleException(ex1);
1217 }
1218
1219 } else {
1220 return HandleException(ex);
1221 }
1222 }
1223 if (d != null) {
1224 try {
1225 ret.append(PrettyPrintJaxbObject(d));
1226 } catch (Exception ex) {
1227 return HandleException(ex);
1228 }
1229
1230 } else {
1231 ret.append("No data returned");
1232 }
1233 return ret.toString();
1234 }
1235
1236 private static String PrettyPrintXML(String input) {
1237 try {
1238 TransformerFactory transFactory = TransformerFactory.newInstance();
1239 transFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
1240 transFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
1241 Transformer transformer = transFactory.newTransformer();
1242 transformer.setOutputProperty(OutputKeys.INDENT, "yes");
1243
1244 StreamResult result = new StreamResult(new StringWriter());
1245 StreamSource source = new StreamSource(new StringReader(input));
1246 transformer.transform(source, result);
1247 String xmlString = result.getWriter().toString();
1248 return (xmlString);
1249 } catch (Exception ex) {
1250 }
1251 return null;
1252 }
1253
1254 public String getSampleSave_ClientSubscriptionInfo() {
1255 SaveClientSubscriptionInfo x = new SaveClientSubscriptionInfo();
1256 x.setAuthInfo("");
1257 x.getClientSubscriptionInfo().add(new ClientSubscriptionInfo());
1258 x.getClientSubscriptionInfo().get(0).setFromClerk(new Clerk());
1259 x.getClientSubscriptionInfo().get(0).setToClerk(new Clerk());
1260 x.getClientSubscriptionInfo().get(0).setSubscriptionKey("subscription key");
1261 x.getClientSubscriptionInfo().get(0).setLastModified(null);
1262 x.getClientSubscriptionInfo().get(0).setLastNotified(null);
1263 x.getClientSubscriptionInfo().get(0).getFromClerk().setName("ClerkName");
1264 x.getClientSubscriptionInfo().get(0).getFromClerk().setPublisher("username");
1265 x.getClientSubscriptionInfo().get(0).getFromClerk().setPassword("password");
1266 x.getClientSubscriptionInfo().get(0).getFromClerk().setNode(new Node());
1267 x.getClientSubscriptionInfo().get(0).getFromClerk().getNode().setClientName("clientname");
1268 x.getClientSubscriptionInfo().get(0).getFromClerk().getNode().setName("nodename");
1269 x.getClientSubscriptionInfo().get(0).getFromClerk().getNode().setDescription("description");
1270 x.getClientSubscriptionInfo().get(0).getFromClerk().getNode().setInquiryUrl("http://localhost:8080/juddiv3/services/inquiry");
1271 x.getClientSubscriptionInfo().get(0).getFromClerk().getNode().setPublishUrl("http://localhost:8080/juddiv3/services/publish");
1272 x.getClientSubscriptionInfo().get(0).getFromClerk().getNode().setCustodyTransferUrl("http://localhost:8080/juddiv3/services/custody-transfer");
1273 x.getClientSubscriptionInfo().get(0).getFromClerk().getNode().setSubscriptionUrl("http://localhost:8080/juddiv3/services/subscription");
1274 x.getClientSubscriptionInfo().get(0).getFromClerk().getNode().setSubscriptionListenerUrl("http://localhost:8080/juddiv3/services/subscription-listener");
1275 x.getClientSubscriptionInfo().get(0).getFromClerk().getNode().setJuddiApiUrl("http://localhost:8080/juddiv3/services/juddi-api");
1276 x.getClientSubscriptionInfo().get(0).getFromClerk().getNode().setReplicationUrl("http://localhost:8080/juddiv3/services/replication");
1277
1278 x.getClientSubscriptionInfo().get(0).getToClerk().setName("ClerkName");
1279 x.getClientSubscriptionInfo().get(0).getToClerk().setPublisher("username");
1280 x.getClientSubscriptionInfo().get(0).getToClerk().setPassword("password");
1281 x.getClientSubscriptionInfo().get(0).getToClerk().setNode(new Node());
1282 x.getClientSubscriptionInfo().get(0).getToClerk().getNode().setClientName("clientname");
1283 x.getClientSubscriptionInfo().get(0).getToClerk().getNode().setName("nodename");
1284 x.getClientSubscriptionInfo().get(0).getToClerk().getNode().setDescription("description");
1285 x.getClientSubscriptionInfo().get(0).getToClerk().getNode().setInquiryUrl("http://localhost:8080/juddiv3/services/inquiry");
1286 x.getClientSubscriptionInfo().get(0).getToClerk().getNode().setPublishUrl("http://localhost:8080/juddiv3/services/publish");
1287 x.getClientSubscriptionInfo().get(0).getToClerk().getNode().setCustodyTransferUrl("http://localhost:8080/juddiv3/services/custody-transfer");
1288 x.getClientSubscriptionInfo().get(0).getToClerk().getNode().setSubscriptionUrl("http://localhost:8080/juddiv3/services/subscription");
1289 x.getClientSubscriptionInfo().get(0).getToClerk().getNode().setSubscriptionListenerUrl("http://localhost:8080/juddiv3/services/subscription-listener");
1290 x.getClientSubscriptionInfo().get(0).getToClerk().getNode().setJuddiApiUrl("http://localhost:8080/juddiv3/services/juddi-api");
1291 x.getClientSubscriptionInfo().get(0).getToClerk().getNode().setReplicationUrl("http://localhost:8080/juddiv3/services/replication");
1292 StringWriter sw = new StringWriter();
1293 JAXB.marshal(x, sw);
1294 return sw.toString();
1295 }
1296
1297 private String save_ClientSubscriptionInfo(HttpServletRequest parameters) {
1298 StringBuilder ret = new StringBuilder();
1299 SaveClientSubscriptionInfo sb = new SaveClientSubscriptionInfo();
1300
1301 if (parameters.getParameter("ClientSubscriptionInfoDetailXML") == null) {
1302 return "No input!";
1303 }
1304 ClientSubscriptionInfoDetail d = null;
1305 try {
1306 StringReader sr = new StringReader(parameters.getParameter("ClientSubscriptionInfoDetailXML").trim());
1307 sb = (JAXB.unmarshal(sr, SaveClientSubscriptionInfo.class));
1308 sb.setAuthInfo(GetToken());
1309 d = juddi.saveClientSubscriptionInfo(sb);
1310 } catch (Exception ex) {
1311 if (ex instanceof DispositionReportFaultMessage) {
1312 DispositionReportFaultMessage f = (DispositionReportFaultMessage) ex;
1313 if (f.getFaultInfo().countainsErrorCode(DispositionReport.E_AUTH_TOKEN_EXPIRED)) {
1314 token = null;
1315 sb.setAuthInfo(GetToken());
1316 try {
1317 d = juddi.saveClientSubscriptionInfo(sb);
1318 } catch (Exception ex1) {
1319 return HandleException(ex1);
1320 }
1321 }
1322 } else {
1323 return HandleException(ex);
1324 }
1325 }
1326 if (d != null) {
1327 try {
1328 ret.append(PrettyPrintJaxbObject(d));
1329 } catch (Exception ex) {
1330 return HandleException(ex);
1331 }
1332
1333 } else {
1334 ret.append("No data returned");
1335 }
1336 return ret.toString();
1337 }
1338
1339
1340
1341
1342
1343
1344
1345
1346 public static boolean isExceptionExpiration(Exception ex) {
1347 if (ex == null) {
1348 return false;
1349 }
1350 if (ex instanceof DispositionReportFaultMessage) {
1351 DispositionReportFaultMessage f = (DispositionReportFaultMessage) ex;
1352 if (f.getFaultInfo().countainsErrorCode(DispositionReport.E_AUTH_TOKEN_EXPIRED) || ex.getMessage().contains(DispositionReport.E_AUTH_TOKEN_EXPIRED) || ex.getMessage().toLowerCase().contains("expired")) {
1353 return true;
1354 }
1355 }
1356
1357 if (ex.getMessage() == null) {
1358 return false;
1359 }
1360 if (ex.getMessage().toLowerCase().contains("expire")) {
1361 return true;
1362 }
1363
1364 if (ex.getMessage().toLowerCase().contains(DispositionReport.E_AUTH_TOKEN_EXPIRED.toLowerCase())) {
1365 return true;
1366 }
1367 if (ex.getLocalizedMessage() == null) {
1368 return false;
1369 }
1370 if (ex.getLocalizedMessage().toLowerCase().contains("expire")) {
1371 return true;
1372 }
1373 return false;
1374 }
1375
1376 private String save_publisher(HttpServletRequest parameters) {
1377
1378 SavePublisher sb = new SavePublisher();
1379 Publisher p = new Publisher();
1380 p.setAuthorizedName(parameters.getParameter("savePublisherAuthorizedName"));
1381 p.setPublisherName(parameters.getParameter("savePublisherNAME"));
1382 p.setEmailAddress(parameters.getParameter("savePublisherEMAIL"));
1383 try {
1384 p.setIsAdmin(Boolean.parseBoolean(parameters.getParameter("savePublisherIsAdmin")));
1385 } catch (Exception ex) {
1386 }
1387 try {
1388 p.setIsEnabled(Boolean.parseBoolean(parameters.getParameter("savePublisherIsEnabled")));
1389 } catch (Exception ex) {
1390 }
1391
1392 PublisherDetail d = null;
1393 sb.setAuthInfo(GetToken());
1394 try {
1395 if (parameters.getParameter("savePublisherMaxBindings") != null) {
1396 p.setMaxBindingsPerService(Integer.parseInt(parameters.getParameter("savePublisherMaxBindings")));
1397 }
1398 } catch (Exception ex) {
1399 }
1400 try {
1401 if (parameters.getParameter("savePublisherMaxServices") != null) {
1402 p.setMaxServicePerBusiness(Integer.parseInt(parameters.getParameter("savePublisherMaxServices")));
1403 }
1404 } catch (Exception ex) {
1405 }
1406 try {
1407 if (parameters.getParameter("savePublisherMaxBusiness") != null) {
1408 p.setMaxBusinesses(Integer.parseInt(parameters.getParameter("savePublisherMaxBusiness")));
1409 }
1410 } catch (Exception ex) {
1411 }
1412 try {
1413 if (parameters.getParameter("savePublisherMaxTModels") != null) {
1414 p.setMaxTModels(Integer.parseInt(parameters.getParameter("savePublisherMaxTModels")));
1415 }
1416 } catch (Exception ex) {
1417 }
1418 sb.getPublisher().add(p);
1419 try {
1420
1421 d = juddi.savePublisher(sb);
1422 } catch (Exception ex) {
1423
1424 if (isExceptionExpiration(ex)) {
1425 token = null;
1426 sb.setAuthInfo(GetToken());
1427 try {
1428 d = juddi.savePublisher(sb);
1429 } catch (Exception ex1) {
1430 return HandleException(ex1);
1431 }
1432 } else {
1433 return HandleException(ex);
1434 }
1435 }
1436 return "Success";
1437 }
1438
1439 private String adminDelete_tmodel(HttpServletRequest parameters) {
1440 DeleteTModel sb = new DeleteTModel();
1441 sb.getTModelKey().add(parameters.getParameter("adminDelete_tmodelKEY"));
1442 sb.setAuthInfo(GetToken());
1443 try {
1444 juddi.adminDeleteTModel(sb);
1445 } catch (Exception ex) {
1446 if (isExceptionExpiration(ex)) {
1447 token = null;
1448 sb.setAuthInfo(GetToken());
1449 try {
1450 juddi.adminDeleteTModel(sb);
1451 } catch (Exception ex1) {
1452 return HandleException(ex1);
1453 }
1454 } else {
1455 return HandleException(ex);
1456 }
1457 }
1458 return "Success";
1459 }
1460
1461 private String delete_ClientSubscriptionInfo(HttpServletRequest parameters) {
1462 DeleteClientSubscriptionInfo sb = new DeleteClientSubscriptionInfo();
1463 sb.getSubscriptionKey().add(parameters.getParameter("delete_ClientSubscriptionInfoKEY"));
1464 sb.setAuthInfo(GetToken());
1465 try {
1466 juddi.deleteClientSubscriptionInfo(sb);
1467 } catch (Exception ex) {
1468 if (isExceptionExpiration(ex)) {
1469 token = null;
1470 sb.setAuthInfo(GetToken());
1471 try {
1472 juddi.deleteClientSubscriptionInfo(sb);
1473 } catch (Exception ex1) {
1474 return HandleException(ex1);
1475 }
1476
1477 } else {
1478 return HandleException(ex);
1479 }
1480 }
1481 return "Success";
1482 }
1483
1484
1485
1486
1487
1488
1489
1490
1491 public boolean isAdminLocalhostOnly() {
1492 return clientConfig.getConfiguration().getBoolean(PROP_ADMIN_LOCALHOST_ONLY, true);
1493 }
1494
1495 public String verifyLogin() {
1496 EnsureConfig();
1497 if (style != AuthStyle.UDDI_AUTH) {
1498 if (WS_Transport) {
1499 BindingProvider bp = null;
1500 Map<String, Object> context = null;
1501
1502 bp = (BindingProvider) juddi;
1503 context = bp.getRequestContext();
1504 context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
1505 context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));
1506 }
1507 FindBusiness fb = new FindBusiness();
1508 fb.setListHead(0);
1509 fb.setMaxRows(1);
1510 fb.setFindQualifiers(new FindQualifiers());
1511 fb.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
1512 fb.getName().add(new Name(UDDIConstants.WILDCARD, null));
1513 try {
1514 GetPublisherDetail publisherDetail = new GetPublisherDetail();
1515 publisherDetail.getPublisherId().add((String) session.getAttribute("username"));
1516 juddi.getPublisherDetail(publisherDetail);
1517
1518 } catch (Exception ex) {
1519 return HandleException(ex);
1520 }
1521
1522
1523
1524
1525
1526 return null;
1527 } else {
1528 if (token != null) {
1529 return token;
1530 }
1531 if (WS_Transport) {
1532 BindingProvider bp = null;
1533 Map<String, Object> context = null;
1534
1535 bp = (BindingProvider) juddi;
1536 context = bp.getRequestContext();
1537 context.remove(BindingProvider.USERNAME_PROPERTY);
1538 context.remove(BindingProvider.PASSWORD_PROPERTY);
1539 }
1540 GetAuthToken req = new GetAuthToken();
1541 try {
1542 if (security == null) {
1543 security = transport.getUDDISecurityService();
1544 }
1545 } catch (Exception ex) {
1546 return HandleException(ex);
1547 }
1548 if (session.getAttribute("username") != null
1549 && session.getAttribute("password") != null) {
1550 req.setUserID((String) session.getAttribute("username"));
1551 req.setCred(AES.Decrypt((String) session.getAttribute("password"), (String) properties.get("key")));
1552 log.info("AUDIT: fetching auth token for " + req.getUserID() + " Auth Mode is " + ((security == null) ? "HTTP" : "AUTH_TOKEN"));
1553 try {
1554 AuthToken authToken = security.getAuthToken(req);
1555 token = authToken.getAuthInfo();
1556 return null;
1557 } catch (Exception ex) {
1558 return HandleException(ex);
1559 }
1560 }
1561 }
1562 return "Unexpected error";
1563 }
1564
1565 public String SendAdvanced(Object request, String method) {
1566 StringWriter sw = new StringWriter();
1567 Object result=null;
1568 try {
1569 if (method.equalsIgnoreCase("save_ClientSubscriptionInfo")) {
1570 SaveClientSubscriptionInfo x = (SaveClientSubscriptionInfo) request;
1571 x.setAuthInfo(GetToken());
1572 ClientSubscriptionInfoDetail saveClientSubscriptionInfo = null;
1573 try {
1574 result = juddi.saveClientSubscriptionInfo(x);
1575 sw.append("Success:<br>");
1576
1577 } catch (Exception ex) {
1578 if (isExceptionExpiration(ex)) {
1579 token = null;
1580 x.setAuthInfo(GetToken());
1581 result = juddi.saveClientSubscriptionInfo(x);
1582 sw.append("Success:<br>");
1583
1584
1585 } else {
1586 throw ex;
1587 }
1588 }
1589
1590 }
1591 if (method.equalsIgnoreCase("invoke_SyncSubscription")) {
1592 SyncSubscription x = (SyncSubscription) request;
1593 x.setAuthInfo(GetToken());
1594 SyncSubscriptionDetail invokeSyncSubscription = null;
1595 try {
1596 result = juddi.invokeSyncSubscription(x);
1597 sw.append("Success:<br>");
1598
1599 } catch (Exception ex) {
1600 if (isExceptionExpiration(ex)) {
1601 token = null;
1602 x.setAuthInfo(GetToken());
1603 result = juddi.invokeSyncSubscription(x);
1604 sw.append("Success:<br>");
1605
1606
1607 } else {
1608 throw ex;
1609 }
1610 }
1611
1612 }
1613 if (method.equalsIgnoreCase("admin_SaveBusiness")) {
1614 AdminSaveBusiness x = (AdminSaveBusiness) request;
1615
1616 DispositionReport adminSaveBusiness = null;
1617
1618 try {
1619 result = juddi.adminSaveBusiness(GetToken(), x.getValues());
1620 sw.append("Success:<br>");
1621
1622
1623 } catch (Exception ex) {
1624 if (isExceptionExpiration(ex)) {
1625 token = null;
1626 x.setAuthInfo(GetToken());
1627 result = juddi.adminSaveBusiness(GetToken(), x.getValues());
1628 sw.append("Success:<br>");
1629
1630
1631 } else {
1632 throw ex;
1633 }
1634 }
1635 }
1636 if (method.equalsIgnoreCase("admin_SaveTModel")) {
1637 AdminSaveTModel x = (AdminSaveTModel) request;
1638
1639 DispositionReport adminSaveTModel = null;
1640 try {
1641 result = juddi.adminSaveTModel(GetToken(), x.getValues());
1642 sw.append("Success:<br>");
1643
1644
1645 } catch (Exception ex) {
1646 if (isExceptionExpiration(ex)) {
1647 token = null;
1648 x.setAuthInfo(GetToken());
1649 result = juddi.adminSaveTModel(GetToken(), x.getValues());
1650 sw.append("Success:<br>");
1651
1652
1653 } else {
1654 throw ex;
1655 }
1656 }
1657
1658 }
1659
1660 if (method.equalsIgnoreCase("admin_SaveSubscription")) {
1661 AdminSaveSubscriptionRequest x = (AdminSaveSubscriptionRequest) request;
1662 Holder<List<Subscription>> holder = new Holder<List<Subscription>>(x.getSubscriptions());
1663 try {
1664 juddi.adminSaveSubscription(GetToken(), x.getPublisherOrUsername(), holder);
1665 sw.append("Success:<br>");
1666 result=holder;
1667 } catch (Exception ex) {
1668 if (isExceptionExpiration(ex)) {
1669 token = null;
1670
1671 juddi.adminSaveSubscription(GetToken(), x.getPublisherOrUsername(), holder);
1672 sw.append("Success:<br>");
1673 result=holder;
1674
1675 } else {
1676 throw ex;
1677 }
1678 }
1679 }
1680 if (method.equalsIgnoreCase("set_ReplicationNodes")) {
1681 ReplicationConfiguration x = (ReplicationConfiguration) request;
1682
1683 try {
1684 result = juddi.setReplicationNodes(GetToken(), x);
1685 sw.append("Success:<br>");
1686
1687 } catch (Exception ex) {
1688 if (isExceptionExpiration(ex)) {
1689 token = null;
1690
1691 result = juddi.setReplicationNodes(GetToken(), x);
1692 sw.append("Success:<br>");
1693
1694
1695 } else {
1696 throw ex;
1697 }
1698 }
1699 }
1700
1701 } catch (Exception ex) {
1702 return HandleException(ex);
1703 }
1704 if (result!=null){
1705 try {
1706 return sw.toString() + "<br>" + PrettyPrintJaxbObject(result);
1707 } catch (Exception ex) {
1708 return HandleException(ex);
1709 }
1710 }
1711 return "Error! no work was done?";
1712
1713 }
1714
1715 }