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