4b179daa7c7d267cb26da0b08b38c00ae301e3b8
[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 org.openecomp.mso.logger.MsoLogger;\r
24 import org.apache.http.HttpResponse;\r
25 import org.apache.http.client.ClientProtocolException;\r
26 import org.apache.http.client.methods.HttpGet;\r
27 import org.apache.http.client.methods.HttpPost;\r
28 import org.apache.http.entity.StringEntity;\r
29 \r
30 import javax.xml.bind.DatatypeConverter;\r
31 import java.io.IOException;\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)\r
42                                         throws ClientProtocolException, IOException{\r
43                 HttpPost post = new HttpPost(url);\r
44                 msoLogger.debug("Camunda Task url is: "+ url);          \r
45 \r
46                 StringEntity input = new StringEntity(jsonReq);\r
47                 input.setContentType(CommonConstants.CONTENT_TYPE_JSON);\r
48 \r
49                 String encryptedCredentials;\r
50                 if(props!=null){\r
51                         encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH,null);\r
52                         if(encryptedCredentials != null){\r
53                                 String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH, CommonConstants.ENCRYPTION_KEY);\r
54                                 if(userCredentials != null){\r
55                                         post.addHeader("Authorization", "Basic " + DatatypeConverter\r
56                         .printBase64Binary(userCredentials.getBytes()));\r
57                                 }\r
58                         }\r
59                 }\r
60 \r
61                 post.setEntity(input);\r
62                 return client.execute(post);\r
63         }\r
64         \r
65         @Override\r
66         public HttpResponse post(String camundaReqXML, String requestId,\r
67                         String requestTimeout, String schemaVersion, String serviceInstanceId, String action)\r
68                                         throws ClientProtocolException, IOException{\r
69                 msoLogger.debug("Method not supported");\r
70                 return null;\r
71         }\r
72         \r
73         @Override\r
74         public HttpResponse post(String requestId, boolean isBaseVfModule,\r
75                         int recipeTimeout, String requestAction, String serviceInstanceId,\r
76                         String vnfId, String vfModuleId, String volumeGroupId, String networkId,\r
77                         String serviceType, String vnfType, String vfModuleType, String networkType,\r
78                         String requestDetails, String recipeParamXsd)\r
79                                         throws ClientProtocolException, IOException{\r
80                 msoLogger.debug("Method not supported");\r
81                 return null;\r
82         }\r
83         \r
84         @Override\r
85         public HttpResponse get() throws ClientProtocolException, IOException{\r
86                 HttpGet get = new HttpGet(url);\r
87                 msoLogger.debug("Camunda Task url is: "+ url);  \r
88                 String encryptedCredentials;\r
89                 if(props!=null){\r
90                         encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH,null);\r
91                         if(encryptedCredentials != null){\r
92                                 String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH, CommonConstants.ENCRYPTION_KEY);\r
93                                 if(userCredentials != null){\r
94                                         get.addHeader("Authorization", "Basic " + DatatypeConverter\r
95                         .printBase64Binary(userCredentials.getBytes()));\r
96                                 }\r
97                         }\r
98                 }\r
99                 \r
100                 return client.execute(get);\r
101         }\r
102 \r
103 }\r