C:\uddi\inspireit\uddi\examples\SaveBusinessExample.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 business entity. 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    * If the size of your account is limited, you will have to make a clean-up 
19    * first, for example via the Web interface of the on-line registry. 
20    * 
21    * @author Bertrand Fontaine, <a href="http://www.inspireit.biz" target="INSPIREIT">INSPIRE IT</a> 
22    */ 
23   public class SaveBusinessExample { 
24    
25       protected BusinessKey businessKey = null; 
26    
27       public SaveBusinessExample(String queryURL, String publishURL, String securityURL, String username, String password) throws Exception { 
28           System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol"); 
29           java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); 
30    
31           // we define a profile to connect to the UDDI registry 
32           UDDIProfile profile = new UDDIProfile(); 
33           profile.setQueryURL(new URL(queryURL)); 
34           profile.setPublishURL(new URL(publishURL)); 
35           if (securityURL != null) profile.setSecurityURL(new URL(securityURL)); 
36           profile.setUsername(username); 
37           profile.setPassword(password); 
38    
39           // uncomment one of the following lines to use UDDI V2 or V3 messaging instead of the default V1 
40           // profile.setVersion(UDDIConstants.UDDI_V2); 
41           // profile.setVersion(UDDIConstants.UDDI_V3); 
42    
43           try { 
44               // get an appropriate publisher 
45               UDDIPublisher publisher = UDDIPublisher.getPublisher(profile); 
46    
47               // build up the BusinessEntity to save in the registry 
48               Name name = new Name("INSPIRE IT UDDI - Sample Business"); 
49               BusinessKey businessKey = null; // it's a new business... 
50               BusinessEntity businessEntity = new BusinessEntity(businessKey, name); 
51    
52               // execute the SaveBusiness operation and get back the BusinessDetail 
53               BusinessDetail businessDetail = publisher.saveBusiness(businessEntity); 
54    
55               // get the saved BusinessEntity 
56               BusinessEntitys businessEntities = businessDetail.getBusinessEntitys(); 
57               BusinessEntity savedBusinessEntity = (businessEntities.toArray())[0]; 
58    
59               this.businessKey = savedBusinessEntity.getBusinessKey(); 
60               System.out.println("BusinessEntity saved with business key : " + this.businessKey); 
61           } catch(UDDIException e) { 
62               System.out.println("An error has occured. More information follows."); 
63               DispositionReport dispositionReport = e.getDispositionReport(); 
64    
65               if (dispositionReport != null) { 
66                   Results results  = dispositionReport.getResults(); 
67                   Result  result[] = results.toArray(); 
68    
69                   for(int i=0; i< result.length; i++) { 
70                       System.out.println("Errno   : " + result[i].getErrNo() + 
71                                       "\n KeyType : " + result[i].getKeyType() + 
72                                       "\n ErrInfo : " + result[i].getErrInfo()); 
73                   } 
74               } else { 
75                   System.out.println(e.getMessage()); 
76               } 
77           } 
78       } 
79    
80       public BusinessKey getBusinessKey() { 
81           return businessKey; 
82       } 
83    
84       public static void main(String args[]) throws Exception { 
85           if ((args.length != 4) && (args.length != 5)) { 
86               System.out.println("SaveBusinessExample usage: java SaveBusinessExample <queryURL> <publishURL> [<securityURL>] <username> <password>"); 
87               System.exit(0); 
88           } 
89    
90           String queryURL    = args[0]; 
91           String publishURL  = args[1]; 
92           String securityURL = null; 
93           String username    = null; 
94           String password    = null; 
95    
96           if (args.length == 4) { 
97               username = args[2]; 
98               password = args[3]; 
99           } else { // must be 5 ... 
100              securityURL = args[2]; 
101              username = args[3]; 
102              password = args[4]; 
103          } 
104   
105          new SaveBusinessExample(queryURL, publishURL, securityURL, username, password); 
106          return; 
107      } 
108  }