This project has retired. For details please refer to its Attic page.
UddiSubscribeAssertionStatus 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 javax.xml.datatype.DatatypeFactory;
20  import org.apache.juddi.jaxb.PrintUDDI;
21  import org.apache.juddi.v3.client.config.UDDIClerk;
22  import org.apache.juddi.v3.client.config.UDDIClient;
23  import org.apache.juddi.v3.client.subscription.ISubscriptionCallback;
24  import org.apache.juddi.v3.client.subscription.SubscriptionCallbackListener;
25  import org.apache.juddi.v3.client.transport.Transport;
26  import org.uddi.api_v3.*;
27  import org.uddi.sub_v3.Subscription;
28  import org.uddi.sub_v3.SubscriptionFilter;
29  import org.uddi.sub_v3.SubscriptionResultsList;
30  
31  /**
32   * Thie class shows you how to create a business and a subscription using UDDI
33   * Subscription asynchronous callbacks for Assertion Status Reports
34   *
35   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
36   */
37  public class UddiSubscribeAssertionStatus implements ISubscriptionCallback {
38  
39       
40          private UDDIClerk clerk = null;
41          private UDDIClient client = null;
42  
43          public UddiSubscribeAssertionStatus() {
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                          
50                  } catch (Exception e) {
51                          e.printStackTrace();
52                  }
53          }
54  
55           public UddiSubscribeAssertionStatus(Transport transport) {
56                
57          }
58  
59           
60          public static void main(String args[]) throws Exception {
61                  UddiSubscribeAssertionStatus sp = new UddiSubscribeAssertionStatus();
62                  sp.fire("default");
63          }
64  
65          public void fire(String nodename) throws Exception {
66  
67                  TModel createKeyGenator = UDDIClerk.createKeyGenator("somebusiness", "A test key domain SubscriptionCallbackTest1", "SubscriptionCallbackTest1");
68  
69                  clerk.register(createKeyGenator);
70                  System.out.println("Registered tModel keygen: " + createKeyGenator.getTModelKey());
71  
72                  //setup the business to attach to
73                  BusinessEntity be = new BusinessEntity();
74                  be.setBusinessKey("uddi:somebusiness:somebusinesskey");
75                  be.getName().add(new Name("somebusiness SubscriptionCallbackTest1", null));
76                  be.setBusinessServices(new BusinessServices());
77                  BusinessService bs = new BusinessService();
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);
82                  BusinessEntity register = clerk.register(be);
83                  System.out.println("Registered business keygen: " + register.getBusinessKey());
84  
85                  //start up our listener
86                  BindingTemplate start = SubscriptionCallbackListener.start(client, nodename);
87  
88                  //register for callbacks
89                  SubscriptionCallbackListener.registerCallback(this);
90  
91                  Subscription sub = new Subscription();
92                  sub.setNotificationInterval(DatatypeFactory.newInstance().newDuration(1000));
93                  sub.setBindingKey(start.getBindingKey());
94                  sub.setSubscriptionFilter(new SubscriptionFilter());
95                  sub.getSubscriptionFilter().setGetAssertionStatusReport(new GetAssertionStatusReport());
96                  //it's optional
97                  
98                  //sub.getSubscriptionFilter().getGetAssertionStatusReport().setCompletionStatus(CompletionStatus.STATUS_COMPLETE);
99                  Subscription subscriptionBiz = clerk.register(sub, clerk.getUDDINode().getApiNode());
100 
101                 System.out.println("Registered GetAssertionStatus subscription key: " + (subscriptionBiz.getSubscriptionKey()) + " bindingkey: " + subscriptionBiz.getBindingKey());
102 
103                 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);
106                 
107                         System.in.read();
108                 
109                 SubscriptionCallbackListener.stop(client, nodename, start.getBindingKey());
110                 clerk.unRegisterSubscription(subscriptionBiz.getSubscriptionKey());
111 
112                 clerk.unRegisterTModel(createKeyGenator.getTModelKey());
113 
114                 clerk.unRegisterBusiness("uddi:somebusiness:somebusinesskey");
115 
116                 //Runtime.getRuntime().removeShutdownHook(hook);
117         }
118 
119         PrintUDDI<SubscriptionResultsList> p = new PrintUDDI<SubscriptionResultsList>();
120 
121         @Override
122         public void handleCallback(SubscriptionResultsList body) {
123                 System.out.println("Callback received!");
124                 System.out.println(p.print(body));
125         }
126 
127         @Override
128         public void notifyEndpointStopped() {
129                 System.out.println("The endpoint was stopped!");
130         }
131 
132        
133 }