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 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.v3.client.cli;
1819import javax.xml.bind.JAXB;
20import org.apache.juddi.v3.client.config.UDDIClient;
21import org.apache.juddi.v3.client.transport.Transport;
22import org.uddi.api_v3.*;
23import org.uddi.v3_service.UDDIInquiryPortType;
24import org.uddi.v3_service.UDDISecurityPortType;
2526/**27 * This class show you how to get all available information for service28 * (excluding OperationalInfo)29 *30 * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>31 */32publicclassUddiGetServiceDetails {
3334privateUDDISecurityPortType security = null;
35privateUDDIInquiryPortType inquiry = null;
3637publicUddiGetServiceDetails() {
38try {
39// create a manager and read the config in the archive; 40// you can use your config file name41UDDIClient clerkManager = newUDDIClient("META-INF/simple-publish-uddi.xml");
42Transport transport = clerkManager.getTransport();
43// Now you create a reference to the UDDI API44 security = transport.getUDDISecurityService();
45 inquiry = transport.getUDDIInquiryService();
46 } catch (Exception e) {
47 e.printStackTrace();
48 }
49 }
5051publicvoid fire(String token, String key) {
52if (key == null) {
53 System.out.println("No key provided!");
54return;
55 }
56try {
57// Setting up the values to get an authentication token for the 'root' user ('root' user has admin privileges58// and can save other publishers).59if (token == null) {
6061GetAuthToken getAuthTokenRoot = newGetAuthToken();
62 getAuthTokenRoot.setUserID("root");
63 getAuthTokenRoot.setCred("root");
6465// Making API call that retrieves the authentication token for the 'root' user.66AuthToken rootAuthToken = security.getAuthToken(getAuthTokenRoot);
67 System.out.println("root AUTHTOKEN = " + "don't log auth tokens!");
68 token = rootAuthToken.getAuthInfo();
69 }
70GetServiceDetail fs = newGetServiceDetail();
71 fs.setAuthInfo(token);
72 fs.getServiceKey().add(key);
73ServiceDetail serviceDetail = inquiry.getServiceDetail(fs);
74if (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 }
8384publicstaticvoid main(String args[]) {
85UddiGetServiceDetails sp = newUddiGetServiceDetails();
86 sp.fire(null, "uddi:juddi.apache.org:services-inquiry");
87 }
88 }