Merge "Fix problem with singleton impact on TC execution"
[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.methods.HttpGet;\r
29 import org.apache.http.client.methods.HttpPost;\r
30 import org.apache.http.entity.StringEntity;\r
31 import org.openecomp.mso.logger.MsoLogger;\r
32 \r
33 public class CamundaTaskClient extends RequestClient{\r
34         private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH);\r
35 \r
36         public CamundaTaskClient() {\r
37                 super(CommonConstants.CAMUNDATASK);\r
38         }\r
39         \r
40         @Override\r
41         public HttpResponse post(String jsonReq) throws IOException{\r
42                 HttpPost post = new HttpPost(url);\r
43                 msoLogger.debug("Camunda Task url is: "+ url);          \r
44 \r
45                 StringEntity input = new StringEntity(jsonReq);\r
46                 input.setContentType(CommonConstants.CONTENT_TYPE_JSON);\r
47 \r
48                 String encryptedCredentials;\r
49                 if(props!=null){\r
50                         encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH,null);\r
51                         if(encryptedCredentials != null){\r
52                                 String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH, CommonConstants.ENCRYPTION_KEY);\r
53                                 if(userCredentials != null){\r
54                                         post.addHeader("Authorization", "Basic " + DatatypeConverter\r
55                                                 .printBase64Binary(userCredentials.getBytes()));\r
56                                 }\r
57                         }\r
58                 }\r
59 \r
60                 post.setEntity(input);\r
61                 return client.execute(post);\r
62         }\r
63         \r
64         @Override\r
65         public HttpResponse post(String camundaReqXML, String requestId,\r
66                         String requestTimeout, String schemaVersion, String serviceInstanceId, String action) {\r
67                 throw new UnsupportedOperationException("Method not supported.");\r
68         }\r
69 \r
70         @Override\r
71         public HttpResponse post(RequestClientParamater params) {\r
72                 throw new UnsupportedOperationException("Method not supported.");\r
73         }\r
74 \r
75         @Override\r
76         public HttpResponse get() throws IOException {\r
77                 HttpGet get = new HttpGet(url);\r
78                 msoLogger.debug("Camunda Task url is: "+ url);\r
79                 String encryptedCredentials;\r
80                 if(props!=null){\r
81                         encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH,null);\r
82                         if(encryptedCredentials != null){\r
83                                 String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH, CommonConstants.ENCRYPTION_KEY);\r
84                                 if(userCredentials != null){\r
85                                         get.addHeader("Authorization", "Basic " + new String(DatatypeConverter\r
86                                                 .printBase64Binary(userCredentials.getBytes())));\r
87                                 }\r
88                         }\r
89                 }\r
90                 return client.execute(get);\r
91         }\r
92 \r
93 }\r