This project has retired. For details please refer to its Attic page.
Publish xref
View Javadoc
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.wsdl2uddi;
18  
19  import java.net.MalformedURLException;
20  import java.net.URL;
21  import java.rmi.RemoteException;
22  
23  import javax.xml.ws.Endpoint;
24  
25  import org.apache.commons.configuration.ConfigurationException;
26  import org.apache.juddi.api_v3.Publisher;
27  import org.apache.juddi.api_v3.SavePublisher;
28  import org.apache.juddi.v3.client.config.UDDIClerk;
29  import org.apache.juddi.v3.client.config.UDDIClient;
30  import org.apache.juddi.v3.client.transport.TransportException;
31  import org.apache.juddi.v3_service.JUDDIApiPortType;
32  import org.uddi.api_v3.AuthToken;
33  import org.uddi.api_v3.BusinessEntity;
34  import org.uddi.api_v3.CategoryBag;
35  import org.uddi.api_v3.Description;
36  import org.uddi.api_v3.GetAuthToken;
37  import org.uddi.api_v3.KeyedReference;
38  import org.uddi.api_v3.Name;
39  import org.uddi.api_v3.OverviewDoc;
40  import org.uddi.api_v3.OverviewURL;
41  import org.uddi.api_v3.TModel;
42  import org.uddi.v3_service.DispositionReportFaultMessage;
43  import org.uddi.v3_service.UDDISecurityPortType;
44  
45  public class Publish {
46  	
47  	static UDDIClient uddiClient;
48  	
49  	public void publishBusiness(UDDIClerk clerk) {
50  		// Creating the parent business entity that will contain our service.
51  		BusinessEntity myBusEntity = new BusinessEntity();
52  		Name myBusName = new Name();
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  	}	
58  	
59  	public void publishWSDL(UDDIClerk clerk) throws MalformedURLException {
60  		// Register the wsdls for this clerk, referenced in the wsdl2uddi-uddi.xml
61  		clerk.registerWsdls(new URL("http://localhost:18080"));
62  	}
63  
64  	public static void main (String args[]) {
65  		
66  		System.out.println("1. Bring up the hello world endpoint at port 18080");
67  		Endpoint helloWorldEndPoint = Endpoint.create(new HelloWorldImpl());
68  		helloWorldEndPoint.publish("http://localhost:18080/services/helloworld");
69  		
70  		System.out.println("2. Programmatically publish the endpoint to UDDI");
71  		Publish sp = new Publish();
72  		try {
73  			uddiClient = new UDDIClient("META-INF/wsdl2uddi-uddi.xml");
74  			UDDIClerk clerk = uddiClient.getClerk("joe");
75  			
76  			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);
82  			
83  			System.out.println("waiting for calls into the HelloWorldImpl...");
84  			
85  		} catch (Exception e) {
86  			e.printStackTrace();
87  		}
88  	}
89  	
90  	// This setup needs to be done once, either using the console or using code like this
91  	private void setupJoePublisher(UDDIClerk clerk) throws DispositionReportFaultMessage, RemoteException, ConfigurationException, TransportException {
92  		
93  		UDDISecurityPortType security = uddiClient.getTransport("default").getUDDISecurityService();
94  		
95  		//login as root so we can create joe publisher
96  		GetAuthToken getAuthTokenRoot = new GetAuthToken();
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 code
103 		JUDDIApiPortType juddiApi = uddiClient.getTransport("default").getJUDDIApiService();
104 		Publisher p = new Publisher();
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 = new SavePublisher();
109 		sp.getPublisher().add(p);
110 		sp.setAuthInfo(rootAuthToken.getAuthInfo());
111 		juddiApi.savePublisher(sp);
112 		//END jUDDI specific code
113                 
114 		//Every publisher should have a keyGenerator, Joe has his:
115 		TModel keyGenerator = new TModel();
116 		keyGenerator.setTModelKey("uddi:uddi.joepublisher.com:keygenerator");
117 		Name name = new Name();
118 		name.setValue("Joe Publisher's Key Generator");
119 		keyGenerator.setName(name);
120 		Description description = new Description();
121 		description.setValue("This is the key generator for Joe Publisher's UDDI entities!");
122 		keyGenerator.getDescription().add(description);
123 		OverviewDoc overviewDoc = new OverviewDoc();
124 		OverviewURL overviewUrl = new OverviewURL();
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 = new CategoryBag();
130 		KeyedReference keyedReference = new KeyedReference();
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 }