This project has retired. For details please refer to its Attic page.
UDDIInquiryJAXRS xref
View Javadoc
1   /*
2    * Copyright 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  package org.apache.juddi.api.impl.rest;
17  
18  import java.net.URL;
19  import java.util.ArrayList;
20  import java.util.Arrays;
21  import java.util.List;
22  import java.util.Properties;
23  
24  import javax.ws.rs.*;
25  import javax.wsdl.Definition;
26  
27  import org.apache.commons.logging.Log;
28  import org.apache.commons.logging.LogFactory;
29  import org.apache.juddi.api.impl.UDDIInquiryImpl;
30  import org.apache.juddi.api_v3.AccessPointType;
31  import org.apache.juddi.api_v3.rest.UriContainer;
32  import org.apache.juddi.v3.client.UDDIConstants;
33  import org.apache.juddi.v3.client.mapping.URLLocalizerDefaultImpl;
34  import org.apache.juddi.v3.client.mapping.wsdl.ReadWSDL;
35  import org.apache.juddi.v3.client.mapping.wsdl.WSDL2UDDI;
36  import org.apache.juddi.v3.error.UDDIErrorHelper;
37  import org.uddi.api_v3.*;
38  import org.uddi.sub_v3.KeyBag;
39  import org.uddi.v3_service.DispositionReportFaultMessage;
40  
41  /**
42   * UDDI Inquiry functions via a JAX-RS REST API. It's basically a wrapper for
43   * the REST fans to access UDDI from a URL pattern This class will ONLY deploy
44   * using the Apache CXF WS stack for REST (JAX-RS)
45   *
46   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
47   */
48  @Path("/")
49  @Produces({"application/xml", "application/json", "text/html"})
50  @org.apache.cxf.jaxrs.model.wadl.Description("This service provides access to UDDIv3 data via a REST interface, including the "
51          + "recommendation specified in the UDDIv3 spec titled, HTTP GET, as well as a number of methods above and beyond.")
52  public class UDDIInquiryJAXRS {
53  
54          private static org.apache.juddi.api.impl.UDDIInquiryImpl inquiry = new UDDIInquiryImpl();
55          private static final Log log = LogFactory.getLog(UDDIInquiryJAXRS.class);
56  
57          /**
58           * Returns the details of a business entity in JSON
59           *
60           * @param id
61           * @return json
62           */
63          @GET
64          @Path("/JSON/businessKey/{id}")
65          @Produces("application/json")
66          @org.apache.cxf.jaxrs.model.wadl.Description("Returns the details of a business entity in JSON")
67          public org.uddi.api_v3.BusinessEntity getBusinessDetailJSON(@PathParam("id") String id) throws WebApplicationException {
68                  return getBusinessDetail(id);
69          }
70  
71          /**
72           * Returns the details of a business entity in XML
73           *
74           * @param id
75           * @return xml
76           * @throws WebApplicationException
77           */
78          @GET
79          @Path("/XML/businessKey/{id}")
80          @Produces("application/xml")
81          @org.apache.cxf.jaxrs.model.wadl.Description("Returns the details of a business entity in XML")
82          public org.uddi.api_v3.BusinessEntity getBusinessDetailXML(@PathParam("id") String id) throws WebApplicationException {
83                  return getBusinessDetail(id);
84          }
85  
86          private org.uddi.api_v3.BusinessEntity getBusinessDetail(String id) {
87                  GetBusinessDetail gbd = new GetBusinessDetail();
88                  gbd.getBusinessKey().add(id);
89                  BusinessDetail businessDetail;
90                  try {
91                          businessDetail = inquiry.getBusinessDetail(gbd);
92                          return businessDetail.getBusinessEntity().get(0);
93                  } catch (DispositionReportFaultMessage ex) {
94                          HandleException(ex);
95                  }
96                  return null;
97          }
98  
99          /**
100          * Returns the details of a tModel entity in XML
101          *
102          * @param id
103          * @return xml
104          * @throws WebApplicationException
105          */
106         @GET
107         @Path("/XML/tModelKey/{id}")
108         @Produces("application/xml")
109         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the details of a tModel entity in XML")
110         public org.uddi.api_v3.TModel getTModelDetailXML(@PathParam("id") String id) throws WebApplicationException {
111                 return getTModelDetail(id);
112         }
113 
114         /**
115          * Returns the details of a tModel entity in JSON
116          *
117          * @param id
118          * @return json
119          * @throws WebApplicationException
120          */
121         @GET
122         @Path("/JSON/tModelKey/{id}")
123         @Produces("application/json")
124         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the details of a tModel entity in JSON")
125         public org.uddi.api_v3.TModel getTModelDetailJSON(@PathParam("id") String id) throws WebApplicationException {
126                 return getTModelDetail(id);
127         }
128 
129         private org.uddi.api_v3.TModel getTModelDetail(String id) {
130                 GetTModelDetail gbd = new GetTModelDetail();
131                 gbd.getTModelKey().add(id);
132 
133                 try {
134                         TModelDetail tModelDetail = inquiry.getTModelDetail(gbd);
135                         return tModelDetail.getTModel().get(0);
136                 } catch (DispositionReportFaultMessage ex) {
137                         HandleException(ex);
138                 }
139                 return null;
140         }
141 
142         /**
143          * Returns the details of a service entity in JSON
144          *
145          * @param id
146          * @return json
147          * @throws WebApplicationException
148          */
149         @GET
150         @Path("/JSON/serviceKey/{id}")
151         @Produces("application/json")
152         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the details of a service entity in JSON")
153         public org.uddi.api_v3.BusinessService getServiceDetailJSON(@PathParam("id") String id) throws WebApplicationException {
154                 return getServiceDetail(id);
155         }
156 
157         /**
158          * This method implements the UDDIv3 spec for HTTP GET Inquiry services
159          * Returns the details of a UDDI entity in JSON, use query parameters
160          * serviceKey,businessKey,tModelKey, or bindingKey
161          *
162          * @param serviceKey
163          * @param businessKey
164          * @param tModelKey
165          * @param bindingKey
166          * @return json
167          * @throws WebApplicationException
168          */
169         @GET
170         @Path("/JSON/getDetail")
171         @Produces("application/json")
172         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the details of a UDDI entity in JSON, use query parameters"
173                 + "serviceKey,businessKey,tModelKey, bindingKey")
174         public Object getDetailJSON(@QueryParam("serviceKey") String serviceKey,
175                 @QueryParam("businessKey") String businessKey,
176                 @QueryParam("tModelKey") String tModelKey,
177                 @QueryParam("bindingKey") String bindingKey) throws WebApplicationException {
178                 int params = 0;
179                 if (businessKey != null) {
180                         params++;
181                 }
182                 if (tModelKey != null) {
183                         params++;
184                 }
185                 if (bindingKey != null) {
186                         params++;
187                 }
188                 if (serviceKey != null) {
189                         params++;
190                 }
191                 if (params != 1) {
192                         throw new WebApplicationException(400);
193                 }
194 
195                 if (businessKey != null) {
196                         return getBusinessDetail(businessKey);
197                 }
198                 if (tModelKey != null) {
199                         return getTModelDetail(tModelKey);
200                 }
201                 if (bindingKey != null) {
202                         return getBindingDetail(bindingKey);
203                 }
204                 if (serviceKey != null) {
205                         return getServiceDetail(serviceKey);
206                 }
207                 throw new WebApplicationException(400);
208         }
209 
210         /**
211          * This method implements the UDDIv3 spec for HTTP GET Inquiry services.
212          * Returns the details of a UDDI entity in XML, use query parameters
213          * serviceKey,businessKey,tModelKey, or bindingKey
214          *
215          * @param serviceKey
216          * @param businessKey
217          * @param tModelKey
218          * @param bindingKey
219          * @return xml
220          * @throws WebApplicationException
221          */
222         @GET
223         @Path("/XML/getDetail")
224         @Produces("application/xml")
225         @org.apache.cxf.jaxrs.model.wadl.Description("This method implements the UDDIv3 spec for HTTP GET Inquiry services. Returns the details of a UDDI entity in XML, use query parameters"
226                 + "serviceKey,businessKey,tModelKey, bindingKey")
227         public Object getDetailXML(@QueryParam("serviceKey") String serviceKey,
228                 @QueryParam("businessKey") String businessKey,
229                 @QueryParam("tModelKey") String tModelKey,
230                 @QueryParam("bindingKey") String bindingKey) throws WebApplicationException {
231                 int params = 0;
232                 if (businessKey != null) {
233                         params++;
234                 }
235                 if (tModelKey != null) {
236                         params++;
237                 }
238                 if (bindingKey != null) {
239                         params++;
240                 }
241                 if (serviceKey != null) {
242                         params++;
243                 }
244                 if (params != 1) {
245                         throw new WebApplicationException(400);
246                 }
247                 if (businessKey != null) {
248                         return getBusinessDetail(businessKey);
249                 }
250                 if (tModelKey != null) {
251                         return getTModelDetail(tModelKey);
252                 }
253                 if (bindingKey != null) {
254                         return getBindingDetail(bindingKey);
255                 }
256                 if (serviceKey != null) {
257                         return getServiceDetail(serviceKey);
258                 }
259                 throw new WebApplicationException(400);
260         }
261 
262         /**
263          * Returns the details of a service entity in XML
264          *
265          * @param id
266          * @return xml
267          * @throws WebApplicationException
268          */
269         @GET
270         @Path("/XML/serviceKey/{id}")
271         @Produces("application/xml")
272         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the details of a service entity in XML")
273         public org.uddi.api_v3.BusinessService getServiceDetailXML(@PathParam("id") String id) throws WebApplicationException {
274                 return getServiceDetail(id);
275         }
276 
277         private BusinessService getServiceDetail(String id) {
278                 GetServiceDetail gbd = new GetServiceDetail();
279                 gbd.getServiceKey().add(id);
280 
281                 try {
282                         ServiceDetail serviceDetail = inquiry.getServiceDetail(gbd);
283                         return serviceDetail.getBusinessService().get(0);
284                 } catch (DispositionReportFaultMessage ex) {
285                         HandleException(ex);
286                 }
287                 return null;
288         }
289 
290         /**
291          * Returns the operational details of a given entity in JSON
292          *
293          * @param id
294          * @return json
295          * @throws WebApplicationException
296          */
297         @GET
298         @Path("/JSON/opInfo/{id}")
299         @Produces("application/json")
300         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the operational details of a given entity in JSON")
301         public org.uddi.api_v3.OperationalInfo getOpInfoJSON(@PathParam("id") String id) throws WebApplicationException {
302                 return getOpInfoDetail(id);
303         }
304 
305         /**
306          * Returns the operational details of a given entity in XML
307          *
308          * @param id
309          * @return xml
310          * @throws WebApplicationException
311          */
312         @GET
313         @Path("/XML/opInfo/{id}")
314         @Produces("application/xml")
315         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the operational details of a given entity in XML")
316         public org.uddi.api_v3.OperationalInfo getOpInfoXML(@PathParam("id") String id) throws WebApplicationException {
317                 return getOpInfoDetail(id);
318         }
319 
320         private OperationalInfo getOpInfoDetail(String id) {
321                 GetOperationalInfo req = new GetOperationalInfo();
322                 req.getEntityKey().add(id);
323                 try {
324                         OperationalInfos operationalInfo = inquiry.getOperationalInfo(req);
325                         return operationalInfo.getOperationalInfo().get(0);
326                 } catch (DispositionReportFaultMessage ex) {
327                         HandleException(ex);
328                 }
329                 return null;
330         }
331 
332         /**
333          * Returns the binding details of a given entity in JSON
334          *
335          * @param id
336          * @return json
337          * @throws WebApplicationException
338          */
339         @GET
340         @Path("/JSON/bindingKey/{id}")
341         @Produces("application/json")
342         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the binding details of a given entity in JSON")
343         public org.uddi.api_v3.BindingTemplate getBindingDetailJSON(@PathParam("id") String id) throws WebApplicationException {
344                 return getBindingDetail(id);
345         }
346 
347         /**
348          * Returns the binding details of a given entity in XML
349          *
350          * @param id
351          * @return xml
352          * @throws WebApplicationException
353          */
354         @GET
355         @Path("/XML/bindingKey/{id}")
356         @Produces("application/xml")
357         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the binding details of a given entity in XML")
358         public org.uddi.api_v3.BindingTemplate getBindingDetailXML(@PathParam("id") String id) throws WebApplicationException {
359                 return getBindingDetail(id);
360         }
361 
362         private BindingTemplate getBindingDetail(String id) {
363                 GetBindingDetail req = new GetBindingDetail();
364                 req.getBindingKey().add(id);
365                 try {
366                         BindingDetail bindingDetail = inquiry.getBindingDetail(req);
367                         return bindingDetail.getBindingTemplate().get(0);
368                 } catch (DispositionReportFaultMessage ex) {
369                         HandleException(ex);
370                 }
371                 return null;
372         }
373 
374         /**
375          * Returns the binding details of a given entity in JSON
376          *
377          * @param id
378          * @return json
379          * @throws WebApplicationException
380          */
381         @GET
382         @Path("/JSON/endpointsByService/{id}")
383         @Produces("application/json")
384         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the service access points of a given service in JSON")
385         public UriContainer geEndpointsByServiceJSON(@PathParam("id") String id) throws WebApplicationException {
386                 return getEndpointsByService(id);
387         }
388 
389         /**
390          * Returns the binding details of a given entity in XML
391          *
392          * @param id
393          * @return xml
394          * @throws WebApplicationException
395          */
396         @GET
397         @Path("/XML/endpointsByService/{id}")
398         @Produces("application/xml")
399         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the service access points of a given service in XML")
400         public UriContainer getEndpointsByServiceXML(@PathParam("id") String id) throws WebApplicationException {
401                 return getEndpointsByService(id);
402         }
403 
404         /**
405          * Returns the business keys of the first 100 registered businesses in
406          * XML
407          *
408          * @return xml
409          * @throws WebApplicationException
410          */
411         @GET
412         @Path("/XML/businessList")
413         @Produces("application/xml")
414         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the business keys of the first 100 registered businesses in XML")
415         public KeyBag getBusinessListXML() throws WebApplicationException {
416                 return getBusinessListData();
417         }
418 
419         /**
420          * Returns the business keys of the first 100 registered businesses in
421          * JSON
422          *
423          * @return json
424          * @throws WebApplicationException
425          */
426         @GET
427         @Path("/JSON/businessList")
428         @Produces("application/json")
429         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the business keys of the first 100 registered businesses in JSON")
430         public KeyBag getBusinessListJSON() throws WebApplicationException {
431                 return getBusinessListData();
432         }
433 
434         /**
435          * Returns the Service keys of the first 100 registered services in XML
436          *
437          * @return xml
438          * @throws WebApplicationException
439          */
440         @GET
441         @Path("/XML/serviceList")
442         @Produces("application/xml")
443         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the Service keys of the first 100 registered services in XML")
444         public KeyBag getServiceListXML() throws WebApplicationException {
445                 return getServiceListData();
446         }
447 
448         /**
449          * Returns the Service keys of the first 100 registered services in JSON
450          *
451          * @return json
452          * @throws WebApplicationException
453          */
454         @GET
455         @Path("/JSON/serviceList")
456         @Produces("application/json")
457         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the Service keys of the first 100 registered services in JSON")
458         public KeyBag getServiceListJSON() throws WebApplicationException {
459                 return getServiceListData();
460         }
461 
462         /**
463          * Returns the tModel keys of the first 100 registered services in XML
464          *
465          * @return xml
466          * @throws WebApplicationException
467          */
468         @GET
469         @Path("/XML/tModelList")
470         @Produces("application/xml")
471         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the tModel keys of the first 100 registered services in XML")
472         public KeyBag getTModelListXML() throws WebApplicationException {
473                 return getTmodelListData();
474         }
475 
476         /**
477          * Returns the search results for registered businesses in XML
478          *
479          * @param name
480          * @param lang
481          * @param findQualifiers
482          * @param maxrows
483          * @param offset
484          * @return BusinessList
485          * @throws WebApplicationException
486          */
487         @GET
488         @Path("/XML/businessSearch")
489         @Produces("application/xml")
490         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the search results for registered businesses in XML")
491         public BusinessList getBusinessSearchXML(@QueryParam("name") String name,
492                 @QueryParam("lang") String lang,
493                 @QueryParam("findQualifiers") String findQualifiers,
494                 @QueryParam("maxrows") Integer maxrows,
495                 @QueryParam("offset") Integer offset) throws WebApplicationException {
496                 return getBusinessSearch(name, lang, findQualifiers, maxrows, offset);
497         }
498 
499         /**
500          * Returns the search results for registered businesses in JSON
501          *
502          * @param name
503          * @param lang
504          * @param findQualifiers
505          * @param maxrows
506          * @param offset
507          * @return BusinessList
508          * @throws WebApplicationException
509          */
510         @GET
511         @Path("/JSON/businessSearch")
512         @Produces("application/json")
513         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the search results for registered businesses in JSON")
514         public BusinessList getBusinessSearchJSON(@QueryParam("name") String name,
515                 @QueryParam("lang") String lang,
516                 @QueryParam("findQualifiers") String findQualifiers,
517                 @QueryParam("maxrows") Integer maxrows,
518                 @QueryParam("offset") Integer offset) throws WebApplicationException {
519                 return getBusinessSearch(name, lang, findQualifiers, maxrows, offset);
520         }
521 
522         /**
523          * Returns the search results for registered services in JSON
524          *
525          * @param name
526          * @param lang
527          * @param findQualifiers
528          * @param maxrows
529          * @param offset
530          * @return serviceList
531          * @throws WebApplicationException
532          */
533         @GET
534         @Path("/JSON/serviceSearch")
535         @Produces("application/json")
536         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the search results for registered services in JSON")
537         public ServiceList getServiceSearchJSON(@QueryParam("name") String name,
538                 @QueryParam("lang") String lang,
539                 @QueryParam("findQualifiers") String findQualifiers,
540                 @QueryParam("maxrows") Integer maxrows,
541                 @QueryParam("offset") Integer offset) throws WebApplicationException {
542                 return getServiceSearch(name, lang, findQualifiers, maxrows, offset);
543         }
544 
545         /**
546          * Returns the search results for registered services in XML
547          *
548          * @param name
549          * @param lang
550          * @param findQualifiers
551          * @param maxrows
552          * @param offset
553          * @return serviceList
554          * @throws WebApplicationException
555          */
556         @GET
557         @Path("/XML/serviceSearch")
558         @Produces("application/json")
559         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the search results for registered services in XML")
560         public ServiceList getServiceSearchXML(@QueryParam("name") String name,
561                 @QueryParam("lang") String lang,
562                 @QueryParam("findQualifiers") String findQualifiers,
563                 @QueryParam("maxrows") Integer maxrows,
564                 @QueryParam("offset") Integer offset) throws WebApplicationException {
565                 return getServiceSearch(name, lang, findQualifiers, maxrows, offset);
566         }
567 
568         /**
569          * Returns the tModel keys of the first 100 registered services in JSON
570          *
571          * @return json
572          * @throws WebApplicationException
573          */
574         @GET
575         @Path("/JSON/tModelList")
576         @Produces("application/json")
577         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the tModel keys of the first 100 registered services in JSON")
578         public KeyBag getTModelListJSON() throws WebApplicationException {
579                 return getTmodelListData();
580         }
581 
582         /**
583          * Returns the search results for registered tModel in JSON
584          *
585          * @param name
586          * @param lang
587          * @param findQualifiers
588          * @param maxrows
589          * @param offset
590          * @return TModelList
591          * @throws WebApplicationException
592          */
593         @GET
594         @Path("/JSON/searchTModel")
595         @Produces("application/json")
596         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the search results for registered tModel in JSON")
597         public TModelList getTModelSearchJSON(@QueryParam("name") String name,
598                 @QueryParam("lang") String lang,
599                 @QueryParam("findQualifiers") String findQualifiers,
600                 @QueryParam("maxrows") Integer maxrows,
601                 @QueryParam("offset") Integer offset) throws WebApplicationException {
602                 return getTModelSearch(name, lang, findQualifiers, maxrows, offset);
603         }
604 
605         /**
606          * Returns the search results for registered tModel in XML
607          *
608          * @param name
609          * @param lang
610          * @param findQualifiers
611          * @param maxrows
612          * @param offset
613          * @return TModelList
614          * @throws WebApplicationException
615          */
616         @GET
617         @Path("/XML/searchTModel")
618         @Produces("application/json")
619         @org.apache.cxf.jaxrs.model.wadl.Description("Returns the search results for registered tModel in XML")
620         public TModelList getTModelSearchXML(@QueryParam("name") String name,
621                 @QueryParam("lang") String lang,
622                 @QueryParam("findQualifiers") String findQualifiers,
623                 @QueryParam("maxrows") Integer maxrows,
624                 @QueryParam("offset") Integer offset) throws WebApplicationException {
625                 return getTModelSearch(name, lang, findQualifiers, maxrows, offset);
626         }
627 
628         private UriContainer getEndpointsByService(String id) throws WebApplicationException {
629                 UriContainer c = new UriContainer();
630                 List<String> ret = new ArrayList<String>();
631                 GetServiceDetail fs = new GetServiceDetail();
632 
633                 fs.getServiceKey().add(id);
634                 try {
635                         ServiceDetail serviceDetail = inquiry.getServiceDetail(fs);
636                         if (serviceDetail == null || serviceDetail.getBusinessService().isEmpty()) {
637                                 throw new WebApplicationException(400);
638                         } else {
639                                 List<String> endpoints = GetEndpoints(serviceDetail, null);
640                                 ret.addAll(endpoints);
641                         }
642                 } catch (DispositionReportFaultMessage ex) {
643                         HandleException(ex);
644                 }
645                 c.setUriList(ret);
646                 return c;
647         }
648 
649         private List<String> GetEndpoints(ServiceDetail serviceDetail, String authInfo) throws DispositionReportFaultMessage {
650                 List<String> items = new ArrayList<String>();
651                 if (serviceDetail == null) {
652                         return items;
653                 }
654                 for (int i = 0; i < serviceDetail.getBusinessService().size(); i++) {
655                         if (serviceDetail.getBusinessService().get(i).getBindingTemplates() != null) {
656                                 for (int k = 0; k < serviceDetail.getBusinessService().get(i).getBindingTemplates().getBindingTemplate().size(); k++) {
657                                         items.addAll(ParseBinding(serviceDetail.getBusinessService().get(i).getBindingTemplates().getBindingTemplate().get(k), authInfo));
658                                 }
659                         }
660                 }
661                 return items;
662         }
663 
664         private List<String> GetBindingInfo(String value, String cred) throws DispositionReportFaultMessage {
665                 List<String> items = new ArrayList<String>();
666                 if (value == null) {
667                         return items;
668                 }
669                 GetBindingDetail b = new GetBindingDetail();
670                 b.setAuthInfo(cred);
671                 b.getBindingKey().add(value);
672                 BindingDetail bindingDetail = inquiry.getBindingDetail(b);
673                 for (int i = 0; i < bindingDetail.getBindingTemplate().size(); i++) {
674                         items.addAll(ParseBinding(bindingDetail.getBindingTemplate().get(i), cred));
675                 }
676                 return items;
677         }
678 
679         private List<String> FetchWSDL(String value) {
680                 List<String> items = new ArrayList<String>();
681 
682                 if (value.startsWith("http://") || value.startsWith("https://")) {
683                         //here, we need an HTTP Get for WSDLs
684                         org.apache.juddi.v3.client.mapping.wsdl.ReadWSDL r = new ReadWSDL();
685                         r.setIgnoreSSLErrors(true);
686                         try {
687                                 Definition wsdlDefinition = r.readWSDL(new URL(value));
688                                 Properties properties = new Properties();
689 
690                                 properties.put("keyDomain", "domain");
691                                 properties.put("businessName", "biz");
692                                 properties.put("serverName", "localhost");
693                                 properties.put("serverPort", "80");
694 
695                                 WSDL2UDDI wsdl2UDDI = new WSDL2UDDI(null, new URLLocalizerDefaultImpl(), properties);
696                                 BusinessServices businessServices = wsdl2UDDI.createBusinessServices(wsdlDefinition);
697                                 for (int i = 0; i < businessServices.getBusinessService().size(); i++) {
698                                         if (businessServices.getBusinessService().get(i).getBindingTemplates() != null) {
699                                                 for (int k = 0; k < businessServices.getBusinessService().get(i).getBindingTemplates().getBindingTemplate().size(); k++) {
700                                                         items.addAll(ParseBinding(businessServices.getBusinessService().get(i).getBindingTemplates().getBindingTemplate().get(k), null));
701                                                 }
702                                         }
703                                 }
704                         } catch (Exception ex) {
705                         }
706 
707                 }
708                 return items;
709         }
710 
711         private List<String> ParseBinding(BindingTemplate get, String authInfo) throws DispositionReportFaultMessage {
712                 List<String> items = new ArrayList<String>();
713                 if (get == null || get.getAccessPoint() == null) {
714                         return items;
715                 }
716                 if (get.getHostingRedirector() != null) {
717                         //hosting Redirector is the same as "reference this other binding template". It's actually deprecated so 
718                         //don't expect to see this too often
719                         items.addAll(GetBindingInfo(get.getHostingRedirector().getBindingKey(), authInfo));
720                 }
721                 if (get.getAccessPoint() != null) {
722                         String usetype = get.getAccessPoint().getUseType();
723                         if (usetype == null) {
724 
725                                 //this is unexpected, usetype is a required field
726                                 items.add((get.getAccessPoint().getValue()));
727 
728                         } else if (usetype.equalsIgnoreCase(AccessPointType.BINDING_TEMPLATE.toString())) {
729                                 //referencing another binding template
730                                 items.addAll(GetBindingInfo(get.getAccessPoint().getValue(), authInfo));
731                         } else if (usetype.equalsIgnoreCase(AccessPointType.HOSTING_REDIRECTOR.toString())) {
732                                 //this one is a bit strange. the value should be a binding template
733 
734                                 items.addAll(GetBindingInfo(get.getAccessPoint().getValue(), authInfo));
735 
736                         } else if (usetype.equalsIgnoreCase(AccessPointType.WSDL_DEPLOYMENT.toString())) {
737                                 //fetch wsdl and parse
738                                 items.addAll(FetchWSDL(get.getAccessPoint().getValue()));
739                         } else if (usetype.equalsIgnoreCase(AccessPointType.END_POINT.toString())) {
740 
741                                 items.add((get.getAccessPoint().getValue()));
742 
743                         } else {
744 
745                                 //treat it has an extension or whatever
746                                 items.add((get.getAccessPoint().getValue()));
747 
748                         }
749 
750                 }
751                 return items;
752         }
753 
754         private static void HandleException(Exception ex) throws WebApplicationException {
755                 if (ex == null) {
756                         throw new WebApplicationException(500);
757                 }
758                 log.error(ex.getMessage());
759                 log.debug(ex);
760                 if (ex instanceof DispositionReportFaultMessage) {
761                         DispositionReportFaultMessage dr = (DispositionReportFaultMessage) ex;
762                         if (dr.getFaultInfo() == null) {
763                                 throw new WebApplicationException(500);
764                         }
765                         if (dr.getFaultInfo().countainsErrorCode(UDDIErrorHelper.lookupErrCode(UDDIErrorHelper.E_AUTH_TOKEN_EXPIRED))) {
766                                 throw new WebApplicationException(ex, 401);
767                         }
768                         if (dr.getFaultInfo().countainsErrorCode(UDDIErrorHelper.lookupErrCode(UDDIErrorHelper.E_AUTH_TOKEN_REQUIRED))) {
769                                 throw new WebApplicationException(ex, 401);
770                         }
771                         if (dr.getFaultInfo().countainsErrorCode(UDDIErrorHelper.lookupErrCode(UDDIErrorHelper.E_FATAL_ERROR))) {
772                                 throw new WebApplicationException(ex, 500);
773                         }
774                 }
775                 throw new WebApplicationException(ex, 400);
776         }
777         private final int MAX_ROWS = 100;
778 
779         private KeyBag getBusinessListData() {
780                 FindBusiness fb = new FindBusiness();
781                 fb.getName().add(new Name(UDDIConstants.WILDCARD, null));
782                 fb.setFindQualifiers(new FindQualifiers());
783                 fb.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
784                 fb.setMaxRows(MAX_ROWS);
785                 BusinessList findBusiness = null;
786                 try {
787                         findBusiness = inquiry.findBusiness(fb);
788                 } catch (Exception ex) {
789                         HandleException(ex);
790                 }
791                 KeyBag kb = new KeyBag();
792                 if (findBusiness != null && findBusiness.getBusinessInfos() != null) {
793                         for (int i = 0; i < findBusiness.getBusinessInfos().getBusinessInfo().size(); i++) {
794                                 kb.getBusinessKey().add(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getBusinessKey());
795                         }
796                 }
797                 return kb;
798         }
799 
800         private KeyBag getServiceListData() {
801                 FindService fb = new FindService();
802                 fb.getName().add(new Name(UDDIConstants.WILDCARD, null));
803                 fb.setFindQualifiers(new FindQualifiers());
804                 fb.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
805                 fb.setMaxRows(MAX_ROWS);
806                 ServiceList findBusiness = null;
807                 try {
808                         findBusiness = inquiry.findService(fb);
809                 } catch (Exception ex) {
810                         HandleException(ex);
811                 }
812                 KeyBag kb = new KeyBag();
813                 if (findBusiness != null && findBusiness.getServiceInfos() != null) {
814                         for (int i = 0; i < findBusiness.getServiceInfos().getServiceInfo().size(); i++) {
815                                 kb.getServiceKey().add(findBusiness.getServiceInfos().getServiceInfo().get(i).getServiceKey());
816                         }
817                 }
818                 return kb;
819         }
820 
821         private KeyBag getTmodelListData() {
822                 FindTModel fb = new FindTModel();
823                 fb.setName(new Name(UDDIConstants.WILDCARD, null));
824                 fb.setFindQualifiers(new FindQualifiers());
825                 fb.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
826                 fb.setMaxRows(MAX_ROWS);
827                 TModelList findBusiness = null;
828                 try {
829                         findBusiness = inquiry.findTModel(fb);
830                 } catch (Exception ex) {
831                         HandleException(ex);
832                 }
833                 KeyBag kb = new KeyBag();
834                 if (findBusiness != null && findBusiness.getTModelInfos() != null) {
835                         for (int i = 0; i < findBusiness.getTModelInfos().getTModelInfo().size(); i++) {
836                                 kb.getTModelKey().add(findBusiness.getTModelInfos().getTModelInfo().get(i).getTModelKey());
837                         }
838                 }
839                 return kb;
840         }
841 
842         private BusinessList getBusinessSearch(String name, String lang, String findQualifiers, Integer maxrows, Integer offset) {
843                 FindBusiness fb = new FindBusiness();
844 
845                 fb.getName().add(new Name(UDDIConstants.WILDCARD, null));
846                 if (name != null) {
847                         fb.getName().get(0).setValue(name);
848                 }
849                 if (lang != null) {
850                         fb.getName().get(0).setValue(lang);
851                 }
852                 fb.setFindQualifiers(new FindQualifiers());
853                 if (findQualifiers == null) {
854                         fb.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
855                 } else {
856                         String[] fqs = findQualifiers.split(",");
857                         fb.getFindQualifiers().getFindQualifier().addAll(Arrays.asList(fqs));
858                 }
859                 fb.setMaxRows(MAX_ROWS);
860 
861                 if (maxrows != null) {
862                         fb.setMaxRows(maxrows);
863                 }
864                 fb.setListHead(0);
865                 if (offset != null) {
866                         fb.setListHead(offset);
867                 }
868 
869                 BusinessList findBusiness = null;
870                 try {
871                         findBusiness = inquiry.findBusiness(fb);
872                 } catch (Exception ex) {
873                         HandleException(ex);
874                 }
875                 return findBusiness;
876 
877         }
878 
879         private ServiceList getServiceSearch(String name, String lang, String findQualifiers, Integer maxrows, Integer offset) {
880                 FindService fb = new FindService();
881 
882                 fb.getName().add(new Name(UDDIConstants.WILDCARD, null));
883                 if (name != null) {
884                         fb.getName().get(0).setValue(name);
885                 }
886                 if (lang != null) {
887                         fb.getName().get(0).setValue(lang);
888                 }
889                 fb.setFindQualifiers(new FindQualifiers());
890                 if (findQualifiers == null) {
891                         fb.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
892                 } else {
893                         String[] fqs = findQualifiers.split(",");
894                         fb.getFindQualifiers().getFindQualifier().addAll(Arrays.asList(fqs));
895                 }
896                 fb.setMaxRows(MAX_ROWS);
897 
898                 if (maxrows != null) {
899                         fb.setMaxRows(maxrows);
900                 }
901                 fb.setListHead(0);
902                 if (offset != null) {
903                         fb.setListHead(offset);
904                 }
905 
906                 ServiceList findBusiness = null;
907                 try {
908                         findBusiness = inquiry.findService(fb);
909                 } catch (Exception ex) {
910                         HandleException(ex);
911                 }
912 
913                 return findBusiness;
914         }
915 
916         private TModelList getTModelSearch(String name, String lang, String findQualifiers, Integer maxrows, Integer offset) {
917                 FindTModel fb = new FindTModel();
918 
919                 fb.setName(new Name(UDDIConstants.WILDCARD, null));
920                 if (name != null) {
921                         fb.getName().setValue(name);
922                 }
923                 if (lang != null) {
924                         fb.getName().setValue(lang);
925                 }
926                 fb.setFindQualifiers(new FindQualifiers());
927                 if (findQualifiers == null) {
928                         fb.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
929                 } else {
930                         String[] fqs = findQualifiers.split(",");
931                         fb.getFindQualifiers().getFindQualifier().addAll(Arrays.asList(fqs));
932                 }
933                 fb.setMaxRows(MAX_ROWS);
934 
935                 if (maxrows != null) {
936                         fb.setMaxRows(maxrows);
937                 }
938                 fb.setListHead(0);
939                 if (offset != null) {
940                         fb.setListHead(offset);
941                 }
942 
943                 TModelList findBusiness = null;
944                 try {
945                         findBusiness = inquiry.findTModel(fb);
946                 } catch (Exception ex) {
947                         HandleException(ex);
948                 }
949 
950                 return findBusiness;
951 
952         }
953 }