Merge "Reorder modifiers"
[so.git] / mso-api-handlers / mso-api-handler-common / src / main / java / org / openecomp / mso / apihandler / common / RequestClient.java
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.HttpClient;
28 import org.openecomp.mso.logger.MsoLogger;
29 import org.openecomp.mso.properties.MsoJavaProperties;
30 import org.openecomp.mso.utils.CryptoUtils;
31
32 public abstract class RequestClient {
33         private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH);
34         protected MsoJavaProperties props;
35         protected String url;
36         protected HttpClient client;
37         private int type;
38         
39         public RequestClient(int type){
40                 this.type = type;
41         }
42         
43         public void setProps(MsoJavaProperties props) {
44                 this.props = props;
45         }
46
47         public void setUrl(String url) {
48                 this.url = url;
49         }
50         
51         public String getUrl() {
52                 return url;
53         }
54
55         public int getType(){
56                 return type;
57         }
58
59         public HttpClient getClient() {
60                 return client;
61         }
62
63         public void setClient(HttpClient client) {
64                 this.client = client;
65         }
66
67         public abstract HttpResponse post(String request, String requestId, String requestTimeout, String schemaVersion, String serviceInstanceId, String action) throws IOException;
68
69         public abstract HttpResponse post(String request) throws IOException;
70
71         public abstract HttpResponse post(RequestClientParamater params) throws IOException;
72         
73         public abstract HttpResponse get() throws  IOException;
74         
75         protected String getEncryptedPropValue (String prop, String defaultValue, String encryptionKey) {
76                  try {
77                          return CryptoUtils.decrypt(prop, encryptionKey);
78                  }      
79                  catch (GeneralSecurityException e) {
80                          msoLogger.debug("Security exception", e);
81                  }
82                  return defaultValue;
83          }
84 }