2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the “License”);
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.onap.portalsdk.core.onboarding.crossapi;
40 import java.io.BufferedReader;
41 import java.io.InputStreamReader;
42 import java.net.HttpURLConnection;
45 import org.apache.commons.logging.Log;
46 import org.apache.commons.logging.LogFactory;
48 public class SessionCommunicationService {
50 protected static final Log logger = LogFactory.getLog(SessionCommunicationService.class);
53 * Calls the ECOMP Portal to retrieve the session slot check interval.
58 * application user name used for authentication at Portal
60 * application password used for authentication at Portal
62 * application UEB key (basically application ID) used for
63 * authentication at Portal
64 * @return Content read from the remote REST endpoint
66 public static String getSessionSlotCheckInterval(String ecompRestURL, String userName, String password,
69 String url = ecompRestURL + "/getSessionSlotCheckInterval";
71 URL obj = new URL(url);
73 HttpURLConnection con = (HttpURLConnection) obj.openConnection();
75 // optional default is GET
76 con.setRequestMethod("GET");
77 con.setConnectTimeout(3000);
78 con.setReadTimeout(8000);
80 con.setRequestProperty("username", userName);
81 con.setRequestProperty("password", password);
82 con.setRequestProperty("uebkey", uebKey);
84 int responseCode = con.getResponseCode();
85 if (logger.isDebugEnabled()) {
86 logger.debug("getSessionSlotCheckInterval: Sending 'GET' request to URL : " + url);
87 logger.debug("getSessionSlotCheckInterval: Response Code : " + responseCode);
90 StringBuffer response = new StringBuffer();
91 try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"))) {
93 while ((inputLine = in.readLine()) != null)
94 response.append(inputLine);
96 catch (Exception ex) {
97 logger.error("getSessionSlotCheckInterval failed to read stream", ex);
99 return response.toString();
100 } catch (Exception e) {
101 logger.error("getSessionSlotCheckInterval: failed to fetch the session slot check", e);
108 * Calls the ECOMP Portal to request an extension of the current session.
110 * @param ecompRestURL
113 * application user name used for authentication at Portal
115 * application password used for authentication at Portal
117 * application UEB key (basically application ID) used for
118 * authentication at Portal
119 * @param sessionTimeoutMap
120 * Session timeout map
121 * @return Content read from the remote REST endpoint
123 public static String requestPortalSessionTimeoutExtension(String ecompRestURL, String userName, String password,
124 String uebKey, String sessionTimeoutMap) {
128 String url = ecompRestURL + "/extendSessionTimeOuts";
129 URL obj = new URL(url);
131 HttpURLConnection con = (HttpURLConnection) obj.openConnection();
133 con.setRequestMethod("POST");
134 con.setConnectTimeout(3000);
135 con.setReadTimeout(15000);
137 // add request header
138 con.setRequestProperty("username", userName);
139 con.setRequestProperty("password", password);
140 con.setRequestProperty("uebkey", uebKey);
141 con.setRequestProperty("sessionMap", sessionTimeoutMap);
142 con.setDoInput(true);
143 con.setDoOutput(true);
144 con.getOutputStream().write(sessionTimeoutMap.getBytes());
145 con.getOutputStream().flush();
146 con.getOutputStream().close();
150 int responseCode = con.getResponseCode();
151 if (logger.isDebugEnabled()) {
152 logger.debug("requestPortalSessionTimeoutExtension: Sending 'GET' request to URL : " + url);
153 logger.debug("requestPortalSessionTimeoutExtension: Response Code : " + responseCode);
156 StringBuffer response = new StringBuffer();
157 try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
159 while ((inputLine = in.readLine()) != null) {
160 response.append(inputLine);
162 } catch (Exception ex) {
163 logger.error("requestPortalSessionTimeoutExtension failed", ex);
165 return response.toString();
166 } catch (Exception e) {
167 logger.error("requestPortalSessionTimeoutExtension: failed to request Portal to extend time out ", e);