Change the header to SO
[so.git] / mso-api-handlers / mso-api-handler-common / src / main / java / org / openecomp / mso / apihandler / common / BPELRestClient.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.openecomp.mso.apihandler.common;
22
23 import java.io.IOException;
24
25 import javax.ws.rs.core.MediaType;
26 import javax.xml.bind.DatatypeConverter;
27
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;
32
33 import org.openecomp.mso.logger.MsoLogger;
34
35 public class BPELRestClient extends RequestClient {
36
37     private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH);
38
39     public BPELRestClient () {
40         super (CommonConstants.BPEL);
41     }
42
43     @Override
44     public HttpResponse post (String bpelReqXML,
45                               String requestId,
46                               String requestTimeout,
47                               String schemaVersion,
48                               String serviceInstanceId,
49                               String action) throws ClientProtocolException, IOException {
50         String encryptedCredentials = null;
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);
55         if (props != null) {
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 " + new String (DatatypeConverter.printBase64Binary (userCredentials.getBytes ())));
64                 }
65             }
66         }
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);
72         }
73         if (action != null) {
74             post.addHeader (CommonConstants.ACTION_HEADER, action);
75         }
76         post.setEntity (input);
77         HttpResponse response = client.execute (post);
78         msoLogger.debug ("bpel response " + response);
79         return response;
80     }
81
82     @Override
83     public HttpResponse post (String bpelReqXML) {
84         return null;
85     }
86
87     @Override
88     public HttpResponse post(String requestId, boolean isBaseVfModule,
89                              int recipeTimeout, String requestAction, String serviceInstanceId,
90                              String vnfId, String vfModuleId, String volumeGroupId, String networkId,
91                              String serviceType, String vnfType, String vfModuleType, String networkType,
92                              String requestDetails) {
93         return null;
94     }
95     
96     @Override
97     public HttpResponse get() {
98         return null;
99     }
100 }