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.samples;
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 */37publicclassUddiSubscribeAssertionStatusimplements ISubscriptionCallback {
3839boolean callbackRecieved = false;
40private UDDIClerk clerk = null;
41private UDDIClient client = null;
4243publicUddiSubscribeAssertionStatus() {
44try {
45// create a manager and read the config in the archive; 46// you can use your config file name47 client = new UDDIClient("META-INF/simple-publish-uddi.xml");
48 clerk = client.getClerk("default");
4950 } catch (Exception e) {
51 e.printStackTrace();
52 }
53 }
545556publicstaticvoid main(String args[]) throws Exception {
57UddiSubscribeAssertionStatus sp = newUddiSubscribeAssertionStatus();
58 sp.fire("default");
59 }
6061publicvoid fire(String nodename) throws Exception {
6263 TModel createKeyGenator = UDDIClerk.createKeyGenator("somebusiness", "A test key domain SubscriptionCallbackTest1", "SubscriptionCallbackTest1");
6465 clerk.register(createKeyGenator);
66 System.out.println("Registered tModel keygen: " + createKeyGenator.getTModelKey());
6768//setup the business to attach to69 BusinessEntity be = new BusinessEntity();
70 be.setBusinessKey("uddi:somebusiness:somebusinesskey");
71 be.getName().add(new Name("somebusiness SubscriptionCallbackTest1", null));
72 be.setBusinessServices(new BusinessServices());
73 BusinessService bs = new BusinessService();
74 bs.setBusinessKey("uddi:somebusiness:somebusinesskey");
75 bs.setServiceKey("uddi:somebusiness:someservicekey");
76 bs.getName().add(new Name("service SubscriptionCallbackTest1", null));
77 be.getBusinessServices().getBusinessService().add(bs);
78 BusinessEntity register = clerk.register(be);
79 System.out.println("Registered business keygen: " + register.getBusinessKey());
8081//start up our listener82 BindingTemplate start = SubscriptionCallbackListener.start(client, nodename);
8384//register for callbacks85 SubscriptionCallbackListener.registerCallback(this);
8687 Subscription sub = new Subscription();
88 sub.setNotificationInterval(DatatypeFactory.newInstance().newDuration(1000));
89 sub.setBindingKey(start.getBindingKey());
90 sub.setSubscriptionFilter(new SubscriptionFilter());
91 sub.getSubscriptionFilter().setGetAssertionStatusReport(new GetAssertionStatusReport());
92//it's optional9394//sub.getSubscriptionFilter().getGetAssertionStatusReport().setCompletionStatus(CompletionStatus.STATUS_COMPLETE);95 Subscription subscriptionBiz = clerk.register(sub, clerk.getUDDINode().getApiNode());
9697 System.out.println("Registered GetAssertionStatus subscription key: " + (subscriptionBiz.getSubscriptionKey()) + " bindingkey: " + subscriptionBiz.getBindingKey());
9899 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!");
100101 System.in.read();
102103 SubscriptionCallbackListener.stop(client, nodename, start.getBindingKey());
104 clerk.unRegisterSubscription(subscriptionBiz.getSubscriptionKey());
105106 clerk.unRegisterTModel(createKeyGenator.getTModelKey());
107108 clerk.unRegisterBusiness("uddi:somebusiness:somebusinesskey");
109110 }
111112private PrintUDDI<SubscriptionResultsList> printer = new PrintUDDI<SubscriptionResultsList>();
113114 @Override
115publicvoid handleCallback(SubscriptionResultsList body) {
116 System.out.println("Callback received!");
117 System.out.println(printer.print(body));
118 }
119120 @Override
121publicvoid notifyEndpointStopped() {
122 System.out.println("The endpoint was stopped!");
123 }
124125 }