This project has retired. For details please refer to its Attic page.
HelloWorld xref
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.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 JAXWS transport, meaning that you
29   * need a functioning UDDI server to use this
30   *
31   */
32  public class HelloWorld {
33  
34          private static UDDISecurityPortType security = null;
35  
36          public HelloWorld() {
37                  try {
38          	// create a client and read the config in the archive; 
39                          // you can use your config file name
40                          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.xml
44                          Transport transport = uddiClient.getTransport("default");
45                          // Now you create a reference to the UDDI API
46                          security = transport.getUDDISecurityService();
47                  } catch (Exception e) {
48                          e.printStackTrace();
49                  }
50          }
51  
52          public void getAuthToken() {
53                  GetAuthToken getAuthToken = new GetAuthToken();
54                  getAuthToken.setUserID("root");
55                  getAuthToken.setCred("");
56                  try {
57                          AuthToken authToken = security.getAuthToken(getAuthToken);
58                          System.out.println("Login successful!");
59                          System.out.println("AUTHTOKEN = "
60                                  + "(don't log auth tokens!)");
61                          
62                          security.discardAuthToken(new DiscardAuthToken(authToken.getAuthInfo()));
63                          System.out.println("Logged out");
64                  } catch (Exception e) {
65                          e.printStackTrace();
66                  }
67          }
68  
69          public static void main(String args[]) {
70                  HelloWorld hw = new HelloWorld();
71                  hw.getAuthToken();
72          }
73  }