318b3ba5af9b2f9376ce88f8f7dd9bfebe6bb214
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.apihandler.common;
24
25 import java.io.IOException;
26 import java.security.GeneralSecurityException;
27 import org.apache.http.HttpResponse;
28 import org.apache.http.client.HttpClient;
29 import org.onap.so.utils.CryptoUtils;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.core.env.Environment;
33
34 public abstract class RequestClient {
35     private static Logger logger = LoggerFactory.getLogger(RequestClient.class);
36     protected Environment props;
37     protected String url;
38     protected HttpClient client;
39     private int type;
40
41     public RequestClient(int type) {
42         this.type = type;
43     }
44
45     public void setProps(Environment env) {
46         this.props = env;
47     }
48
49     public void setUrl(String url) {
50         this.url = url;
51     }
52
53     public String getUrl() {
54         return url;
55     }
56
57     public int getType() {
58         return type;
59     }
60
61     public HttpClient getClient() {
62         return client;
63     }
64
65     public void setClient(HttpClient client) {
66         this.client = client;
67     }
68
69     public abstract HttpResponse post(String request, String requestId, String requestTimeout, String schemaVersion,
70             String serviceInstanceId, String action) throws IOException;
71
72     public abstract HttpResponse post(String request) throws IOException;
73
74     public abstract HttpResponse post(RequestClientParameter parameterObject) throws IOException;
75
76     public abstract HttpResponse get() throws IOException;
77
78     protected String getEncryptedPropValue(String prop, String defaultValue, String encryptionKey) {
79         try {
80             return CryptoUtils.decrypt(prop, encryptionKey);
81         } catch (GeneralSecurityException e) {
82             logger.debug("Security exception", e);
83         }
84         return defaultValue;
85     }
86 }