2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.apihandler.common;
23 import java.io.IOException;
25 import javax.ws.rs.core.MediaType;
26 import javax.xml.bind.DatatypeConverter;
28 import org.apache.http.HttpResponse;
29 import org.apache.http.client.ClientProtocolException;
30 import org.apache.http.client.methods.HttpPost;
31 import org.apache.http.entity.StringEntity;
33 import org.openecomp.mso.logger.MsoLogger;
35 public class BPELRestClient extends RequestClient {
37 private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH);
39 public BPELRestClient () {
40 super (CommonConstants.BPEL);
44 public HttpResponse post (String bpelReqXML,
46 String requestTimeout,
48 String serviceInstanceId,
49 String action) throws ClientProtocolException, IOException {
50 String encryptedCredentials;
51 HttpPost post = new HttpPost (url);
52 msoLogger.debug ("BPEL url is: " + url);
53 StringEntity input = new StringEntity (bpelReqXML);
54 input.setContentType (MediaType.TEXT_XML);
56 encryptedCredentials = props.getProperty (CommonConstants.BPEL_AUTH,null);
57 if (encryptedCredentials != null) {
58 String userCredentials = getEncryptedPropValue (encryptedCredentials,
59 CommonConstants.DEFAULT_BPEL_AUTH,
60 CommonConstants.ENCRYPTION_KEY);
61 if (userCredentials != null) {
62 post.addHeader ("Authorization",
63 "Basic " + DatatypeConverter.printBase64Binary (userCredentials.getBytes ()));
67 post.addHeader (CommonConstants.REQUEST_ID_HEADER, requestId);
68 post.addHeader (CommonConstants.REQUEST_TIMEOUT_HEADER, requestTimeout);
69 post.addHeader (CommonConstants.SCHEMA_VERSION_HEADER, schemaVersion);
70 if (serviceInstanceId != null) {
71 post.addHeader (CommonConstants.SERVICE_INSTANCE_ID_HEADER, serviceInstanceId);
74 post.addHeader (CommonConstants.ACTION_HEADER, action);
76 post.setEntity (input);
77 HttpResponse response = client.execute (post);
78 msoLogger.debug ("bpel response " + response);
83 public HttpResponse post (String bpelReqXML) {
88 public HttpResponse post(RequestClientParamater params) {
93 public HttpResponse get() {