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.rmi.RemoteException;
20  
21  import org.apache.commons.configuration.ConfigurationException;
22  import org.apache.juddi.api_v3.Publisher;
23  import org.apache.juddi.api_v3.SavePublisher;
24  import org.apache.juddi.v3.client.config.UDDIClerk;
25  import org.apache.juddi.v3.client.config.UDDIClient;
26  import org.apache.juddi.v3.client.transport.TransportException;
27  import org.apache.juddi.v3_service.JUDDIApiPortType;
28  import org.uddi.api_v3.AuthToken;
29  import org.uddi.api_v3.BusinessEntity;
30  import org.uddi.api_v3.CategoryBag;
31  import org.uddi.api_v3.Description;
32  import org.uddi.api_v3.GetAuthToken;
33  import org.uddi.api_v3.KeyedReference;
34  import org.uddi.api_v3.Name;
35  import org.uddi.api_v3.OverviewDoc;
36  import org.uddi.api_v3.OverviewURL;
37  import org.uddi.api_v3.TModel;
38  import org.uddi.v3_service.DispositionReportFaultMessage;
39  import org.uddi.v3_service.UDDISecurityPortType;
40  
41  public class Setup {
42  	
43  	static UDDIClient uddiClient;
44  	
45  	public void publishBusiness(UDDIClerk clerk) {
46  		// Creating the parent business entity that will contain our service.
47  		BusinessEntity myBusEntity = new BusinessEntity();
48  		Name myBusName = new Name();
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  	}	
54  
55  	public static void main (String args[]) {
56  		
57  		Setup sp = new Setup();
58  		try {
59  			uddiClient = new UDDIClient("META-INF/wsdl2uddi-uddi.xml");
60  			UDDIClerk clerk = uddiClient.getClerk("joe");
61  			
62  			//setting up the publisher
63  			sp.setupJoePublisher(clerk);
64  			//publish the business
65  			sp.publishBusiness(clerk);
66  			
67  		} catch (Exception e) {
68  			e.printStackTrace();
69  		}
70  	}
71  	
72  	// This setup needs to be done once, either using the console or using code like this
73  	private void setupJoePublisher(UDDIClerk clerk) throws DispositionReportFaultMessage, RemoteException, ConfigurationException, TransportException {
74  		
75  		UDDISecurityPortType security = uddiClient.getTransport("default").getUDDISecurityService();
76  		
77  		//login as root so we can create joe publisher
78  		GetAuthToken getAuthTokenRoot = new GetAuthToken();
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 publisher
85  		JUDDIApiPortType juddiApi = uddiClient.getTransport("default").getJUDDIApiService();
86  		Publisher p = new Publisher();
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 = new SavePublisher();
91  		sp.getPublisher().add(p);
92  		sp.setAuthInfo(rootAuthToken.getAuthInfo());
93  		juddiApi.savePublisher(sp);
94  		
95  		//Joe should have a keyGenerator
96  		TModel keyGenerator = new TModel();
97  		keyGenerator.setTModelKey("uddi:uddi.joepublisher.com:keygenerator");
98  		Name name = new Name();
99  		name.setValue("Joe Publisher's Key Generator");
100 		keyGenerator.setName(name);
101 		Description description = new Description();
102 		description.setValue("This is the key generator for Joe Publisher's UDDI entities!");
103 		keyGenerator.getDescription().add(description);
104 		OverviewDoc overviewDoc = new OverviewDoc();
105 		OverviewURL overviewUrl = new OverviewURL();
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 = new CategoryBag();
111 		KeyedReference keyedReference = new KeyedReference();
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 }