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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 *16 */17package org.apache.juddi.v3.client.cli;
1819import java.util.Calendar;
20import java.util.GregorianCalendar;
21import javax.xml.datatype.DatatypeFactory;
22import javax.xml.datatype.XMLGregorianCalendar;
23import org.apache.juddi.v3.client.config.UDDIClient;
24import org.apache.juddi.v3.client.transport.Transport;
25import org.uddi.api_v3.*;
26import org.uddi.sub_v3.CoveragePeriod;
27import org.uddi.sub_v3.GetSubscriptionResults;
28import org.uddi.sub_v3.SubscriptionResultsList;
29import org.uddi.v3_service.UDDISecurityPortType;
30import org.uddi.v3_service.UDDISubscriptionPortType;
3132/**33 * This class shows you how to get the results of an existing subscription in34 * UDDI.35 *36 * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>37 */38publicclassUddiSubscribeValidate {
3940privateUDDISecurityPortType security = null;
41privateUDDISubscriptionPortType uddiSubscriptionService = null;
4243publicUddiSubscribeValidate() {
44try {
45// create a manager and read the config in the archive; 46// you can use your config file name47UDDIClient clerkManager = newUDDIClient("META-INF/simple-publish-uddi.xml");
48Transport transport = clerkManager.getTransport();
49// Now you create a reference to the UDDI API50 security = transport.getUDDISecurityService();
51 uddiSubscriptionService = transport.getUDDISubscriptionService();
52 } catch (Exception e) {
53 e.printStackTrace();
54 }
55 }
5657publicUddiSubscribeValidate(Transport transport) {
58try {
59// Now you create a reference to the UDDI API60 security = transport.getUDDISecurityService();
61 uddiSubscriptionService = transport.getUDDISubscriptionService();
6263 } catch (Exception e) {
64 e.printStackTrace();
65 }
66 }
6768/**69 * gets subscription results synchronously70 *71 * @param authtoken72 * @param key73 */74publicvoid go(String authtoken, String key) {
75if (key == null) {
76 System.out.println("No key was specified!");
77return;
78 }
79try {
8081// Setting up the values to get an authentication token for the 'root' user ('root' user has admin privileges82// and can save other publishers).83if (authtoken == null) {
84GetAuthToken getAuthTokenRoot = newGetAuthToken();
85 getAuthTokenRoot.setUserID("root");
86 getAuthTokenRoot.setCred("root");
8788// Making API call that retrieves the authentication token for the 'root' user.89AuthToken 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);
9798//99GetSubscriptionResults req = newGetSubscriptionResults();
100 req.setAuthInfo(authtoken);
101//insert your subscription key values here102 req.setSubscriptionKey(key);
103 req.setCoveragePeriod(newCoveragePeriod());
104 req.getCoveragePeriod().setEndPoint(xcal);
105106 gcal = new GregorianCalendar();
107//Time range that we want change logs on108 gcal.add(Calendar.MONTH, -1);
109 req.getCoveragePeriod().setStartPoint(df.newXMLGregorianCalendar(gcal));
110SubscriptionResultsList subscriptionResults = uddiSubscriptionService.getSubscriptionResults(req);
111 System.out.println("items modified: " + subscriptionResults.getBusinessDetail().getBusinessEntity().size());
112113 } catch (Exception e) {
114 e.printStackTrace();
115 }
116 }
117118publicstaticvoid main(String args[]) {
119UddiSubscribeValidate sp = newUddiSubscribeValidate();
120 sp.go(null, null);
121 }
122 }