This project has retired. For details please refer to its Attic page.
SearchByQos 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.v3.client.cli;
17  
18  import javax.xml.bind.JAXB;
19  import org.apache.juddi.jaxb.PrintUDDI;
20  import org.apache.juddi.v3.client.UDDIConstants;
21  import org.apache.juddi.v3.client.ext.wsdm.WSDMQosConstants;
22  import org.apache.juddi.v3.client.transport.Transport;
23  import org.uddi.api_v3.BindingDetail;
24  import org.uddi.api_v3.BusinessList;
25  import org.uddi.api_v3.FindBinding;
26  import org.uddi.api_v3.FindBusiness;
27  import org.uddi.api_v3.FindQualifiers;
28  import org.uddi.api_v3.FindService;
29  import org.uddi.api_v3.Name;
30  import org.uddi.api_v3.ServiceList;
31  import org.uddi.api_v3.TModelBag;
32  import org.uddi.v3_service.UDDIInquiryPortType;
33  
34  /**
35   *
36   * @author Alex O'Ree
37   */
38  public class SearchByQos {
39  
40          private UDDIInquiryPortType inquiry;
41  
42          public void doFindService(String token, Transport transport) throws Exception {
43  
44                  // Now you create a reference to the UDDI API
45              
46                  inquiry = transport.getUDDIInquiryService();
47                  
48                  // Making API call that retrieves the authentication token for the 'root' user.
49                  //String rootAuthToken = clerk.getAuthToken(clerk.getUDDINode().getSecurityUrl());
50                  String uddi = token;// security.getAuthToken(getAuthTokenRoot).getAuthInfo();
51  
52                  ServiceList after = getServiceList(uddi);
53                  if (after.getServiceInfos()==null || after.getServiceInfos().getServiceInfo() == null) {
54                          System.out.println("no services returned!");
55                          return;
56                  }
57                  //PrintUDDI<ServiceList> p = new PrintUDDI<ServiceList>();
58                  System.out.println(after.getServiceInfos().getServiceInfo().size() + " services returned!");
59                  JAXB.marshal(after,System.out);
60                  
61  
62          }
63  
64          public void doFindBinding(String token, Transport transport) throws Exception {
65  
66                  // Now you create a reference to the UDDI API
67                  inquiry = transport.getUDDIInquiryService();
68  
69                  // Making API call that retrieves the authentication token for the 'root' user.
70                  //String rootAuthToken = clerk.getAuthToken(clerk.getUDDINode().getSecurityUrl());
71                  String uddi = token;//security.getAuthToken(getAuthTokenRoot).getAuthInfo();
72  
73                  BindingDetail after = getBindingList(uddi);
74                  if (after.getBindingTemplate() == null) {
75                          System.out.println("no bindings returned!");
76                          return;
77                  } 
78                  PrintUDDI<BindingDetail> p = new PrintUDDI<BindingDetail>();
79  
80                  System.out.println(p.print(after));
81  
82          }
83  
84          public void doFindBusiness(String token, Transport transport) throws Exception {
85                  // create a manager and read the config in the archive; 
86                  // you can use your config file name
87  
88                  // Now you create a reference to the UDDI API
89                  inquiry = transport.getUDDIInquiryService();
90                  String uddi = token;//security.getAuthToken(getAuthTokenRoot).getAuthInfo();
91  
92                  BusinessList after2 = getBusinessList(uddi);
93  
94                  PrintUDDI<BusinessList> p2 = new PrintUDDI<BusinessList>();
95  
96                  System.out.println(p2.print(after2));
97  
98          }
99  
100 
101         private BusinessList getBusinessList(String token) throws Exception {
102                 FindBusiness fb = new FindBusiness();
103                 fb.setAuthInfo(token);
104                 org.uddi.api_v3.FindQualifiers fq = new org.uddi.api_v3.FindQualifiers();
105                 fq.getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
106                 fq.getFindQualifier().add(UDDIConstants.OR_ALL_KEYS);
107                 fb.setFindQualifiers(fq);
108                 fb.getName().add((new Name(UDDIConstants.WILDCARD, null)));
109 
110                 fb.setTModelBag(new TModelBag());
111                 fb.getTModelBag().getTModelKey().addAll(WSDMQosConstants.getAllQOSKeys());
112 
113                 return inquiry.findBusiness(fb);
114         }
115 
116         private ServiceList getServiceList(String token) throws Exception {
117                 FindService fb = new FindService();
118                 fb.setAuthInfo(token);
119                 org.uddi.api_v3.FindQualifiers fq = new org.uddi.api_v3.FindQualifiers();
120                 fq.getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
121                 fq.getFindQualifier().add(UDDIConstants.OR_ALL_KEYS);
122                 fb.setFindQualifiers(fq);
123                 fb.getName().add((new Name(UDDIConstants.WILDCARD, null)));
124 
125                 fb.setTModelBag(new TModelBag());
126                 fb.getTModelBag().getTModelKey().addAll(WSDMQosConstants.getAllQOSKeys());
127 
128                 return inquiry.findService(fb);
129         }
130 
131         private BindingDetail getBindingList(String token) throws Exception {
132                 FindBinding fb = new FindBinding();
133                 fb.setAuthInfo(token);
134                 fb.setTModelBag(new TModelBag());
135                 fb.getTModelBag().getTModelKey().addAll(WSDMQosConstants.getAllQOSKeys());
136                 fb.setFindQualifiers(new FindQualifiers());
137                 fb.getFindQualifiers().getFindQualifier().add(UDDIConstants.OR_ALL_KEYS_TMODEL);
138                 return inquiry.findBinding(fb);
139         }
140 
141         
142 }