2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.cadi.aaf.test;
24 import java.net.HttpURLConnection;
27 import org.onap.aaf.cadi.CadiException;
28 import org.onap.aaf.cadi.PropAccess;
29 import org.onap.aaf.cadi.SecuritySetter;
30 import org.onap.aaf.cadi.Access.Level;
31 import org.onap.aaf.cadi.Locator.Item;
32 import org.onap.aaf.cadi.aaf.v2_0.AAFLocator;
33 import org.onap.aaf.cadi.aaf.v2_0.AbsAAFLocator;
34 import org.onap.aaf.cadi.client.Future;
35 import org.onap.aaf.cadi.client.Rcli;
36 import org.onap.aaf.cadi.client.Retryable;
37 import org.onap.aaf.cadi.config.Config;
38 import org.onap.aaf.cadi.config.SecurityInfoC;
39 import org.onap.aaf.cadi.http.HBasicAuthSS;
40 import org.onap.aaf.cadi.http.HMangr;
41 import org.onap.aaf.misc.env.APIException;
42 import org.onap.aaf.misc.env.impl.BasicTrans;
44 public class TestHClient {
45 public static void main(String[] args) {
47 PropAccess access = new PropAccess(args);
48 String aaf_url = access.getProperty(Config.AAF_URL);
50 access.log(Level.ERROR, Config.AAF_URL," is required");
54 SecurityInfoC<HttpURLConnection> si = SecurityInfoC.instance(access, HttpURLConnection.class);
55 AbsAAFLocator<BasicTrans> loc = new AAFLocator(si,new URI(aaf_url));
56 for(Item item = loc.first(); item!=null; item=loc.next(item)) {
57 System.out.println(loc.get(item));
59 SecuritySetter<HttpURLConnection> ss = new HBasicAuthSS(si);
60 // SecuritySetter<HttpURLConnection> ss = new X509SS(si, "aaf");
62 hman = new HMangr(access,loc);
63 final String path = String.format("/authz/perms/user/%s",
64 access.getProperty(Config.AAF_APPID,"xx9999@csp.att.com"));
65 hman.best(ss, new Retryable<Void>() {
67 public Void code(Rcli<?> cli) throws APIException, CadiException {
68 Future<String> ft = cli.read(path,"application/json");
70 System.out.println("Hurray,\n"+ft.body());
72 System.out.println("not quite: " + ft.code());
82 } catch (Exception e) {