|
C:\uddi\inspireit\uddi\examples\SaveServiceExample.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 service. You will have to open an account at
14 * one of the official UDDI registries if you don't have access to a local UDDI
15 * registry. For example, you can use the beta registry of IBM located at
16 * http://uddi.ibm.com/beta/registry.html.<p>
17 *
18 * The example first saves a business entity via the SaveBusinessExample
19 * example. If the size of your account is limited, you will have to make a
20 * clean-up first, for example via 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 SaveServiceExample {
25
26 protected BusinessKey businessKey = null;
27 protected ServiceKey serviceKey = null;
28
29 public SaveServiceExample(String queryURL, String publishURL, String securityURL, String username, String password) throws Exception {
30 // first invoke the SaveBusiness example to create a parent
31 // BusinessEntity to the BusinessService we are going to create and save
32 SaveBusinessExample saveBusiness = new SaveBusinessExample(queryURL, publishURL, securityURL, username, password);
33 businessKey = saveBusiness.getBusinessKey();
34
35 // now we can safely start our example by defining our profile
36 System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
37 java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
38
39 UDDIProfile profile = new UDDIProfile();
40 profile.setQueryURL(new URL(queryURL));
41 profile.setPublishURL(new URL(publishURL));
42
43 if (securityURL != null) {
44 profile.setSecurityURL(new URL(securityURL));
45 }
46
47 profile.setUsername(username);
48 profile.setPassword(password);
49
50 // uncomment the following line to use UDDI V2 or V3 messaging instead of the default V1
51 // profile.setVersion(UDDIConstants.UDDI_V2);
52 // profile.setVersion(UDDIConstants.UDDI_V3);
53
54 try {
55 // get an appropriate publisher for a UDDI V1-compatible registry
56 UDDIPublisher publisher = UDDIPublisher.getPublisher(profile);
57
58 // build up the BusinessEntity to save in the registry
59 Name name = new Name("INSPIRE IT UDDI - Sample Service");
60 Names names = new Names();
61 names.add(name);
62 ServiceKey serviceKey = null; // it's a new service...
63
64 BindingKey bindingKey = null; // we are saving
65 AccessPoint accessPoint = new AccessPoint("http://www.mysite.com/myaccesspoint", AccessPoint.HTTP);
66 TModelInstanceDetails tModelInstanceDetails = new TModelInstanceDetails(); // mandatory node
67 BindingTemplate bindingTemplate = new BindingTemplate(bindingKey, serviceKey, accessPoint, tModelInstanceDetails);
68 BindingTemplates bindingTemplates = new BindingTemplates();
69 bindingTemplates.add(bindingTemplate);
70
71 BusinessService businessService = new BusinessService(serviceKey, businessKey, names, bindingTemplates);
72
73 // execute the SaveService operation and get back the ServiceDetail
74 ServiceDetail serviceDetail = publisher.saveService(businessService);
75
76 // get the saved BusinessService
77 BusinessServices businessServices = serviceDetail.getBusinessServices();
78 BusinessService savedBusinessService = (businessServices.toArray())[0];
79
80 this.serviceKey = savedBusinessService.getServiceKey();
81 System.out.println("BusinessService saved with service key : " + this.serviceKey);
82
83 } catch(UDDIException e) {
84 System.out.println("An error has occured. More information follows.");
85
86 DispositionReport dispositionReport = e.getDispositionReport();
87 Results results = dispositionReport.getResults();
88 Result result[] = results.toArray();
89
90 for(int i=0; i< result.length; i++) {
91 System.out.println("Errno : " + result[i].getErrNo() +
92 "\n KeyType : " + result[i].getKeyType() +
93 "\n ErrInfo : " + result[i].getErrInfo());
94 }
95 }
96 }
97
98 public ServiceKey getServiceKey() {
99 return serviceKey;
100 }
101
102
103 public BusinessKey getBusinessKey() {
104 return businessKey;
105 }
106
107 public static void main(String args[]) throws Exception {
108 if ((args.length != 4) && (args.length != 5)) {
109 System.out.println("SaveServiceExample usage: java SaveServiceExample <queryURL> <publishURL> [<securityURL>] <username> <password>");
110 System.exit(0);
111 }
112
113 String queryURL = args[0];
114 String publishURL = args[1];
115 String securityURL = null;
116 String username = null;
117 String password = null;
118
119 if (args.length == 4) {
120 username = args[2];
121 password = args[3];
122 } else { // must be 5 ...
123 securityURL = args[2];
124 username = args[3];
125 password = args[4];
126 }
127
128 new SaveServiceExample(queryURL, publishURL, securityURL, username, password);
129 return;
130 }
131 }