This project has retired. For details please refer to its Attic page.
UddiFindBinding 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.v3.client.cli;
18  
19  import org.apache.juddi.v3.client.UDDIConstants;
20  import org.apache.juddi.v3.client.config.UDDIClient;
21  import org.apache.juddi.v3.client.transport.Transport;
22  import org.uddi.api_v3.*;
23  import org.uddi.v3_service.UDDIInquiryPortType;
24  import org.uddi.v3_service.UDDISecurityPortType;
25  
26  /**
27   * This class shows you how to find an endpoint by searching through all
28   * services
29   *
30   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
31   */
32  public class UddiFindBinding {
33  
34          private UDDISecurityPortType security = null;
35          private UDDIInquiryPortType inquiry = null;
36  
37          public UddiFindBinding() {
38                  try {
39                          // create a manager and read the config in the archive; 
40                          // you can use your config file name
41                          UDDIClient clerkManager = new UDDIClient("META-INF/simple-publish-uddi.xml");
42                          Transport transport = clerkManager.getTransport();
43                          // Now you create a reference to the UDDI API
44                          security = transport.getUDDISecurityService();
45                          inquiry = transport.getUDDIInquiryService();
46                  } catch (Exception e) {
47                          e.printStackTrace();
48                  }
49          }
50  
51          public void fire(String token) {
52                  try {
53                          // Setting up the values to get an authentication token for the 'root' user ('root' user has admin privileges
54                          // and can save other publishers).
55                          GetAuthToken getAuthTokenRoot = new GetAuthToken();
56                          getAuthTokenRoot.setUserID("root");
57                          getAuthTokenRoot.setCred("root");
58  
59                          if (token == null) {
60                                  // Making API call that retrieves the authentication token for the 'root' user.
61                                  AuthToken rootAuthToken = security.getAuthToken(getAuthTokenRoot);
62                                  System.out.println("root AUTHTOKEN = " + "don't log auth tokens!");
63                                  token = rootAuthToken.getAuthInfo();
64                          }
65                          FindService fs = new FindService();
66                          fs.setAuthInfo(token);
67                          fs.getName().add(new Name());
68                          fs.getName().get(0).setValue("%");
69                          fs.setFindQualifiers(new FindQualifiers());
70                          fs.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
71  
72                          ServiceList findService = inquiry.findService(fs);
73                          System.out.println(findService.getServiceInfos().getServiceInfo().size());
74                          GetServiceDetail gs = new GetServiceDetail();
75                          for (int i = 0; i < findService.getServiceInfos().getServiceInfo().size(); i++) {
76                                  gs.getServiceKey().add(findService.getServiceInfos().getServiceInfo().get(i).getServiceKey());
77                          }
78  
79                          ServiceDetail serviceDetail = inquiry.getServiceDetail(gs);
80                          for (int i = 0; i < serviceDetail.getBusinessService().size(); i++) {
81                                  //System.out.println(serviceDetail.getBusinessService().get(i).getBindingTemplates().getBindingTemplate().size());
82                                  if (serviceDetail.getBusinessService().get(i).getBindingTemplates() != null) {
83                                          for (int k = 0; k < serviceDetail.getBusinessService().get(i).getBindingTemplates().getBindingTemplate().size(); k++) {
84                                                  if (serviceDetail.getBusinessService().get(i).getBindingTemplates().getBindingTemplate().get(k).getAccessPoint() != null) {
85                                                          System.out.println(serviceDetail.getBusinessService().get(i).getBindingTemplates().getBindingTemplate().get(k).getAccessPoint().getValue());
86                                                  }
87                                          }
88                                  }
89                          }
90                  } catch (Exception e) {
91                          e.printStackTrace();
92                  }
93          }
94  
95          public static void main(String args[]) {
96                  UddiFindBinding sp = new UddiFindBinding();
97                  sp.fire(null);
98          }
99  }