1/*2 * Copyright 2001-2008 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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 *16 */17package org.apache.juddi.examples.service.version;
1819import java.util.Iterator;
20import java.util.Set;
21import org.apache.juddi.v3.client.UDDIConstants;
22import org.apache.juddi.v3.client.config.UDDIClerk;
23import org.apache.juddi.v3.client.config.UDDIClient;
24import org.apache.juddi.v3.client.transport.Transport;
25import org.uddi.api_v3.AccessPoint;
26import org.uddi.api_v3.BindingTemplate;
27import org.uddi.api_v3.BindingTemplates;
28import org.uddi.api_v3.BusinessEntity;
29import org.uddi.api_v3.BusinessService;
30import org.uddi.api_v3.BusinessServices;
31import org.uddi.api_v3.FindQualifiers;
32import org.uddi.api_v3.FindService;
33import org.uddi.api_v3.GetServiceDetail;
34import org.uddi.api_v3.Name;
35import org.uddi.api_v3.ServiceDetail;
36import org.uddi.api_v3.ServiceList;
37import org.uddi.api_v3.TModel;
38import org.uddi.api_v3.TModelInstanceDetails;
39import org.uddi.v3_service.UDDIInquiryPortType;
40import org.uddi.v3_service.UDDIPublicationPortType;
41import org.uddi.v3_service.UDDISecurityPortType;
4243/**44 * Hello world!45 *46 * This gives you an example of one way to use service version with UDDI and is47 * a partial solution to https://issues.apache.org/jira/browse/JUDDI-509 which 48 * references the following49 * http://www.ibm.com/developerworks/webservices/library/ws-version/50 *51 */52publicclassServiceVersioningExample {
5354publicstaticvoid main(String[] args) throws Exception {
55 System.out.println("Hello World!");
56newServiceVersioningExample().go();
57 }
5859/**60 * Main entry point61 */62privatevoid go() throws Exception {
6364 Init();
6566 Setup();
6768 ServiceLookUpByName();
6970 ServiceLookUpByVersion();
7172 Destroy();
73 }
7475/**76 * This will setup new a business, service, and binding template that's77 * versioned per the article linked above78 */79privatevoid Setup() {
8081BusinessEntity be = newBusinessEntity();
82 keygen = clerk.register(UDDIClerk.createKeyGenator(domain_prefix + "keygenerator", "my domain", lang)).getTModel().get(0);
83 be.setBusinessServices(newBusinessServices());
84 be.setBusinessKey(domain_prefix + "zerocoolbiz");
85 be.getName().add(new Name("ZeroCool Business", lang));
86BusinessService bs = newBusinessService();
87 bs.getName().add(new Name("ZeroCool Service", lang));
88 bs.setBindingTemplates(newBindingTemplates());
89 bs.setBusinessKey(domain_prefix + "zerocoolbiz");
90 bs.setServiceKey(domain_prefix + "zerocoolsvc");
9192//version 193BindingTemplate bt1 = newBindingTemplate();
94 String version = "1.0.0.0";
95 bt1.setBindingKey(domain_prefix + "binding10");
96 bt1.setAccessPoint(newAccessPoint("http://localhost", "wsdl"));
97 bt1.setTModelInstanceDetails(newTModelInstanceDetails());
98 bt1.getTModelInstanceDetails().getTModelInstanceInfo().add(UDDIClerk.createServiceInterfaceVersion(version, lang));
99 bt1 = UDDIClient.addSOAPtModels(bt1);
100 bs.getBindingTemplates().getBindingTemplate().add(bt1);
101102103104//version 2105BindingTemplate bt2 = newBindingTemplate();
106 bt2.setBindingKey(domain_prefix + "binding12");
107 String version2 = "1.2.0.0";
108 bt2.setAccessPoint(newAccessPoint("http://localhost", "wsdl"));
109 bt2.setTModelInstanceDetails(newTModelInstanceDetails());
110 bt2.getTModelInstanceDetails().getTModelInstanceInfo().add(UDDIClerk.createServiceInterfaceVersion(version2, lang));
111 bt2 = UDDIClient.addSOAPtModels(bt2);
112 bs.getBindingTemplates().getBindingTemplate().add(bt2);
113114 be.getBusinessServices().getBusinessService().add(bs);
115 clerk.register(be);
116117 }
118private String domain_prefix = "uddi:mydomain.com:";
119 ;
120private String lang = "en";
121122/**123 * this will look up our service by name and we'll discover multiple124 * bindings with different versions125 */126privatevoid ServiceLookUpByName() throws Exception {
127128//here we are assuming we don't know what key is used for the service, so we look it up129FindService fs = newFindService();
130 fs.setFindQualifiers(newFindQualifiers());
131 fs.getFindQualifiers().getFindQualifier().add(UDDIConstants.EXACT_MATCH);
132 fs.getName().add(new Name("ZeroCool Service", lang));
133ServiceList findService = inquiry.findService(fs);
134135//parse the results and get a list of services to get the details on136GetServiceDetail gsd = newGetServiceDetail();
137for (int i = 0; i < findService.getServiceInfos().getServiceInfo().size(); i++) {
138 gsd.getServiceKey().add(findService.getServiceInfos().getServiceInfo().get(i).getServiceKey());
139 }
140ServiceDetail serviceDetail = inquiry.getServiceDetail(gsd);
141142//parse the service details, looking for our versioned service143if (serviceDetail != null) {
144for (int i = 0; i < serviceDetail.getBusinessService().size(); i++) {
145if (serviceDetail.getBusinessService().get(i).getBindingTemplates() != null) {
146 Set<BindingTemplate> bindingByVersion = UDDIClerk.getBindingByVersion("1.2.0.0", serviceDetail.getBusinessService().get(i).getBindingTemplates().getBindingTemplate());
147 Iterator<BindingTemplate> iterator = bindingByVersion.iterator();
148while (iterator.hasNext()) {
149BindingTemplate next = iterator.next();
150 System.out.println("SUCCESS! Found the right version on key " + next.getBindingKey());
151//TODO so now that you've found the right version of the right service152//now you can go execute that the url153 }
154155 }
156 }
157 }
158 }
159160/**161 * this will look up our service by name and version number162 */163privatevoid ServiceLookUpByVersion() throws Exception {
164//here we are assuming we don't know what key is used for the service, so we look it up165//TODO166 }
167privateTModel keygen = null;
168privateUDDISecurityPortType security = null;
169privateUDDIInquiryPortType inquiry = null;
170privateUDDIPublicationPortType publish = null;
171privateUDDIClient client = null;
172privateUDDIClerk clerk = null;
173174privatevoid Init() {
175try {
176// create a client and read the config in the archive; 177// you can use your config file name178 client = newUDDIClient("META-INF/uddi.xml");
179 clerk = client.getClerk("default");
180// a UddiClient can be a client to multiple UDDI nodes, so 181// supply the nodeName (defined in your uddi.xml.182// The transport can be WS, inVM etc which is defined in the uddi.xml183Transport transport = client.getTransport("default");
184// Now you create a reference to the UDDI API185 security = transport.getUDDISecurityService();
186 inquiry = transport.getUDDIInquiryService();
187 publish = transport.getUDDIPublishService();
188 } catch (Exception e) {
189 e.printStackTrace();
190 }
191192 }
193194privatevoid Destroy() {
195 clerk.unRegisterBusiness(domain_prefix + "zerocoolbiz");
196 clerk.unRegisterTModel(keygen.getTModelKey());
197 clerk.discardAuthToken();
198 }
199 }