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 INVM transport, meaning that you29 * don't need a functioning UDDI server to use this. The jUDDI services in this30 * case fire up in without any J2EE container. A database is still required,31 * however by default it uses Derby, but any JPA database can be used32 *33 */34publicclassHelloWorld {
3536privatestatic UDDISecurityPortType security = null;
3738publicHelloWorld() {
39try {
40// create a client & server and read the config in the archive; 41// you can use your config file name42 UDDIClient uddiClient = new UDDIClient("META-INF/embedded-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 } catch (Exception e) {
50 e.printStackTrace();
51 }
52 }
5354publicvoid getAuthToken() {
55 GetAuthToken getAuthToken = new GetAuthToken();
56 getAuthToken.setUserID("root");
57 getAuthToken.setCred("");
58try {
59 AuthToken authToken = security.getAuthToken(getAuthToken);
60 System.out.println("Login successful!");
61 System.out.println("AUTHTOKEN = "62 + "(don't log auth tokens!)");
6364 security.discardAuthToken(new DiscardAuthToken(authToken.getAuthInfo()));
65 System.out.println("Logged out");
66 } catch (Exception e) {
67 e.printStackTrace();
68 }
69 }
7071publicstaticvoid main(String args[]) {
72HelloWorld hw = newHelloWorld();
73 hw.getAuthToken();
74 }
75 }