1/*2 * Copyright 2001-2010 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.example.publish;
1819import org.uddi.api_v3.*;
20import org.apache.juddi.api_v3.*;
21import org.apache.juddi.v3.client.config.UDDIClerk;
22import org.apache.juddi.v3.client.config.UDDIClient;
2324/**25 * This shows you to interact with a UDDI server by publishing a Business,26 * Service and Binding Template. It uses code that is specific to the jUDDI27 * client jar's and represents an easier, simpler way to do things. (UDDIClient28 * and UDDIClerk classes). Credentials and URLs are all set via uddi.xml29 */30publicclassSimplePublishClerk {
3132privatestatic UDDIClerk clerk = null;
3334publicSimplePublishClerk() {
35try {
36// create a client and read the config in the archive; 37// you can use your config file name38 UDDIClient uddiClient = new UDDIClient("META-INF/uddi.xml");
39//get the clerk40 clerk = uddiClient.getClerk("default");
41if (clerk==null)
42thrownew Exception("the clerk wasn't found, check the config file!");
43 } catch (Exception e) {
44 e.printStackTrace();
45 }
46 }
4748/**49 * This function shows you how to publish to UDDI using a fairly generic50 * mechanism that should be portable (meaning use any UDDI v3 library51 * with this code)52 */53publicvoid publish() {
54try {
55// Creating the parent business entity that will contain our service.56 BusinessEntity myBusEntity = new BusinessEntity();
57 Name myBusName = new Name();
58 myBusName.setValue("My Business");
59 myBusEntity.getName().add(myBusName);
60// Adding the business entity to the "save" structure, using our publisher's authentication info and saving away.61 BusinessEntity register = clerk.register(myBusEntity);
62if (register == null) {
63 System.out.println("Save failed!");
64 System.exit(1);
65 }
66 String myBusKey = register.getBusinessKey();
67 System.out.println("myBusiness key: " + myBusKey);
6869// Creating a service to save. Only adding the minimum data: the parent business key retrieved from saving the business 70// above and a single name.71 BusinessService myService = new BusinessService();
72 myService.setBusinessKey(myBusKey);
73 Name myServName = new Name();
74 myServName.setValue("My Service");
75 myService.getName().add(myServName);
7677// Add binding templates, etc...78 BindingTemplate myBindingTemplate = new BindingTemplate();
79 AccessPoint accessPoint = new AccessPoint();
80 accessPoint.setUseType(AccessPointType.WSDL_DEPLOYMENT.toString());
81 accessPoint.setValue("http://example.org/services/myservice?wsdl");
82 myBindingTemplate.setAccessPoint(accessPoint);
83 BindingTemplates myBindingTemplates = new BindingTemplates();
84//optional but recommended step, this annotations our binding with all the standard SOAP tModel instance infos85 myBindingTemplate = UDDIClient.addSOAPtModels(myBindingTemplate);
86 myBindingTemplates.getBindingTemplate().add(myBindingTemplate);
87 myService.setBindingTemplates(myBindingTemplates);
88// Adding the service to the "save" structure, using our publisher's authentication info and saving away.89 BusinessService svc = clerk.register(myService);
90if (svc==null){
91 System.out.println("Save failed!");
92 System.exit(1);
93 }
9495 String myServKey = svc.getServiceKey();
96 System.out.println("myService key: " + myServKey);
9798 clerk.discardAuthToken();
99// Now you have a business and service via 100// the jUDDI API!101 System.out.println("Success!");
102103 } catch (Exception e) {
104 e.printStackTrace();
105 }
106 }
107108publicstaticvoid main(String args[]) {
109SimplePublishClerk sp = newSimplePublishClerk();
110 sp.publish();
111 }
112 }