AT&T 1712 and 1802 release code
[so.git] / mso-api-handlers / mso-api-handler-common / src / main / java / org / openecomp / mso / apihandler / common / CamundaTaskClient.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP - SO\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package org.openecomp.mso.apihandler.common;\r
22 \r
23 import java.io.IOException;\r
24 \r
25 import javax.xml.bind.DatatypeConverter;\r
26 \r
27 import org.apache.http.HttpResponse;\r
28 import org.apache.http.client.ClientProtocolException;\r
29 import org.apache.http.client.methods.HttpGet;\r
30 import org.apache.http.client.methods.HttpPost;\r
31 import org.apache.http.entity.StringEntity;\r
32 import org.openecomp.mso.logger.MsoLogger;\r
33 \r
34 public class CamundaTaskClient extends RequestClient{\r
35         private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH);\r
36 \r
37         public CamundaTaskClient() {\r
38                 super(CommonConstants.CAMUNDATASK);\r
39         }\r
40         \r
41         @Override\r
42         public HttpResponse post(String jsonReq)\r
43                                         throws ClientProtocolException, IOException{\r
44                 HttpPost post = new HttpPost(url);\r
45                 msoLogger.debug("Camunda Task url is: "+ url);          \r
46 \r
47                 StringEntity input = new StringEntity(jsonReq);\r
48                 input.setContentType(CommonConstants.CONTENT_TYPE_JSON);\r
49 \r
50                 String encryptedCredentials;\r
51                 if(props!=null){\r
52                         encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH,null);\r
53                         if(encryptedCredentials != null){\r
54                                 String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH, CommonConstants.ENCRYPTION_KEY);\r
55                                 if(userCredentials != null){\r
56                                         post.addHeader("Authorization", "Basic " + DatatypeConverter\r
57                                                 .printBase64Binary(userCredentials.getBytes()));\r
58                                 }\r
59                         }\r
60                 }\r
61 \r
62                 post.setEntity(input);\r
63                 return client.execute(post);\r
64         }\r
65         \r
66         @Override\r
67         public HttpResponse post(String camundaReqXML, String requestId,\r
68                         String requestTimeout, String schemaVersion, String serviceInstanceId, String action)\r
69                                         throws ClientProtocolException, IOException{\r
70                 msoLogger.debug("Method not supported");\r
71                 return null;\r
72         }\r
73         \r
74         @Override\r
75         public HttpResponse post(String requestId, boolean isBaseVfModule,\r
76                         int recipeTimeout, String requestAction, String serviceInstanceId,\r
77                         String vnfId, String vfModuleId, String volumeGroupId, String networkId, String configurationId,\r
78                         String serviceType, String vnfType, String vfModuleType, String networkType,\r
79                         String requestDetails, String recipeParamXsd)\r
80                                         throws ClientProtocolException, IOException{\r
81                 msoLogger.debug("Method not supported");\r
82                 return null;\r
83         }\r
84         \r
85         @Override\r
86         public HttpResponse get() throws ClientProtocolException, IOException{\r
87                 HttpGet get = new HttpGet(url);\r
88                 msoLogger.debug("Camunda Task url is: "+ url);  \r
89                 String encryptedCredentials;\r
90                 if(props!=null){\r
91                         encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH,null);\r
92                         if(encryptedCredentials != null){\r
93                                 String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH, CommonConstants.ENCRYPTION_KEY);\r
94                                 if(userCredentials != null){\r
95                                         get.addHeader("Authorization", "Basic " + new String(DatatypeConverter\r
96                                                 .printBase64Binary(userCredentials.getBytes())));\r
97                                 }\r
98                         }\r
99                 }\r
100                 \r
101                 return client.execute(get);\r
102         }\r
103 \r
104 }\r