2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
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 * ================================================================================
20 package org.openecomp.portalsdk.core.onboarding.crossapi;
22 import java.io.BufferedReader;
23 import java.io.InputStreamReader;
24 import java.net.HttpURLConnection;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
30 public class SessionCommunicationService {
32 protected static final Log logger = LogFactory.getLog(SessionCommunicationService.class);
35 * Calls the ECOMP Portal to retrieve the session slot check interval.
39 * application user name used for authentication at Portal
41 * application password used for authentication at Portal
43 * application UEB key (basically application ID) used for
44 * authentication at Portal
45 * @return Content read from the remote REST endpoint
47 public static String getSessionSlotCheckInterval(String ecompRestURL, String userName, String password,
50 String url = ecompRestURL + "/getSessionSlotCheckInterval";
52 URL obj = new URL(url);
54 HttpURLConnection con = (HttpURLConnection) obj.openConnection();
56 // optional default is GET
57 con.setRequestMethod("GET");
58 con.setConnectTimeout(3000);
59 con.setReadTimeout(8000);
61 con.setRequestProperty("username", userName);
62 con.setRequestProperty("password", password);
63 con.setRequestProperty("uebkey", uebKey);
65 int responseCode = con.getResponseCode();
66 if (logger.isDebugEnabled()) {
67 logger.debug("getSessionSlotCheckInterval: Sending 'GET' request to URL : " + url);
68 logger.debug("getSessionSlotCheckInterval: Response Code : " + responseCode);
71 StringBuffer response = new StringBuffer();
73 BufferedReader in = null;
75 in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
77 while ((inputLine = in.readLine()) != null)
78 response.append(inputLine);
82 return response.toString();
83 } catch (Exception e) {
84 logger.error("getSessionSlotCheckInterval: failed to fetch the session slot check", e);
91 * Calls the ECOMP Portal to request an extension of the current session.
95 * application user name used for authentication at Portal
97 * application password used for authentication at Portal
99 * application UEB key (basically application ID) used for
100 * authentication at Portal
101 * @param sessionTimeoutMap
102 * @return Content read from the remote REST endpoint
105 public static String requestPortalSessionTimeoutExtension(String ecompRestURL, String userName, String password,
106 String uebKey, String sessionTimeoutMap) throws Exception {
110 String url = ecompRestURL + "/extendSessionTimeOuts";
111 // String decreptedPwd =
112 // app.appPassword;//CipherUtil.decrypt(encriptedPwdDB,
113 // SystemProperties.getProperty(SystemProperties.SECRET_KEY));
115 URL obj = new URL(url);
117 HttpURLConnection con = (HttpURLConnection) obj.openConnection();
119 con.setRequestMethod("POST");
120 con.setConnectTimeout(3000);
121 con.setReadTimeout(15000);
123 // add request header
124 con.setRequestProperty("username", userName);
125 con.setRequestProperty("password", password);
126 con.setRequestProperty("uebkey", uebKey);
127 con.setRequestProperty("sessionMap", sessionTimeoutMap);
128 con.setDoInput(true);
129 con.setDoOutput(true);
130 con.getOutputStream().write(sessionTimeoutMap.getBytes());
131 con.getOutputStream().flush();
132 con.getOutputStream().close();
136 int responseCode = con.getResponseCode();
137 if (logger.isDebugEnabled()) {
138 logger.debug("requestPortalSessionTimeoutExtension: Sending 'GET' request to URL : " + url);
139 logger.debug("requestPortalSessionTimeoutExtension: Response Code : " + responseCode);
142 StringBuffer response = new StringBuffer();
143 BufferedReader in = null;
145 in = new BufferedReader(new InputStreamReader(con.getInputStream()));
147 while ((inputLine = in.readLine()) != null) {
148 response.append(inputLine);
153 return response.toString();
154 } catch (Exception e) {
155 logger.error("requestPortalSessionTimeoutExtension: failed to request Portal to extend time out ", e);