Update AAF Version 1.0.0
[aaf/cadi.git] / client / src / test / java / com / client / test / TestHClient.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aaf\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * ===========================================================================\r
7  * * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * * you may not use this file except in compliance with the License.\r
9  * * You may obtain a copy of the License at\r
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \r
13  *  * Unless required by applicable law or agreed to in writing, software\r
14  * * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * * See the License for the specific language governing permissions and\r
17  * * limitations under the License.\r
18  * * ============LICENSE_END====================================================\r
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package com.client.test;\r
24 \r
25 import java.net.HttpURLConnection;\r
26 import java.net.URI;\r
27 import java.util.Properties;\r
28 \r
29 import com.att.aft.dme2.api.DME2Manager;\r
30 import com.att.cadi.CadiException;\r
31 import com.att.cadi.Locator;\r
32 import com.att.cadi.Locator.Item;\r
33 import com.att.cadi.PropAccess;\r
34 import com.att.cadi.SecuritySetter;\r
35 import com.att.cadi.client.Future;\r
36 import com.att.cadi.client.Rcli;\r
37 import com.att.cadi.client.Retryable;\r
38 import com.att.cadi.config.Config;\r
39 import com.att.cadi.config.SecurityInfoC;\r
40 import com.att.cadi.http.HBasicAuthSS;\r
41 import com.att.cadi.http.HMangr;\r
42 import com.att.cadi.locator.DME2Locator;\r
43 import com.att.inno.env.APIException;\r
44 \r
45 public class TestHClient {\r
46         public static void main(String[] args) {\r
47                 try {\r
48                         PropAccess access = new PropAccess();\r
49                         DME2Manager dm = new DME2Manager("DME2Manager TestHClient",access.getProperties());\r
50                         Locator<URI> loc = new DME2Locator(access,dm,"com.att.authz.AuthorizationService","2.0","DEV","BAU_SE");\r
51 \r
52                         for(Item item = loc.first(); item!=null; item=loc.next(item)) {\r
53                                 System.out.println(loc.get(item));\r
54                         }\r
55                         \r
56                         \r
57                         SecurityInfoC<HttpURLConnection> si = new SecurityInfoC<HttpURLConnection>(access);\r
58                         SecuritySetter<HttpURLConnection> ss = new HBasicAuthSS("m12345@aaf.att.com", \r
59                                         access.decrypt("enc:7K6yjLQqha_S9yApkIul2K_by5Moemcos1HRAVnhMXu",false), si);\r
60 //                      SecuritySetter<HttpURLConnection> ss = new X509SS(si, "aaf");\r
61                         \r
62                         HMangr hman = new HMangr(access,loc);\r
63                         try {\r
64                                 hman.best(ss, new Retryable<Void>() {\r
65                                         @Override\r
66                                         public Void code(Rcli<?> cli) throws APIException, CadiException {\r
67                                                 Future<String> ft = cli.read("/authz/nss/com.att.aaf","text/json");  \r
68                                                 if(ft.get(10000)) {\r
69                                                         System.out.println("Hurray,\n"+ft.body());\r
70                                                 } else {\r
71                                                         System.out.println("not quite: " + ft.code());\r
72                                                 }\r
73                                                 return null;\r
74                                         }});\r
75                         } finally {\r
76                                 hman.close();\r
77                         }\r
78                 } catch (Exception e) {\r
79                         e.printStackTrace();\r
80                 }\r
81         }\r
82         \r
83 }\r