C:\uddi\inspireit\uddi\examples\SaveBindingExample.java

1    package inspireit.uddi.examples; 
2     
3    import java.net.*; 
4     
5    import inspireit.uddi.*; 
6    import inspireit.uddi.base.*; 
7    import inspireit.uddi.collections.*; 
8    import inspireit.uddi.request.*; 
9    import inspireit.uddi.response.*; 
10   import inspireit.uddi.response.base.*; 
11    
12   /** 
13    * This example shows how to save a binding template. You will have to open an 
14    * account at one of the official UDDI registries if you don't have access to a 
15    * local UDDI registry. For example, you can use the beta registry of IBM 
16    * located at http://uddi.ibm.com/beta/registry.html.<p> 
17    * 
18    * The example first saves a business entity, a service and a tModel via the 
19    * SaveTModelExample example. If the size of your account is limited, you will 
20    * have to make a clean-up first, for example via the Web interface of the 
21    * on-line registry. 
22    * 
23    * @author Bertrand Fontaine, <a href="http://www.inspireit.biz" target="INSPIREIT">INSPIRE IT</a> 
24    */ 
25   public class SaveBindingExample { 
26    
27       protected BusinessKey businessKey = null; 
28       protected ServiceKey serviceKey = null; 
29       protected BindingKey bindingKey = null; 
30       protected TModelKey  tModelKey  = null; 
31    
32       public SaveBindingExample(String queryURL, String publishURL, String securityURL, String username, String password) throws Exception { 
33           SaveTModelExample saveTModel = new SaveTModelExample(queryURL, publishURL, securityURL, username, password); 
34           businessKey = saveTModel.getBusinessKey(); 
35           serviceKey  = saveTModel.getServiceKey(); 
36           tModelKey   = saveTModel.getTModelKey(); 
37    
38           System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol"); 
39           java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); 
40    
41           UDDIProfile profile = new UDDIProfile(); 
42           profile.setQueryURL(new URL(queryURL)); 
43           profile.setPublishURL(new URL(publishURL)); 
44    
45           if (securityURL != null) { 
46               profile.setSecurityURL(new URL(securityURL)); 
47           } 
48    
49           profile.setUsername(username); 
50           profile.setPassword(password); 
51    
52           // uncomment one of the following lines to use UDDI V2 or V3 messaging instead of the default V1 
53           // profile.setVersion(UDDIConstants.UDDI_V2); 
54           // profile.setVersion(UDDIConstants.UDDI_V3); 
55    
56           try { 
57               // get an appropriate publisher 
58               UDDIPublisher publisher = UDDIPublisher.getPublisher(profile); 
59    
60               BindingKey bindingKey = null; // we are saving 
61               AccessPoint accessPoint = new AccessPoint("http://www.mysite.com/myaccesspoint", AccessPoint.HTTP); 
62    
63               TModelInstanceInfo info = new TModelInstanceInfo(tModelKey); 
64               TModelInstanceDetails tModelInstanceDetails = new TModelInstanceDetails(); 
65               tModelInstanceDetails.addTModelInstanceInfo(info); 
66    
67               BindingTemplate bindingTemplate = new BindingTemplate(bindingKey, serviceKey, accessPoint, tModelInstanceDetails); 
68               BindingDetail bindingDetail = publisher.saveBinding(bindingTemplate); 
69    
70               // get the saved BindingTemplate 
71               BindingTemplates bindingTemplates = bindingDetail.getBindingTemplates(); 
72               BindingTemplate savedBindingTemplate = (bindingTemplates.toArray())[0]; 
73    
74               this.bindingKey = savedBindingTemplate.getBindingKey(); 
75               System.out.println("BindingTemplate saved with binding template key : " + this.bindingKey); 
76    
77           } catch(UDDIException e) { 
78               System.out.println("An error has occured. More information follows."); 
79    
80               DispositionReport dispositionReport = e.getDispositionReport(); 
81               Results results  = dispositionReport.getResults(); 
82               Result  result[] = results.toArray(); 
83    
84               for(int i=0; i< result.length; i++) { 
85                   System.out.println("Errno   : " + result[i].getErrNo() + 
86                                   "\n KeyType : " + result[i].getKeyType() + 
87                                   "\n ErrInfo : " + result[i].getErrInfo()); 
88               } 
89           } 
90       } 
91    
92       public BusinessKey getBusinessKey() { 
93           return businessKey; 
94       } 
95    
96       public ServiceKey getServiceKey() { 
97           return serviceKey; 
98       } 
99    
100      public BindingKey getBindingKey() { 
101          return bindingKey; 
102      } 
103   
104      public TModelKey getTModelKey() { 
105          return tModelKey; 
106      } 
107   
108      public static void main(String args[]) throws Exception { 
109          if ((args.length != 4) && (args.length != 5)) { 
110              System.out.println("SaveBindingExample usage: java SaveBindingExample <queryURL> <publishURL> [<securityURL>] <username> <password>"); 
111              System.exit(0); 
112          } 
113   
114          String queryURL    = args[0]; 
115          String publishURL  = args[1]; 
116          String securityURL = null; 
117          String username    = null; 
118          String password    = null; 
119   
120          if (args.length == 4) { 
121              username = args[2]; 
122              password = args[3]; 
123          } else { // must be 5 ... 
124              securityURL = args[2]; 
125              username = args[3]; 
126              password = args[4]; 
127          } 
128   
129          new SaveBindingExample(queryURL, publishURL, securityURL, username, password); 
130          return; 
131      } 
132  }