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.helloworld;
1819import org.uddi.api_v3.*;
20import org.apache.juddi.v3.client.config.UDDIClient;
21import org.apache.juddi.v3.client.transport.Transport;
22import org.uddi.v3_service.UDDISecurityPortType;
2324/**25 * This basic hello world example shows you how to sign into a UDDI server that26 * supports the Security API to issue "auth tokens". 27 * 28 * The config loads from META-INF and uses JAXWS transport, meaning that you29 * need a functioning UDDI server to use this30 *31 */32publicclassHelloWorld {
3334privatestatic UDDISecurityPortType security = null;
3536publicHelloWorld() {
37try {
38// create a client and read the config in the archive; 39// you can use your config file name40 UDDIClient uddiClient = new UDDIClient("META-INF/hello-world-uddi.xml");
41// a UddiClient can be a client to multiple UDDI nodes, so 42// supply the nodeName (defined in your uddi.xml.43// The transport can be WS, inVM etc which is defined in the uddi.xml44 Transport transport = uddiClient.getTransport("default");
45// Now you create a reference to the UDDI API46 security = transport.getUDDISecurityService();
47 } catch (Exception e) {
48 e.printStackTrace();
49 }
50 }
5152publicvoid getAuthToken() {
53 GetAuthToken getAuthToken = new GetAuthToken();
54 getAuthToken.setUserID("root");
55 getAuthToken.setCred("");
56try {
57 AuthToken authToken = security.getAuthToken(getAuthToken);
58 System.out.println("Login successful!");
59 System.out.println("AUTHTOKEN = "60 + "(don't log auth tokens!)");
6162 security.discardAuthToken(new DiscardAuthToken(authToken.getAuthInfo()));
63 System.out.println("Logged out");
64 } catch (Exception e) {
65 e.printStackTrace();
66 }
67 }
6869publicstaticvoid main(String args[]) {
70HelloWorld hw = newHelloWorld();
71 hw.getAuthToken();
72 }
73 }