This project has retired. For details please refer to its Attic page.
UddiSubscribeValidate 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 java.util.Calendar;
20  import java.util.GregorianCalendar;
21  import javax.xml.datatype.DatatypeFactory;
22  import javax.xml.datatype.XMLGregorianCalendar;
23  import org.apache.juddi.v3.client.config.UDDIClient;
24  import org.apache.juddi.v3.client.transport.Transport;
25  import org.uddi.api_v3.*;
26  import org.uddi.sub_v3.CoveragePeriod;
27  import org.uddi.sub_v3.GetSubscriptionResults;
28  import org.uddi.sub_v3.SubscriptionResultsList;
29  import org.uddi.v3_service.UDDISecurityPortType;
30  import org.uddi.v3_service.UDDISubscriptionPortType;
31  
32  /**
33   * This class shows you how to get the results of an existing subscription in
34   * UDDI.
35   *
36   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
37   */
38  public class UddiSubscribeValidate {
39  
40          private UDDISecurityPortType security = null;
41          private UDDISubscriptionPortType uddiSubscriptionService = null;
42  
43          public UddiSubscribeValidate() {
44                  try {
45                          // create a manager and read the config in the archive; 
46                          // you can use your config file name
47                          UDDIClient clerkManager = new UDDIClient("META-INF/simple-publish-uddi.xml");
48                          Transport transport = clerkManager.getTransport();
49                          // Now you create a reference to the UDDI API
50                          security = transport.getUDDISecurityService();
51                          uddiSubscriptionService = transport.getUDDISubscriptionService();
52                  } catch (Exception e) {
53                          e.printStackTrace();
54                  }
55          }
56          
57            public UddiSubscribeValidate(Transport transport) {
58                  try {
59                          // Now you create a reference to the UDDI API
60                          security = transport.getUDDISecurityService();
61                          uddiSubscriptionService = transport.getUDDISubscriptionService();
62  
63                  } catch (Exception e) {
64                          e.printStackTrace();
65                  }
66          }
67  
68          /**
69           * gets subscription results synchronously
70           *
71           * @param authtoken
72           * @param key
73           */
74          public void go(String authtoken, String key) {
75                  if (key == null) {
76                          System.out.println("No key was specified!");
77                          return;
78                  }
79                  try {
80  
81                          // Setting up the values to get an authentication token for the 'root' user ('root' user has admin privileges
82                          // and can save other publishers).
83                          if (authtoken == null) {
84                                  GetAuthToken getAuthTokenRoot = new GetAuthToken();
85                                  getAuthTokenRoot.setUserID("root");
86                                  getAuthTokenRoot.setCred("root");
87  
88                                  // Making API call that retrieves the authentication token for the 'root' user.
89                                  AuthToken rootAuthToken = security.getAuthToken(getAuthTokenRoot);
90                                  System.out.println("root AUTHTOKEN = " + "don't log 'em");
91                                  authtoken = rootAuthToken.getAuthInfo();
92                          }
93                          DatatypeFactory df = DatatypeFactory.newInstance();
94                          GregorianCalendar gcal = new GregorianCalendar();
95                          gcal.setTimeInMillis(System.currentTimeMillis());
96                          XMLGregorianCalendar xcal = df.newXMLGregorianCalendar(gcal);
97  
98                          //
99                          GetSubscriptionResults req = new GetSubscriptionResults();
100                         req.setAuthInfo(authtoken);
101                         //insert your subscription key values here
102                         req.setSubscriptionKey(key);
103                         req.setCoveragePeriod(new CoveragePeriod());
104                         req.getCoveragePeriod().setEndPoint(xcal);
105 
106                         gcal = new GregorianCalendar();
107                         //Time range that we want change logs on
108                         gcal.add(Calendar.MONTH, -1);
109                         req.getCoveragePeriod().setStartPoint(df.newXMLGregorianCalendar(gcal));
110                         SubscriptionResultsList subscriptionResults = uddiSubscriptionService.getSubscriptionResults(req);
111                         System.out.println("items modified: " + subscriptionResults.getBusinessDetail().getBusinessEntity().size());
112 
113                 } catch (Exception e) {
114                         e.printStackTrace();
115                 }
116         }
117 
118         public static void main(String args[]) {
119                 UddiSubscribeValidate sp = new UddiSubscribeValidate();
120                 sp.go(null, null);
121         }
122 }