This project has retired. For details please refer to its Attic page.
UddiSubscriptionManagement xref
View Javadoc
1   /*
2    * Copyright 2014 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.samples;
17  
18  import java.util.List;
19  import org.apache.juddi.jaxb.PrintUDDI;
20  import org.apache.juddi.v3.client.config.UDDIClerk;
21  import org.apache.juddi.v3.client.config.UDDIClient;
22  import org.apache.juddi.v3.client.transport.Transport;
23  import org.uddi.sub_v3.DeleteSubscription;
24  import org.uddi.sub_v3.Subscription;
25  import org.uddi.v3_service.UDDISubscriptionPortType;
26  
27  /**
28   *
29   * @author Alex O'Ree
30   */
31  public class UddiSubscriptionManagement {
32          public static void main(String args[]) throws Exception {
33                  UddiSubscriptionManagement sp = new UddiSubscriptionManagement();
34                  sp.printSubscriptions(null);
35          }
36  
37          private UDDISubscriptionPortType uddiSubscriptionService = null;
38  
39          private UDDIClerk clerk = null;
40          private UDDIClient client = null;
41          private PrintUDDI<Subscription> printer = new PrintUDDI<Subscription>();
42  
43          public UddiSubscriptionManagement() {
44                  try {
45                          // create a manager and read the config in the archive; 
46                          // you can use your config file name
47                          client = new UDDIClient("META-INF/simple-publish-uddi.xml");
48                          clerk = client.getClerk("default");
49                          Transport transport = client.getTransport();
50                          // Now you create a reference to the UDDI API
51                          uddiSubscriptionService = transport.getUDDISubscriptionService();
52                  } catch (Exception e) {
53                          e.printStackTrace();
54                  }
55          }
56  
57          public UddiSubscriptionManagement(Transport transport) {
58                  try {
59  
60                          // Now you create a reference to the UDDI API
61                          uddiSubscriptionService = transport.getUDDISubscriptionService();
62                  } catch (Exception e) {
63                          e.printStackTrace();
64                  }
65          }
66  
67  
68          public void printSubscriptions(String authtoken) throws Exception {
69  
70                  if (authtoken == null) {
71                          authtoken = clerk.getAuthToken();
72                  }
73                  List<Subscription> subscriptions = uddiSubscriptionService.getSubscriptions(authtoken);
74                  System.out.println(subscriptions.size() + " subscriptions found");
75                  for (int i = 0; i < subscriptions.size(); i++) {
76                          System.out.println("_____________________________________");
77  
78                          System.out.println(printer.print(subscriptions.get(i)));
79                  }
80          }
81  
82          public void deleteSubscription(String authtoken, String key) throws Exception {
83  
84                  if (authtoken == null) {
85                          authtoken = clerk.getAuthToken();
86                  }
87                  if (key == null) {
88                          System.out.println("No key specified!");
89                          return;
90                  }
91                  DeleteSubscription ds = new DeleteSubscription();
92                  ds.setAuthInfo(authtoken);
93                  ds.getSubscriptionKey().add(key);
94                  uddiSubscriptionService.deleteSubscription(ds);
95                  System.out.println("Deleted!");
96  
97          }
98  
99          public void deleteAllSubscriptions(String authtoken) throws Exception {
100 
101                 if (authtoken == null) {
102                         authtoken = clerk.getAuthToken();
103                 }
104                 List<Subscription> subscriptions = uddiSubscriptionService.getSubscriptions(authtoken);
105                 System.out.println(subscriptions.size() + " subscriptions found");
106                 for (int i = 0; i < subscriptions.size(); i++) {
107                         System.out.println("_____________________________________");
108                         System.out.println(subscriptions.get(i).getSubscriptionKey());
109                         DeleteSubscription ds = new DeleteSubscription();
110                         ds.setAuthInfo(authtoken);
111                         ds.getSubscriptionKey().add(subscriptions.get(i).getSubscriptionKey());
112                         uddiSubscriptionService.deleteSubscription(ds);
113                         System.out.println("Deleted!");
114                 }
115 
116         }
117 
118 
119 }