This project has retired. For details please refer to its Attic page.
UddiHub xref
View Javadoc
1   /*
2    * Copyright 2001-2013 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  package org.apache.juddi.webconsole.hub;
18  
19  import java.io.ByteArrayInputStream;
20  import java.io.InputStream;
21  import java.io.Serializable;
22  import java.io.StringReader;
23  import java.io.StringWriter;
24  import java.net.URL;
25  import java.net.URLEncoder;
26  import java.rmi.RemoteException;
27  import java.security.cert.CertificateFactory;
28  import java.security.cert.X509Certificate;
29  import java.util.ArrayList;
30  import java.util.Arrays;
31  import java.util.GregorianCalendar;
32  import java.util.Iterator;
33  import java.util.List;
34  import java.util.Map;
35  import java.util.Properties;
36  import java.util.concurrent.atomic.AtomicReference;
37  import java.util.logging.Level;
38  import java.util.logging.Logger;
39  import javax.servlet.ServletContext;
40  import javax.servlet.http.HttpServletRequest;
41  import javax.servlet.http.HttpSession;
42  import javax.xml.bind.JAXB;
43  import javax.xml.bind.JAXBElement;
44  import javax.xml.datatype.DatatypeConfigurationException;
45  import javax.xml.datatype.DatatypeFactory;
46  import javax.xml.datatype.XMLGregorianCalendar;
47  import javax.xml.ws.BindingProvider;
48  import javax.xml.ws.Holder;
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.Node;
54  import org.apache.juddi.v3.client.ClassUtil;
55  import org.apache.juddi.v3.client.UDDIConstants;
56  import org.apache.juddi.v3.client.config.ClientConfig;
57  import org.apache.juddi.v3.client.config.UDDIClient;
58  import org.apache.juddi.v3.client.config.UDDINode;
59  import org.apache.juddi.v3.client.cryptor.XmlUtils;
60  import org.apache.juddi.v3.client.transport.Transport;
61  import org.apache.juddi.webconsole.AES;
62  import org.apache.juddi.webconsole.PostBackConstants;
63  import org.apache.juddi.webconsole.hub.builders.Builders;
64  import org.apache.juddi.webconsole.hub.builders.Printers;
65  import org.apache.juddi.webconsole.resources.ResourceLoader;
66  import org.uddi.api_v3.*;
67  import org.uddi.custody_v3.DiscardTransferToken;
68  import org.uddi.custody_v3.GetTransferToken;
69  import org.uddi.custody_v3.TransferEntities;
70  import org.uddi.custody_v3.TransferToken;
71  import org.uddi.sub_v3.*;
72  import org.uddi.v3_service.DispositionReportFaultMessage;
73  import org.uddi.v3_service.UDDICustodyTransferPortType;
74  import org.uddi.v3_service.UDDIInquiryPortType;
75  import org.uddi.v3_service.UDDIPublicationPortType;
76  import org.uddi.v3_service.UDDISecurityPortType;
77  import org.uddi.v3_service.UDDISubscriptionPortType;
78  import org.w3._2000._09.xmldsig_.SignatureType;
79  import org.w3._2000._09.xmldsig_.X509DataType;
80  
81  /**
82   * UddiHub - The hub acts as a single point for managing browser to uddi
83   * services. At most 1 instance is allowed per http session. In general, all
84   * methods in the class trigger web service call outs. All callouts also support
85   * expired UDDI tokens and will attempt to reauthenticate and retry the request.
86   *
87   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
88   */
89  public class UddiHub implements Serializable {
90  
91          /**
92           * The logger name
93           */
94          public static final String LOGGER_NAME = "org.apache.juddi";
95          private static final long serialVersionUID = 1L;
96          AuthStyle style = null;
97          private String nodename = null;
98          private static final String DEFAULT_NODE_NAME = "default";
99          private final String clientName = "juddigui";
100         private boolean WS_Transport = false;
101         private boolean WS_securePorts = false;
102         private transient HttpSession session;
103         private transient Transport transport = null;
104         private transient ClientConfig clientConfig;
105         private transient Properties properties;
106         private transient UDDISubscriptionPortType subscription = null;
107         private transient UDDISecurityPortType security = null;
108         private transient UDDIInquiryPortType inquiry = null;
109         private transient UDDIPublicationPortType publish = null;
110         private transient UDDICustodyTransferPortType custody = null;
111         //private JUDDIApiPortType juddi = null;
112         private transient String token = null;
113         /**
114          * The Log4j logger. This is also referenced from the Builders class,
115          * thus it is public
116          */
117         public transient static final Log log = LogFactory.getLog(LOGGER_NAME);
118         private transient DatatypeFactory df;
119         /**
120          * the name of the 'node' property in the config
121          */
122         public static final String PROP_CONFIG_NODE = "config.props.node";
123         /**
124          * "config.props.authtype"
125          */
126         public static final String PROP_AUTH_TYPE = "config.props.authtype";
127         /**
128          * "config.props.automaticLogouts.enable"
129          */
130         public static final String PROP_AUTO_LOGOUT = "config.props.automaticLogouts.enable";
131         /**
132          * "config.props.automaticLogouts.duration"
133          */
134         public static final String PROP_AUTO_LOGOUT_TIMER = "config.props.automaticLogouts.duration";
135         /**
136          * "config.props."
137          */
138         public static final String PROP_PREFIX = "config.props.";
139         /**
140          * "config.props.configLocalHostOnly"
141          *
142          */
143         public static final String PROP_ADMIN_LOCALHOST_ONLY = "config.props.configLocalHostOnly";
144 
145         private UddiHub() throws DatatypeConfigurationException {
146                 df = DatatypeFactory.newInstance();
147         }
148 
149         /**
150          * removes the Hub from the current http session
151          *
152          * @param _session
153          */
154         public static void reset(HttpSession _session) {
155                 _session.removeAttribute("hub");
156                 // token = null;
157         }
158 
159         public String verifyLogin() {
160                 EnsureConfig();
161                 token = null;
162                 if (style != AuthStyle.UDDI_AUTH) {
163                         if (WS_Transport) {
164                                 BindingProvider bp = null;
165                                 Map<String, Object> context = null;
166                                 bp = (BindingProvider) inquiry;
167                                 context = bp.getRequestContext();
168                                 context.remove(BindingProvider.USERNAME_PROPERTY);
169                                 context.remove(BindingProvider.PASSWORD_PROPERTY);
170 
171                                 context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
172                                 context.put(BindingProvider.PASSWORD_PROPERTY, session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));
173 
174                                 bp = (BindingProvider) publish;
175                                 context = bp.getRequestContext();
176                                 context.remove(BindingProvider.USERNAME_PROPERTY);
177                                 context.remove(BindingProvider.PASSWORD_PROPERTY);
178 
179                                 context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
180                                 context.put(BindingProvider.PASSWORD_PROPERTY, session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));
181 
182                                 bp = (BindingProvider) custody;
183                                 context = bp.getRequestContext();
184                                 context.remove(BindingProvider.USERNAME_PROPERTY);
185                                 context.remove(BindingProvider.PASSWORD_PROPERTY);
186 
187                                 context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
188                                 context.put(BindingProvider.PASSWORD_PROPERTY, session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));
189 
190                                 bp = (BindingProvider) subscription;
191                                 context = bp.getRequestContext();
192                                 context.remove(BindingProvider.USERNAME_PROPERTY);
193                                 context.remove(BindingProvider.PASSWORD_PROPERTY);
194 
195                                 context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
196                                 context.put(BindingProvider.PASSWORD_PROPERTY, session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));
197                         }
198                         FindBusiness fb = new FindBusiness();
199                         fb.setListHead(0);
200                         fb.setMaxRows(1);
201                         fb.setFindQualifiers(new FindQualifiers());
202                         fb.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
203                         fb.getName().add(new Name(UDDIConstants.WILDCARD, null));
204                         try {
205                                 inquiry.findBusiness(fb);
206                         } catch (Exception ex) {
207                                 return HandleException(ex);
208                         }
209                         /*
210                          bp = (BindingProvider) juddi;
211                          context = bp.getRequestContext();
212                          context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
213                          context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));*/
214                         return null;
215                 } else {
216 
217                         if (WS_Transport) {
218                                 BindingProvider bp = null;
219                                 Map<String, Object> context = null;
220 
221                                 bp = (BindingProvider) inquiry;
222                                 context = bp.getRequestContext();
223                                 context.remove(BindingProvider.USERNAME_PROPERTY);
224                                 context.remove(BindingProvider.PASSWORD_PROPERTY);
225 
226                                 bp = (BindingProvider) publish;
227                                 context = bp.getRequestContext();
228                                 context.remove(BindingProvider.USERNAME_PROPERTY);
229                                 context.remove(BindingProvider.PASSWORD_PROPERTY);
230 
231                                 bp = (BindingProvider) custody;
232                                 context = bp.getRequestContext();
233                                 context.remove(BindingProvider.USERNAME_PROPERTY);
234                                 context.remove(BindingProvider.PASSWORD_PROPERTY);
235 
236                                 bp = (BindingProvider) subscription;
237                                 context = bp.getRequestContext();
238                                 context.remove(BindingProvider.USERNAME_PROPERTY);
239                                 context.remove(BindingProvider.PASSWORD_PROPERTY);
240                         }
241                         GetAuthToken req = new GetAuthToken();
242                         try {
243                                 if (security == null) {
244                                         security = transport.getUDDISecurityService();
245                                 }
246                         } catch (Exception ex) {
247                                 return HandleException(ex);
248                         }
249                         if (session.getAttribute("username") != null
250                              && session.getAttribute("password") != null) {
251                                 req.setUserID((String) session.getAttribute("username"));
252                                 req.setCred(AES.Decrypt((String) session.getAttribute("password"), (String) properties.get("key")));
253                                 log.info("AUDIT: fetching auth token for " + req.getUserID() + " Auth Mode is " + ((security == null) ? "HTTP" : "AUTH_TOKEN"));
254                                 try {
255                                         AuthToken authToken = security.getAuthToken(req);
256                                         token = authToken.getAuthInfo();
257                                         return null;
258                                 } catch (Exception ex) {
259                                         return HandleException(ex);
260                                 }
261                         }
262                 }
263                 return "Unexpected error";
264         }
265 
266         /**
267          * This kills any authentication tokens, logs the user out and nulls out
268          * all services
269          */
270         public void die() {
271                 DiscardAuthToken da = new DiscardAuthToken();
272                 da.setAuthInfo(token);
273                 try {
274                         if (token != null && security != null) {
275                                 security.discardAuthToken(da);
276                         }
277                 } catch (Exception ex) {
278                         HandleException(ex);
279                 }
280 
281                 token = null;
282                 inquiry = null;
283                 publish = null;
284                 custody = null;
285                 security = null;
286                 //juddi = null;
287                 subscription = null;
288                 if (session != null) {
289                         session.removeAttribute("username");
290                         session.removeAttribute("password");
291                 }
292         }
293 
294         /**
295          * This is the singleton accessor UddiHub. There should be at most 1
296          * instance per HTTP Session (user login)
297          *
298          * @param application
299          * @param _session
300          * @return instance
301          * @throws Exception
302          */
303         public static UddiHub getInstance(ServletContext application, HttpSession _session) throws Exception {
304                 Object j = _session.getAttribute("hub");
305                 if (j == null) {
306                         UddiHub hub = new UddiHub(application, _session);
307                         _session.setAttribute("hub", hub);
308                         hub.locale = (String) _session.getAttribute("locale");
309                         return hub;
310                 }
311                 UddiHub hub = (UddiHub) j;
312                 hub.locale = (String) _session.getAttribute("locale");
313                 return hub;
314         }
315         String locale = "en";
316 
317         /**
318          * gets the user selected locale
319          *
320          * @return something like "en" or "es"
321          */
322         public String getLocale() {
323                 if (session != null) {
324                         if (session.getAttribute("locale") != null) {
325                                 locale = (String) session.getAttribute("locale");
326                         }
327                 }
328                 if (locale == null) {
329                         locale = "en";
330                 }
331                 return locale;
332         }
333 
334         private void EnsureConfig() {
335                 if (clientConfig == null) {
336                         String clazz = null;
337                         try {
338                                 UDDIClient client = new UDDIClient();
339                                 clientConfig = client.getClientConfig();
340                                 try {
341                                         style = AuthStyle.valueOf(clientConfig.getConfiguration().getString(PROP_AUTH_TYPE));
342                                 } catch (Exception ex) {
343                                         log.warn("'UDDI_AUTH' is not defined in the config (" + PROP_AUTH_TYPE + ")! defaulting to UDDI_AUTH");
344                                         style = AuthStyle.UDDI_AUTH;
345                                 }
346 //                                String newNodename = clientConfig.getConfiguration().getString(PROP_CONFIG_NODE);
347 //                                if (newNodename != null && !newNodename.equals("")) {
348 //                                        nodename = newNodename;
349 //                                }
350                                 if (nodename == null) {
351                                         nodename = clientConfig.getConfiguration().getString(PROP_CONFIG_NODE);
352                                 }
353                                 if (nodename == null || nodename.equals("")) {
354                                         log.warn("'node' is not defined in the config! defaulting to '" + DEFAULT_NODE_NAME + "'");
355                                         nodename = DEFAULT_NODE_NAME;
356                                 }
357                                 UDDINode uddiNode = clientConfig.getUDDINode(nodename);
358 
359                                 clazz = uddiNode.getProxyTransport();
360                                 if (clazz.contains("JAXWS")) {
361                                         WS_Transport = true;
362                                 }
363 
364                                 transport = client.getTransport(nodename);
365 
366                                 security = transport.getUDDISecurityService();
367                                 inquiry = transport.getUDDIInquiryService();
368                                 subscription = transport.getUDDISubscriptionService();
369                                 publish = transport.getUDDIPublishService();
370                                 custody = transport.getUDDICustodyTransferService();
371 
372                                 if (WS_Transport) {
373                                         if (uddiNode.getPublishUrl().toLowerCase().startsWith("https://")
374                                              && (uddiNode.getSecurityUrl() != null && uddiNode.getSecurityUrl().toLowerCase().startsWith("https://"))
375                                              && uddiNode.getInquiryUrl().toLowerCase().startsWith("https://")
376                                              && (uddiNode.getCustodyTransferUrl() != null && uddiNode.getCustodyTransferUrl().toLowerCase().startsWith("https://"))
377                                              && (uddiNode.getSubscriptionUrl() != null && uddiNode.getSubscriptionUrl().toLowerCase().startsWith("https://"))) {
378                                                 WS_securePorts = true;
379                                         } else {
380                                                 WS_securePorts = false;
381                                         }
382                                 }
383                         } catch (Exception ex) {
384                                 HandleException(ex);
385                                 log.info("DEBUG info node=" + nodename + " transport=" + clazz);
386                         }
387                 }
388 
389         }
390 
391         private UddiHub(ServletContext application, HttpSession _session) throws Exception {
392                 session = _session;
393 
394                 URL prop = application.getResource("/META-INF/config.properties");
395                 if (prop == null) {
396                         prop = application.getResource("META-INF/config.properties");
397                 }
398                 if (prop == null) {
399                         throw new Exception("Cannot locate the configuration file.");
400                 }
401 
402                 InputStream in = prop.openStream();
403                 Properties p = new Properties();
404                 p.load(in);
405                 in.close();
406                 properties = p;
407 
408                 EnsureConfig();
409         }
410 
411         /**
412          * returns true if we are using JAXWS transport AND all of the URLs
413          * start with https://
414          *
415          * @return true if all coms are SSL based
416          */
417         public boolean isSecure() {
418                 EnsureConfig();
419                 return WS_securePorts;
420         }
421 
422         /**
423          * gets a reference to the current juddi client config file. this is a
424          * live instance changes can be stored to disk
425          *
426          * @return client config
427          * @throws ConfigurationException g
428          */
429         public ClientConfig GetJuddiClientConfig() throws ConfigurationException {
430                 EnsureConfig();
431                 return clientConfig;
432         }
433 
434         /**
435          * gets the configuration file's node name element of the currently
436          * connected node
437          *
438          * @return
439          */
440         public String getNodeName() {
441                 EnsureConfig();
442                 return nodename;
443         }
444 
445         private boolean NodeExists(String newnode) {
446                 try {
447                         List<Node> uddiNodeList = GetJuddiClientConfig().getUDDINodeList();
448                         for (int i = 0; i < uddiNodeList.size(); i++) {
449                                 if (uddiNodeList.get(i).getName().equals(newnode)) {
450                                         return true;
451                                 }
452                         }
453                 } catch (Exception ex) {
454                         log.error(ex);
455                         return false;
456                 }
457                 return false;
458         }
459 
460         /**
461          * attempts to switch the current context to the proposed node id. if
462          * the node does not exist in the config file, null is returned and no
463          * changes are made. if the node does exist in the config file, the
464          * current login token is discard, all web service client objects are
465          * destroyed, user credentials are removed from the session. The client
466          * objects are then recreated from the config using the new node name
467          * and transport
468          *
469          * @param newnode
470          * @return the new node name if successful, or null on failure
471          */
472         public String switchNodes(String newnode) {
473                 EnsureConfig();
474                 if (this.nodename.equalsIgnoreCase(newnode)) {
475                         return newnode;
476                 }
477                 if (NodeExists(newnode)) {
478                         this.die();
479                         clientConfig = null;
480                         this.nodename = newnode;
481                 } else {
482                         return null;
483                 }
484                 EnsureConfig();
485                 return this.nodename;
486         }
487 
488         /**
489          * returns all of the current properties defining digital signatures
490          *
491          * @return digsig properties
492          */
493         public Properties GetDigitalSignatureConfig() {
494                 try {
495                         return GetJuddiClientConfig().getDigitalSignatureConfiguration();
496                 } catch (Exception ex) {
497                         log.error("error fetching uddi.xml", ex);
498                 }
499                 return new Properties();
500         }
501 
502         private String GetToken() {
503                 EnsureConfig();
504                 if (style != AuthStyle.UDDI_AUTH) {
505                         if (WS_Transport) {
506                                 BindingProvider bp = null;
507                                 Map<String, Object> context = null;
508                                 bp = (BindingProvider) inquiry;
509                                 context = bp.getRequestContext();
510                                 context.remove(BindingProvider.USERNAME_PROPERTY);
511                                 context.remove(BindingProvider.PASSWORD_PROPERTY);
512 
513                                 context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
514                                 context.put(BindingProvider.PASSWORD_PROPERTY, session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));
515 
516                                 bp = (BindingProvider) publish;
517                                 context = bp.getRequestContext();
518                                 context.remove(BindingProvider.USERNAME_PROPERTY);
519                                 context.remove(BindingProvider.PASSWORD_PROPERTY);
520 
521                                 context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
522                                 context.put(BindingProvider.PASSWORD_PROPERTY, session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));
523 
524                                 bp = (BindingProvider) custody;
525                                 context = bp.getRequestContext();
526                                 context.remove(BindingProvider.USERNAME_PROPERTY);
527                                 context.remove(BindingProvider.PASSWORD_PROPERTY);
528 
529                                 context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
530                                 context.put(BindingProvider.PASSWORD_PROPERTY, session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));
531 
532                                 bp = (BindingProvider) subscription;
533                                 context = bp.getRequestContext();
534                                 context.remove(BindingProvider.USERNAME_PROPERTY);
535                                 context.remove(BindingProvider.PASSWORD_PROPERTY);
536 
537                                 context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
538                                 context.put(BindingProvider.PASSWORD_PROPERTY, session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));
539                         }
540                         /*
541                          bp = (BindingProvider) juddi;
542                          context = bp.getRequestContext();
543                          context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute("username"));
544                          context.put(BindingProvider.USERNAME_PROPERTY, session.getAttribute(AES.Decrypt("password", (String) properties.get("key"))));*/
545                         return null;
546                 } else {
547                         if (token != null) {
548                                 return token;
549                         }
550                         if (WS_Transport) {
551                                 BindingProvider bp = null;
552                                 Map<String, Object> context = null;
553 
554                                 bp = (BindingProvider) inquiry;
555                                 context = bp.getRequestContext();
556                                 context.remove(BindingProvider.USERNAME_PROPERTY);
557                                 context.remove(BindingProvider.PASSWORD_PROPERTY);
558 
559                                 bp = (BindingProvider) publish;
560                                 context = bp.getRequestContext();
561                                 context.remove(BindingProvider.USERNAME_PROPERTY);
562                                 context.remove(BindingProvider.PASSWORD_PROPERTY);
563 
564                                 bp = (BindingProvider) custody;
565                                 context = bp.getRequestContext();
566                                 context.remove(BindingProvider.USERNAME_PROPERTY);
567                                 context.remove(BindingProvider.PASSWORD_PROPERTY);
568 
569                                 bp = (BindingProvider) subscription;
570                                 context = bp.getRequestContext();
571                                 context.remove(BindingProvider.USERNAME_PROPERTY);
572                                 context.remove(BindingProvider.PASSWORD_PROPERTY);
573                         }
574                         GetAuthToken req = new GetAuthToken();
575                         try {
576                                 if (security == null) {
577                                         security = transport.getUDDISecurityService();
578                                 }
579                         } catch (Exception ex) {
580                                 log.error(ex);
581                         }
582                         if (session != null && session.getAttribute("username") != null
583                              && session.getAttribute("password") != null) {
584                                 req.setUserID((String) session.getAttribute("username"));
585                                 req.setCred(AES.Decrypt((String) session.getAttribute("password"), (String) properties.get("key")));
586                                 log.info("AUDIT: fetching auth token for " + req.getUserID() + " Auth Mode is " + ((security == null) ? "HTTP" : "AUTH_TOKEN"));
587                                 try {
588                                         AuthToken authToken = security.getAuthToken(req);
589                                         token = authToken.getAuthInfo();
590                                 } catch (Exception ex) {
591                                         return HandleException(ex);
592                                 }
593                         }
594                 }
595                 return token;
596         }
597 
598         /**
599          * Returns true if the current user has a token and is signed in. Does
600          * not apply to non-UDDI security API logins
601          *
602          * @return true if authenticated
603          */
604         public boolean getUddiIsAuthenticated() {
605                 return (token != null && !token.isEmpty());
606         }
607 
608         /**
609          * Performs a find_business call in the inquiry API
610          *
611          * @param offset
612          * @param maxrecords
613          * @param keyword
614          * @param lang
615          * @param isChooser
616          * @return PagableContainer of businesses
617          */
618         public PagableContainer GetBusinessListAsHtml(int offset, int maxrecords, String keyword, String lang, boolean isChooser) {
619                 PagableContainer ret = new PagableContainer();
620                 ret.offset = offset;
621                 ret.displaycount = 0;
622                 ret.totalrecords = 0;
623 
624                 try {
625                         FindBusiness fb = new FindBusiness();
626                         fb.setMaxRows(maxrecords);
627                         fb.setListHead(offset);
628                         fb.setAuthInfo(GetToken());
629                         org.uddi.api_v3.FindQualifiers fq = new org.uddi.api_v3.FindQualifiers();
630                         fq.getFindQualifier().add(UDDIConstants.CASE_INSENSITIVE_MATCH);
631                         fq.getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
632                         fq.getFindQualifier().add(UDDIConstants.SORT_BY_NAME_ASC);
633                         fb.setFindQualifiers(fq);
634                         Name searchname = new Name();
635                         searchname.setLang(lang);
636                         searchname.setValue(keyword);
637                         fb.getName().add(searchname);
638                         //transport
639                         BusinessList findBusiness = null;
640                         try {
641                                 findBusiness = inquiry.findBusiness(fb);
642                         } catch (Exception ex) {
643                                 if (isExceptionExpiration(ex)) {
644                                         token = null;
645                                         fb.setAuthInfo(GetToken());
646                                         findBusiness = inquiry.findBusiness(fb);
647                                 } else {
648                                         throw ex;
649                                 }
650                         }
651                         if (findBusiness == null || findBusiness.getBusinessInfos() == null) {
652                                 ret.renderedHtml = (ResourceLoader.GetResource(session, "errors.nodatareturned"));
653                         } else {
654                                 if (findBusiness.getListDescription() != null) {
655                                         ret.displaycount = findBusiness.getListDescription().getIncludeCount();
656                                         ret.offset = findBusiness.getListDescription().getListHead();
657                                         ret.totalrecords = findBusiness.getListDescription().getActualCount();
658                                 } else {
659                                         ret.displaycount = findBusiness.getBusinessInfos().getBusinessInfo().size();
660                                         ret.offset = offset;
661                                         ret.totalrecords = findBusiness.getBusinessInfos().getBusinessInfo().size();
662                                 }
663                                 ret.renderedHtml = Printers.BusinessListAsTable(findBusiness, session, isChooser);
664                         }
665 
666                 } catch (Exception ex) {
667                         ret.renderedHtml = (HandleException(ex));
668                 }
669 
670                 return ret;
671         }
672 
673         /**
674          * The get_registeredInfo API call is used to get an abbreviated list of
675          * all businessEntity and tModel data that are controlled by a
676          * publisher. When the registry distinguishes between publishers, this
677          * is the individual associated with the credentials passed in the
678          * authInfo element. This returned information is intended, for example,
679          * for driving tools that display lists of registered information and
680          * then provide drill-down features. This is the recommended API to use
681          * after a network problem results in an unknown status of saved
682          * information.
683          *
684          * @param businesses
685          * @param tModels
686          * @return returns all of "my" keys
687          */
688         public String GetMyTransferableKeys(boolean businesses, boolean tModels) {
689 
690                 StringBuilder sb = new StringBuilder();
691 
692                 RegisteredInfo findBusiness = null;
693                 try {
694                         GetRegisteredInfo r = new GetRegisteredInfo();
695                         r.setAuthInfo(GetToken());
696                         if (r.getAuthInfo() == null) {
697                                 return ToErrorAlert(ResourceLoader.GetResource(session, "errors.notsignedin"));
698                         }
699                         r.setInfoSelection(InfoSelection.ALL);
700 
701                         try {
702                                 findBusiness = publish.getRegisteredInfo(r);
703                         } catch (Exception ex) {
704                                 if (isExceptionExpiration(ex)) {
705                                         token = null;
706                                         r.setAuthInfo(GetToken());
707                                         findBusiness = publish.getRegisteredInfo(r);
708                                 } else {
709                                         throw ex;
710                                 }
711                         }
712 
713                 } catch (Exception ex) {
714                         return (HandleException(ex));
715                 }
716 
717                 if (findBusiness == null || findBusiness.getBusinessInfos() == null) {
718                         return (ResourceLoader.GetResource(session, "errors.nodatareturned"));
719 
720                 } else {
721                         if (findBusiness.getBusinessInfos() != null && businesses) {
722                                 sb.append("<select id=\"businesslist\" multiple=\"multiple\" size=\"10\">");
723                                 for (int i = 0; i < findBusiness.getBusinessInfos().getBusinessInfo().size(); i++) {
724                                         sb.append("<option class=\"transferable\" id=\"").
725                                              append(StringEscapeUtils.escapeHtml(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getBusinessKey())).
726                                              append("\" title=\"").
727                                              append(StringEscapeUtils.escapeHtml(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getBusinessKey())).
728                                              append("\">").
729                                              append(StringEscapeUtils.escapeHtml(Printers.ListNamesToString(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getName()))).
730                                              append("</option>");
731                                 }
732                                 sb.append("</select>");
733                         }
734                         if (findBusiness.getTModelInfos() != null && tModels) {
735                                 sb.append("<select id=\"tmodellist\" multiple=\"multiple\" size=\"10\">");
736                                 for (int i = 0; i < findBusiness.getTModelInfos().getTModelInfo().size(); i++) {
737                                         sb.append("<option  class=\"transferable\" id=\"").
738                                              append(StringEscapeUtils.escapeHtml(findBusiness.getTModelInfos().getTModelInfo().get(i).getTModelKey())).
739                                              append("\" title=\"").
740                                              append(StringEscapeUtils.escapeHtml(findBusiness.getTModelInfos().getTModelInfo().get(i).getTModelKey())).
741                                              append("\">").
742                                              append(StringEscapeUtils.escapeHtml((findBusiness.getTModelInfos().getTModelInfo().get(i).getName().getValue()))).
743                                              append("</option>");
744                                 }
745                                 sb.append("</select>");
746                         }
747 
748                         return sb.toString();
749                 }
750 
751         }
752 
753         /**
754          * Performs Inquiry Find_service API used from servicedetails.jsp
755          *
756          * @param serviceid
757          * @return string
758          */
759         public String GetServiceDetailAsHtml(String serviceid) {
760                 if (serviceid == null || serviceid.length() == 0) {
761                         return ResourceLoader.GetResource(session, "errors.noinput");
762                 }
763                 StringBuilder sb = new StringBuilder();
764                 try {
765                         GetServiceDetail gbd = new GetServiceDetail();
766                         gbd.setAuthInfo(GetToken());
767                         gbd.getServiceKey().add(serviceid);
768                         ServiceDetail get = null;//inquiry.getServiceDetail(gbd);
769                         try {
770                                 get = inquiry.getServiceDetail(gbd);
771                         } catch (Exception ex) {
772                                 if (isExceptionExpiration(ex)) {
773                                         token = null;
774                                         gbd.setAuthInfo(GetToken());
775                                         get = inquiry.getServiceDetail(gbd);
776 
777                                 } else {
778                                         throw ex;
779                                 }
780                         }
781                         if (get != null) {
782                                 for (int i = 0; i < get.getBusinessService().size(); i++) {
783                                         session.setAttribute(get.getBusinessService().get(i).getServiceKey(), get.getBusinessService().get(i));
784                                         sb.append("<b>").append(ResourceLoader.GetResource(session, "items.name")).append(":</b><div class=\"editable\" id=\"ServiceName\">").append(StringEscapeUtils.escapeHtml(Printers.ListNamesToString(get.getBusinessService().get(i).getName()))).append("</div><Br>");
785                                         sb.append("<b>").append(ResourceLoader.GetResource(session, "items.description")).append(":</b><div class=\"editable\" id=\"ServiceDescription\">").append(StringEscapeUtils.escapeHtml((Printers.ListToDescString(get.getBusinessService().get(i).getDescription())))).append("</div><Br>");
786                                         sb.append("<b>").append(ResourceLoader.GetResource(session, "items.key")).append(":</b><div class=\"editable\" id=\"ServiceKey\">").append(StringEscapeUtils.escapeHtml((get.getBusinessService().get(i).getServiceKey()))).append("</div><Br>");
787                                         sb.append("<b>").append(ResourceLoader.GetResource(session, "items.keyrefcat")).append(":</b> ").append(Printers.CatBagToString(get.getBusinessService().get(i).getCategoryBag(), getLocale())).append("<Br>");
788                                         if (!get.getBusinessService().get(i).getSignature().isEmpty()) {
789                                                 sb.append(ResourceLoader.GetResource(session, "items.signed")).append("<Br>");
790                                         } else {
791                                                 sb.append(ResourceLoader.GetResource(session, "items.signed.not")).append("<Br>");
792                                         }
793 
794                                         sb.append(Printers.PrintBindingTemplates(get.getBusinessService().get(i).getBindingTemplates(), getLocale())).append("<Br>");
795                                 }
796                         } else {
797                                 sb.append(ResourceLoader.GetResource(session, "errors.nodatareturned"));
798                         }
799                 } catch (Exception ex) {
800                         sb.append(HandleException(ex));
801                 }
802                 return sb.toString();
803         }
804 
805         /**
806          * return true if the word expire is in the exception or the UDDI error
807          * code representing an expired token
808          *
809          * @param ex
810          * @return true if it's an expired token
811          */
812         public static boolean isExceptionExpiration(Exception ex) {
813                 if (ex == null) {
814                         return false;
815                 }
816                 if (ex instanceof DispositionReportFaultMessage) {
817                         DispositionReportFaultMessage f = (DispositionReportFaultMessage) ex;
818                         if (f.getFaultInfo().countainsErrorCode(DispositionReport.E_AUTH_TOKEN_EXPIRED)
819                              || ex.getMessage().contains(DispositionReport.E_AUTH_TOKEN_EXPIRED)
820                              || ex.getMessage().toLowerCase().contains("expire")) {
821                                 return true;
822                         }
823                 }
824 
825                 if (ex.getMessage() == null) {
826                         return false;
827                 }
828                 if (ex.getMessage().toLowerCase().contains("expire")) {
829                         return true;
830                 }
831 
832                 if (ex.getMessage().toLowerCase().contains(DispositionReport.E_AUTH_TOKEN_EXPIRED.toLowerCase())) {
833                         return true;
834                 }
835                 if (ex.getLocalizedMessage() == null) {
836                         return false;
837                 }
838                 if (ex.getLocalizedMessage().toLowerCase().contains("expire")) {
839                         return true;
840                 }
841                 return false;
842         }
843 
844         /**
845          * returns an html formatted list of services for a specific business
846          * used on browse.jsp
847          *
848          * @param bizid
849          * @return string
850          */
851         public String GetServiceList(String bizid) {
852                 if (bizid == null || bizid.isEmpty()) {
853                         return ResourceLoader.GetResource(session, "errors.nobusinessid");
854                 }
855                 StringBuilder sb = new StringBuilder();
856                 try {
857                         GetBusinessDetail gbd = new GetBusinessDetail();
858                         gbd.setAuthInfo(GetToken());
859                         gbd.getBusinessKey().add(bizid);
860                         BusinessDetail businessDetail = null;
861                         try {
862                                 businessDetail = inquiry.getBusinessDetail(gbd);
863                         } catch (Exception ex) {
864                                 if (isExceptionExpiration(ex)) {
865 
866                                         token = null;
867                                         gbd.setAuthInfo(GetToken());
868                                         businessDetail = inquiry.getBusinessDetail(gbd);
869 
870                                 } else {
871                                         throw ex;
872                                 }
873                         }
874                         if (businessDetail != null) {
875                                 for (int i = 0; i < businessDetail.getBusinessEntity().size(); i++) {
876                                         if (businessDetail.getBusinessEntity().get(i).getBusinessServices() == null) {
877                                                 sb.append(ResourceLoader.GetResource(session, "errors.noservicesdefined"));
878                                         } else {
879                                                 for (int k = 0; k < businessDetail.getBusinessEntity().get(i).getBusinessServices().getBusinessService().size(); k++) {
880                                                         sb.append("<div><a href=\"serviceEditor.jsp?id=").
881                                                              append(StringEscapeUtils.escapeHtml(businessDetail.getBusinessEntity().get(i).getBusinessServices().getBusinessService().get(k).getServiceKey())).append("\">").
882                                                              append(StringEscapeUtils.escapeHtml(Printers.ListNamesToString(businessDetail.getBusinessEntity().get(i).getBusinessServices().getBusinessService().get(k).getName()))).append("</a></div>");
883                                                 }
884                                         }
885                                 }
886                         } else {
887                                 sb.append(ResourceLoader.GetResource(session, "errors.nodatareturned"));
888                         }
889                 } catch (Exception ex) {
890                         sb.append(ResourceLoader.GetResource(session, "errors.generic")).append(ex.getMessage());
891                 }
892                 return sb.toString();
893         }
894 
895         /**
896          * Performs a getServiceDetails in Inquiry API
897          *
898          * @param serviceid
899          * @return null if no id was specified or if it didn't exist
900          */
901         public BusinessService GetServiceDetail(String serviceid) {
902                 if (serviceid == null || serviceid.length() == 0) {
903                         return null;
904                 }
905 
906                 if (serviceid.equalsIgnoreCase(ResourceLoader.GetResource(session, "items.clicktoedit"))) {
907                         return null;
908                 }
909                 try {
910                         GetServiceDetail gbd = new GetServiceDetail();
911                         gbd.setAuthInfo(GetToken());
912                         gbd.getServiceKey().add(serviceid);
913                         ServiceDetail get = null;
914                         try {
915                                 get = inquiry.getServiceDetail(gbd);
916                         } catch (Exception ex) {
917                                 if (isExceptionExpiration(ex)) {
918                                         token = null;
919                                         gbd.setAuthInfo(GetToken());
920                                         get = inquiry.getServiceDetail(gbd);
921 
922                                 } else {
923                                         throw ex;
924                                 }
925                         }
926 
927                         if (get == null || get.getBusinessService().isEmpty()) {
928                                 return null;
929                         }
930                         return get.getBusinessService().get(0);
931 
932                 } catch (Exception ex) {
933                         HandleException(ex);
934                 }
935                 return null;
936         }
937 
938         /**
939          * this is used from the save from xml.jsp page
940          *
941          * @param be
942          * @return status message
943          */
944         public String SaveBindingTemplate(BindingTemplate be) {
945                 try {
946                         SaveBinding sb = new SaveBinding();
947                         sb.setAuthInfo(GetToken());
948                         sb.getBindingTemplate().add(be);
949                         BindingDetail saveBinding = null;
950                         try {
951                                 saveBinding = publish.saveBinding(sb);
952                         } catch (Exception ex) {
953                                 if (isExceptionExpiration(ex)) {
954                                         token = null;
955                                         sb.setAuthInfo(GetToken());
956                                         saveBinding = publish.saveBinding(sb);
957 
958                                 } else {
959                                         throw ex;
960                                 }
961                         }
962                         return ResourceLoader.GetResource(session, "actions.saved") + " "
963                              + "<a href=\"bindingEditor.jsp?id=" + URLEncoder.encode(saveBinding.getBindingTemplate().get(0).getBindingKey(), "UTF8")
964                              + "\">" + StringEscapeUtils.escapeHtml(saveBinding.getBindingTemplate().get(0).getBindingKey()) + "</a>";
965                 } catch (Exception ex) {
966                         return HandleException(ex);
967                 }
968         }
969 
970         /**
971          * This method will rebuild a Service entity from the HTTP request from
972          * the Service Editor page and will then attempt to save it.
973          *
974          * @param request
975          * @return a localized Saved or an error message
976          */
977         public String SaveServiceDetails(HttpServletRequest request) {
978 
979                 BusinessService be = new BusinessService();
980                 be.setBusinessKey(request.getParameter(PostBackConstants.BUSINESSKEY).trim());
981                 be.setServiceKey(request.getParameter(PostBackConstants.SERVICEKEY).trim());
982 
983                 if (be.getServiceKey().equalsIgnoreCase(ResourceLoader.GetResource(session, "items.clicktoedit"))) {
984                         be.setServiceKey(null);
985                 }
986                 if (be.getBusinessKey() == null || be.getBusinessKey().length() == 0) {
987                         return ResourceLoader.GetResource(session, "errors.noinput.businesskey");
988                 }
989 
990                 be.getName().addAll(Builders.BuildNames(Builders.MapFilter(request.getParameterMap(), PostBackConstants.NAME), PostBackConstants.NAME, ResourceLoader.GetResource(session, "items.clicktoedit"), getLocale()));
991                 //JUDDI-806get existing service details and copy over binding templates
992                 BusinessService GetServiceDetail = GetServiceDetail(request.getParameter(PostBackConstants.SERVICEKEY).trim());
993                 if (GetServiceDetail != null) {
994                         be.setBindingTemplates(GetServiceDetail.getBindingTemplates());
995                 }
996                 /*JUDDI-806
997                  BindingTemplates bt = new BindingTemplates();
998                  bt.getBindingTemplate().addAll(Builders.BuildBindingTemplates(Builders.MapFilter(request.getParameterMap(), PostBackConstants.BINDINGTEMPLATE), PostBackConstants.BINDINGTEMPLATE, ResourceLoader.GetResource(session, "items.clicktoedit"), getLocale()));
999                  if (!bt.getBindingTemplate().isEmpty()) {
1000                  be.setBindingTemplates(bt);
1001                  }*/
1002 
1003                 be.getDescription().addAll(Builders.BuildDescription(Builders.MapFilter(request.getParameterMap(), PostBackConstants.DESCRIPTION), PostBackConstants.DESCRIPTION, ResourceLoader.GetResource(session, "items.clicktoedit"), getLocale()));
1004 
1005                 CategoryBag cb = new CategoryBag();
1006                 cb.getKeyedReference().addAll(Builders.BuildKeyedReference(Builders.MapFilter(request.getParameterMap(), PostBackConstants.CATBAG_KEY_REF), PostBackConstants.CATBAG_KEY_REF, getLocale()));
1007                 cb.getKeyedReferenceGroup().addAll(Builders.BuildKeyedReferenceGroup(Builders.MapFilter(request.getParameterMap(), PostBackConstants.CATBAG_KEY_REF_GRP), PostBackConstants.CATBAG_KEY_REF_GRP, getLocale()));
1008 
1009                 if (!cb.getKeyedReference().isEmpty() || !cb.getKeyedReferenceGroup().isEmpty()) {
1010                         be.setCategoryBag(cb);
1011                 }
1012 
1013                 return SaveServiceDetails(be);
1014         }
1015 
1016         /**
1017          * Saves a Service
1018          *
1019          * @param be
1020          * @return a readable error message or, success
1021          */
1022         public String SaveServiceDetails(BusinessService be) {
1023                 try {
1024                         SaveService sb = new SaveService();
1025                         sb.setAuthInfo(GetToken());
1026                         ServiceDetail saveService = null;
1027                         sb.getBusinessService().add(be);
1028                         try {
1029                                 saveService = publish.saveService(sb);
1030                         } catch (Exception ex) {
1031                                 if (isExceptionExpiration(ex)) {
1032                                         token = null;
1033                                         sb.setAuthInfo(GetToken());
1034                                         saveService = publish.saveService(sb);
1035 
1036                                 } else {
1037                                         throw ex;
1038                                 }
1039                         }
1040                     return ResourceLoader.GetResource(session, "actions.saved") + " "
1041                             + " <script type=\"text/javascript\">window.location.href='"
1042                             + StringEscapeUtils.escapeJavaScript("serviceEditor.jsp?id=" + URLEncoder.encode(saveService.getBusinessService().get(0).getServiceKey(), "UTF8")) + "';</script>"
1043                             + "<a href=\"serviceEditor.jsp?id=" + URLEncoder.encode(saveService.getBusinessService().get(0).getServiceKey(), "UTF8")
1044                             + "\">" + StringEscapeUtils.escapeHtml(saveService.getBusinessService().get(0).getServiceKey()) + "</a>";
1045                 } catch (Exception ex) {
1046                     return HandleException(ex);
1047                 }
1048         }
1049 
1050         /**
1051          * Saves a business entity
1052          *
1053          * @param be
1054          * @return a readable error message
1055          */
1056         public String SaveBusinessDetails(BusinessEntity be) {
1057                 try {
1058                         SaveBusiness sb = new SaveBusiness();
1059                         sb.setAuthInfo(GetToken());
1060                         sb.getBusinessEntity().add(be);
1061                         BusinessDetail saveBusiness = null;
1062                         try {
1063                                 saveBusiness = publish.saveBusiness(sb);
1064                         } catch (Exception ex) {
1065                                 if (isExceptionExpiration(ex)) {
1066                                         token = null;
1067                                         sb.setAuthInfo(GetToken());
1068                                         saveBusiness = publish.saveBusiness(sb);
1069 
1070                                 } else {
1071                                         throw ex;
1072                                 }
1073                         }
1074 
1075                         return ResourceLoader.GetResource(session, "actions.saved") + " "
1076                              + " <script type=\"text/javascript\">window.location.href='"+ 
1077                                 StringEscapeUtils.escapeJavaScript("businessEditor2.jsp?id=" + URLEncoder.encode(saveBusiness.getBusinessEntity().get(0).getBusinessKey(), "UTF8")) + "';</script>"
1078                              + "<a href=\"businessEditor2.jsp?id=" + URLEncoder.encode(saveBusiness.getBusinessEntity().get(0).getBusinessKey(), "UTF8")
1079                              + "\">" + StringEscapeUtils.escapeHtml(saveBusiness.getBusinessEntity().get(0).getBusinessKey()) + "</a>";
1080                 } catch (Exception ex) {
1081                         return HandleException(ex);
1082                 }
1083         }
1084 
1085         /**
1086          * Save Business
1087          *
1088          * This method saves a business to a UDDI registry, preserving the
1089          * service listing The request is build from the HTTP post back
1090          * parameters. A human readable response message is returned
1091          *
1092          * @param request
1093          * @return string
1094          */
1095         public String SaveBusinessDetails(HttpServletRequest request) {
1096 
1097                 BusinessEntity be = new BusinessEntity();
1098                 be.setBusinessKey(request.getParameter(PostBackConstants.BUSINESSKEY).trim());
1099                 if (be.getBusinessKey().equalsIgnoreCase(ResourceLoader.GetResource(session, "items.clicktoedit"))) {
1100                         be.setBusinessKey(null);
1101                 } else {
1102                         BusinessEntity GetBusinessDetails = GetBusinessDetails(be.getBusinessKey());
1103                         if (GetBusinessDetails == null) //this is a new business
1104                         {
1105                         } else {
1106                                 //copy over the existing child element, business
1107                                 be.setBusinessServices(GetBusinessDetails.getBusinessServices());
1108                         }
1109                 }
1110                 be.getName().addAll(Builders.BuildNames(Builders.MapFilter(request.getParameterMap(), PostBackConstants.NAME), PostBackConstants.NAME, ResourceLoader.GetResource(session, "items.clicktoedit"), getLocale()));
1111 
1112                 be.setContacts(Builders.BuildContacts(request.getParameterMap(), ResourceLoader.GetResource(session, "items.clicktoedit"), getLocale()));
1113 
1114                 be.getDescription().addAll(Builders.BuildDescription(Builders.MapFilter(request.getParameterMap(), PostBackConstants.DESCRIPTION), PostBackConstants.DESCRIPTION, ResourceLoader.GetResource(session, "items.clicktoedit"), getLocale()));
1115                 be.setDiscoveryURLs(Builders.BuildDisco(Builders.MapFilter(request.getParameterMap(), PostBackConstants.DISCOVERYURL), PostBackConstants.DISCOVERYURL, getLocale()));
1116                 CategoryBag cb = new CategoryBag();
1117                 cb.getKeyedReference().addAll(Builders.BuildKeyedReference(Builders.MapFilter(request.getParameterMap(), PostBackConstants.CATBAG_KEY_REF), PostBackConstants.CATBAG_KEY_REF, getLocale()));
1118                 cb.getKeyedReferenceGroup().addAll(Builders.BuildKeyedReferenceGroup(Builders.MapFilter(request.getParameterMap(), PostBackConstants.CATBAG_KEY_REF_GRP), PostBackConstants.CATBAG_KEY_REF_GRP, getLocale()));
1119 
1120                 if (!cb.getKeyedReference().isEmpty() || !cb.getKeyedReferenceGroup().isEmpty()) {
1121                         be.setCategoryBag(cb);
1122                 }
1123                 be.setIdentifierBag(Builders.BuildIdentBag(Builders.MapFilter(request.getParameterMap(), PostBackConstants.IDENT_KEY_REF), PostBackConstants.IDENT_KEY_REF, getLocale()));
1124                 return SaveBusinessDetails(be);
1125         }
1126 
1127         /**
1128          * Gets a business's details used for the businessEditor
1129          *
1130          * @param bizid
1131          * @return null if no id is provided or if there is a remote error
1132          */
1133         public BusinessEntity GetBusinessDetails(String bizid) {
1134                 if (bizid == null || bizid.isEmpty()) {
1135                         return null;
1136                 }
1137                 if (bizid.equalsIgnoreCase(ResourceLoader.GetResource(session, "items.clicktoedit"))) {
1138                         return null;
1139                 }
1140 
1141                 try {
1142                         GetBusinessDetail gbd = new GetBusinessDetail();
1143                         gbd.setAuthInfo(GetToken());
1144 
1145                         gbd.getBusinessKey().add(bizid);
1146 
1147                         BusinessDetail businessDetail = null;
1148                         try {
1149                                 businessDetail = inquiry.getBusinessDetail(gbd);
1150                         } catch (Exception ex) {
1151                                 if (isExceptionExpiration(ex)) {
1152                                         token = null;
1153                                         gbd.setAuthInfo(GetToken());
1154                                         businessDetail = inquiry.getBusinessDetail(gbd);
1155 
1156                                 } else {
1157                                         throw ex;
1158                                 }
1159                         }
1160                         if (businessDetail != null && businessDetail.getBusinessEntity().size() == 1) {
1161                                 return businessDetail.getBusinessEntity().get(0);
1162                         }
1163                 } catch (Exception ex) {
1164                         HandleException(ex);
1165                 }
1166                 return null;
1167 
1168         }
1169 
1170         /**
1171          * returns a bootstrap html stylizies an error message with a warning
1172          * icon
1173          *
1174          * @param HandleException, any string representing an error message
1175          * @return string
1176          */
1177         public static String ToErrorAlert(String HandleException) {
1178                 return "<div class=\"alert alert-error\"><i class=\"icon-warning-sign icon-large\"></i>&nbsp;" + HandleException + "</div>";
1179         }
1180 
1181         private String deleteBinding(List<String> serviceId) {
1182 
1183                 if (serviceId == null || serviceId.isEmpty()) {
1184                         return ResourceLoader.GetResource(session, "errors.noinput");
1185                 }
1186                 DeleteBinding db = new DeleteBinding();
1187                 db.setAuthInfo(GetToken());
1188                 db.getBindingKey().addAll(serviceId);
1189                 try {
1190                         try {
1191                                 publish.deleteBinding(db);
1192                         } catch (Exception ex) {
1193                                 if (isExceptionExpiration(ex)) {
1194                                         token = null;
1195                                         db.setAuthInfo(GetToken());
1196                                         publish.deleteBinding(db);
1197 
1198                                 } else {
1199                                         throw ex;
1200                                 }
1201                         }
1202                 } catch (Exception ex) {
1203                         return HandleException(ex);
1204                 }
1205                 return ResourceLoader.GetResource(session, "actions.delete.binding");
1206 
1207         }
1208 
1209         /**
1210          * AuthStyles for the Hub to use, default is UDDI_AUTH
1211          */
1212         public enum AuthStyle {
1213 
1214                 /**
1215                  * Http
1216                  */
1217                 HTTP,
1218                 /**
1219                  * UDDI Authentication via the Security API
1220                  */
1221                 UDDI_AUTH
1222         }
1223 
1224         /**
1225          * Search for services using find_services
1226          *
1227          * @param keyword
1228          * @param lang
1229          * @param maxrecords
1230          * @param offset
1231          * @param isChooser
1232          * @return PagableContainer of services
1233          */
1234         public PagableContainer SearchForServices(String keyword, String lang, int maxrecords, int offset, boolean isChooser) {
1235                 PagableContainer ret = new PagableContainer();
1236                 ret.displaycount = 0;
1237                 ret.offset = offset;
1238                 ret.totalrecords = 0;
1239                 try {
1240 
1241                         FindService fs = new FindService();
1242                         fs.setAuthInfo(GetToken());
1243                         fs.setMaxRows(maxrecords);
1244                         fs.setListHead(offset);
1245                         Name n = new Name();
1246                         if (lang == null || lang.equalsIgnoreCase(ResourceLoader.GetResource(session, "items.clicktoedit"))) {
1247                                 n.setLang(null);
1248                         } else {
1249                                 n.setLang(lang);
1250                         }
1251                         n.setValue(keyword);
1252                         fs.getName().add(n);
1253                         fs.setFindQualifiers(new org.uddi.api_v3.FindQualifiers());
1254                         fs.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
1255                         fs.getFindQualifiers().getFindQualifier().add(UDDIConstants.CASE_INSENSITIVE_MATCH);
1256                         fs.getFindQualifiers().getFindQualifier().add(UDDIConstants.SORT_BY_NAME_ASC);
1257                         ServiceList findService = null;//inquiry.findService(fs);
1258                         try {
1259                                 findService = inquiry.findService(fs);
1260                         } catch (Exception ex) {
1261                                 if (isExceptionExpiration(ex)) {
1262                                         token = null;
1263                                         fs.setAuthInfo(GetToken());
1264                                         findService = inquiry.findService(fs);
1265 
1266                                 } else {
1267                                         throw ex;
1268                                 }
1269                         }
1270 
1271                         if (findService == null || findService.getServiceInfos() == null) {
1272                                 ret.renderedHtml = ResourceLoader.GetResource(session, "errors.norecordsfound");
1273                                 return ret;
1274                         }
1275                         if (findService.getListDescription() != null) {
1276                                 ret.displaycount = findService.getListDescription().getIncludeCount();
1277                                 ret.totalrecords = findService.getListDescription().getActualCount();
1278                         } else {
1279                                 ret.displaycount = findService.getServiceInfos().getServiceInfo().size();
1280                                 ret.totalrecords = findService.getServiceInfos().getServiceInfo().size();
1281                         }
1282                         ret.renderedHtml = Printers.ServiceListAsHtml(findService, isChooser, session);
1283 
1284                         //  ret.renderedHtml = sb.toString();
1285                         return ret;
1286                 } catch (Exception ex) {
1287                         ret.renderedHtml = HandleException(ex);
1288                 }
1289                 return ret;
1290 
1291         }
1292 
1293         /**
1294          * Adds a special tModel key generator keyGenerator: Marking a tModel
1295          * with this categorization designates it as one whose tModelKey
1296          * identifies a key generator partition that can be used by its owner to
1297          * derive and assign other entity keys. This categorization is reserved
1298          * for key generator tModels. Any attempt to use this categorization for
1299          * something other than a key generator tModel will fail with
1300          * E_valueNotAllowed returned.
1301          *
1302          * @param partitionName
1303          * @param name
1304          * @param lang
1305          * @return string
1306          */
1307         public String AddTmodelKenGenerator(String partitionName, String name, String lang) {
1308                 if (partitionName == null || partitionName.equalsIgnoreCase(ResourceLoader.GetResource(session, "items.clicktoedit"))) {
1309                         return ToErrorAlert(ResourceLoader.GetResource(session, "errors.noinput"));
1310                 }
1311                 try {
1312                         if (!partitionName.toLowerCase().startsWith("uddi:")) {
1313                                 return ResourceLoader.GetResource(session, "errors.tmodel.prefix");
1314 
1315                         }
1316                         if (!partitionName.toLowerCase().endsWith(":keygenerator")) {
1317                                 return ResourceLoader.GetResource(session, "errors.tmodel.postfix");
1318                         }
1319 
1320                         SaveTModel st = new SaveTModel();
1321                         st.setAuthInfo(GetToken());
1322                         TModel tm = new TModel();
1323                         tm.setName(new Name());
1324                         tm.getName().setValue(name);
1325                         if (lang == null || lang.equalsIgnoreCase(ResourceLoader.GetResource(session, "items.clicktoedit"))) {
1326                                 tm.getName().setLang(null);
1327                         } else {
1328                                 tm.getName().setLang(lang);
1329                         }
1330                         tm.setCategoryBag(new CategoryBag());
1331                         KeyedReference kr = new KeyedReference();
1332                         kr.setTModelKey("uddi:uddi.org:categorization:types");
1333                         kr.setKeyName("uddi-org:keyGenerator");
1334                         kr.setKeyValue("keyGenerator");
1335                         tm.getCategoryBag().getKeyedReference().add(kr);
1336                         OverviewDoc overviewDoc = new OverviewDoc();
1337                         OverviewURL overviewUrl = new OverviewURL();
1338                         overviewUrl.setUseType("text");
1339                         overviewUrl.setValue("http://uddi.org/pubs/uddi_v3.htm#keyGen");
1340                         overviewDoc.setOverviewURL(overviewUrl);
1341                         tm.getOverviewDoc().add(overviewDoc);
1342                         tm.setTModelKey(partitionName.toLowerCase());
1343                         st.getTModel().add(tm);
1344                         TModelDetail saveTModel = publish.saveTModel(st);
1345                         return "<div class=\"alert alert-success\"><i class=\"icon-2x icon-thumbs-up\"></i> " + ResourceLoader.GetResource(session, "messages.success") + " <a href=\"tmodelEditor.jsp?id="
1346                              + URLEncoder.encode(saveTModel.getTModel().get(0).getTModelKey(), "UTF8") + "\">"
1347                              + StringEscapeUtils.escapeHtml(saveTModel.getTModel().get(0).getTModelKey()) + "</a></div>";
1348                         // "Success";
1349                 } catch (Exception ex) {
1350                         return ToErrorAlert(HandleException(ex));
1351                 }
1352         }
1353 
1354         /**
1355          * This function provides a basic error handling rutine that will pull
1356          * out the true error message in a UDDI fault message, returning
1357          * bootstrap stylized html error message
1358          *
1359          * @param ex
1360          * @return string
1361          */
1362         public String HandleException(Exception ex) {
1363                 if (ex instanceof DispositionReportFaultMessage) {
1364                         DispositionReportFaultMessage f = (DispositionReportFaultMessage) ex;
1365                         log.error(ex.getMessage() + (f.detail != null && f.detail.getMessage() != null ? StringEscapeUtils.escapeHtml(f.detail.getMessage()) : ""));
1366                         log.debug(ex.getMessage(), ex);
1367                         return ResourceLoader.GetResource(session, "errors.generic") + " " + StringEscapeUtils.escapeHtml(ex.getMessage()) + " " + (f.detail != null && f.detail.getMessage() != null ? StringEscapeUtils.escapeHtml(f.detail.getMessage()) : "") + " " + ex.getClass().getCanonicalName();
1368                 } else if (ex instanceof RemoteException) {
1369                         RemoteException f = (RemoteException) ex;
1370                         log.error("RemoteException " + ex.getMessage());
1371                         log.debug("RemoteException " + ex.getMessage(), ex);
1372                         return ResourceLoader.GetResource(session, "errors.generic") + " " + StringEscapeUtils.escapeHtml(ex.getMessage()) + " " + (f.detail != null && f.detail.getMessage() != null ? StringEscapeUtils.escapeHtml(f.detail.getMessage()) : "") + " " + ex.getClass().getCanonicalName();
1373                 } else if (ex instanceof NullPointerException) {
1374                         log.error("NPE! Please report! " + ex.getMessage(), ex);
1375                         return ResourceLoader.GetResource(session, "errors.generic") + " " + StringEscapeUtils.escapeHtml(ex.getMessage()) + " " + ex.getClass().getCanonicalName();
1376                 } else if (ex instanceof javax.xml.ws.soap.SOAPFaultException) {
1377                         javax.xml.ws.soap.SOAPFaultException x = (javax.xml.ws.soap.SOAPFaultException) ex;
1378 
1379                         log.error("SOAP Fault returned: " + x.getMessage() + (x.getFault() != null ? x.getFault().getFaultString() : ""));
1380                         String err = null;
1381                         if (x.getFault() != null
1382                              && x.getFault().getDetail() != null) {
1383                                 Iterator detailEntries = x.getFault().getDetail().getDetailEntries();
1384                                 while (detailEntries.hasNext()) {
1385                                         err += detailEntries.next().toString();
1386                                 }
1387                         }
1388                         return ResourceLoader.GetResource(session, "errors.generic") + " " + StringEscapeUtils.escapeHtml(ex.getMessage() + " " + err) + " " + ex.getClass().getCanonicalName();
1389 
1390                 } else {
1391                         log.error("Unexpected error " + ex.getMessage(), ex);
1392                         //log.debug(ex.getMessage(), ex);
1393                         return ResourceLoader.GetResource(session, "errors.generic") + " " + StringEscapeUtils.escapeHtml(ex.getMessage()) + " " + ex.getClass().getCanonicalName();
1394                 }
1395         }
1396 
1397         /**
1398          * provides based tmodel searching/browser capability that's pagable
1399          *
1400          * @param keyword
1401          * @param lang
1402          * @param offset
1403          * @param maxrecords
1404          * @param isChooser if true, tModel keys will not be clickable and will
1405          * instead be render for a modal dialog box
1406          * @return PagableContainer tmodel
1407          */
1408         public PagableContainer tModelListAsHtml(String keyword, String lang, int offset, int maxrecords, boolean isChooser) {
1409                 PagableContainer ret = new PagableContainer();
1410                 try {
1411                         FindTModel fm = new FindTModel();
1412                         fm.setAuthInfo(GetToken());
1413                         fm.setMaxRows(maxrecords);
1414                         fm.setListHead(offset);
1415                         fm.setName(new Name());
1416                         if (lang == null || lang.equalsIgnoreCase(ResourceLoader.GetResource(session, "items.clicktoedit"))) {
1417                                 fm.getName().setLang(null);
1418                         } else {
1419                                 fm.getName().setLang(lang);
1420                         }
1421                         fm.getName().setValue(keyword);
1422                         fm.setFindQualifiers(new org.uddi.api_v3.FindQualifiers());
1423                         fm.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
1424                         fm.getFindQualifiers().getFindQualifier().add(UDDIConstants.CASE_INSENSITIVE_MATCH);
1425                         fm.getFindQualifiers().getFindQualifier().add(UDDIConstants.SORT_BY_NAME_ASC);
1426                         TModelList findTModel = null;
1427                         try {
1428                                 findTModel = inquiry.findTModel(fm);
1429                         } catch (Exception ex) {
1430                                 if (isExceptionExpiration(ex)) {
1431                                         token = null;
1432                                         fm.setAuthInfo(GetToken());
1433                                         findTModel = inquiry.findTModel(fm);
1434 
1435                                 } else {
1436                                         throw ex;
1437                                 }
1438                         }
1439 
1440                         ret.offset = offset;
1441                         if (findTModel.getListDescription() != null) {
1442                                 ret.displaycount = findTModel.getListDescription().getIncludeCount();
1443                                 ret.totalrecords = findTModel.getListDescription().getActualCount();
1444                         }
1445                         else
1446                         {
1447                                 ret.displaycount = findTModel.getTModelInfos().getTModelInfo().size();
1448                                 ret.totalrecords = findTModel.getTModelInfos().getTModelInfo().size();
1449                         }
1450                         if (findTModel.getTModelInfos() == null || findTModel.getTModelInfos().getTModelInfo().isEmpty()) {
1451                                 ret.renderedHtml = ResourceLoader.GetResource(session, "errors.norecordsfound");//"No tModels are defined";
1452                         } else {
1453                                 ret.renderedHtml = Printers.PrintTModelListAsHtml(findTModel, session, isChooser);
1454                         }
1455                 } catch (Exception ex) {
1456                         ret.renderedHtml = HandleException(ex);
1457                 }
1458                 return ret;
1459         }
1460 
1461         /**
1462          * Returns the details of a tModel by tModelKey
1463          *
1464          * @param id
1465          * @return the details or null if it doesn't exist or a null value was
1466          * passed tmodel
1467          */
1468         public TModel getTmodelDetails(String id) {
1469                 try {
1470                         if (id == null || id.length() == 0) {
1471                                 return null;
1472                         }
1473 
1474                         GetTModelDetail req = new GetTModelDetail();
1475                         req.setAuthInfo(GetToken());
1476                         req.getTModelKey().add(id);
1477                         TModelDetail tModelDetail = null;
1478                         try {
1479                                 tModelDetail = inquiry.getTModelDetail(req);
1480 
1481                         } catch (Exception ex) {
1482                                 if (isExceptionExpiration(ex)) {
1483                                         token = null;
1484                                         req.setAuthInfo(GetToken());
1485                                         tModelDetail = inquiry.getTModelDetail(req);
1486 
1487                                 } else {
1488                                         throw ex;
1489                                 }
1490                         }
1491 
1492                         if (tModelDetail != null && !tModelDetail.getTModel().isEmpty()) {
1493                                 return tModelDetail.getTModel().get(0);
1494                         }
1495 
1496                 } catch (Exception ex) {
1497                         HandleException(ex);
1498                 }
1499                 return null;
1500         }
1501 
1502         /**
1503          * A convenience function for GetBusinessDetails
1504          *
1505          * @param key
1506          * @return be
1507          */
1508         public BusinessEntity GetBusinessDetailsAsObject(String key) {
1509                 return GetBusinessDetails(key);
1510         }
1511 
1512         /**
1513          * A convenience function for GetServiceDetail
1514          *
1515          * @param key
1516          * @return bs
1517          */
1518         public BusinessService GetServiceDetailsAsObject(String key) {
1519                 return GetServiceDetail(key);
1520         }
1521 
1522         /**
1523          * Returns a specific binding template as an object
1524          *
1525          * @param key
1526          * @return null if not found
1527          */
1528         public BindingTemplate GetBindingDetailsAsObject(String key) {
1529                 try {
1530                         GetBindingDetail r = new GetBindingDetail();
1531                         r.setAuthInfo(GetToken());
1532                         r.getBindingKey().add(key);
1533                         BindingDetail bindingDetail = null;
1534                         try {
1535                                 bindingDetail = inquiry.getBindingDetail(r);
1536                         } catch (Exception ex) {
1537                                 if (isExceptionExpiration(ex)) {
1538                                         token = null;
1539                                         r.setAuthInfo(GetToken());
1540                                         bindingDetail = inquiry.getBindingDetail(r);
1541 
1542                                 } else {
1543                                         throw ex;
1544                                 }
1545                         }
1546                         return bindingDetail.getBindingTemplate().get(0);
1547                 } catch (Exception ex) {
1548                         HandleException(ex);
1549                 }
1550                 return null;
1551         }
1552 
1553         /**
1554          * Returns a tmodel given the key
1555          *
1556          * @param key
1557          * @return null if not found
1558          */
1559         public TModel GettModelDetailsAsObject(String key) {
1560                 try {
1561                         GetTModelDetail r = new GetTModelDetail();
1562                         r.setAuthInfo(GetToken());
1563                         r.getTModelKey().add(key);
1564                         TModelDetail tModelDetail = null;
1565                         try {
1566                                 tModelDetail = inquiry.getTModelDetail(r);
1567                         } catch (Exception ex) {
1568                                 if (isExceptionExpiration(ex)) {
1569                                         token = null;
1570                                         r.setAuthInfo(GetToken());
1571                                         tModelDetail = inquiry.getTModelDetail(r);
1572                                 } else {
1573                                         throw ex;
1574                                 }
1575                         }
1576 
1577                         return tModelDetail.getTModel().get(0);
1578                 } catch (Exception ex) {
1579                         HandleException(ex);
1580                 }
1581                 return null;
1582         }
1583 
1584         /**
1585          * An enum to help make UDDI searching easier to work with
1586          */
1587         public enum FindType {
1588 
1589                 /**
1590                  * search for a business
1591                  */
1592                 Business,
1593                 /**
1594                  * search for a related business
1595                  */
1596                 RelatedBusiness,
1597                 /**
1598                  * search for a business
1599                  */
1600                 Service,
1601                 /**
1602                  * search for a tmodel
1603                  */
1604                 tModel,
1605                 /**
1606                  * search for a binding template
1607                  */
1608                 BindingTemplate
1609         }
1610 
1611         /**
1612          * An enum to help make UDDI searching easier to work with
1613          */
1614         public enum CriteriaType {
1615 
1616                 /**
1617                  * search by name
1618                  */
1619                 Name,
1620                 /**
1621                  * by category
1622                  */
1623                 Category,
1624                 /**
1625                  * by key
1626                  */
1627                 uid,
1628                 /**
1629                  * by tmodel
1630                  */
1631                 tmodel,
1632                 /**
1633                  * by identifier bag
1634                  */
1635                 identbag
1636         }
1637 
1638         /**
1639          * Provides a simple search interface for the complex UDDI search APIs
1640          *
1641          * @param type
1642          * @param criteria
1643          * @param parameters
1644          * @param lang
1645          * @param findqualifier
1646          * @return stylized html
1647          */
1648         public String Search(FindType type, CriteriaType criteria, String parameters, String lang, String[] findqualifier) {
1649                 switch (type) {
1650                         case BindingTemplate:
1651                                 return FindBindingTemplateToHtml(criteria, parameters, lang, findqualifier);
1652                         case Business:
1653                                 return FindBusiness(criteria, parameters, lang, findqualifier);
1654                         case RelatedBusiness:
1655                                 return FindRelatedBusiness(criteria, parameters, lang, findqualifier);
1656 
1657                         case Service:
1658                                 return FindService(criteria, parameters, lang, findqualifier);
1659                         case tModel:
1660                                 return FindtModels(criteria, parameters, lang, findqualifier);
1661                 }
1662                 return ResourceLoader.GetResource(session, "items.unknown");
1663         }
1664 
1665         private String FindBindingTemplateToHtml(CriteriaType criteria, String parameters, String lang, String[] fq) {
1666                 try {
1667                         FindBinding fb = new FindBinding();
1668                         fb.setAuthInfo(GetToken());
1669                         if (fq != null) {
1670                                 fb.setFindQualifiers(new org.uddi.api_v3.FindQualifiers());
1671                                 for (int i = 0; i < fq.length; i++) {
1672                                         fb.getFindQualifiers().getFindQualifier().add(fq[i]);
1673                                 }
1674                         }
1675                         BindingDetail findBusiness = null;
1676                         switch (criteria) {
1677                                 case Category:
1678                                         fb.setCategoryBag(new CategoryBag());
1679                                         KeyedReference kr = new KeyedReference();
1680                                         kr.setTModelKey(parameters);
1681                                         kr.setKeyName("%");
1682                                         kr.setKeyValue("%");
1683                                         fb.getCategoryBag().getKeyedReference().add(kr);
1684                                         break;
1685                                 case Name:
1686                                         break;
1687                                 case tmodel:
1688                                         fb.setTModelBag(new TModelBag());
1689                                         fb.getTModelBag().getTModelKey().add(parameters);
1690                                         break;
1691                                 case uid:
1692                                         //BusinessEntity t = GetBusinessDetails(parameters);
1693                                         findBusiness = new BindingDetail();
1694                                         BindingTemplate bt = GetBindingDetailsAsObject(parameters);
1695                                         if (bt != null) {
1696                                                 findBusiness.getBindingTemplate().add(bt);
1697                                         }
1698 
1699                                         break;
1700 
1701                         }
1702                         if (findBusiness == null) {
1703                                 try {
1704                                         findBusiness = inquiry.findBinding(fb);
1705                                 } catch (Exception ex) {
1706                                         if (isExceptionExpiration(ex)) {
1707                                                 token = null;
1708                                                 fb.setAuthInfo(GetToken());
1709                                                 findBusiness = inquiry.findBinding(fb);
1710 
1711                                         } else {
1712                                                 throw ex;
1713                                         }
1714                                 }
1715 
1716                         }
1717                         if (findBusiness != null && !findBusiness.getBindingTemplate().isEmpty()) {
1718                                 StringBuilder sb = new StringBuilder();
1719                                 sb.append("<table class=\"table\">");
1720                                 for (int i = 0; i < findBusiness.getBindingTemplate().size(); i++) {
1721                                         sb.append("<tr><td>");
1722                                         sb.append(ResourceLoader.GetResource(session, "items.service.key")).append(": ");
1723                                         sb.append("<a href=\"serviceEditor.jsp?id=").
1724                                              append(StringEscapeUtils.escapeHtml(findBusiness.getBindingTemplate().get(i).getServiceKey())).
1725                                              append("\">");
1726                                         if (findBusiness.getBindingTemplate().get(i).getDescription().isEmpty()) {
1727                                                 sb.append(StringEscapeUtils.escapeHtml(findBusiness.getBindingTemplate().get(i).getBindingKey()));
1728                                         } else {
1729                                                 String t = StringEscapeUtils.escapeHtml(Printers.ListToDescString(findBusiness.getBindingTemplate().get(i).getDescription()));
1730                                                 if (t == null || t.trim().length() == 0) {
1731                                                         sb.append(StringEscapeUtils.escapeHtml(findBusiness.getBindingTemplate().get(i).getBindingKey()));
1732                                                 } else {
1733                                                         sb.append(t);
1734                                                 }
1735                                         }
1736                                         sb.append("</a><br>");
1737                                         sb.append(ResourceLoader.GetResource(session, "items.bindingtemplate.key"));
1738                                         sb.append(": <a href=\"bindingEditor.jsp?id=");
1739                                         sb.append(StringEscapeUtils.escapeHtml(findBusiness.getBindingTemplate().get(i).getBindingKey()));
1740                                         sb.append("\">");
1741                                         sb.append(StringEscapeUtils.escapeHtml(findBusiness.getBindingTemplate().get(i).getBindingKey()));
1742                                         sb.append("</a>");
1743                                         sb.append("</td></tr>");
1744                                 }
1745                                 sb.append("</table>");
1746                                 return sb.toString();
1747                         } else {
1748                                 return ResourceLoader.GetResource(session, "errors.norecordsfound");
1749                         }
1750                 } catch (Exception ex) {
1751                         return HandleException(ex);
1752                 }
1753         }
1754 
1755         private String FindBusiness(CriteriaType criteria, String parameters, String lang, String[] fq) {
1756                 try {
1757                         FindBusiness fb = new FindBusiness();
1758                         fb.setAuthInfo(GetToken());
1759                         if (fq != null) {
1760                                 fb.setFindQualifiers(new org.uddi.api_v3.FindQualifiers());
1761                                 if (fq != null) {
1762                                         for (int i = 0; i < fq.length; i++) {
1763                                                 fb.getFindQualifiers().getFindQualifier().add(fq[i]);
1764                                         }
1765                                 }
1766                         }
1767                         BusinessList findBusiness = null;
1768                         switch (criteria) {
1769                                 case Category:
1770                                         fb.setCategoryBag(new CategoryBag());
1771                                         KeyedReference kr = new KeyedReference();
1772                                         kr.setTModelKey(parameters);
1773                                         kr.setKeyName("%");
1774                                         kr.setKeyValue("%");
1775                                         fb.getCategoryBag().getKeyedReference().add(kr);
1776                                         break;
1777                                 case Name:
1778                                         Name n = new Name();
1779                                         n.setLang(lang);
1780                                         n.setValue(parameters);
1781                                         fb.getName().add(n);
1782                                         break;
1783                                 case tmodel:
1784                                         fb.setTModelBag(new TModelBag());
1785                                         fb.getTModelBag().getTModelKey().add(parameters);
1786                                         break;
1787                                 case uid:
1788                                         BusinessEntity t = GetBusinessDetails(parameters);
1789                                         findBusiness = new BusinessList();
1790                                         if (t != null) {
1791                                                 findBusiness.setBusinessInfos(new BusinessInfos());
1792                                                 BusinessInfo bd = new BusinessInfo();
1793                                                 bd.setBusinessKey(t.getBusinessKey());
1794                                                 bd.getName().addAll(t.getName());
1795                                                 findBusiness.getBusinessInfos().getBusinessInfo().add(bd);
1796                                         }
1797                                         break;
1798 
1799                         }
1800                         if (findBusiness == null) {
1801 
1802                                 try {
1803                                         findBusiness = inquiry.findBusiness(fb);
1804                                 } catch (Exception ex) {
1805                                         if (isExceptionExpiration(ex)) {
1806                                                 token = null;
1807                                                 fb.setAuthInfo(GetToken());
1808                                                 findBusiness = inquiry.findBusiness(fb);
1809 
1810                                         } else {
1811                                                 throw ex;
1812                                         }
1813                                 }
1814                         }
1815                         if (findBusiness != null && findBusiness.getBusinessInfos() != null) {
1816                                 StringBuilder sb = new StringBuilder();
1817                                 sb.append("<table class=\"table\">");
1818                                 for (int i = 0; i < findBusiness.getBusinessInfos().getBusinessInfo().size(); i++) {
1819                                         sb.append("<tr><td>");
1820                                         sb.append("<a href=\"businessEditor2.jsp?id=").
1821                                              append(StringEscapeUtils.escapeHtml(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getBusinessKey())).
1822                                              append("\">");
1823                                         if (findBusiness.getBusinessInfos().getBusinessInfo().get(i).getName().isEmpty()) {
1824                                                 sb.append(StringEscapeUtils.escapeHtml(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getBusinessKey()));
1825                                         } else {
1826                                                 sb.append(StringEscapeUtils.escapeHtml(Printers.ListNamesToString(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getName())));
1827                                         }
1828                                         sb.append("</a>");
1829                                         sb.append("</td></tr>");
1830                                 }
1831                                 sb.append("</table>");
1832                                 return sb.toString();
1833                         } else {
1834                                 return ResourceLoader.GetResource(session, "errors.norecordsfound");
1835                         }
1836                 } catch (Exception ex) {
1837                         return HandleException(ex);
1838                 }
1839         }
1840 
1841         private String FindRelatedBusiness(CriteriaType criteria, String parameters, String lang, String[] fq) {
1842                 try {
1843                         FindRelatedBusinesses fb = new FindRelatedBusinesses();
1844                         fb.setAuthInfo(GetToken());
1845                         fb.setBusinessKey(parameters);
1846                         RelatedBusinessesList findBusiness = null;
1847                         switch (criteria) {
1848                                 case Category:
1849                                         break;
1850                                 case Name:
1851                                         break;
1852                                 case tmodel:
1853                                         break;
1854                                 case uid:
1855                                         break;
1856                         }
1857 
1858                         try {
1859                                 findBusiness = inquiry.findRelatedBusinesses(fb);
1860                         } catch (Exception ex) {
1861                                 if (isExceptionExpiration(ex)) {
1862                                         token = null;
1863                                         fb.setAuthInfo(GetToken());
1864                                         findBusiness = inquiry.findRelatedBusinesses(fb);
1865 
1866                                 } else {
1867                                         throw ex;
1868                                 }
1869                         }
1870 
1871                         if (findBusiness != null && findBusiness.getRelatedBusinessInfos() != null) {
1872                                 StringBuilder sb = new StringBuilder();
1873                                 sb.append("<table class=\"table table-hover\">");
1874                                 sb.append("<tr><th>").append(ResourceLoader.GetResource(session, "items.business")).append("</th><th>").append(ResourceLoader.GetResource(session, "items.publisherassertions.relationship")).append("</th><tr>");
1875                                 for (int i = 0; i < findBusiness.getRelatedBusinessInfos().getRelatedBusinessInfo().size(); i++) {
1876                                         sb.append("<tr><td>");
1877                                         sb.append("<a href=\"businessEditor2.jsp?id=").
1878                                              append(StringEscapeUtils.escapeHtml(findBusiness.getRelatedBusinessInfos().getRelatedBusinessInfo().get(i).getBusinessKey())).
1879                                              append("\">");
1880                                         if (findBusiness.getRelatedBusinessInfos().getRelatedBusinessInfo().get(i).getName().isEmpty()) {
1881                                                 sb.append(StringEscapeUtils.escapeHtml(findBusiness.getRelatedBusinessInfos().getRelatedBusinessInfo().get(i).getBusinessKey()));
1882                                         } else {
1883                                                 sb.append(StringEscapeUtils.escapeHtml(Printers.ListNamesToString(findBusiness.getRelatedBusinessInfos().getRelatedBusinessInfo().get(i).getName())));
1884                                         }
1885                                         sb.append("</a>");
1886 
1887                                         sb.append("</td><td>");
1888                                         sb.append(Printers.PrintPublisherAssertion(findBusiness.getRelatedBusinessInfos().getRelatedBusinessInfo().get(i).getSharedRelationships(), getLocale()));
1889                                         sb.append("</td></tr>");
1890                                 }
1891                                 sb.append("</table>");
1892                                 return sb.toString();
1893                         } else {
1894                                 return ResourceLoader.GetResource(session, "errors.norecordsfound");
1895                         }
1896                 } catch (Exception ex) {
1897                         return HandleException(ex);
1898                 }
1899         }
1900 
1901         private String FindService(CriteriaType criteria, String parameters, String lang, String[] fq) {
1902                 try {
1903                         FindService fb = new FindService();
1904                         fb.setAuthInfo(GetToken());
1905                         if (fq != null) {
1906                                 fb.setFindQualifiers(new org.uddi.api_v3.FindQualifiers());
1907                                 if (fq != null) {
1908                                         fb.getFindQualifiers().getFindQualifier().addAll(Arrays.asList(fq));
1909                                 }
1910                         }
1911                         ServiceList findBusiness = null;
1912                         switch (criteria) {
1913                                 case Category:
1914                                         fb.setCategoryBag(new CategoryBag());
1915                                         KeyedReference kr = new KeyedReference();
1916                                         kr.setTModelKey(parameters);
1917                                         kr.setKeyName("%");
1918                                         kr.setKeyValue("%");
1919                                         fb.getCategoryBag().getKeyedReference().add(kr);
1920                                         break;
1921                                 case Name:
1922                                         Name n = new Name();
1923                                         n.setLang(lang);
1924                                         n.setValue(parameters);
1925                                         fb.getName().add(n);
1926                                         break;
1927                                 case tmodel:
1928                                         fb.setTModelBag(new TModelBag());
1929                                         fb.getTModelBag().getTModelKey().add(parameters);
1930                                         break;
1931                                 case uid:
1932 
1933                                         findBusiness = new ServiceList();
1934 
1935                                         BusinessService GetServiceDetail = GetServiceDetail(parameters);
1936                                         if (GetServiceDetail != null) {
1937                                                 findBusiness.setServiceInfos(new ServiceInfos());
1938                                                 ServiceInfo si = new ServiceInfo();
1939                                                 si.setBusinessKey(GetServiceDetail.getBusinessKey());
1940                                                 si.setServiceKey(GetServiceDetail.getServiceKey());
1941                                                 si.getName().addAll(GetServiceDetail.getName());
1942                                                 findBusiness.getServiceInfos().getServiceInfo().add(si);
1943                                         }
1944                                         break;
1945 
1946                         }
1947                         if (findBusiness == null) {
1948                                 try {
1949                                         findBusiness = inquiry.findService(fb);
1950                                 } catch (Exception ex) {
1951                                         if (isExceptionExpiration(ex)) {
1952                                                 token = null;
1953                                                 fb.setAuthInfo(GetToken());
1954                                                 findBusiness = inquiry.findService(fb);
1955 
1956                                         } else {
1957                                                 throw ex;
1958                                         }
1959                                 }
1960 
1961                         }
1962                         if (findBusiness != null && findBusiness.getServiceInfos() != null) {
1963                                 StringBuilder sb = new StringBuilder();
1964                                 sb.append("<table class=\"table\">");
1965                                 for (int i = 0; i < findBusiness.getServiceInfos().getServiceInfo().size(); i++) {
1966                                         sb.append("<tr><td>");
1967                                         sb.append("<a href=\"serviceEditor.jsp?id=").
1968                                              append(StringEscapeUtils.escapeHtml(findBusiness.getServiceInfos().getServiceInfo().get(i).getServiceKey())).
1969                                              append("\">");
1970                                         if (findBusiness.getServiceInfos().getServiceInfo().get(i).getName().isEmpty()) {
1971                                                 sb.append(StringEscapeUtils.escapeHtml(findBusiness.getServiceInfos().getServiceInfo().get(i).getServiceKey()));
1972                                         } else {
1973                                                 sb.append(StringEscapeUtils.escapeHtml(Printers.ListNamesToString(findBusiness.getServiceInfos().getServiceInfo().get(i).getName())));
1974                                         }
1975                                         sb.append("</a>");
1976                                         sb.append("</td></tr>");
1977                                 }
1978                                 sb.append("</table>");
1979                                 return sb.toString();
1980                         } else {
1981                                 return ResourceLoader.GetResource(session, "errors.norecordsfound");
1982                         }
1983                 } catch (Exception ex) {
1984                         return HandleException(ex);
1985                 }
1986         }
1987 
1988         private String FindtModels(CriteriaType criteria, String parameters, String lang, String[] fq) {
1989                 try {
1990                         FindTModel fb = new FindTModel();
1991                         fb.setAuthInfo(GetToken());
1992                         if (fq != null) {
1993                                 fb.setFindQualifiers(new org.uddi.api_v3.FindQualifiers());
1994 
1995                                 for (int i = 0; i < fq.length; i++) {
1996                                         fb.getFindQualifiers().getFindQualifier().add(fq[i]);
1997                                 }
1998 
1999                         }
2000                         TModelList findBusiness = null;
2001                         switch (criteria) {
2002                                 case Category:
2003                                         fb.setCategoryBag(new CategoryBag());
2004                                         KeyedReference kr = new KeyedReference();
2005                                         kr.setTModelKey(parameters);
2006                                         kr.setKeyName("%");
2007                                         kr.setKeyValue("%");
2008                                         fb.getCategoryBag().getKeyedReference().add(kr);
2009                                         break;
2010                                 case Name:
2011                                         Name n = new Name();
2012                                         n.setLang(lang);
2013                                         n.setValue(parameters);
2014                                         fb.setName(n);
2015                                         break;
2016                                 case tmodel:
2017                                         fb.setCategoryBag(new CategoryBag());
2018                                         KeyedReference kr2 = new KeyedReference();
2019                                         kr2.setTModelKey(parameters);
2020                                         kr2.setKeyName("%");
2021                                         kr2.setKeyValue("%");
2022                                         fb.getCategoryBag().getKeyedReference().add(kr2);
2023                                         break;
2024                                 case uid:
2025                                         TModel tmodelDetails = this.getTmodelDetails(parameters);
2026                                         findBusiness = new TModelList();
2027                                         if (tmodelDetails != null) {
2028                                                 findBusiness.setTModelInfos(new TModelInfos());
2029                                                 TModelInfo tmi = new TModelInfo();
2030                                                 tmi.setName(tmodelDetails.getName());
2031                                                 tmi.setTModelKey(tmodelDetails.getTModelKey());
2032                                                 tmi.getDescription().addAll(tmodelDetails.getDescription());
2033                                                 findBusiness.getTModelInfos().getTModelInfo().add(tmi);
2034                                         }
2035                                         break;
2036 
2037                         }
2038                         if (findBusiness == null) {
2039                                 try {
2040                                         findBusiness = inquiry.findTModel(fb);
2041                                 } catch (Exception ex) {
2042                                         if (isExceptionExpiration(ex)) {
2043                                                 token = null;
2044                                                 fb.setAuthInfo(GetToken());
2045                                                 findBusiness = inquiry.findTModel(fb);
2046 
2047                                         } else {
2048                                                 throw ex;
2049                                         }
2050                                 }
2051 
2052                         }
2053                         if (findBusiness != null && findBusiness.getTModelInfos() != null) {
2054                                 StringBuilder sb = new StringBuilder();
2055                                 sb.append("<table class=\"table\">");
2056                                 for (int i = 0; i < findBusiness.getTModelInfos().getTModelInfo().size(); i++) {
2057                                         sb.append("<tr><td>");
2058                                         sb.append("<a href=\"tmodelEditor.jsp?id=").
2059                                              append(StringEscapeUtils.escapeHtml(findBusiness.getTModelInfos().getTModelInfo().get(i).getTModelKey())).
2060                                              append("\">");
2061                                         if (findBusiness.getTModelInfos().getTModelInfo().get(i).getName() == null) {
2062                                                 sb.append(StringEscapeUtils.escapeHtml(findBusiness.getTModelInfos().getTModelInfo().get(i).getTModelKey()));
2063                                         } else {
2064                                                 sb.append(StringEscapeUtils.escapeHtml((findBusiness.getTModelInfos().getTModelInfo().get(i).getName().getValue())));
2065                                         }
2066                                         sb.append("</a>");
2067                                         sb.append("</td></tr>");
2068                                 }
2069                                 sb.append("</table>");
2070                                 return sb.toString();
2071                         } else {
2072                                 return ResourceLoader.GetResource(session, "errors.norecordsfound");
2073                         }
2074                 } catch (Exception ex) {
2075                         return HandleException(ex);
2076                 }
2077         }
2078 
2079         /**
2080          * Deletes a business
2081          *
2082          * @param bizid
2083          * @return null if successful, otherwise an error message
2084          */
2085         public String deleteBusiness(String bizid) {
2086                 if (bizid == null || bizid.length() == 0) {
2087                         return ResourceLoader.GetResource(session, "errors.noinput");
2088                 }
2089                 List<String> x = new ArrayList<String>();
2090                 x.add(bizid.trim());
2091                 return deleteBusiness(x);
2092         }
2093 
2094         /**
2095          * delete a service
2096          *
2097          * @param serviceId
2098          * @return status msg
2099          */
2100         public String deleteService(String serviceId) {
2101                 if (serviceId == null || serviceId.length() == 0) {
2102                         return ResourceLoader.GetResource(session, "errors.noinput");
2103                 }
2104                 List<String> x = new ArrayList<String>();
2105                 x.add(serviceId.trim());
2106                 return deleteService(x);
2107         }
2108 
2109         /**
2110          * deletes a list of services
2111          *
2112          * @param serviceId
2113          * @return status msg
2114          */
2115         public String deleteService(List<String> serviceId) {
2116                 if (serviceId == null || serviceId.isEmpty()) {
2117                         return ResourceLoader.GetResource(session, "errors.noinput");
2118                 }
2119                 DeleteService db = new DeleteService();
2120                 db.setAuthInfo(GetToken());
2121                 db.getServiceKey().addAll(serviceId);
2122                 try {
2123                         try {
2124                                 publish.deleteService(db);
2125                         } catch (Exception ex) {
2126                                 if (isExceptionExpiration(ex)) {
2127                                         token = null;
2128                                         db.setAuthInfo(GetToken());
2129                                         publish.deleteService(db);
2130 
2131                                 } else {
2132                                         throw ex;
2133                                 }
2134                         }
2135                 } catch (Exception ex) {
2136                         return HandleException(ex);
2137                 }
2138                 return ResourceLoader.GetResource(session, "actions.delete.service");
2139         }
2140 
2141         /**
2142          * Deletes a list of UDDI businesses by key
2143          *
2144          * @param bizid
2145          * @return null if successful, otherwise an error message
2146          */
2147         public String deleteBusiness(List<String> bizid) {
2148                 if (bizid == null || bizid.isEmpty()) {
2149                         return ResourceLoader.GetResource(session, "errors.noinput");
2150                 }
2151                 DeleteBusiness db = new DeleteBusiness();
2152                 db.setAuthInfo(GetToken());
2153                 db.getBusinessKey().addAll(bizid);
2154                 try {
2155                         try {
2156                                 publish.deleteBusiness(db);
2157                         } catch (Exception ex) {
2158                                 if (isExceptionExpiration(ex)) {
2159                                         token = null;
2160                                         db.setAuthInfo(GetToken());
2161                                         publish.deleteBusiness(db);
2162 
2163                                 } else {
2164                                         throw ex;
2165                                 }
2166                         }
2167                 } catch (Exception ex) {
2168                         return HandleException(ex);
2169                 }
2170                 return ResourceLoader.GetResource(session, "actions.delete.business");
2171         }
2172 
2173         /**
2174          * delete a tmodel
2175          *
2176          * @param bizid
2177          * @return status msg
2178          */
2179         public String deleteTmodel(String bizid) {
2180                 if (bizid == null || bizid.length() == 0) {
2181                         return ResourceLoader.GetResource(session, "errors.noinput");
2182                 }
2183                 List<String> x = new ArrayList<String>();
2184                 x.add(bizid);
2185                 return deleteTmodel(x);
2186         }
2187 
2188         /**
2189          * Deletes a list of UDDI tModels by key
2190          *
2191          * @param bizid
2192          * @return null if successful, otherwise an error message
2193          */
2194         public String deleteTmodel(List<String> bizid) {
2195                 if (bizid == null || bizid.isEmpty()) {
2196                         return ResourceLoader.GetResource(session, "errors.noinput");
2197                 }
2198                 DeleteTModel db = new DeleteTModel();
2199                 db.setAuthInfo(GetToken());
2200                 db.getTModelKey().addAll(bizid);
2201                 try {
2202                         try {
2203                                 publish.deleteTModel(db);
2204                         } catch (Exception ex) {
2205                                 if (isExceptionExpiration(ex)) {
2206                                         token = null;
2207                                         db.setAuthInfo(GetToken());
2208                                         publish.deleteTModel(db);
2209 
2210                                 } else {
2211                                         throw ex;
2212                                 }
2213                         }
2214                 } catch (Exception ex) {
2215                         return HandleException(ex);
2216                 }
2217                 return ResourceLoader.GetResource(session, "actions.delete.tmodel");
2218         }
2219 
2220         /**
2221          * saves a tmodel object
2222          *
2223          * @param be
2224          * @return status msg
2225          */
2226         public String SaveTModel(TModel be) {
2227                 try {
2228                         SaveTModel sb = new SaveTModel();
2229                         sb.setAuthInfo(GetToken());
2230                         TModelDetail saveTModel = null;
2231                         sb.getTModel().add(be);
2232                         //JAXB.marshal(be, System.out);
2233                         try {
2234                                 saveTModel = publish.saveTModel(sb);
2235                         } catch (Exception ex) {
2236                                 if (isExceptionExpiration(ex)) {
2237                                         token = null;
2238                                         sb.setAuthInfo(GetToken());
2239                                         saveTModel = publish.saveTModel(sb);
2240 
2241                                 } else {
2242                                         throw ex;
2243                                 }
2244                         }
2245                         //return ResourceLoader.GetResource(session, "actions.saved");
2246                         return ResourceLoader.GetResource(session, "actions.saved") + 
2247                                 " <script type=\"text/javascript\">window.location.href='"+
2248                                 StringEscapeUtils.escapeJavaScript("tmodelEditor.jsp?id=" + URLEncoder.encode(saveTModel.getTModel().get(0).getTModelKey(), "UTF8")) + "';</script>"
2249                              + "<a href=\"tmodelEditor.jsp?id=" + URLEncoder.encode(saveTModel.getTModel().get(0).getTModelKey(), "UTF8")
2250                              + "\">" + StringEscapeUtils.escapeHtml(saveTModel.getTModel().get(0).getTModelKey()) + "</a>";
2251                 } catch (Exception ex) {
2252                         return HandleException(ex);
2253                 }
2254         }
2255 
2256         /**
2257          * This rebuild a tmodel from the http request, such as from the tmodel
2258          * editor page
2259          *
2260          * @param request
2261          * @return status msg
2262          */
2263         public String SaveTModel(HttpServletRequest request) {
2264 
2265                 TModel be = new TModel();
2266                 be.setTModelKey(request.getParameter(PostBackConstants.SERVICEKEY).trim());
2267                 if (be.getTModelKey() != null && (be.getTModelKey().equalsIgnoreCase(ResourceLoader.GetResource(session, "items.clicktoedit")))
2268                      || be.getTModelKey().length() == 0) {
2269                         be.setTModelKey(null);
2270                 }
2271                 be.setName(new Name());
2272                 String t = request.getParameter(PostBackConstants.NAME + PostBackConstants.VALUE);
2273                 if (t != null && !t.equalsIgnoreCase(ResourceLoader.GetResource(session, "items.clicktoedit")) && t.length() > 0) {
2274                         be.getName().setValue(t);
2275                 }
2276                 t = request.getParameter(PostBackConstants.NAME + PostBackConstants.LANG);
2277                 if (t != null && !t.equalsIgnoreCase(ResourceLoader.GetResource(session, "items.clicktoedit")) && t.length() > 0) {
2278                         be.getName().setLang(t);
2279                 }
2280 
2281                 t = request.getParameter(PostBackConstants.TMODEL_DELETED);
2282                 if (t != null) {
2283                         if (t.equalsIgnoreCase("checked")) {
2284                                 be.setDeleted(Boolean.TRUE);
2285                         }
2286                 }
2287                 if (!be.isDeleted()) {
2288                         be.setDeleted(Boolean.FALSE);
2289                 }
2290 
2291                 be.getDescription().addAll(Builders.BuildDescription(Builders.MapFilter(request.getParameterMap(), PostBackConstants.DESCRIPTION), PostBackConstants.DESCRIPTION, ResourceLoader.GetResource(session, "items.clicktoedit"), getLocale()));
2292                 be.getOverviewDoc().addAll(Builders.BuildOverviewDocs(Builders.MapFilter(request.getParameterMap(), PostBackConstants.OVERVIEW), PostBackConstants.OVERVIEW, ResourceLoader.GetResource(session, "items.clicktoedit"), getLocale()));
2293 
2294                 CategoryBag cb = new CategoryBag();
2295                 cb.getKeyedReference().addAll(Builders.BuildKeyedReference(Builders.MapFilter(request.getParameterMap(), PostBackConstants.CATBAG_KEY_REF), PostBackConstants.CATBAG_KEY_REF, getLocale()));
2296                 cb.getKeyedReferenceGroup().addAll(Builders.BuildKeyedReferenceGroup(Builders.MapFilter(request.getParameterMap(), PostBackConstants.CATBAG_KEY_REF_GRP), PostBackConstants.CATBAG_KEY_REF_GRP, getLocale()));
2297 
2298                 if (!cb.getKeyedReference().isEmpty() || !cb.getKeyedReferenceGroup().isEmpty()) {
2299                         be.setCategoryBag(cb);
2300                 }
2301                 be.setIdentifierBag(Builders.BuildIdentBag(Builders.MapFilter(request.getParameterMap(), PostBackConstants.IDENT_KEY_REF), PostBackConstants.IDENT_KEY_REF, getLocale()));
2302 
2303                 return SaveTModel(be);
2304 
2305         }
2306 
2307         /**
2308          * Converts a UDDI Signature to a readable representation of the signing
2309          * certificate subject name
2310          *
2311          * @param sig
2312          * @return human readable signature
2313          */
2314         public static String SignatureToReadable(SignatureType sig) {
2315                 StringBuilder sb = new StringBuilder();
2316                 // X509Certificate signingcert = null;
2317                 //sb.append("Signature Id: ").append(sig.getKeyInfo().getId());
2318                 for (int i = 0; i < sig.getKeyInfo().getContent().size(); i++) {
2319                         //sb.append("Signature #").append((i + 1)).append(": ");
2320                         JAXBElement get = (JAXBElement) sig.getKeyInfo().getContent().get(i);
2321 
2322                         if (get.getValue() instanceof org.w3._2000._09.xmldsig_.X509DataType) {
2323                                 X509DataType xd = (X509DataType) get.getValue();
2324                                 for (int k = 0; k < xd.getX509IssuerSerialOrX509SKIOrX509SubjectName().size(); k++) {
2325                                         if (xd.getX509IssuerSerialOrX509SKIOrX509SubjectName().get(k) instanceof JAXBElement) {
2326                                                 JAXBElement element = (JAXBElement) xd.getX509IssuerSerialOrX509SKIOrX509SubjectName().get(k);
2327                                                 if (element.getValue() instanceof byte[]) {
2328                                                         try {
2329                                                                 CertificateFactory cf = CertificateFactory.getInstance("X.509");
2330                                                                 InputStream is = new ByteArrayInputStream((byte[]) element.getValue());
2331                                                                 X509Certificate cert = (X509Certificate) cf.generateCertificate(is);
2332                                                                 is.close();
2333                                                                 sb.append(cert.getSubjectDN().getName());
2334                                                         } catch (Exception ex) {
2335                                                         }
2336                                                 } else if (element.getValue() instanceof String) {
2337                                                         // sb.append((String) element.getValue());
2338                                                 }
2339                                         }
2340                                 }
2341                         }
2342                 }
2343                 return sb.toString();
2344         }
2345 
2346         /**
2347          * converts a UDDI Signature Type element into a base64 string
2348          * containing the raw data for the signing certificate, if present
2349          *
2350          * @param sig
2351          * @return x509 cert
2352          */
2353         public String SignatureToBase64(SignatureType sig) {
2354                 if (sig == null) {
2355                         return "Error, the signature was nullavailable";
2356                 }
2357                 for (int i = 0; i < sig.getKeyInfo().getContent().size(); i++) {
2358                         JAXBElement get = (JAXBElement) sig.getKeyInfo().getContent().get(i);
2359 
2360                         if (get.getValue() instanceof org.w3._2000._09.xmldsig_.X509DataType) {
2361                                 X509DataType xd = (X509DataType) get.getValue();
2362                                 for (int k = 0; k < xd.getX509IssuerSerialOrX509SKIOrX509SubjectName().size(); k++) {
2363                                         if (xd.getX509IssuerSerialOrX509SKIOrX509SubjectName().get(k) instanceof JAXBElement) {
2364                                                 JAXBElement element = (JAXBElement) xd.getX509IssuerSerialOrX509SKIOrX509SubjectName().get(k);
2365                                                 if (element.getValue() instanceof byte[]) {
2366                                                         try {
2367                                                                 CertificateFactory cf = CertificateFactory.getInstance("X.509");
2368                                                                 InputStream is = new ByteArrayInputStream((byte[]) element.getValue());
2369                                                                 X509Certificate cert = (X509Certificate) cf.generateCertificate(is);
2370                                                                 is.close();
2371                                                                 //this is the most supportable way to do this
2372                                                                 return org.apache.commons.codec.binary.Base64.encodeBase64String(cert.getEncoded());
2373                                                                 //BASE64Encoder encoder = new BASE64Encoder();
2374                                                                 //return encoder.encodeBuffer(cert.getEncoded());
2375 
2376                                                         } catch (Exception ex) {
2377                                                                 return HandleException(ex);
2378                                                         }
2379                                                 } else if (element.getValue() instanceof String) {
2380                                                 }
2381                                         }
2382                                 }
2383                         }
2384                 }
2385                 return ResourceLoader.GetResource(session, "errors.nocertavaiable");
2386         }
2387 
2388         /**
2389          * Retrieves the UDDI entity, then attempts to return a base64 encoded
2390          * certificate of the N'th indexed signature
2391          *
2392          * @param ft The type of item requested
2393          * @param id the unique identifier of the entity
2394          * @param index the offset of the signature, starting at 0
2395          * @return the base64 encoded certification, omitting headers and
2396          * footers OR "Error" with an error message
2397          */
2398         public String GetCertificate(FindType ft, String id, int index) {
2399                 SignatureType st = null;
2400                 switch (ft) {
2401                         case BindingTemplate:
2402                                 BindingTemplate GetBindingDetailsAsObject = GetBindingDetailsAsObject(id);
2403                                 if (GetBindingDetailsAsObject != null) {
2404                                         return SignatureToBase64(GetBindingDetailsAsObject.getSignature().get(index));
2405                                 }
2406                                 break;
2407                         case Business:
2408                                 BusinessEntity GetBusinessDetailsAsObject = GetBusinessDetailsAsObject(id);
2409                                 if (GetBusinessDetailsAsObject != null) {
2410                                         return SignatureToBase64(GetBusinessDetailsAsObject.getSignature().get(index));
2411                                 }
2412                                 break;
2413                         case Service:
2414                                 BusinessService GetServiceDetailsAsObject = GetServiceDetailsAsObject(id);
2415                                 if (GetServiceDetailsAsObject != null) {
2416                                         return SignatureToBase64(GetServiceDetailsAsObject.getSignature().get(index));
2417                                 }
2418                                 break;
2419                         case tModel:
2420                                 TModel GettModelDetailsAsObject = GettModelDetailsAsObject(id);
2421                                 if (GettModelDetailsAsObject != null) {
2422                                         return SignatureToBase64(GettModelDetailsAsObject.getSignature().get(index));
2423                                 }
2424                                 break;
2425 
2426                 }
2427                 return ResourceLoader.GetResource(session, "errors.unknownentity");
2428         }
2429 
2430         /**
2431          * gets all of my subscriptions
2432          *
2433          * @return null if there's an error
2434          */
2435         public List<Subscription> GetSubscriptions() {
2436                 try {
2437                         try {
2438                                 return subscription.getSubscriptions(GetToken());
2439                         } catch (Exception ex) {
2440                                 if (isExceptionExpiration(ex)) {
2441                                         token = null;
2442                                         return subscription.getSubscriptions(GetToken());
2443 
2444                                 } else {
2445                                         throw ex;
2446                                 }
2447                         }
2448                 } catch (Exception ex) {
2449                         HandleException(ex);
2450                 }
2451                 return null;
2452         }
2453 
2454         /**
2455          * attempts to save subscription
2456          *
2457          * @param sub
2458          * @return a success or fail message
2459          */
2460         public String AddSubscription(Subscription sub) {
2461                 Holder<List<Subscription>> data = new Holder<List<Subscription>>();
2462                 data.value = new ArrayList<Subscription>();
2463                 data.value.add(sub);
2464                 try {
2465                         try {
2466                                 subscription.saveSubscription(GetToken(), data);
2467                         } catch (Exception ex) {
2468                                 if (isExceptionExpiration(ex)) {
2469                                         token = null;
2470                                         subscription.saveSubscription(GetToken(), data);
2471 
2472                                 } else {
2473                                         throw ex;
2474                                 }
2475                         }
2476                         return ResourceLoader.GetResource(session, "messages.success")
2477                              + " <a href=\"editSubscription.jsp?id=" + URLEncoder.encode(data.value.get(0).getSubscriptionKey(), "UTF8")
2478                              + "\">" + StringEscapeUtils.escapeHtml(data.value.get(0).getSubscriptionKey()) + "</a>";
2479                 } catch (Exception ex) {
2480                         return HandleException(ex);
2481                 }
2482         }
2483 
2484         /**
2485          * Removes/deletes a subscription
2486          *
2487          * @param key
2488          * @return success or failure message
2489          */
2490         public String RemoveSubscription(String key) {
2491                 DeleteSubscription ds = new DeleteSubscription();
2492                 ds.setAuthInfo(GetToken());
2493                 ds.getSubscriptionKey().add(key);
2494                 try {
2495                         try {
2496                                 subscription.deleteSubscription(ds);
2497                                 return ResourceLoader.GetResource(session, "actions.deleted");
2498                         } catch (Exception ex) {
2499                                 if (isExceptionExpiration(ex)) {
2500                                         token = null;
2501                                         ds.setAuthInfo(GetToken());
2502                                         subscription.deleteSubscription(ds);
2503                                         return ResourceLoader.GetResource(session, "actions.deleted");
2504 
2505                                 } else {
2506                                         throw ex;
2507                                 }
2508                         }
2509                 } catch (Exception ex) {
2510                         return HandleException(ex);
2511                 }
2512                 // return ResourceLoader.GetResource(session, "messages.success");
2513         }
2514 
2515         /**
2516          * gets the opinfo on an item
2517          *
2518          * @param id
2519          * @return null if theres an error
2520          */
2521         public List<OperationalInfo> GetOperationalInfo(String id) {
2522                 if (id == null || id.equalsIgnoreCase("null")) {
2523                         return null;
2524                 }
2525                 GetOperationalInfo goi = new GetOperationalInfo();
2526                 goi.setAuthInfo(GetToken());
2527                 goi.getEntityKey().add(id);
2528                 OperationalInfos operationalInfo = null;
2529                 try {
2530                         try {
2531                                 operationalInfo = inquiry.getOperationalInfo(goi);
2532                         } catch (Exception ex) {
2533                                 if (isExceptionExpiration(ex)) {
2534                                         token = null;
2535                                         goi.setAuthInfo(GetToken());
2536                                         operationalInfo = inquiry.getOperationalInfo(goi);
2537                                 } else {
2538                                         throw ex;
2539                                 }
2540                         }
2541 
2542                         return operationalInfo.getOperationalInfo();
2543                 } catch (Exception ex) {
2544                         HandleException(ex);
2545                 }
2546                 return null;
2547         }
2548 
2549         /**
2550          * GetOperationalInfo
2551          *
2552          * @param info
2553          * @return formatted html
2554          */
2555         public String GetOperationalInfo(List<OperationalInfo> info) {
2556                 StringBuilder sb = new StringBuilder();
2557 
2558                 if (info != null && !info.isEmpty()) {
2559                         sb.append("<table class=\"table table-hover\">");
2560                         sb.append("<tr><th>").
2561                              append(ResourceLoader.GetResource(session, "items.nodeid")).
2562                              append("</th><th>").
2563                              append(ResourceLoader.GetResource(session, "items.authorizedname")).
2564                              append("</th><th>").
2565                              append(ResourceLoader.GetResource(session, "items.key")).
2566                              append("</th><th>").
2567                              append(ResourceLoader.GetResource(session, "items.created")).
2568                              append("</th><th>").
2569                              append(ResourceLoader.GetResource(session, "items.modified")).
2570                              append("</th><th>").
2571                              append(ResourceLoader.GetResource(session, "items.modifiedwithchildren")).
2572                              append("</th></tr>");
2573 
2574                         for (int i = 0; i < info.size(); i++) {
2575                                 if (info.get(i) == null) {
2576                                         continue;
2577                                 }
2578                                 sb.append("<tr><td>");
2579                                 sb.append((info.get(i).getNodeID() != null ? StringEscapeUtils.escapeHtml(info.get(i).getNodeID()) : ""))
2580                                      .append("</td><td>")
2581                                      .append((info.get(i).getAuthorizedName() != null ? StringEscapeUtils.escapeHtml(info.get(i).getAuthorizedName()) : ""))
2582                                      .append("</td><td>")
2583                                      .append((info.get(i).getEntityKey() != null ? StringEscapeUtils.escapeHtml(info.get(i).getEntityKey()) : ""))
2584                                      .append("</td><td>")
2585                                      .append((info.get(i).getCreated() != null ? StringEscapeUtils.escapeHtml(info.get(i).getCreated().toString()) : ""))
2586                                      .append("</td><td>")
2587                                      .append((info.get(i).getModified() != null ? StringEscapeUtils.escapeHtml(info.get(i).getModified().toString()) : ""))
2588                                      .append("</td><td>")
2589                                      .append((info.get(i).getModifiedIncludingChildren() != null ? StringEscapeUtils.escapeHtml(info.get(i).getModifiedIncludingChildren().toString()) : ""))
2590                                      .append("</td></tr>");
2591                         }
2592                         sb.append("</table>");
2593                 } else {
2594                         sb.append(ResourceLoader.GetResource(session, "errors.nooperationalinfo"));
2595                 }
2596                 return sb.toString();
2597         }
2598 
2599         /**
2600          * This function returns all businesses that the current user
2601          * owns<br><br>
2602          * The get_registeredInfo API call is used to get an abbreviated list of
2603          * all businessEntity and tModel data that are controlled by a
2604          * publisher. When the registry distinguishes between publishers, this
2605          * is the individual associated with the credentials passed in the
2606          * authInfo element. This returned information is intended, for example,
2607          * for driving tools that display lists of registered information and
2608          * then provide drill-down features. This is the recommended API to use
2609          * after a network problem results in an unknown status of saved
2610          * information.
2611          *
2612          * @return RegisteredInfo
2613          */
2614         public RegisteredInfo GetNodeInformation(AtomicReference<String> outmsg) {
2615                 if (outmsg == null) {
2616                         outmsg = new AtomicReference<String>();
2617                 }
2618                 try {
2619                         GetRegisteredInfo r = new GetRegisteredInfo();
2620                         r.setAuthInfo(GetToken());
2621                         if (r.getAuthInfo() == null) {
2622                                 outmsg.set(ResourceLoader.GetResource(session, "errors.notsignedin"));
2623                                 return null;
2624                         }
2625                         r.setInfoSelection(InfoSelection.ALL);
2626                         RegisteredInfo registeredInfo = null;
2627                         try {
2628                                 registeredInfo = publish.getRegisteredInfo(r);
2629                         } catch (Exception ex) {
2630                                 if (isExceptionExpiration(ex)) {
2631                                         token = null;
2632                                         r.setAuthInfo(GetToken());
2633                                         registeredInfo = publish.getRegisteredInfo(r);
2634 
2635                                 } else {
2636                                         throw ex;
2637                                 }
2638                         }
2639                         return registeredInfo;
2640                 } catch (Exception ex) {
2641                         outmsg.set(HandleException(ex));
2642                 }
2643                 return null;
2644         }
2645 
2646         /**
2647          * Gets a list of all assertions for all businesses owned by the current
2648          * user
2649          *
2650          * The get_assertionStatusReport API call provides administrative
2651          * support for determining the status of current and outstanding
2652          * publisher assertions that involve any of the business registrations
2653          * managed by the individual publisher. Using this API, a publisher can
2654          * see the status of assertions that they have made, as well as see
2655          * assertions that others have made that involve businessEntity
2656          * structures controlled by the requesting publisher. See Appendix A
2657          * Relationships and Publisher Assertions for more information.
2658          *
2659          * @param msg
2660          * @return list
2661          */
2662         public List<AssertionStatusItem> GetPublisherAssertions(AtomicReference<String> msg) {
2663                 List<AssertionStatusItem> out = new ArrayList<AssertionStatusItem>();
2664 
2665                 if (GetToken() == null) {
2666                         msg.set(ResourceLoader.GetResource(session, "errors.notsignedin"));
2667                         return null;
2668                 }
2669                 List<AssertionStatusItem> STATUS_COMPLETE = null;
2670 
2671                 try {
2672                         try {
2673                                 STATUS_COMPLETE = publish.getAssertionStatusReport(GetToken(), CompletionStatus.STATUS_COMPLETE);
2674                         } catch (Exception ex) {
2675                                 if (isExceptionExpiration(ex)) {
2676                                         token = null;
2677                                         STATUS_COMPLETE = publish.getAssertionStatusReport(GetToken(), CompletionStatus.STATUS_COMPLETE);
2678 
2679                                 } else {
2680                                         throw ex;
2681                                 }
2682                         }
2683                 } catch (Exception ex) {
2684                         msg.set(HandleException(ex));
2685                 }
2686                 if (STATUS_COMPLETE != null) {
2687                         out.addAll(STATUS_COMPLETE);
2688                 }
2689                 List<AssertionStatusItem> STATUS_FROM_KEY_INCOMPLETE = null;
2690                 try {
2691                         try {
2692                                 STATUS_FROM_KEY_INCOMPLETE = publish.getAssertionStatusReport(GetToken(), CompletionStatus.STATUS_FROM_KEY_INCOMPLETE);
2693                         } catch (Exception ex) {
2694                                 if (isExceptionExpiration(ex)) {
2695                                         token = null;
2696                                         STATUS_FROM_KEY_INCOMPLETE = publish.getAssertionStatusReport(GetToken(), CompletionStatus.STATUS_FROM_KEY_INCOMPLETE);
2697 
2698                                 } else {
2699                                         throw ex;
2700                                 }
2701                         }
2702                 } catch (Exception ex) {
2703                         msg.set(HandleException(ex));
2704                 }
2705                 if (STATUS_FROM_KEY_INCOMPLETE != null) {
2706                         out.addAll(STATUS_FROM_KEY_INCOMPLETE);
2707                 }
2708                 List<AssertionStatusItem> STATUS_TO_KEY_INCOMPLETE = null;
2709                 try {
2710                         try {
2711                                 STATUS_TO_KEY_INCOMPLETE = publish.getAssertionStatusReport(GetToken(), CompletionStatus.STATUS_TO_KEY_INCOMPLETE);
2712 
2713                         } catch (Exception ex) {
2714                                 if (isExceptionExpiration(ex)) {
2715                                         token = null;
2716                                         STATUS_TO_KEY_INCOMPLETE = publish.getAssertionStatusReport(GetToken(), CompletionStatus.STATUS_TO_KEY_INCOMPLETE);
2717 
2718                                 } else {
2719                                         throw ex;
2720                                 }
2721                         }
2722                 } catch (Exception ex) {
2723                         msg.set(HandleException(ex));
2724                 }
2725                 if (STATUS_TO_KEY_INCOMPLETE != null) {
2726                         out.addAll(STATUS_TO_KEY_INCOMPLETE);
2727                 }
2728 
2729                 return out;
2730                 //return publisherAssertions;
2731         }
2732 
2733         /**
2734          * deletes a publisher assertion, all fields must match exactly
2735          *
2736          * @param tokey
2737          * @param fromkey
2738          * @param tmodelkey
2739          * @param keyname
2740          * @param keyvalue
2741          * @return status msg
2742          */
2743         public String DeletePublisherAssertion(String tokey, String fromkey, String tmodelkey, String keyname, String keyvalue) {
2744                 DeletePublisherAssertions dp = new DeletePublisherAssertions();
2745                 dp.setAuthInfo(GetToken());
2746                 PublisherAssertion add = new PublisherAssertion();
2747                 add.setToKey(tokey);
2748                 add.setFromKey(fromkey);
2749                 add.setKeyedReference(new KeyedReference());
2750                 add.getKeyedReference().setTModelKey(tmodelkey);
2751                 add.getKeyedReference().setKeyName(keyname);
2752                 add.getKeyedReference().setKeyValue(keyvalue);
2753                 dp.getPublisherAssertion().add(add);
2754                 try {
2755                         try {
2756                                 publish.deletePublisherAssertions(dp);
2757                         } catch (Exception ex) {
2758                                 if (isExceptionExpiration(ex)) {
2759                                         token = null;
2760                                         dp.setAuthInfo(GetToken());
2761                                         publish.deletePublisherAssertions(dp);
2762 
2763                                 } else {
2764                                         throw ex;
2765                                 }
2766                         }
2767                 } catch (Exception ex) {
2768                         return HandleException(ex);
2769                 }
2770                 return ResourceLoader.GetResource(session, "actions.saved");
2771         }
2772 
2773         /**
2774          * Adds a new publisher assertion
2775          *
2776          * @param tokey
2777          * @param fromkey
2778          * @param keyname
2779          * @param keyvalue
2780          * @return status msg, expected value is actions.saved
2781          */
2782         public String AddPublisherAssertion(String tokey, String fromkey, String tmodelkey, String keyname, String keyvalue) {
2783                 // List<PublisherAssertion> x = GetPublisherAssertions();
2784                 AddPublisherAssertions r = new AddPublisherAssertions();
2785                 r.setAuthInfo(GetToken());
2786                 PublisherAssertion add = new PublisherAssertion();
2787                 add.setToKey(tokey);
2788                 add.setFromKey(fromkey);
2789                 add.setKeyedReference(new KeyedReference());
2790                 add.getKeyedReference().setTModelKey(tmodelkey);
2791                 add.getKeyedReference().setKeyName(keyname);
2792                 add.getKeyedReference().setKeyValue(keyvalue);
2793                 //TODO signatures? :(
2794                 r.getPublisherAssertion().add(add);
2795                 try {
2796                         try {
2797                                 publish.addPublisherAssertions(r);
2798 
2799                         } catch (Exception ex) {
2800                                 if (isExceptionExpiration(ex)) {
2801                                         token = null;
2802                                         r.setAuthInfo(GetToken());
2803                                         publish.addPublisherAssertions(r);
2804 
2805                                 } else {
2806                                         throw ex;
2807                                 }
2808                         }
2809                 } catch (Exception ex) {
2810                         return HandleException(ex);
2811                 }
2812                 return ResourceLoader.GetResource(session, "actions.saved");
2813         }
2814 
2815         /**
2816          * Returns bootstrap stylized html representing all changes in the last
2817          * refresh
2818          *
2819          * @param lastRefresh
2820          * @return formatted html
2821          * @throws DatatypeConfigurationException
2822          */
2823         public String GetNewsFeed(XMLGregorianCalendar lastRefresh) throws DatatypeConfigurationException {
2824                 if (GetToken() == null) {
2825                         return ToErrorAlert(ResourceLoader.GetResource(session, "errors.notsignedin"));
2826                 }
2827                 if (df == null) {
2828                         df = DatatypeFactory.newInstance();
2829                 }
2830                 List<Subscription> subscriptions = new ArrayList<Subscription>();
2831                 try {
2832                         try {
2833                                 subscriptions = subscription.getSubscriptions(GetToken());
2834 
2835                         } catch (Exception ex) {
2836                                 if (isExceptionExpiration(ex)) {
2837                                         token = null;
2838 
2839                                         subscriptions = subscription.getSubscriptions(GetToken());
2840 
2841                                 } else {
2842                                         throw ex;
2843                                 }
2844                         }
2845                 } catch (Exception ex) {
2846                         return HandleException(ex);
2847                 }
2848 
2849                 GregorianCalendar gcal = new GregorianCalendar();
2850                 gcal.setTimeInMillis(System.currentTimeMillis());
2851 
2852                 GetSubscriptionResults r = new GetSubscriptionResults();
2853                 r.setAuthInfo(GetToken());
2854                 r.setCoveragePeriod(new CoveragePeriod());
2855                 r.getCoveragePeriod().setEndPoint(df.newXMLGregorianCalendar(gcal));
2856 
2857                 r.getCoveragePeriod().setStartPoint(lastRefresh);
2858                 StringBuilder sb = new StringBuilder();
2859                 if (subscriptions.isEmpty()) {
2860                         return ToErrorAlert(ResourceLoader.GetResource(session, "errors.subscriptionfeed.nosubs"));
2861                 }
2862                 for (int k = 0; k < subscriptions.size(); k++) {
2863 
2864                         r.setSubscriptionKey(subscriptions.get(k).getSubscriptionKey());
2865                         SubscriptionResultsList subscriptionResults = null;
2866                         try {
2867                                 try {
2868                                         subscriptionResults = subscription.getSubscriptionResults(r);
2869 
2870                                 } catch (Exception ex) {
2871                                         if (isExceptionExpiration(ex)) {
2872                                                 token = null;
2873                                                 r.setAuthInfo(GetToken());
2874                                                 subscriptionResults = subscription.getSubscriptionResults(r);
2875 
2876                                         } else {
2877                                                 throw ex;
2878                                         }
2879                                 }
2880                         } catch (Exception ex) {
2881                                 return HandleException(ex);
2882                         }
2883 
2884                         if (subscriptionResults != null) {
2885                                 //    subscriptionResults.getAssertionStatusReport().
2886                                 if (subscriptionResults.getAssertionStatusReport() != null) {
2887                                         sb.append(ResourceLoader.GetResource(session, "items.subscriptions.assertion")).
2888                                              append("<table class=\"table table-hover\">");
2889                                         for (int i = 0; i < subscriptionResults.getAssertionStatusReport().getAssertionStatusItem().size(); i++) {
2890                                                 sb.append("<tr><td>");
2891                                                 sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getAssertionStatusReport().getAssertionStatusItem().get(i).getFromKey()));
2892                                                 sb.append("</td><td>");
2893                                                 sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getAssertionStatusReport().getAssertionStatusItem().get(i).getToKey()));
2894                                                 sb.append("</td><td>");
2895                                                 sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getAssertionStatusReport().getAssertionStatusItem().get(i).getCompletionStatus().toString()));
2896                                                 sb.append("</td></tr>");
2897                                         }
2898                                         sb.append("</table><br>");
2899                                 }
2900                                 if (subscriptionResults.getBindingDetail() != null) {
2901                                         sb.append(ResourceLoader.GetResource(session, "items.subscriptions.bindings")).
2902                                              append("<table class=\"table table-hover\">");
2903                                         for (int i = 0; i < subscriptionResults.getBindingDetail().getBindingTemplate().size(); i++) {
2904                                                 sb.append("<tr><td>");
2905                                                 sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getBindingDetail().getBindingTemplate().get(i).getServiceKey()));
2906                                                 sb.append("</td><td>");
2907                                                 sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getBindingDetail().getBindingTemplate().get(i).getBindingKey()));
2908                                                 sb.append("</td></tr>");
2909                                         }
2910                                         sb.append("</table><br>");
2911                                 }
2912                                 if (subscriptionResults.getBusinessDetail() != null) {
2913                                         sb.append(ResourceLoader.GetResource(session, "items.subscriptions.business")).
2914                                              append("<table class=\"table table-hover\">");
2915                                         for (int i = 0; i < subscriptionResults.getBusinessDetail().getBusinessEntity().size(); i++) {
2916                                                 sb.append("<tr><td><a href=\"businessEditor2.jsp?id=");
2917                                                 sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getBusinessDetail().getBusinessEntity().get(i).getBusinessKey()));
2918                                                 sb.append("\">");
2919                                                 sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getBusinessDetail().getBusinessEntity().get(i).getBusinessKey()));
2920                                                 sb.append("<i class=\"icon-large icon-edit\"></i></a></td></tr>");
2921                                         }
2922                                         sb.append("</table><br>");
2923                                 }
2924                                 if (subscriptionResults.getRelatedBusinessesList() != null) {
2925                                         sb.append(ResourceLoader.GetResource(session, "items.subscriptions.assertion2")).
2926                                              append("<table class=\"table table-hover\">");
2927                                         // for (int i = 0; i < subscriptionResults.getRelatedBusinessesList().getBusinessKey().size(); i++) {
2928                                         sb.append("<tr><td>");
2929                                         sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getRelatedBusinessesList().getBusinessKey()));
2930                                         sb.append("</td></tr>");
2931                                         //}
2932                                         sb.append("</table><br>");
2933                                 }
2934                                 if (subscriptionResults.getServiceDetail() != null) {
2935                                         sb.append(ResourceLoader.GetResource(session, "items.subscriptions.services")).
2936                                              append("<table class=\"table table-hover\">");
2937                                         for (int i = 0; i < subscriptionResults.getServiceDetail().getBusinessService().size(); i++) {
2938                                                 sb.append("<tr><td><a href=\"serviceEditor.jsp?id=");
2939                                                 sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getServiceDetail().getBusinessService().get(i).getServiceKey()));
2940                                                 sb.append("\">");
2941                                                 sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getServiceDetail().getBusinessService().get(i).getServiceKey()));
2942                                                 sb.append("<i class=\"icon-large icon-edit\"></i></a></td></tr>");
2943                                         }
2944                                         sb.append("</table><br>");
2945                                 }
2946                                 if (subscriptionResults.getServiceList() != null) {
2947                                         sb.append(ResourceLoader.GetResource(session, "items.subscriptions.servicelist")).
2948                                              append("<table class=\"table table-hover\">");
2949                                         for (int i = 0; i < subscriptionResults.getServiceList().getServiceInfos().getServiceInfo().size(); i++) {
2950                                                 sb.append("<tr><td>");
2951                                                 sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getServiceList().getServiceInfos().getServiceInfo().get(i).getServiceKey()));
2952 
2953                                                 sb.append("</td><td>");
2954                                                 sb.append(StringEscapeUtils.escapeHtml(Printers.ListNamesToString(subscriptionResults.getServiceList().getServiceInfos().getServiceInfo().get(i).getName())));
2955                                                 sb.append("</td></tr>");
2956                                         }
2957                                         sb.append("</table><br>");
2958                                 }
2959                                 if (subscriptionResults.getTModelDetail() != null) {
2960                                         sb.append(ResourceLoader.GetResource(session, "items.subscriptions.tmodels")).append("<br><table class=\"table table-hover\">");
2961                                         for (int i = 0; i < subscriptionResults.getTModelDetail().getTModel().size(); i++) {
2962                                                 sb.append("<tr><td>");
2963                                                 sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getTModelDetail().getTModel().get(i).getTModelKey()));
2964                                                 sb.append("</td><td>");
2965                                                 sb.append(StringEscapeUtils.escapeHtml((subscriptionResults.getTModelDetail().getTModel().get(i).getName().getValue())));
2966                                                 sb.append("</td></tr>");
2967                                         }
2968                                         sb.append("</table><br>");
2969                                 }
2970                                 if (subscriptionResults.getTModelList() != null) {
2971                                         sb.append(ResourceLoader.GetResource(session, "items.subscriptions.tmodels2"))
2972                                              .append("<table class=\"table table-hover\">");
2973                                         for (int i = 0; i < subscriptionResults.getTModelList().getTModelInfos().getTModelInfo().size(); i++) {
2974                                                 sb.append("<tr><td><a href=\"serviceEditor.jsp?id=");
2975                                                 sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getTModelList().getTModelInfos().getTModelInfo().get(i).getTModelKey()));
2976                                                 sb.append("\">");
2977                                                 sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getTModelList().getTModelInfos().getTModelInfo().get(i).getTModelKey()));
2978                                                 sb.append("<i class=\"icon-large icon-edit\"></i></a></td><td>");
2979                                                 sb.append(StringEscapeUtils.escapeHtml((subscriptionResults.getTModelList().getTModelInfos().getTModelInfo().get(i).getName().getValue())));
2980                                                 sb.append("</td></tr>");
2981                                         }
2982                                         sb.append("</table>");
2983                                 }
2984 
2985                         }
2986                 }
2987                 return sb.toString();
2988         }
2989 
2990         /**
2991          * Searches first for a service, then iterates through to identify
2992          * bindings matching the specified criteria. Since UDDI does not have name/keyword searches for a
2993          * find_binding API, this is as good as it gets.
2994          *
2995          * @param keyword
2996          * @param lang
2997          * @param offset
2998          * @param maxrecords
2999          * @param isChooser
3000          * @return PagableContainer
3001          */
3002         public PagableContainer SearchForBinding(String keyword, String lang, int offset, int maxrecords, boolean isChooser) {
3003                 PagableContainer ret = new PagableContainer();
3004                 ret.displaycount = 0;
3005                 ret.offset = offset;
3006                 ret.totalrecords = 0;
3007                 try {
3008 
3009                         FindService fs = new FindService();
3010                         fs.setAuthInfo(GetToken());
3011                         fs.setMaxRows(maxrecords);
3012                         fs.setListHead(offset);
3013                         Name n = new Name();
3014                         if (lang == null || lang.equalsIgnoreCase(ResourceLoader.GetResource(session, "items.clicktoedit"))) {
3015                                 n.setLang(null);
3016                         } else {
3017                                 n.setLang(lang);
3018                         }
3019                         n.setValue(keyword);
3020                         fs.getName().add(n);
3021                         fs.setFindQualifiers(new org.uddi.api_v3.FindQualifiers());
3022                         fs.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
3023                         fs.getFindQualifiers().getFindQualifier().add(UDDIConstants.SORT_BY_NAME_ASC);
3024                         ServiceList findService = null;//inquiry.findService(fs);
3025                         try {
3026                                 findService = inquiry.findService(fs);
3027                         } catch (Exception ex) {
3028                                 if (isExceptionExpiration(ex)) {
3029                                         token = null;
3030                                         fs.setAuthInfo(GetToken());
3031                                         findService = inquiry.findService(fs);
3032 
3033                                 } else {
3034                                         throw ex;
3035                                 }
3036                         }
3037 
3038                         if (findService == null || findService.getServiceInfos() == null) {
3039                                 ret.renderedHtml = ResourceLoader.GetResource(session, "errors.norecordsfound");
3040                                 return ret;
3041                         }
3042                         if (findService.getListDescription() != null) {
3043                                 ret.displaycount = findService.getListDescription().getIncludeCount();
3044                                 ret.totalrecords = findService.getListDescription().getActualCount();
3045                         } else {
3046                                 ret.displaycount = findService.getServiceInfos().getServiceInfo().size();
3047                                 ret.totalrecords = findService.getServiceInfos().getServiceInfo().size();
3048                         }
3049                         GetServiceDetail gs = new GetServiceDetail();
3050                         gs.setAuthInfo(GetToken());
3051                         for (int i = 0; i < findService.getServiceInfos().getServiceInfo().size(); i++) {
3052                                 gs.getServiceKey().add(findService.getServiceInfos().getServiceInfo().get(i).getServiceKey());
3053                         }
3054                         ServiceDetail serviceDetail = null;
3055                         try {
3056                                 serviceDetail = inquiry.getServiceDetail(gs);
3057                         } catch (Exception ex) {
3058                                 if (isExceptionExpiration(ex)) {
3059                                         token = null;
3060                                         fs.setAuthInfo(GetToken());
3061                                         serviceDetail = inquiry.getServiceDetail(gs);
3062 
3063                                 } else {
3064                                         throw ex;
3065                                 }
3066                         }
3067                         if (serviceDetail == null || serviceDetail.getBusinessService().isEmpty()) {
3068                                 ret.renderedHtml = ResourceLoader.GetResource(session, "errors.norecordsfound");
3069                                 return ret;
3070                         }
3071 
3072                         StringBuilder sb = new StringBuilder();
3073                         sb.append("<table class=\"table\"><tr><th>").
3074                              append("</th><th>").
3075                              append(ResourceLoader.GetResource(session, "items.business")).
3076                              append("</th><th>").
3077                              append(ResourceLoader.GetResource(session, "items.service")).
3078                              append("</th><th>").
3079                              append(ResourceLoader.GetResource(session, "items.bindingtemplate.key")).
3080                              append("</th><th>").
3081                              append(ResourceLoader.GetResource(session, "items.accesspoint.value")).
3082                              append("</th></tr>");
3083 
3084                         for (int i = 0; i < serviceDetail.getBusinessService().size(); i++) {
3085                                 //   System.out.println(serviceDetail.getBusinessService().get(i).getBindingTemplates().getBindingTemplate().size());
3086                                 if (serviceDetail.getBusinessService().get(i).getBindingTemplates() != null) {
3087                                         for (int k = 0; k < serviceDetail.getBusinessService().get(i).getBindingTemplates().getBindingTemplate().size(); k++) {
3088                                                 //System.out.println(serviceDetail.getBusinessService().get(i).getBindingTemplates().getBindingTemplate().get(k).getAccessPoint().getValue());
3089                                                 sb.append("<tr><td><input type=\"checkbox\" class=\"modalableBinding\" id=\"").
3090                                                      append(StringEscapeUtils.escapeHtml(serviceDetail.getBusinessService().get(i).getBindingTemplates().getBindingTemplate().get(k).getBindingKey())).
3091                                                      append("\">").
3092                                                      append("</td><td>").
3093                                                      append("<a href=\"businessEditor2.jsp?id=").
3094                                                      append(StringEscapeUtils.escapeHtml(findService.getServiceInfos().getServiceInfo().get(i).getBusinessKey())).
3095                                                      append("\">").
3096                                                      append(StringEscapeUtils.escapeHtml((findService.getServiceInfos().getServiceInfo().get(i).getBusinessKey()))).
3097                                                      append("</a>").
3098                                                      append("</td><td>").append("<a href=\"serviceEditor.jsp?id=").
3099                                                      append(StringEscapeUtils.escapeHtml(serviceDetail.getBusinessService().get(i).getServiceKey())).
3100                                                      append("\" title=\"").
3101                                                      append(StringEscapeUtils.escapeHtml(serviceDetail.getBusinessService().get(i).getServiceKey())).
3102                                                      append("\">").
3103                                                      append(Printers.ListNamesToString(serviceDetail.getBusinessService().get(i).getName())).
3104                                                      append("</a>").
3105                                                      append("</td><td>").
3106                                                      append(StringEscapeUtils.escapeHtml(serviceDetail.getBusinessService().get(i).getBindingTemplates().getBindingTemplate().get(k).getBindingKey())).
3107                                                      append("</td><td>");
3108                                                 if (serviceDetail.getBusinessService().get(i).getBindingTemplates().getBindingTemplate().get(k).getAccessPoint() != null) {
3109                                                         sb.append(StringEscapeUtils.escapeHtml(serviceDetail.getBusinessService().get(i).getBindingTemplates().getBindingTemplate().get(k).getAccessPoint().getValue()));
3110                                                 }
3111                                                 sb.append("</td></tr>");
3112                                         }
3113                                 }
3114                         }
3115 
3116                         sb.append("</table>");
3117                         ret.renderedHtml = sb.toString();
3118                         return ret;
3119                 } catch (Exception ex) {
3120                         ret.renderedHtml = HandleException(ex);
3121                 }
3122                 return ret;
3123 
3124         }
3125 
3126         /**
3127          * Get a custody transfer token for giving away control of the specified
3128          * business or tmodel keys
3129          *
3130          * authInfo: This OPTIONAL argument is an element that contains an
3131          * authentication token. Authentication tokens are obtained using the
3132          * get_authToken API call or through some other means external to this
3133          * specification, and represent the identity of the publisher at a UDDI
3134          * node.
3135          *
3136          * · transferToken: This is a known transferToken obtained by a
3137          * publisher at the node where the get_transferToken API was invoked.
3138          *
3139          * · keyBag: One or more uddiKeys associated either with businessEntity
3140          * or tModel entities owned by the publisher that were to be transferred
3141          * to some other publisher and/or node in the registry as the result of
3142          * invocation of get_transferToken. At least one businessKey or
3143          * tModelKey must be provided in a keyBag.
3144          *
3145          * @param keys
3146          * @param nodeid
3147          * @param outExpires
3148          * @param outToken
3149          * @return status
3150          */
3151         public String GetCustodyTransferToken(org.uddi.custody_v3.KeyBag keys, Holder<String> nodeid, Holder<XMLGregorianCalendar> outExpires, Holder<byte[]> outToken) {
3152 
3153                 // org.uddi.custody_v3.KeyBag kb = new org.uddi.custody_v3.KeyBag();
3154                 // kb.getKey().addAll(keys);
3155                 try {
3156                         try {
3157                                 custody.getTransferToken(GetToken(), keys, nodeid, outExpires, outToken);
3158                         } catch (Exception ex) {
3159                                 if (isExceptionExpiration(ex)) {
3160                                         token = null;
3161                                         custody.getTransferToken(GetToken(), keys, nodeid, outExpires, outToken);
3162 
3163                                 } else {
3164                                         throw ex;
3165                                 }
3166                         }
3167                 } catch (Exception ex) {
3168                         return HandleException(ex);
3169 
3170                 }
3171                 return null;//"Success";
3172         }
3173 
3174         /**
3175          *
3176          * @param tokenxml
3177          * @return The discard_transferToken API is a client API used to discard
3178          * a transferToken obtained through the get_transferToken API at the
3179          * same node. This API accepts either a transferToken or a keyBag as
3180          * parameters to remove the permission to transfer data associated with
3181          * a particular transferToken. If a keyBag is provided, all tokens
3182          * corresponding to the keys in the keyBag will be discarded and will no
3183          * longer be valid for custody or ownership transfer after the
3184          * discard_transferToken is processed, irrespective of whether the keys
3185          * match any known business or tmodelKey values. In the event that the
3186          * keyBag represents a subset of the keyBag for one or more
3187          * transferToken elements, the transferToken is discarded and will no
3188          * longer be valid for transferring any entity. If the token passed in
3189          * the transferToken argument does not match an existing token known to
3190          * the system, no action is taken and success is reported. Keys in the
3191          * keyBag argument that do not have a corresponding token are ignored.
3192          */
3193         public String DiscardToken(String tokenxml) {
3194                 DiscardTransferToken r = new DiscardTransferToken();
3195                 r.setAuthInfo(GetToken());
3196                 r.setTransferToken((TransferToken) XmlUtils.unmarshal(new StringReader(tokenxml), TransferToken.class));
3197 
3198                 try {
3199                         try {
3200                                 custody.discardTransferToken(r);
3201                         } catch (Exception ex) {
3202                                 if (isExceptionExpiration(ex)) {
3203                                         token = null;
3204                                         r.setAuthInfo(GetToken());
3205                                         custody.discardTransferToken(r);
3206 
3207                                 } else {
3208                                         throw ex;
3209                                 }
3210                         }
3211                 } catch (Exception ex) {
3212                         return HandleException(ex);
3213                 }
3214                 return null;//"Success";
3215 
3216         }
3217 
3218         /**
3219          * Accepts a transfer token and transfers the entities.
3220          *
3221          * @param tokenXML
3222          * @param keyBagXML
3223          * @return status msg
3224          */
3225         public String AcceptCustodyTranferToken(String tokenXML, String keyBagXML) {
3226                 try {
3227                         TransferEntities te = new TransferEntities();
3228                         te.setAuthInfo(GetToken());
3229                         StringReader sr = new StringReader(tokenXML.trim());
3230                         te.setTransferToken((TransferToken) XmlUtils.unmarshal(sr, TransferToken.class));
3231                         sr = new StringReader(keyBagXML.trim());
3232                         te.setKeyBag((org.uddi.custody_v3.KeyBag) XmlUtils.unmarshal(sr, org.uddi.custody_v3.KeyBag.class));
3233 
3234                         try {
3235                                 custody.transferEntities(te);
3236                         } catch (Exception ex) {
3237                                 if (isExceptionExpiration(ex)) {
3238                                         token = null;
3239                                         te.setAuthInfo(GetToken());
3240                                         custody.transferEntities(te);
3241 
3242                                 } else {
3243                                         throw ex;
3244                                 }
3245                         }
3246                 } catch (Exception ex) {
3247                         return HandleException(ex);
3248                 }
3249                 return null;//"Success";
3250 
3251         }
3252 
3253         /**
3254          * returns a subscription by id, since UDDI does not provide this
3255          * function, it simply gets all of them for the current user then
3256          * filters out the requested item
3257          *
3258          * @param id
3259          * @return null if not found
3260          */
3261         public Subscription GetSubscriptionDetails(String id) {
3262                 if (id == null) {
3263                         return null;
3264                 }
3265                 List<Subscription> GetSubscriptions = this.GetSubscriptions();
3266                 if (GetSubscriptions == null) {
3267                         return null;
3268                 }
3269                 for (int i = 0; i < GetSubscriptions.size(); i++) {
3270                         if (GetSubscriptions.get(i).getSubscriptionKey() != null && GetSubscriptions.get(i).getSubscriptionKey().equalsIgnoreCase(id)) {
3271                                 return GetSubscriptions.get(i);
3272                         }
3273                 }
3274                 return null;
3275         }
3276 
3277         /**
3278          *
3279          * @param request
3280          * @param service
3281          * @param method
3282          * @return xml response
3283          * @see UDDIRequestsAsXML
3284          */
3285         public String SendAdvancedQuery(Object request, String service, String method) {
3286                 if (service.equalsIgnoreCase(UDDIRequestsAsXML.inquiry)) {
3287                         return SendAdvancedQueryInquiry(method, request);
3288                 }
3289                 if (service.equalsIgnoreCase(UDDIRequestsAsXML.publish)) {
3290                         return SendAdvancedQueryPublish(method, request);
3291                 }
3292                 if (service.equalsIgnoreCase(UDDIRequestsAsXML.custody)) {
3293                         return SendAdvancedQueryCustody(method, request);
3294                 }
3295                 if (service.equalsIgnoreCase(UDDIRequestsAsXML.subscription)) {
3296                         return SendAdvancedQuerySubscription(method, request);
3297                 }
3298                 return "Unknown error";
3299         }
3300 
3301         private String SendAdvancedQueryInquiry(String method, Object request) {
3302                 Object response = null;
3303                 try {
3304                         if (method.equalsIgnoreCase("findBinding")) {
3305                                 ((FindBinding) request).setAuthInfo(GetToken());
3306                                 try {
3307                                         response = inquiry.findBinding((FindBinding) request);
3308                                 } catch (Exception ex) {
3309                                         if (isExceptionExpiration(ex)) {
3310                                                 token = null;
3311                                                 ((FindBinding) request).setAuthInfo(GetToken());
3312                                                 response = inquiry.findBinding((FindBinding) request);
3313 
3314                                         } else {
3315                                                 throw ex;
3316                                         }
3317                                 }
3318                         }
3319                         if (method.equalsIgnoreCase("findBusiness")) {
3320                                 ((FindBusiness) request).setAuthInfo(GetToken());
3321                                 try {
3322                                         response = inquiry.findBusiness((FindBusiness) request);
3323                                 } catch (Exception ex) {
3324                                         if (isExceptionExpiration(ex)) {
3325                                                 token = null;
3326                                                 ((FindBusiness) request).setAuthInfo(GetToken());
3327                                                 response = inquiry.findBusiness((FindBusiness) request);
3328 
3329                                         } else {
3330                                                 throw ex;
3331                                         }
3332                                 }
3333 
3334                         }
3335                         if (method.equalsIgnoreCase("findService")) {
3336                                 ((FindService) request).setAuthInfo(GetToken());
3337                                 try {
3338                                         response = inquiry.findService((FindService) request);
3339                                 } catch (Exception ex) {
3340                                         if (isExceptionExpiration(ex)) {
3341                                                 token = null;
3342                                                 ((FindService) request).setAuthInfo(GetToken());
3343                                                 response = inquiry.findService((FindService) request);
3344 
3345                                         } else {
3346                                                 throw ex;
3347                                         }
3348                                 }
3349 
3350                         }
3351                         if (method.equalsIgnoreCase("findRelatedBusines")) {
3352                                 ((FindRelatedBusinesses) request).setAuthInfo(GetToken());
3353                                 try {
3354                                         response = inquiry.findRelatedBusinesses((FindRelatedBusinesses) request);
3355                                 } catch (Exception ex) {
3356                                         if (isExceptionExpiration(ex)) {
3357                                                 token = null;
3358                                                 ((FindRelatedBusinesses) request).setAuthInfo(GetToken());
3359                                                 response = inquiry.findRelatedBusinesses((FindRelatedBusinesses) request);
3360 
3361                                         } else {
3362                                                 throw ex;
3363                                         }
3364                                 }
3365 
3366                         }
3367                         if (method.equalsIgnoreCase("findTModel")) {
3368                                 ((FindTModel) request).setAuthInfo(GetToken());
3369 
3370                                 try {
3371                                         response = inquiry.findTModel((FindTModel) request);
3372                                 } catch (Exception ex) {
3373                                         if (isExceptionExpiration(ex)) {
3374                                                 token = null;
3375                                                 ((FindTModel) request).setAuthInfo(GetToken());
3376                                                 response = inquiry.findTModel((FindTModel) request);
3377 
3378                                         } else {
3379                                                 throw ex;
3380                                         }
3381                                 }
3382 
3383                         }
3384                         if (method.equalsIgnoreCase("getBindingDetail")) {
3385                                 ((GetBindingDetail) request).setAuthInfo(GetToken());
3386                                 try {
3387                                         response = inquiry.getBindingDetail((GetBindingDetail) request);
3388                                 } catch (Exception ex) {
3389                                         if (isExceptionExpiration(ex)) {
3390                                                 token = null;
3391                                                 ((GetBindingDetail) request).setAuthInfo(GetToken());
3392                                                 response = inquiry.getBindingDetail((GetBindingDetail) request);
3393 
3394                                         } else {
3395                                                 throw ex;
3396                                         }
3397                                 }
3398 
3399                         }
3400                         if (method.equalsIgnoreCase("getBusinessDetail")) {
3401                                 ((GetBusinessDetail) request).setAuthInfo(GetToken());
3402 
3403                                 try {
3404                                         response = inquiry.getBusinessDetail((GetBusinessDetail) request);
3405                                 } catch (Exception ex) {
3406                                         if (isExceptionExpiration(ex)) {
3407                                                 token = null;
3408                                                 ((GetBusinessDetail) request).setAuthInfo(GetToken());
3409                                                 response = inquiry.getBusinessDetail((GetBusinessDetail) request);
3410 
3411                                         } else {
3412                                                 throw ex;
3413                                         }
3414                                 }
3415 
3416                         }
3417                         if (method.equalsIgnoreCase("getServiceDetail")) {
3418                                 ((GetServiceDetail) request).setAuthInfo(GetToken());
3419 
3420                                 try {
3421                                         response = inquiry.getServiceDetail((GetServiceDetail) request);
3422                                 } catch (Exception ex) {
3423                                         if (isExceptionExpiration(ex)) {
3424                                                 token = null;
3425                                                 ((GetServiceDetail) request).setAuthInfo(GetToken());
3426                                                 response = inquiry.getServiceDetail((GetServiceDetail) request);
3427 
3428                                         } else {
3429                                                 throw ex;
3430                                         }
3431                                 }
3432 
3433                         }
3434                         if (method.equalsIgnoreCase("getOperationalInfo")) {
3435                                 ((GetOperationalInfo) request).setAuthInfo(GetToken());
3436 
3437                                 try {
3438                                         response = inquiry.getOperationalInfo((GetOperationalInfo) request);
3439                                 } catch (Exception ex) {
3440                                         if (isExceptionExpiration(ex)) {
3441                                                 token = null;
3442                                                 response = inquiry.getOperationalInfo((GetOperationalInfo) request);
3443 
3444                                         } else {
3445                                                 throw ex;
3446                                         }
3447                                 }
3448 
3449                         }
3450                         if (method.equalsIgnoreCase("getTModelDetail")) {
3451                                 ((GetTModelDetail) request).setAuthInfo(GetToken());
3452 
3453                                 try {
3454                                         response = inquiry.getTModelDetail((GetTModelDetail) request);
3455                                 } catch (Exception ex) {
3456                                         if (isExceptionExpiration(ex)) {
3457                                                 token = null;
3458                                                 response = inquiry.getTModelDetail((GetTModelDetail) request);
3459 
3460                                         } else {
3461                                                 throw ex;
3462                                         }
3463                                 }
3464                         }
3465                         if (response == null) {
3466                                 return ResourceLoader.GetResource(session, "actions.success");
3467                         }
3468                         StringWriter sw = new StringWriter();
3469                         JAXB.marshal(response, sw);
3470                         return sw.toString();
3471                 } catch (Exception ex) {
3472                         return HandleException(ex);
3473                 }
3474         }
3475 
3476         private String SendAdvancedQueryPublish(String method, Object request) {
3477                 Object response = null;
3478                 try {
3479                         if (method.equalsIgnoreCase("addPublisherAssertions")) {
3480                                 ((AddPublisherAssertions) request).setAuthInfo(GetToken());
3481                                 try {
3482                                         publish.addPublisherAssertions((AddPublisherAssertions) request);
3483                                 } catch (Exception ex) {
3484                                         if (isExceptionExpiration(ex)) {
3485                                                 token = null;
3486                                                 ((AddPublisherAssertions) request).setAuthInfo(GetToken());
3487                                                 publish.addPublisherAssertions((AddPublisherAssertions) request);
3488 
3489                                         } else {
3490                                                 throw ex;
3491                                         }
3492                                 }
3493                         }
3494                         if (method.equalsIgnoreCase("deleteBinding")) {
3495                                 try {
3496                                         ((DeleteBinding) request).setAuthInfo(GetToken());
3497                                         publish.deleteBinding((DeleteBinding) request);
3498                                 } catch (Exception ex) {
3499                                         if (isExceptionExpiration(ex)) {
3500                                                 token = null;
3501                                                 ((DeleteBinding) request).setAuthInfo(GetToken());
3502                                                 publish.deleteBinding((DeleteBinding) request);
3503 
3504                                         } else {
3505                                                 throw ex;
3506                                         }
3507                                 }
3508                         }
3509                         if (method.equalsIgnoreCase("deleteBusiness")) {
3510                                 try {
3511                                         ((DeleteBusiness) request).setAuthInfo(GetToken());
3512                                         publish.deleteBusiness((DeleteBusiness) request);
3513                                 } catch (Exception ex) {
3514                                         if (isExceptionExpiration(ex)) {
3515                                                 token = null;
3516                                                 ((DeleteBusiness) request).setAuthInfo(GetToken());
3517                                                 publish.deleteBusiness((DeleteBusiness) request);
3518 
3519                                         } else {
3520                                                 throw ex;
3521                                         }
3522                                 }
3523                         }
3524                         if (method.equalsIgnoreCase("deletePublisherAssertions")) {
3525                                 try {
3526                                         ((DeletePublisherAssertions) request).setAuthInfo(GetToken());
3527                                         publish.deletePublisherAssertions((DeletePublisherAssertions) request);
3528                                 } catch (Exception ex) {
3529                                         if (isExceptionExpiration(ex)) {
3530                                                 token = null;
3531                                                 ((DeleteBusiness) request).setAuthInfo(GetToken());
3532                                                 publish.deletePublisherAssertions((DeletePublisherAssertions) request);
3533 
3534                                         } else {
3535                                                 throw ex;
3536                                         }
3537                                 }
3538                         }
3539                         if (method.equalsIgnoreCase("deleteService")) {
3540                                 try {
3541                                         ((DeleteService) request).setAuthInfo(GetToken());
3542                                         publish.deleteService((DeleteService) request);
3543                                 } catch (Exception ex) {
3544                                         if (isExceptionExpiration(ex)) {
3545                                                 token = null;
3546                                                 ((DeleteBusiness) request).setAuthInfo(GetToken());
3547                                                 publish.deleteService((DeleteService) request);
3548 
3549                                         } else {
3550                                                 throw ex;
3551                                         }
3552                                 }
3553                         }
3554                         if (method.equalsIgnoreCase("deleteTModel")) {
3555                                 try {
3556                                         ((DeleteTModel) request).setAuthInfo(GetToken());
3557                                         publish.deleteTModel((DeleteTModel) request);
3558                                 } catch (Exception ex) {
3559                                         if (isExceptionExpiration(ex)) {
3560                                                 token = null;
3561                                                 ((DeleteTModel) request).setAuthInfo(GetToken());
3562                                                 publish.deleteTModel((DeleteTModel) request);
3563 
3564                                         } else {
3565                                                 throw ex;
3566                                         }
3567                                 }
3568                         }
3569                         if (method.equalsIgnoreCase("getAssertionStatusReport")) {
3570                                 CompletionStatus stat = ((GetAssertionStatusReport) request).getCompletionStatus();
3571                                 try {
3572                                         response = publish.getAssertionStatusReport(GetToken(), stat);
3573                                 } catch (Exception ex) {
3574                                         if (isExceptionExpiration(ex)) {
3575                                                 token = null;
3576                                                 response = publish.getAssertionStatusReport(GetToken(), stat);
3577 
3578                                         } else {
3579                                                 throw ex;
3580                                         }
3581                                 }
3582 
3583                         }
3584                         if (method.equalsIgnoreCase("getPublisherAssertions")) {
3585                                 try {
3586                                         response = publish.getPublisherAssertions(GetToken());
3587                                 } catch (Exception ex) {
3588                                         if (isExceptionExpiration(ex)) {
3589                                                 token = null;
3590                                                 response = publish.getPublisherAssertions(GetToken());
3591 
3592                                         } else {
3593                                                 throw ex;
3594                                         }
3595                                 }
3596                         }
3597                         if (method.equalsIgnoreCase("getRegisteredInfo")) {
3598                                 try {
3599                                         ((GetRegisteredInfo) request).setAuthInfo(GetToken());
3600                                         response = publish.getRegisteredInfo((GetRegisteredInfo) request);
3601                                 } catch (Exception ex) {
3602                                         if (isExceptionExpiration(ex)) {
3603                                                 token = null;
3604                                                 ((GetRegisteredInfo) request).setAuthInfo(GetToken());
3605                                                 publish.getRegisteredInfo((GetRegisteredInfo) request);
3606 
3607                                         } else {
3608                                                 throw ex;
3609                                         }
3610                                 }
3611                         }
3612                         if (method.equalsIgnoreCase("saveBinding")) {
3613                                 try {
3614                                         ((SaveBinding) request).setAuthInfo(GetToken());
3615                                         response = publish.saveBinding((SaveBinding) request);
3616                                 } catch (Exception ex) {
3617                                         if (isExceptionExpiration(ex)) {
3618                                                 token = null;
3619                                                 ((SaveBinding) request).setAuthInfo(GetToken());
3620                                                 publish.saveBinding((SaveBinding) request);
3621 
3622                                         } else {
3623                                                 throw ex;
3624                                         }
3625                                 }
3626                         }
3627                         if (method.equalsIgnoreCase("saveBusiness")) {
3628                                 try {
3629                                         ((SaveBusiness) request).setAuthInfo(GetToken());
3630                                         response = publish.saveBusiness((SaveBusiness) request);
3631                                 } catch (Exception ex) {
3632                                         if (isExceptionExpiration(ex)) {
3633                                                 token = null;
3634                                                 ((SaveBusiness) request).setAuthInfo(GetToken());
3635                                                 publish.saveBusiness((SaveBusiness) request);
3636 
3637                                         } else {
3638                                                 throw ex;
3639                                         }
3640                                 }
3641                         }
3642                         if (method.equalsIgnoreCase("saveTModel")) {
3643                                 try {
3644                                         ((SaveTModel) request).setAuthInfo(GetToken());
3645                                         response = publish.saveTModel((SaveTModel) request);
3646                                 } catch (Exception ex) {
3647                                         if (isExceptionExpiration(ex)) {
3648                                                 token = null;
3649                                                 ((SaveTModel) request).setAuthInfo(GetToken());
3650                                                 publish.saveTModel((SaveTModel) request);
3651 
3652                                         } else {
3653                                                 throw ex;
3654                                         }
3655                                 }
3656                         }
3657                         if (method.equalsIgnoreCase("saveService")) {
3658                                 try {
3659                                         ((SaveService) request).setAuthInfo(GetToken());
3660                                         response = publish.saveService((SaveService) request);
3661                                 } catch (Exception ex) {
3662                                         if (isExceptionExpiration(ex)) {
3663                                                 token = null;
3664                                                 ((SaveService) request).setAuthInfo(GetToken());
3665                                                 publish.saveService((SaveService) request);
3666 
3667                                         } else {
3668                                                 throw ex;
3669                                         }
3670                                 }
3671                         }
3672                         if (method.equalsIgnoreCase("setPublisherAssertions")) {
3673                                 Holder<List<PublisherAssertion>> list = new Holder<List<PublisherAssertion>>();
3674                                 list.value = ((SetPublisherAssertions) request).getPublisherAssertion();
3675                                 try {
3676                                         publish.setPublisherAssertions(GetToken(), list);
3677                                         response = list.value;
3678                                 } catch (Exception ex) {
3679                                         if (isExceptionExpiration(ex)) {
3680                                                 token = null;
3681                                                 ((SetPublisherAssertions) request).setAuthInfo(GetToken());
3682                                                 publish.setPublisherAssertions(GetToken(), list);
3683                                                 response = list.value;
3684 
3685                                         } else {
3686                                                 throw ex;
3687                                         }
3688                                 }
3689 
3690                         }
3691                         if (response == null) {
3692                                 return "The operation completed without error";
3693                         }
3694                         StringWriter sw = new StringWriter();
3695                         JAXB.marshal(response, sw);
3696                         return sw.toString();
3697                 } catch (Exception ex) {
3698                         return HandleException(ex);
3699                 }
3700         }
3701 
3702         private String SendAdvancedQueryCustody(String method, Object request) {
3703                 Object response = null;
3704                 try {
3705 
3706                         if (method.equalsIgnoreCase("discardTransferToken")) {
3707                                 try {
3708                                         ((DiscardTransferToken) request).setAuthInfo(GetToken());
3709                                         custody.discardTransferToken((DiscardTransferToken) request);
3710                                 } catch (Exception ex) {
3711                                         if (isExceptionExpiration(ex)) {
3712                                                 token = null;
3713                                                 ((DiscardTransferToken) request).setAuthInfo(GetToken());
3714                                                 custody.discardTransferToken((DiscardTransferToken) request);
3715 
3716                                         } else {
3717                                                 throw ex;
3718                                         }
3719                                 }
3720                         }
3721                         if (method.equalsIgnoreCase("getTransferToken")) {
3722                                 GetTransferToken r = ((GetTransferToken) request);
3723                                 TransferToken tt = new TransferToken();
3724                                 Holder<String> node = new Holder<String>();
3725                                 Holder<XMLGregorianCalendar> xcal = new Holder<XMLGregorianCalendar>();
3726                                 Holder<byte[]> ttoken = new Holder<byte[]>();
3727                                 try {
3728                                         custody.getTransferToken(GetToken(), r.getKeyBag(), node, xcal, ttoken);
3729                                         tt.setNodeID(node.value);
3730                                         tt.setOpaqueToken(ttoken.value);
3731                                         tt.setExpirationTime(xcal.value);
3732                                         response = tt;
3733                                 } catch (Exception ex) {
3734                                         if (isExceptionExpiration(ex)) {
3735                                                 token = null;
3736                                                 custody.getTransferToken(GetToken(), r.getKeyBag(), node, xcal, ttoken);
3737                                                 tt.setNodeID(node.value);
3738                                                 tt.setOpaqueToken(ttoken.value);
3739                                                 tt.setExpirationTime(xcal.value);
3740                                                 response = tt;
3741 
3742                                         } else {
3743                                                 throw ex;
3744                                         }
3745                                 }
3746                         }
3747                         if (method.equalsIgnoreCase("transferEntities")) {
3748                                 try {
3749                                         ((TransferEntities) request).setAuthInfo(GetToken());
3750                                         custody.transferEntities((TransferEntities) request);
3751                                 } catch (Exception ex) {
3752                                         if (isExceptionExpiration(ex)) {
3753                                                 token = null;
3754                                                 ((TransferEntities) request).setAuthInfo(GetToken());
3755                                                 custody.transferEntities((TransferEntities) request);
3756 
3757                                         } else {
3758                                                 throw ex;
3759                                         }
3760                                 }
3761                         }
3762 
3763                         if (response == null) {
3764                                 return "The operation completed without error";
3765                         }
3766                         StringWriter sw = new StringWriter();
3767                         JAXB.marshal(response, sw);
3768                         return sw.toString();
3769                 } catch (Exception ex) {
3770                         return HandleException(ex);
3771                 }
3772         }
3773 
3774         private String SendAdvancedQuerySubscription(String method, Object request) {
3775                 Object response = null;
3776                 try {
3777                         if (method.equalsIgnoreCase("deleteSubscription")) {
3778                                 try {
3779                                         ((DeleteSubscription) request).setAuthInfo(GetToken());
3780                                         subscription.deleteSubscription((DeleteSubscription) request);
3781                                 } catch (Exception ex) {
3782                                         if (isExceptionExpiration(ex)) {
3783                                                 token = null;
3784                                                 ((DeleteSubscription) request).setAuthInfo(GetToken());
3785                                                 subscription.deleteSubscription((DeleteSubscription) request);
3786 
3787                                         } else {
3788                                                 throw ex;
3789                                         }
3790                                 }
3791                         }
3792                         if (method.equalsIgnoreCase("getSubscriptionResults")) {
3793                                 try {
3794                                         ((GetSubscriptionResults) request).setAuthInfo(GetToken());
3795                                         response = subscription.getSubscriptionResults((GetSubscriptionResults) request);
3796                                 } catch (Exception ex) {
3797                                         if (isExceptionExpiration(ex)) {
3798                                                 token = null;
3799                                                 ((GetSubscriptionResults) request).setAuthInfo(GetToken());
3800                                                 subscription.getSubscriptionResults((GetSubscriptionResults) request);
3801 
3802                                         } else {
3803                                                 throw ex;
3804                                         }
3805                                 }
3806                         }
3807                         if (method.equalsIgnoreCase("getSubscriptions")) {
3808                                 try {
3809 
3810                                         response = subscription.getSubscriptions(GetToken());
3811                                 } catch (Exception ex) {
3812                                         if (isExceptionExpiration(ex)) {
3813                                                 token = null;
3814 
3815                                                 response = subscription.getSubscriptions(GetToken());
3816 
3817                                         } else {
3818                                                 throw ex;
3819                                         }
3820                                 }
3821                         }
3822                         if (method.equalsIgnoreCase("saveSubscription")) {
3823                                 SaveSubscription ss = (SaveSubscription) request;
3824                                 Holder<List<Subscription>> h = new Holder<List<Subscription>>(ss.getSubscription());
3825                                 try {
3826 
3827                                         subscription.saveSubscription(GetToken(), h);
3828                                         response = h.value;
3829                                 } catch (Exception ex) {
3830                                         if (isExceptionExpiration(ex)) {
3831                                                 token = null;
3832                                                 subscription.saveSubscription(GetToken(), h);
3833                                                 response = h.value;
3834 
3835                                         } else {
3836                                                 throw ex;
3837                                         }
3838                                 }
3839                         }
3840                         if (response == null) {
3841                                 return "The operation completed without error";
3842                         }
3843                         StringWriter sw = new StringWriter();
3844                         JAXB.marshal(response, sw);
3845                         return sw.toString();
3846                 } catch (Exception ex) {
3847                         return HandleException(ex);
3848                 }
3849         }
3850 
3851         /**
3852          * returns true if automatic logouts are configured
3853          *
3854          * @return true/false
3855          */
3856         public boolean isAutoLogoutEnabled() {
3857 
3858                 if (clientConfig == null) {
3859                         EnsureConfig();
3860                 }
3861                 String val = clientConfig.getConfiguration().getString(PROP_AUTO_LOGOUT);
3862                 if (val == null) {
3863                         return false;
3864                 }
3865                 try {
3866                         return Boolean.parseBoolean(val);
3867                 } catch (Exception ex) {
3868                         log.warn("unable to parse the value for " + PROP_AUTO_LOGOUT + " in uddi.xml, defaulting to false", ex);
3869                 }
3870                 return false;
3871         }
3872 
3873         /**
3874          * defaults to 15 minutes if not defined
3875          *
3876          * @return duration
3877          */
3878         public long GetAutoLogoutDuration() {
3879                 
3880                 try {
3881                     String val = clientConfig.getConfiguration().getString(PROP_AUTO_LOGOUT_TIMER);
3882                     if (val == null) {
3883                             return 15 * 60 * 1000;
3884                     }
3885                     return Long.parseLong(val);
3886                 } catch (Throwable ex) {
3887                         log.warn("unable to parse the value for " + PROP_AUTO_LOGOUT_TIMER + " in uddi.xml, defaulting to 15 minutes", ex);
3888                 }
3889                 return 15 * 60 * 1000;
3890         }
3891 
3892         /**
3893          * If false, the configuration page will be available from anywhere. If
3894          * true, it will only be accessible from the server hosting juddi-gui.
3895          * if not defined, the result is true.
3896          *
3897          * @return true/false
3898          */
3899         public boolean isAdminLocalhostOnly() {
3900             try{
3901                 return clientConfig.getConfiguration().getBoolean(PROP_ADMIN_LOCALHOST_ONLY, true);
3902             }catch (Throwable ex) {
3903                 log.warn("unable to parse the value for " + PROP_ADMIN_LOCALHOST_ONLY + " in uddi.xml, defaulting to 15 minutes", ex);
3904             }
3905             return true;
3906         }
3907 
3908         public String SaveBindingTemplate(HttpServletRequest request) {
3909 
3910                 BindingTemplate be = new BindingTemplate();
3911                 be.setServiceKey(request.getParameter(PostBackConstants.SERVICEKEY).trim());
3912                 be.setBindingKey(request.getParameter(PostBackConstants.BINDINGKEY).trim());
3913                 if (be.getBindingKey().equalsIgnoreCase(ResourceLoader.GetResource(session, "items.clicktoedit"))) {
3914                         be.setBindingKey(null);
3915                 }
3916                 be.getDescription().addAll(Builders.BuildDescription(Builders.MapFilter(request.getParameterMap(), PostBackConstants.DESCRIPTION), PostBackConstants.DESCRIPTION, ResourceLoader.GetResource(session, "items.clicktoedit"), getLocale()));
3917                 CategoryBag cb = new CategoryBag();
3918                 cb.getKeyedReference().addAll(Builders.BuildKeyedReference(Builders.MapFilter(request.getParameterMap(), PostBackConstants.CATBAG_KEY_REF), PostBackConstants.CATBAG_KEY_REF, getLocale()));
3919                 cb.getKeyedReferenceGroup().addAll(Builders.BuildKeyedReferenceGroup(Builders.MapFilter(request.getParameterMap(), PostBackConstants.CATBAG_KEY_REF_GRP), PostBackConstants.CATBAG_KEY_REF_GRP, getLocale()));
3920 
3921                 if (!cb.getKeyedReference().isEmpty() || !cb.getKeyedReferenceGroup().isEmpty()) {
3922                         be.setCategoryBag(cb);
3923                 }
3924                 Map map = request.getParameterMap();
3925                 String[] t = (String[]) map.get(PostBackConstants.HOSTINGREDIRECTOR);
3926                 if (t != null && t.length > 0) {
3927                         be.setHostingRedirector(new HostingRedirector());
3928                         be.getHostingRedirector().setBindingKey(t[0]);
3929                 }
3930                 AccessPoint ap = new AccessPoint();
3931                 t = (String[]) map.get(PostBackConstants.ACCESSPOINT_TYPE);
3932                 if (t != null && t.length > 0) {
3933                         ap.setUseType(t[0]);
3934                 }
3935                 t = (String[]) map.get(PostBackConstants.ACCESSPOINT_VALUE);
3936                 if (t != null && t.length > 0) {
3937                         ap.setValue(t[0]);
3938                 }
3939                 if (ap.getValue() != null) {
3940                         be.setAccessPoint(ap);
3941                 }
3942 
3943                 be.setTModelInstanceDetails(Builders.BuildTmodelInstanceDetails(
3944                      Builders.MapFilter(map, PostBackConstants.TMODELINSTANCE),
3945                      PostBackConstants.TMODELINSTANCE, ResourceLoader.GetResource(session, "items.clicktoedit"), getLocale()));
3946 
3947                 //JAXB.marshal(be, System.out);
3948                 return SaveBindingTemplate(be);
3949         }
3950 
3951         public String deleteBinding(String id) {
3952 
3953                 if (id == null || id.length() == 0) {
3954                         return ResourceLoader.GetResource(session, "errors.noinput");
3955                 }
3956                 List<String> x = new ArrayList<String>();
3957                 x.add(id.trim());
3958                 return deleteBinding(x);
3959         }
3960         
3961         public String getTmodelDisplayName(String id) {
3962             TModel tmodel = GettModelDetailsAsObject(id);
3963             if (tmodel!=null &&
3964                     tmodel.getName()!=null &&
3965                     tmodel.getName().getValue()!=null) {
3966                 return tmodel.getName().getValue();
3967             }
3968             return "";
3969         }
3970 }