Change the header to SO
[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 import java.util.Properties;
26
27 import org.apache.http.HttpResponse;
28 import org.apache.http.client.ClientProtocolException;
29 import org.apache.http.client.HttpClient;
30
31 import org.openecomp.mso.logger.MsoLogger;
32 import org.openecomp.mso.properties.MsoJavaProperties;
33 import org.openecomp.mso.utils.CryptoUtils;
34
35 public abstract class RequestClient {
36         private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH);
37         protected MsoJavaProperties props;
38         protected String url;
39         protected HttpClient client;
40         private int type;
41         
42         public RequestClient(int type){
43                 this.type = type;
44         }
45         
46         public void setProps(MsoJavaProperties props) {
47                 this.props = props;
48         }
49
50         public void setUrl(String url) {
51                 this.url = url;
52         }
53         
54         public String getUrl() {
55                 return url;
56         }
57
58         public int getType(){
59                 return type;
60         }
61
62         public HttpClient getClient() {
63                 return client;
64         }
65
66         public void setClient(HttpClient client) {
67                 this.client = client;
68         }
69
70         public abstract HttpResponse post(String request, String requestId, String requestTimeout, String schemaVersion, String serviceInstanceId, String action) throws ClientProtocolException, IOException;
71
72         public abstract HttpResponse post(String request) throws ClientProtocolException, IOException;
73         
74         public abstract HttpResponse post(String requestId, boolean isBaseVfModule,
75                         int recipeTimeout, String requestAction, String serviceInstanceId,
76                         String vnfId, String vfModuleId, String volumeGroupId, String networkId,
77                         String serviceType, String vnfType, String vfModuleType, String networkType,
78                         String requestDetails)
79                                         throws ClientProtocolException, IOException;
80         
81         public abstract HttpResponse get() 
82                                         throws ClientProtocolException, IOException;
83         
84         protected String getEncryptedPropValue (String prop, String defaultValue, String encryptionKey) {
85                  try {
86                          String result = CryptoUtils.decrypt(prop, encryptionKey);
87                          return result;
88                  }      
89                  catch (GeneralSecurityException e) {
90                          msoLogger.debug("Security exception", e);
91                  }
92                  return defaultValue;
93          }
94
95         
96
97
98 }