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.net.MalformedURLException;
20import java.net.URL;
21import java.rmi.RemoteException;
2223import javax.xml.ws.Endpoint;
2425import org.apache.commons.configuration.ConfigurationException;
26import org.apache.juddi.api_v3.Publisher;
27import org.apache.juddi.api_v3.SavePublisher;
28import org.apache.juddi.v3.client.config.UDDIClerk;
29import org.apache.juddi.v3.client.config.UDDIClient;
30import org.apache.juddi.v3.client.transport.TransportException;
31import org.apache.juddi.v3_service.JUDDIApiPortType;
32import org.uddi.api_v3.AuthToken;
33import org.uddi.api_v3.BusinessEntity;
34import org.uddi.api_v3.CategoryBag;
35import org.uddi.api_v3.Description;
36import org.uddi.api_v3.GetAuthToken;
37import org.uddi.api_v3.KeyedReference;
38import org.uddi.api_v3.Name;
39import org.uddi.api_v3.OverviewDoc;
40import org.uddi.api_v3.OverviewURL;
41import org.uddi.api_v3.TModel;
42import org.uddi.v3_service.DispositionReportFaultMessage;
43import org.uddi.v3_service.UDDISecurityPortType;
4445publicclassPublish {
4647staticUDDIClient uddiClient;
4849publicvoid publishBusiness(UDDIClerk clerk) {
50// Creating the parent business entity that will contain our service.51 BusinessEntity myBusEntity = newBusinessEntity();
52 Name myBusName = newName();
53 myBusName.setValue("WSDL-Business");
54 myBusEntity.getName().add(myBusName);
55 myBusEntity.setBusinessKey("uddi:uddi.joepublisher.com:business_WSDL-Business");
56 clerk.register(myBusEntity);
57 }
5859publicvoid publishWSDL(UDDIClerk clerk) throws MalformedURLException {
60// Register the wsdls for this clerk, referenced in the wsdl2uddi-uddi.xml61 clerk.registerWsdls(new URL("http://localhost:18080"));
62 }
6364publicstaticvoid main (String args[]) {
6566 System.out.println("1. Bring up the hello world endpoint at port 18080");
67 Endpoint helloWorldEndPoint = Endpoint.create(newHelloWorldImpl());
68 helloWorldEndPoint.publish("http://localhost:18080/services/helloworld");
6970 System.out.println("2. Programmatically publish the endpoint to UDDI");
71 Publish sp = newPublish();
72try {
73 uddiClient = newUDDIClient("META-INF/wsdl2uddi-uddi.xml");
74 UDDIClerk clerk = uddiClient.getClerk("joe");
7576 System.out.println("setting up the publisher");
77 sp.setupJoePublisher(clerk);
78 System.out.println("publish the business");
79 sp.publishBusiness(clerk);
80 System.out.println("and the wsdl");
81 sp.publishWSDL(clerk);
8283 System.out.println("waiting for calls into the HelloWorldImpl...");
8485 } catch (Exception e) {
86 e.printStackTrace();
87 }
88 }
8990// This setup needs to be done once, either using the console or using code like this91privatevoid setupJoePublisher(UDDIClerk clerk) throws DispositionReportFaultMessage, RemoteException, ConfigurationException, TransportException {
9293 UDDISecurityPortType security = uddiClient.getTransport("default").getUDDISecurityService();
9495//login as root so we can create joe publisher96 GetAuthToken getAuthTokenRoot = newGetAuthToken();
97 getAuthTokenRoot.setUserID("root");
98 getAuthTokenRoot.setCred("");
99// Making API call that retrieves the authentication token for the 'root' user.100 AuthToken rootAuthToken = security.getAuthToken(getAuthTokenRoot);
101 System.out.println("root AUTHTOKEN = " + rootAuthToken.getAuthInfo());
102//Creating joe publisher THIS IS JUDDI Specific code103 JUDDIApiPortType juddiApi = uddiClient.getTransport("default").getJUDDIApiService();
104 Publisher p = newPublisher();
105 p.setAuthorizedName("joepublisher");
106 p.setPublisherName("Joe Publisher");
107// Adding the publisher to the "save" structure, using the 'root' user authentication info and saving away. 108 SavePublisher sp = newSavePublisher();
109 sp.getPublisher().add(p);
110 sp.setAuthInfo(rootAuthToken.getAuthInfo());
111 juddiApi.savePublisher(sp);
112//END jUDDI specific code113114//Every publisher should have a keyGenerator, Joe has his:115 TModel keyGenerator = newTModel();
116 keyGenerator.setTModelKey("uddi:uddi.joepublisher.com:keygenerator");
117 Name name = newName();
118 name.setValue("Joe Publisher's Key Generator");
119 keyGenerator.setName(name);
120 Description description = newDescription();
121 description.setValue("This is the key generator for Joe Publisher's UDDI entities!");
122 keyGenerator.getDescription().add(description);
123 OverviewDoc overviewDoc = newOverviewDoc();
124 OverviewURL overviewUrl = newOverviewURL();
125 overviewUrl.setUseType("text");
126 overviewUrl.setValue("http://uddi.org/pubs/uddi_v3.htm#keyGen");
127 overviewDoc.setOverviewURL(overviewUrl);
128 keyGenerator.getOverviewDoc().add(overviewDoc);
129 CategoryBag categoryBag = newCategoryBag();
130 KeyedReference keyedReference = newKeyedReference();
131 keyedReference.setKeyName("uddi-org:types:keyGenerator");
132 keyedReference.setKeyValue("keyGenerator");
133 keyedReference.setTModelKey("uddi:uddi.org:categorization:types");
134 categoryBag.getKeyedReference().add(keyedReference);
135 keyGenerator.setCategoryBag(categoryBag);
136 clerk.register(keyGenerator);
137 }
138 }