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 at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * 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 and 14 * limitations under the License. 15 * 16 */ 17 package org.apache.juddi.example.publish; 18 19 import org.uddi.api_v3.*; 20 import org.apache.juddi.api_v3.*; 21 import org.apache.juddi.v3.client.config.UDDIClerk; 22 import org.apache.juddi.v3.client.config.UDDIClient; 23 24 /** 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 jUDDI 27 * client jar's and represents an easier, simpler way to do things. (UDDIClient 28 * and UDDIClerk classes). Credentials and URLs are all set via uddi.xml 29 */ 30 public class SimplePublishClerk { 31 32 private static UDDIClerk clerk = null; 33 34 public SimplePublishClerk() { 35 try { 36 // create a client and read the config in the archive; 37 // you can use your config file name 38 UDDIClient uddiClient = new UDDIClient("META-INF/uddi.xml"); 39 //get the clerk 40 clerk = uddiClient.getClerk("default"); 41 if (clerk==null) 42 throw new Exception("the clerk wasn't found, check the config file!"); 43 } catch (Exception e) { 44 e.printStackTrace(); 45 } 46 } 47 48 /** 49 * This function shows you how to publish to UDDI using a fairly generic 50 * mechanism that should be portable (meaning use any UDDI v3 library 51 * with this code) 52 */ 53 public void publish() { 54 try { 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); 62 if (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); 68 69 // 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); 76 77 // 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 infos 85 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); 90 if (svc==null){ 91 System.out.println("Save failed!"); 92 System.exit(1); 93 } 94 95 String myServKey = svc.getServiceKey(); 96 System.out.println("myService key: " + myServKey); 97 98 clerk.discardAuthToken(); 99 // Now you have a business and service via 100 // the jUDDI API! 101 System.out.println("Success!"); 102 103 } catch (Exception e) { 104 e.printStackTrace(); 105 } 106 } 107 108 public static void main(String args[]) { 109 SimplePublishClerk sp = new SimplePublishClerk(); 110 sp.publish(); 111 } 112 }