166a5c4d109bffe571c0be1b95224d77f08b71c4
[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  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.apihandler.common;
22
23 import java.io.IOException;
24
25 import javax.xml.bind.DatatypeConverter;
26
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.onap.so.logger.MsoLogger;
32
33 public class CamundaTaskClient extends RequestClient{
34         private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH, CamundaTaskClient.class);
35
36         public CamundaTaskClient() {
37                 super(CommonConstants.CAMUNDATASK);
38         }
39         
40         @Override
41         public HttpResponse post(String jsonReq) throws IOException{
42                 HttpPost post = new HttpPost(url);
43                 msoLogger.debug("Camunda Task url is: "+ url);          
44
45                 StringEntity input = new StringEntity(jsonReq);
46                 input.setContentType(CommonConstants.CONTENT_TYPE_JSON);
47
48                 String encryptedCredentials;
49                 if(props!=null){
50                         encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH);
51                         if(encryptedCredentials != null){
52                                 String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH, CommonConstants.ENCRYPTION_KEY);
53                                 if(userCredentials != null){
54                                         post.addHeader("Authorization", "Basic " + DatatypeConverter
55                                                 .printBase64Binary(userCredentials.getBytes()));
56                                 }
57                         }
58                 }
59
60                 post.setEntity(input);
61                 return client.execute(post);
62         }
63         
64         @Override
65         public HttpResponse post(String camundaReqXML, String requestId,
66                         String requestTimeout, String schemaVersion, String serviceInstanceId, String action) {
67                 throw new UnsupportedOperationException("Method not supported.");
68         }
69
70         @Override
71         public HttpResponse post(RequestClientParameter params) {
72                 throw new UnsupportedOperationException("Method not supported.");
73         }
74
75         @Override
76         public HttpResponse get() throws IOException {
77                 HttpGet get = new HttpGet(url);
78                 msoLogger.debug("Camunda Task url is: "+ url);
79                 String encryptedCredentials;
80                 if(props!=null){
81                         encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH);
82                         if(encryptedCredentials != null){
83                                 String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH, CommonConstants.ENCRYPTION_KEY);
84                                 if(userCredentials != null){
85                                         get.addHeader("Authorization", "Basic " + new String(DatatypeConverter
86                                                 .printBase64Binary(userCredentials.getBytes())));
87                                 }
88                         }
89                 }
90                 return client.execute(get);
91         }
92
93 }