diff options
author | Instrumental <jonathan.gathman@att.com> | 2018-07-05 15:00:18 -0500 |
---|---|---|
committer | Instrumental <jonathan.gathman@att.com> | 2018-07-05 15:00:23 -0500 |
commit | d37b5467a3b8b375b603579d2888a4443a8b06a7 (patch) | |
tree | 54baad3b69be2386bf43e88acac86a15f686a68d /cadi/oauth-enduser/src/main | |
parent | d41c5dc8c946fef66b64e8f95392b07403a93638 (diff) |
Refine Agent for cadi utils
Issue-ID: AAF-361
Change-Id: Id07b60181b906e65aefb24cbe0d192e362c2c3f4
Signed-off-by: Instrumental <jonathan.gathman@att.com>
Diffstat (limited to 'cadi/oauth-enduser/src/main')
-rw-r--r-- | cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/RESTException.java | 66 | ||||
-rw-r--r-- | cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/SimpleRESTClient.java | 28 |
2 files changed, 82 insertions, 12 deletions
diff --git a/cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/RESTException.java b/cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/RESTException.java new file mode 100644 index 00000000..95c9fe85 --- /dev/null +++ b/cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/RESTException.java @@ -0,0 +1,66 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * =========================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END==================================================== + * + */ +package org.onap.aaf.cadi.enduser; + +import org.onap.aaf.cadi.client.Future; + +public class RESTException extends Exception { + /** + * + */ + private static final long serialVersionUID = -5232371598208651058L; + private Future<?> future; + + public RESTException(Future<?> future) { + this.future = future; + } + + public int getCode() { + return future.code(); + } + + public String getMsg() { + return future.body(); + } + + public String errorString() { + String body = future.body(); + return "RESTClient Error: " + future.code() + ": " + (body.isEmpty()?"<no message in call>":body); + } + + /* (non-Javadoc) + * @see java.lang.Throwable#getMessage() + */ + @Override + public String getMessage() { + return errorString(); + } + + /* (non-Javadoc) + * @see java.lang.Throwable#getLocalizedMessage() + */ + @Override + public String getLocalizedMessage() { + return errorString(); + } + + +} diff --git a/cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/SimpleRESTClient.java b/cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/SimpleRESTClient.java index 9535ad64..386d938c 100644 --- a/cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/SimpleRESTClient.java +++ b/cadi/oauth-enduser/src/main/java/org/onap/aaf/cadi/enduser/SimpleRESTClient.java @@ -80,7 +80,7 @@ public class SimpleRESTClient { } //Format:<ID>:<APP>:<protocol>[:AS][,<ID>:<APP>:<protocol>]* - public SimpleRESTClient as(Principal principal) { + public SimpleRESTClient endUser(Principal principal) { if(principal==null) { chain = null; } else { @@ -93,23 +93,27 @@ public class SimpleRESTClient { } return this; } - - public String get(final String path) throws CadiException, LocatorException, APIException { + + public String read(final String path) throws RESTException, CadiException, LocatorException, APIException { + return get(path,"application/json"); + } + + public String get(final String path) throws RESTException, CadiException, LocatorException, APIException { return get(path,"application/json"); } - public String get(final String path, final String accepts) throws CadiException, LocatorException, APIException { - return restClient.best(new Retryable<String>() { + public String get(final String path, final String accepts) throws RESTException, CadiException, LocatorException, APIException { + Future<String> future = restClient.best(new Retryable<Future<String>>() { @Override - public String code(Rcli<?> client) throws CadiException, ConnectException, APIException { - Future<String> future = client.read(path,accepts, headers()); - if(future.get(callTimeout)) { - return future.value; - } else { - throw new APIException(future.code() + future.body()); - } + public Future<String> code(Rcli<?> client) throws CadiException, ConnectException, APIException { + return client.read(path,accepts, headers()); } }); + if(future.get(callTimeout)) { + return future.value; + } else { + throw new RESTException(future); + } } public interface Headers { |