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.publish;
1819import org.uddi.api_v3.*;
20import org.apache.juddi.api_v3.*;
21import org.apache.juddi.v3.client.config.UDDIClient;
22import org.apache.juddi.v3.client.transport.Transport;
23import org.uddi.v3_service.UDDISecurityPortType;
24import org.uddi.v3_service.UDDIPublicationPortType;
2526/**27 * This shows you to interact with a UDDI server by publishing a Business,28 * Service and Binding Template. It uses some fairly generic code that should be29 * mostly portable to any other UDDI client library and is therefore consider30 * "portable". URLs are set in uddi.xml31 *32 */33publicclassSimplePublishPortable {
3435privatestatic UDDISecurityPortType security = null;
36privatestatic UDDIPublicationPortType publish = null;
3738publicSimplePublishPortable() {
39try {
40// create a client and read the config in the archive; 41// you can use your config file name42 UDDIClient uddiClient = new UDDIClient("META-INF/uddi.xml");
43// a UddiClient can be a client to multiple UDDI nodes, so 44// supply the nodeName (defined in your uddi.xml.45// The transport can be WS, inVM etc which is defined in the uddi.xml46 Transport transport = uddiClient.getTransport("default");
47// Now you create a reference to the UDDI API48 security = transport.getUDDISecurityService();
49 publish = transport.getUDDIPublishService();
50 } catch (Exception e) {
51 e.printStackTrace();
52 }
53 }
5455/**56 * This function shows you how to publish to UDDI using a fairly generic57 * mechanism that should be portable (meaning use any UDDI v3 library58 * with this code)59 */60publicvoid publish() {
61try {
6263// Login aka retrieve its authentication token64 GetAuthToken getAuthTokenMyPub = new GetAuthToken();
65 getAuthTokenMyPub.setUserID("bob"); //your username66 getAuthTokenMyPub.setCred("bob"); //your password67 AuthToken myPubAuthToken = security.getAuthToken(getAuthTokenMyPub);
68 System.out.println(getAuthTokenMyPub.getUserID() + "'s AUTHTOKEN = " + "******* never log auth tokens!");
6970// Creating the parent business entity that will contain our service.71 BusinessEntity myBusEntity = new BusinessEntity();
72 Name myBusName = new Name();
73 myBusName.setValue("My Business");
74 myBusEntity.getName().add(myBusName);
7576// Adding the business entity to the "save" structure, using our publisher's authentication info and saving away.77 SaveBusiness sb = new SaveBusiness();
78 sb.getBusinessEntity().add(myBusEntity);
79 sb.setAuthInfo(myPubAuthToken.getAuthInfo());
80 BusinessDetail bd = publish.saveBusiness(sb);
81 String myBusKey = bd.getBusinessEntity().get(0).getBusinessKey();
82 System.out.println("myBusiness key: " + myBusKey);
8384// Creating a service to save. Only adding the minimum data: the parent business key retrieved from saving the business 85// above and a single name.86 BusinessService myService = new BusinessService();
87 myService.setBusinessKey(myBusKey);
88 Name myServName = new Name();
89 myServName.setValue("My Service");
90 myService.getName().add(myServName);
9192// Add binding templates, etc...93 BindingTemplate myBindingTemplate = new BindingTemplate();
94 AccessPoint accessPoint = new AccessPoint();
95 accessPoint.setUseType(AccessPointType.WSDL_DEPLOYMENT.toString());
96 accessPoint.setValue("http://example.org/services/myservice?wsdl");
97 myBindingTemplate.setAccessPoint(accessPoint);
98 BindingTemplates myBindingTemplates = new BindingTemplates();
99//optional but recommended step, this annotations our binding with all the standard SOAP tModel instance infos100 myBindingTemplate = UDDIClient.addSOAPtModels(myBindingTemplate);
101 myBindingTemplates.getBindingTemplate().add(myBindingTemplate);
102103 myService.setBindingTemplates(myBindingTemplates);
104105// Adding the service to the "save" structure, using our publisher's authentication info and saving away.106 SaveService ss = new SaveService();
107 ss.getBusinessService().add(myService);
108 ss.setAuthInfo(myPubAuthToken.getAuthInfo());
109 ServiceDetail sd = publish.saveService(ss);
110 String myServKey = sd.getBusinessService().get(0).getServiceKey();
111 System.out.println("myService key: " + myServKey);
112113 security.discardAuthToken(new DiscardAuthToken(myPubAuthToken.getAuthInfo()));
114// Now you have published a business and service via 115// the jUDDI API!116 System.out.println("Success!");
117118 } catch (Exception e) {
119 e.printStackTrace();
120 }
121 }
122123publicstaticvoid main(String args[]) {
124SimplePublishPortable sp = newSimplePublishPortable();
125 sp.publish();
126 }
127 }