1 /*
2 * Copyright 2001-2013 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.v3.client.cli;
18
19 import javax.xml.bind.JAXB;
20 import org.apache.juddi.v3.client.config.UDDIClient;
21 import org.apache.juddi.v3.client.transport.Transport;
22 import org.uddi.api_v3.*;
23 import org.uddi.v3_service.UDDIInquiryPortType;
24 import org.uddi.v3_service.UDDISecurityPortType;
25
26 /**
27 * This class show you how to get all available information for service
28 * (excluding OperationalInfo)
29 *
30 * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
31 */
32 public class UddiGetServiceDetails {
33
34 private UDDISecurityPortType security = null;
35 private UDDIInquiryPortType inquiry = null;
36
37 public UddiGetServiceDetails() {
38 try {
39 // create a manager and read the config in the archive;
40 // you can use your config file name
41 UDDIClient clerkManager = new UDDIClient("META-INF/simple-publish-uddi.xml");
42 Transport transport = clerkManager.getTransport();
43 // Now you create a reference to the UDDI API
44 security = transport.getUDDISecurityService();
45 inquiry = transport.getUDDIInquiryService();
46 } catch (Exception e) {
47 e.printStackTrace();
48 }
49 }
50
51 public void fire(String token, String key) {
52 if (key == null) {
53 System.out.println("No key provided!");
54 return;
55 }
56 try {
57 // Setting up the values to get an authentication token for the 'root' user ('root' user has admin privileges
58 // and can save other publishers).
59 if (token == null) {
60
61 GetAuthToken getAuthTokenRoot = new GetAuthToken();
62 getAuthTokenRoot.setUserID("root");
63 getAuthTokenRoot.setCred("root");
64
65 // Making API call that retrieves the authentication token for the 'root' user.
66 AuthToken rootAuthToken = security.getAuthToken(getAuthTokenRoot);
67 System.out.println("root AUTHTOKEN = " + "don't log auth tokens!");
68 token = rootAuthToken.getAuthInfo();
69 }
70 GetServiceDetail fs = new GetServiceDetail();
71 fs.setAuthInfo(token);
72 fs.getServiceKey().add(key);
73 ServiceDetail serviceDetail = inquiry.getServiceDetail(fs);
74 if (serviceDetail == null || serviceDetail.getBusinessService().isEmpty()) {
75 System.out.println("mykey is not registered");
76 } else {
77 JAXB.marshal(serviceDetail, System.out);
78 }
79 } catch (Exception e) {
80 e.printStackTrace();
81 }
82 }
83
84 public static void main(String args[]) {
85 UddiGetServiceDetails sp = new UddiGetServiceDetails();
86 sp.fire(null, "uddi:juddi.apache.org:services-inquiry");
87 }
88 }