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

1    package inspireit.uddi.examples; 
2     
3    import java.net.*; 
4     
5    import inspireit.uddi.base.*; 
6    import inspireit.uddi.collections.*; 
7    import inspireit.uddi.request.*; 
8    import inspireit.uddi.response.*; 
9    import inspireit.uddi.response.base.*; 
10    
11   /** 
12    * This example shows how to delete a bindingTemplate. You will have to open an 
13    * account at one of the official UDDI registries if you don't have access to a 
14    * local UDDI registry. For example, you can use the beta registry of IBM 
15    * located at http://uddi.ibm.com/beta/registry.html.<p> 
16    * 
17    * The example first saves a business entity, a service, a tModel and a 
18    * bindingTemplate via the SaveBindingExample example. If the size of your 
19    * account is limited, you will have to make a clean-up first, for example via 
20    * the Web interface of the on-line registry. 
21    * 
22    * @author Bertrand Fontaine, <a href="http://www.inspireit.biz" target="INSPIREIT">INSPIRE IT</a> 
23    */ 
24   public class DeleteBindingExample { 
25    
26       public DeleteBindingExample(String queryURL, String publishURL, String securityURL, String username, String password) throws Exception { 
27           // first call the saveBinding example to be sure that at least one 
28           // BindingTemplate is stored in the UDDI registry 
29           SaveBindingExample saveBinding = new SaveBindingExample(queryURL, publishURL, securityURL, username, password); 
30           BindingKey bindingKey = saveBinding.getBindingKey(); 
31    
32           // set up an appropriate HTTPS protocol handler (requires the SUN JAAS library in classpath) 
33           System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol"); 
34           java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); 
35    
36           // configure a UDDI profile to connect to a UDDI registry 
37           UDDIProfile profile = new UDDIProfile(); 
38           profile.setPublishURL(new URL(publishURL)); 
39    
40           if (securityURL != null) { 
41               profile.setSecurityURL(new URL(securityURL)); 
42           } 
43    
44           profile.setUsername(username); 
45           profile.setPassword(password); 
46    
47           // uncomment one of the following lines to use UDDI V2 or V3 messaging instead of the default V1 
48           // profile.setVersion(UDDIConstants.UDDI_V2); 
49           // profile.setVersion(UDDIConstants.UDDI_V3); 
50    
51           try { 
52               // get an appropriate publisher 
53               UDDIPublisher publisher = UDDIPublisher.getPublisher(profile); 
54    
55               DispositionReport dispositionReport = publisher.deleteBinding(bindingKey); 
56               Results results  = dispositionReport.getResults(); 
57               Result  result[] = results.toArray(); 
58    
59               if (result[0].getErrNo() == Result.E_success) { 
60                  System.out.println("Binding template successfully deleted"); 
61               } else { 
62                   System.out.println("Errno   : " + result[0].getErrNo() + 
63                                   "\n KeyType : " + result[0].getKeyType() + 
64                                   "\n ErrInfo : " + result[0].getErrInfo()); 
65               } 
66           } catch(UDDIException e) { 
67               System.out.println("An error has occured. More information follows."); 
68    
69               DispositionReport dispositionReport = e.getDispositionReport(); 
70               Results results  = dispositionReport.getResults(); 
71               Result  result[] = results.toArray(); 
72    
73               for(int i=0; i< result.length; i++) { 
74                   System.out.println("Errno   : " + result[i].getErrNo() + 
75                                   "\n KeyType : " + result[i].getKeyType() + 
76                                   "\n ErrInfo : " + result[i].getErrInfo()); 
77               } 
78           } 
79       } 
80    
81    
82       public static void main(String args[]) throws Exception { 
83           if ((args.length != 4) && (args.length != 5)) { 
84               System.out.println("DeleteBindingExample usage: java DeleteBindingExample <queryURL> <publishURL> [<securityURL>] <username> <password>"); 
85               System.exit(0); 
86           } 
87    
88           String queryURL    = args[0]; 
89           String publishURL  = args[1]; 
90           String securityURL = null; 
91           String username    = null; 
92           String password    = null; 
93    
94           if (args.length == 4) { 
95               username = args[2]; 
96               password = args[3]; 
97           } else { // must be 5 ... 
98               securityURL = args[2]; 
99               username = args[3]; 
100              password = args[4]; 
101          } 
102   
103          new DeleteBindingExample(queryURL, publishURL, securityURL, username, password); 
104          return; 
105      } 
106  }