ca1ad7a277144c297b994b23425464523300217f
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.apihandler.common;
22
23 import java.io.IOException;
24 import java.security.GeneralSecurityException;
25
26 import org.apache.http.HttpResponse;
27 import org.apache.http.client.ClientProtocolException;
28 import org.apache.http.client.HttpClient;
29 import org.onap.so.logger.MsoLogger;
30 import org.onap.so.utils.CryptoUtils;
31 import org.springframework.core.env.Environment;
32
33 public abstract class RequestClient {
34         private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH,RequestClient.class);
35         protected Environment props;
36         protected String url;
37         protected HttpClient client;
38         private int type;
39         
40         public RequestClient(int type){
41                 this.type = type;
42         }
43         
44         public void setProps(Environment env) {
45                 this.props = env;
46         }
47
48         public void setUrl(String url) {
49                 this.url = url;
50         }
51         
52         public String getUrl() {
53                 return url;
54         }
55
56         public int getType(){
57                 return type;
58         }
59
60         public HttpClient getClient() {
61                 return client;
62         }
63
64         public void setClient(HttpClient client) {
65                 this.client = client;
66         }
67
68         public abstract HttpResponse post(String request, String requestId, String requestTimeout, String schemaVersion, String serviceInstanceId, String action) throws IOException;
69
70         public abstract HttpResponse post(String request) throws ClientProtocolException, IOException;
71         
72         public abstract HttpResponse post(RequestClientParameter parameterObject) throws ClientProtocolException, IOException;
73
74         public abstract HttpResponse get() 
75                                         throws IOException;
76         
77         protected String decryptPropValue(String prop, String defaultValue, String encryptionKey) {
78                  try {
79                          String result = CryptoUtils.decrypt(prop, encryptionKey);
80                          return result;
81                  }      
82                  catch (GeneralSecurityException e) {
83                          msoLogger.debug("Security exception", e);
84                  }
85                  return defaultValue;
86          }
87         
88         protected String getEncryptedPropValue (String prop, String defaultValue, String encryptionKey) {
89                  try {
90                          String result = CryptoUtils.decrypt(prop, encryptionKey);
91                          return result;
92                  }      
93                  catch (GeneralSecurityException e) {
94                          msoLogger.debug("Security exception", e);
95                  }
96                  return defaultValue;
97          }
98
99         
100
101
102 }