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.helloworld; 18 19 import org.uddi.api_v3.*; 20 import org.apache.juddi.v3.client.config.UDDIClient; 21 import org.apache.juddi.v3.client.transport.Transport; 22 import org.uddi.v3_service.UDDISecurityPortType; 23 24 /** 25 * This basic hello world example shows you how to sign into a UDDI server that 26 * supports the Security API to issue "auth tokens". 27 * 28 * The config loads from META-INF and uses INVM transport, meaning that you 29 * don't need a functioning UDDI server to use this. The jUDDI services in this 30 * 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 used 32 * 33 */ 34 public class HelloWorld { 35 36 private static UDDISecurityPortType security = null; 37 38 public HelloWorld() { 39 try { 40 // create a client & server and read the config in the archive; 41 // you can use your config file name 42 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.xml 46 Transport transport = uddiClient.getTransport("default"); 47 // Now you create a reference to the UDDI API 48 security = transport.getUDDISecurityService(); 49 } catch (Exception e) { 50 e.printStackTrace(); 51 } 52 } 53 54 public void getAuthToken() { 55 GetAuthToken getAuthToken = new GetAuthToken(); 56 getAuthToken.setUserID("root"); 57 getAuthToken.setCred(""); 58 try { 59 AuthToken authToken = security.getAuthToken(getAuthToken); 60 System.out.println("Login successful!"); 61 System.out.println("AUTHTOKEN = " 62 + "(don't log auth tokens!)"); 63 64 security.discardAuthToken(new DiscardAuthToken(authToken.getAuthInfo())); 65 System.out.println("Logged out"); 66 } catch (Exception e) { 67 e.printStackTrace(); 68 } 69 } 70 71 public static void main(String args[]) { 72 HelloWorld hw = new HelloWorld(); 73 hw.getAuthToken(); 74 } 75 }