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.wsdl2uddi;
1819import java.rmi.RemoteException;
2021import org.apache.commons.configuration.ConfigurationException;
22import org.apache.juddi.api_v3.Publisher;
23import org.apache.juddi.api_v3.SavePublisher;
24import org.apache.juddi.v3.client.config.UDDIClerk;
25import org.apache.juddi.v3.client.config.UDDIClient;
26import org.apache.juddi.v3.client.transport.TransportException;
27import org.apache.juddi.v3_service.JUDDIApiPortType;
28import org.uddi.api_v3.AuthToken;
29import org.uddi.api_v3.BusinessEntity;
30import org.uddi.api_v3.CategoryBag;
31import org.uddi.api_v3.Description;
32import org.uddi.api_v3.GetAuthToken;
33import org.uddi.api_v3.KeyedReference;
34import org.uddi.api_v3.Name;
35import org.uddi.api_v3.OverviewDoc;
36import org.uddi.api_v3.OverviewURL;
37import org.uddi.api_v3.TModel;
38import org.uddi.v3_service.DispositionReportFaultMessage;
39import org.uddi.v3_service.UDDISecurityPortType;
4041publicclassSetup {
4243staticUDDIClient uddiClient;
4445publicvoid publishBusiness(UDDIClerk clerk) {
46// Creating the parent business entity that will contain our service.47 BusinessEntity myBusEntity = newBusinessEntity();
48 Name myBusName = newName();
49 myBusName.setValue("WSDL-Business");
50 myBusEntity.getName().add(myBusName);
51 myBusEntity.setBusinessKey("uddi:uddi.joepublisher.com:business-for-wsdl");
52 clerk.register(myBusEntity);
53 }
5455publicstaticvoid main (String args[]) {
5657 Setup sp = newSetup();
58try {
59 uddiClient = newUDDIClient("META-INF/wsdl2uddi-uddi.xml");
60 UDDIClerk clerk = uddiClient.getClerk("joe");
6162//setting up the publisher63 sp.setupJoePublisher(clerk);
64//publish the business65 sp.publishBusiness(clerk);
6667 } catch (Exception e) {
68 e.printStackTrace();
69 }
70 }
7172// This setup needs to be done once, either using the console or using code like this73privatevoid setupJoePublisher(UDDIClerk clerk) throws DispositionReportFaultMessage, RemoteException, ConfigurationException, TransportException {
7475 UDDISecurityPortType security = uddiClient.getTransport("default").getUDDISecurityService();
7677//login as root so we can create joe publisher78 GetAuthToken getAuthTokenRoot = newGetAuthToken();
79 getAuthTokenRoot.setUserID("root");
80 getAuthTokenRoot.setCred("");
81// Making API call that retrieves the authentication token for the 'root' user.82 AuthToken rootAuthToken = security.getAuthToken(getAuthTokenRoot);
83 System.out.println ("root AUTHTOKEN = " + rootAuthToken.getAuthInfo());
84//Creating joe publisher85 JUDDIApiPortType juddiApi = uddiClient.getTransport("default").getJUDDIApiService();
86 Publisher p = newPublisher();
87 p.setAuthorizedName("joepublisher");
88 p.setPublisherName("Joe Publisher");
89// Adding the publisher to the "save" structure, using the 'root' user authentication info and saving away. 90 SavePublisher sp = newSavePublisher();
91 sp.getPublisher().add(p);
92 sp.setAuthInfo(rootAuthToken.getAuthInfo());
93 juddiApi.savePublisher(sp);
9495//Joe should have a keyGenerator96 TModel keyGenerator = newTModel();
97 keyGenerator.setTModelKey("uddi:uddi.joepublisher.com:keygenerator");
98 Name name = newName();
99 name.setValue("Joe Publisher's Key Generator");
100 keyGenerator.setName(name);
101 Description description = newDescription();
102 description.setValue("This is the key generator for Joe Publisher's UDDI entities!");
103 keyGenerator.getDescription().add(description);
104 OverviewDoc overviewDoc = newOverviewDoc();
105 OverviewURL overviewUrl = newOverviewURL();
106 overviewUrl.setUseType("text");
107 overviewUrl.setValue("http://uddi.org/pubs/uddi_v3.htm#keyGen");
108 overviewDoc.setOverviewURL(overviewUrl);
109 keyGenerator.getOverviewDoc().add(overviewDoc);
110 CategoryBag categoryBag = newCategoryBag();
111 KeyedReference keyedReference = newKeyedReference();
112 keyedReference.setKeyName("uddi-org:types:keyGenerator");
113 keyedReference.setKeyValue("keyGenerator");
114 keyedReference.setTModelKey("uddi:uddi.org:categorization:types");
115 categoryBag.getKeyedReference().add(keyedReference);
116 keyGenerator.setCategoryBag(categoryBag);
117 clerk.register(keyGenerator);
118 }
119 }