1 /* 2 * Copyright 2001-2013 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.v3.client.cli; 18 19 import org.apache.juddi.v3.client.config.UDDIClerk; 20 import org.apache.juddi.v3.client.config.UDDIClient; 21 import org.apache.juddi.v3.client.transport.Transport; 22 import org.uddi.api_v3.*; 23 import org.uddi.v3_service.UDDIPublicationPortType; 24 import org.uddi.v3_service.UDDISecurityPortType; 25 26 /** 27 * This is an example how to make a UDDI key generator, which will enable you to 28 * make UDDI v3 keys with (almost) whatever pattern you want 29 * 30 * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a> 31 */ 32 public class UddiKeyGenerator { 33 34 private UDDISecurityPortType security = null; 35 private UDDIPublicationPortType publish = null; 36 37 public UddiKeyGenerator() { 38 try { 39 // create a manager and read the config in the archive; 40 // you can use your config file name 41 UDDIClient clerkManager = new UDDIClient("META-INF/simple-publish-uddi.xml"); 42 Transport transport = clerkManager.getTransport(); 43 // Now you create a reference to the UDDI API 44 security = transport.getUDDISecurityService(); 45 publish = transport.getUDDIPublishService(); 46 } catch (Exception e) { 47 e.printStackTrace(); 48 } 49 } 50 51 public void fire(String token, String domain) { 52 try { 53 // Setting up the values to get an authentication token for the 'root' user ('root' user has admin privileges 54 // and can save other publishers). 55 if (token == null) { 56 GetAuthToken getAuthTokenRoot = new GetAuthToken(); 57 getAuthTokenRoot.setUserID("uddi"); 58 getAuthTokenRoot.setCred("uddi"); 59 60 // Making API call that retrieves the authentication token for the 'root' user. 61 AuthToken rootAuthToken = security.getAuthToken(getAuthTokenRoot); 62 System.out.println("uddi AUTHTOKEN = " + "don't log auth tokens!"); 63 token = rootAuthToken.getAuthInfo(); 64 } 65 SaveTModel st = new SaveTModel(); 66 st.setAuthInfo(token); 67 st.getTModel().add(UDDIClerk.createKeyGenator(domain, domain, "en")); 68 TModelDetail saveTModel = publish.saveTModel(st); 69 70 System.out.println("Saved! key = " + saveTModel.getTModel().get(0).getTModelKey()); 71 /* 72 //Hey! tModel Key Generators can be nested too! 73 st = new SaveTModel(); 74 st.setAuthInfo(rootAuthToken.getAuthInfo()); 75 st.getTModel().add(UDDIClerk.createKeyGenator("uddi:bea.com:servicebus.default:keygenerator", "bea.com:servicebus.default", "en")); 76 publish.saveTModel(st); 77 78 // This code block proves that you can create tModels based on a nested keygen 79 st = new SaveTModel(); 80 TModel m = new TModel(); 81 m.setTModelKey("uddi:bea.com:servicebus.default.proxytest2"); 82 m.setName(new Name("name", "lang")); 83 st.setAuthInfo(rootAuthToken.getAuthInfo()); 84 st.getTModel().add(m); 85 publish.saveTModel(st); 86 87 */ 88 } catch (Exception e) { 89 e.printStackTrace(); 90 } 91 } 92 93 public static void main(String args[]) { 94 UddiKeyGenerator sp = new UddiKeyGenerator(); 95 sp.fire(null, "www.juddi.is.cool.org"); 96 } 97 }