d6d999b4b54f4005ef57cfa923738f0d9169f801
[so.git] /
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 import javax.xml.bind.DatatypeConverter;
27 import org.apache.http.HttpResponse;
28 import org.apache.http.client.methods.HttpGet;
29 import org.apache.http.client.methods.HttpPost;
30 import org.apache.http.entity.StringEntity;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 public class CamundaTaskClient extends RequestClient {
35     private static Logger logger = LoggerFactory.getLogger(CamundaTaskClient.class);
36
37     public CamundaTaskClient() {
38         super(CommonConstants.CAMUNDATASK);
39     }
40
41     @Override
42     public HttpResponse post(String jsonReq) throws IOException {
43         HttpPost post = new HttpPost(url);
44         logger.debug("Camunda Task url is: {}", url);
45
46         StringEntity input = new StringEntity(jsonReq);
47         input.setContentType(CommonConstants.CONTENT_TYPE_JSON);
48
49         String encryptedCredentials;
50         if (props != null) {
51             encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH);
52             if (encryptedCredentials != null) {
53                 String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH,
54                         props.getProperty(CommonConstants.ENCRYPTION_KEY_PROP));
55                 if (userCredentials != null) {
56                     post.addHeader("Authorization",
57                             "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes()));
58                 }
59             }
60         }
61
62         post.setEntity(input);
63         return client.execute(post);
64     }
65
66     @Override
67     public HttpResponse post(String camundaReqXML, String requestId, String requestTimeout, String schemaVersion,
68             String serviceInstanceId, String action) {
69         throw new UnsupportedOperationException("Method not supported.");
70     }
71
72     @Override
73     public HttpResponse post(RequestClientParameter params) {
74         throw new UnsupportedOperationException("Method not supported.");
75     }
76
77     @Override
78     public HttpResponse get() throws IOException {
79         HttpGet get = new HttpGet(url);
80         logger.debug("Camunda Task url is: {}", url);
81         String encryptedCredentials;
82         if (props != null) {
83             encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH);
84             if (encryptedCredentials != null) {
85                 String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH,
86                         props.getProperty(CommonConstants.ENCRYPTION_KEY_PROP));
87                 if (userCredentials != null) {
88                     get.addHeader("Authorization",
89                             "Basic " + new String(DatatypeConverter.printBase64Binary(userCredentials.getBytes())));
90                 }
91             }
92         }
93         return client.execute(get);
94     }
95
96 }