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.enduser.test;
24 import java.net.URISyntaxException;
25 import java.security.Principal;
27 import org.onap.aaf.cadi.CadiException;
28 import org.onap.aaf.cadi.LocatorException;
29 import org.onap.aaf.cadi.enduser.ClientFactory;
30 import org.onap.aaf.cadi.enduser.SimpleRESTClient;
31 import org.onap.aaf.misc.env.APIException;
34 public class SimpleRestClientExample {
35 public final static void main(final String args[]) throws URISyntaxException, LocatorException {
37 // Note: Expect ClientFactory to be long-lived... do NOT create more than once.
38 ClientFactory cf = new ClientFactory(args);
41 String urlString = cf.getAccess().getProperty("myurl", null);
43 System.out.println("Note: In your startup, add \"myurl=https://<aaf hello machine>:8130\" to command line\n\t"
45 + " add -Dmyurl=https://<aaf hello machine>:8130 to VM Args\n\t"
46 + "where \"aaf hello machine\" is an aaf Installation you know about.");
48 SimpleRESTClient restClient = cf.simpleRESTClient(urlString,"org.osaaf.aaf");
52 // Call with no Queries
53 String rv = restClient.get("resthello");
54 System.out.println(rv);
57 rv = restClient.get("resthello?perm=org.osaaf.people|*|read");
58 System.out.println(rv);
60 // Call setting ID from principal coming from Trans
61 // Pretend Transaction
62 HRequest req = new HRequest("demo@people.osaaf.org"); // Pretend Trans has Jonathan as Identity
64 rv = restClient.as(req.userPrincipal()).get("resthello?perm=org.osaaf.people|*|read");
65 System.out.println(rv);
67 } catch (CadiException | APIException e) {
72 private static class HRequest {
74 public HRequest(String fqi) {
77 protected final String name;
79 // fake out HttpServletRequest, only for get Principal
80 public Principal userPrincipal() {
81 return new Principal() {
84 public String getName() {