ed5d076d8cc5dc9819046bc5f29f15c2053a47d1
[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.openecomp.mso.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.openecomp.mso.logger.MsoLogger;
30 import org.openecomp.mso.properties.MsoJavaProperties;
31 import org.openecomp.mso.utils.CryptoUtils;
32
33 public abstract class RequestClient {
34         private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH);
35         protected MsoJavaProperties 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(MsoJavaProperties props) {
45                 this.props = props;
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 ClientProtocolException, IOException;
69
70         public abstract HttpResponse post(String request) throws IOException;
71
72         public abstract HttpResponse post(RequestClientParamater params) throws IOException;
73         
74         public abstract HttpResponse get() throws  IOException;
75         
76         protected String getEncryptedPropValue (String prop, String defaultValue, String encryptionKey) {
77                  try {
78                          return CryptoUtils.decrypt(prop, encryptionKey);
79                  }      
80                  catch (GeneralSecurityException e) {
81                          msoLogger.debug("Security exception", e);
82                  }
83                  return defaultValue;
84          }
85 }