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 javax.xml.datatype.DatatypeFactory;
20import org.apache.juddi.jaxb.PrintUDDI;
21import org.apache.juddi.v3.client.config.UDDIClerk;
22import org.apache.juddi.v3.client.config.UDDIClient;
23import org.apache.juddi.v3.client.subscription.ISubscriptionCallback;
24import org.apache.juddi.v3.client.subscription.SubscriptionCallbackListener;
25import org.apache.juddi.v3.client.transport.Transport;
26import org.uddi.api_v3.*;
27import org.uddi.sub_v3.Subscription;
28import org.uddi.sub_v3.SubscriptionFilter;
29import org.uddi.sub_v3.SubscriptionResultsList;
3031/**32 * Thie class shows you how to create a business and a subscription using UDDI33 * Subscription asynchronous callbacks for Assertion Status Reports34 *35 * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>36 */37publicclassUddiSubscribeAssertionStatusimplementsISubscriptionCallback {
383940privateUDDIClerk clerk = null;
41privateUDDIClient client = null;
4243publicUddiSubscribeAssertionStatus() {
44try {
45// create a manager and read the config in the archive; 46// you can use your config file name47 client = newUDDIClient("META-INF/simple-publish-uddi.xml");
48 clerk = client.getClerk("default");
4950 } catch (Exception e) {
51 e.printStackTrace();
52 }
53 }
5455publicUddiSubscribeAssertionStatus(Transport transport) {
5657 }
585960publicstaticvoid main(String args[]) throws Exception {
61UddiSubscribeAssertionStatus sp = newUddiSubscribeAssertionStatus();
62 sp.fire("default");
63 }
6465publicvoid fire(String nodename) throws Exception {
6667TModel createKeyGenator = UDDIClerk.createKeyGenator("somebusiness", "A test key domain SubscriptionCallbackTest1", "SubscriptionCallbackTest1");
6869 clerk.register(createKeyGenator);
70 System.out.println("Registered tModel keygen: " + createKeyGenator.getTModelKey());
7172//setup the business to attach to73BusinessEntity be = newBusinessEntity();
74 be.setBusinessKey("uddi:somebusiness:somebusinesskey");
75 be.getName().add(new Name("somebusiness SubscriptionCallbackTest1", null));
76 be.setBusinessServices(newBusinessServices());
77BusinessService bs = newBusinessService();
78 bs.setBusinessKey("uddi:somebusiness:somebusinesskey");
79 bs.setServiceKey("uddi:somebusiness:someservicekey");
80 bs.getName().add(new Name("service SubscriptionCallbackTest1", null));
81 be.getBusinessServices().getBusinessService().add(bs);
82BusinessEntity register = clerk.register(be);
83 System.out.println("Registered business keygen: " + register.getBusinessKey());
8485//start up our listener86BindingTemplate start = SubscriptionCallbackListener.start(client, nodename);
8788//register for callbacks89 SubscriptionCallbackListener.registerCallback(this);
9091Subscription sub = newSubscription();
92 sub.setNotificationInterval(DatatypeFactory.newInstance().newDuration(1000));
93 sub.setBindingKey(start.getBindingKey());
94 sub.setSubscriptionFilter(newSubscriptionFilter());
95 sub.getSubscriptionFilter().setGetAssertionStatusReport(new GetAssertionStatusReport());
96//it's optional9798//sub.getSubscriptionFilter().getGetAssertionStatusReport().setCompletionStatus(CompletionStatus.STATUS_COMPLETE);99Subscription subscriptionBiz = clerk.register(sub, clerk.getUDDINode().getApiNode());
100101 System.out.println("Registered GetAssertionStatus subscription key: " + (subscriptionBiz.getSubscriptionKey()) + " bindingkey: " + subscriptionBiz.getBindingKey());
102103 System.out.println("Waiting for callbacks. Now would be a good time to launch either another program or juddi-gui to make some changes. Press any key to stop!");
104//Thread hook = new Thread(this);105// Runtime.getRuntime().addShutdownHook(hook);106107 System.in.read();
108109 SubscriptionCallbackListener.stop(client, nodename, start.getBindingKey());
110 clerk.unRegisterSubscription(subscriptionBiz.getSubscriptionKey());
111112 clerk.unRegisterTModel(createKeyGenator.getTModelKey());
113114 clerk.unRegisterBusiness("uddi:somebusiness:somebusinesskey");
115116//Runtime.getRuntime().removeShutdownHook(hook);117 }
118119 PrintUDDI<SubscriptionResultsList> p = new PrintUDDI<SubscriptionResultsList>();
120121 @Override
122publicvoid handleCallback(SubscriptionResultsList body) {
123 System.out.println("Callback received!");
124 System.out.println(p.print(body));
125 }
126127 @Override
128publicvoid notifyEndpointStopped() {
129 System.out.println("The endpoint was stopped!");
130 }
131132133 }