2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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=========================================================
21 package org.onap.so.client;
23 import static org.apache.commons.lang3.StringUtils.isNotBlank;
25 import java.util.Optional;
26 import javax.ws.rs.core.MultivaluedMap;
27 import org.javatuples.Pair;
28 import org.onap.logging.filter.base.ONAPComponentsList;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class HttpClient extends RestClient {
34 protected final Logger log = LoggerFactory.getLogger(HttpClient.class);
35 private ONAPComponentsList targetEntity;
37 HttpClient(URL host, String contentType, ONAPComponentsList targetEntity) {
38 super(host, contentType);
39 this.targetEntity = targetEntity;
42 HttpClient(URL host, String acceptType, String contentType, ONAPComponentsList targetEntity) {
43 super(host, acceptType, contentType);
44 this.targetEntity = targetEntity;
48 public ONAPComponentsList getTargetEntity() {
53 protected void initializeHeaderMap(MultivaluedMap<String, Pair<String, String>> headerMap) {}
56 protected Optional<ResponseExceptionMapper> addResponseExceptionMapper() {
57 return Optional.empty();
61 * Adds a basic authentication header to the request.
63 * @param auth the encrypted credentials
64 * @param key the key for decrypting the credentials
67 public void addBasicAuthHeader(String auth, String key) {
68 if (isNotBlank(auth) && isNotBlank(key)) {
69 super.addBasicAuthHeader(auth, key);
71 log.warn("Not adding basic auth to headers.");
76 * Adds an additional header to the header map
78 * @param encoded basic auth value
80 public void addAdditionalHeader(String name, String value) {
82 if (isNotBlank(name) && isNotBlank(value)) {
83 headerMap.add("ALL", Pair.with(name, value));
85 log.warn("Not adding " + name + " to headers.");
87 } catch (Exception e) {
88 logger.error(e.getMessage(), e);
92 public void setAcceptType(String value) {
94 if (isNotBlank(value)) {
97 log.warn("Not adding accept to headers.");
99 } catch (Exception e) {
100 logger.error(e.getMessage(), e);