2e509b0fdc281108a91a71b3251e3b60c267d397
[aaf/authz.git] / cadi / aaf / src / test / java / org / onap / aaf / cadi / aaf / test / TestHClient.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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====================================================
19  *
20  */
21
22 package org.onap.aaf.cadi.aaf.test;
23
24 import java.net.HttpURLConnection;
25 import java.net.URI;
26
27 import org.onap.aaf.cadi.Access.Level;
28 import org.onap.aaf.cadi.CadiException;
29 import org.onap.aaf.cadi.Locator.Item;
30 import org.onap.aaf.cadi.PropAccess;
31 import org.onap.aaf.cadi.aaf.v2_0.AAFLocator;
32 import org.onap.aaf.cadi.aaf.v2_0.AbsAAFLocator;
33 import org.onap.aaf.cadi.client.Future;
34 import org.onap.aaf.cadi.client.Rcli;
35 import org.onap.aaf.cadi.client.Retryable;
36 import org.onap.aaf.cadi.config.Config;
37 import org.onap.aaf.cadi.config.SecurityInfoC;
38 import org.onap.aaf.cadi.http.HMangr;
39 import org.onap.aaf.misc.env.APIException;
40 import org.onap.aaf.misc.env.impl.BasicTrans;
41
42 public class TestHClient {
43         public static void main(String[] args) {
44                 try {
45                         PropAccess access = new PropAccess(args);
46                         String aaf_url = access.getProperty(Config.AAF_URL);
47                         if(aaf_url == null) {
48                                 access.log(Level.ERROR, Config.AAF_URL," is required");
49                         } else {
50                                 HMangr hman = null;
51                                 try {
52                                         SecurityInfoC<HttpURLConnection> si = SecurityInfoC.instance(access, HttpURLConnection.class);
53                                         AbsAAFLocator<BasicTrans> loc = new AAFLocator(si,new URI(aaf_url));
54                                         for(Item item = loc.first(); item!=null; item=loc.next(item)) {
55                                                 System.out.println(loc.get(item));
56                                         }
57                                         
58                                         hman = new HMangr(access,loc);
59                                         final String path = String.format("/authz/perms/user/%s",
60                                                         access.getProperty(Config.AAF_APPID,"xx9999@people.osaaf.org"));
61                                         hman.best(si.defSS, new Retryable<Void>() {
62                                                 @Override
63                                                 public Void code(Rcli<?> cli) throws APIException, CadiException {
64                                                         Future<String> ft = cli.read(path,"application/json");  
65                                                         if(ft.get(10000)) {
66                                                                 System.out.println("Hurray,\n"+ft.body());
67                                                         } else {
68                                                                 System.out.println("not quite: " + ft.code());
69                                                         }
70                                                         return null;
71                                                 }});
72                                 } finally {
73                                         if(hman!=null) {
74                                                 hman.close();
75                                         }
76                                 }
77                         }
78                 } catch (Exception e) {
79                         e.printStackTrace();
80                 }
81         }
82         
83 }