845b1403483d84de297e2695275a20dcf7356815
[so.git] /
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                 msoLogger.debug("Method not supported");\r
68                 return null;\r
69         }\r
70 \r
71         @Override\r
72         public HttpResponse post(RequestClientParamater params) {\r
73                 return null;\r
74         }\r
75 \r
76         @Override\r
77         public HttpResponse get() throws IOException{\r
78                 HttpGet get = new HttpGet(url);\r
79                 msoLogger.debug("Camunda Task url is: "+ url);  \r
80                 String encryptedCredentials;\r
81                 if(props!=null){\r
82                         encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH,null);\r
83                         if(encryptedCredentials != null){\r
84                                 String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH, CommonConstants.ENCRYPTION_KEY);\r
85                                 if(userCredentials != null){\r
86                                         get.addHeader("Authorization", "Basic " + new String(DatatypeConverter\r
87                                                 .printBase64Binary(userCredentials.getBytes())));\r
88                                 }\r
89                         }\r
90                 }\r
91                 return client.execute(get);\r
92         }\r
93 \r
94 }\r