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 private 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 StringBuilder response = new StringBuilder();
91 try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"))) {
93 while ((inputLine = in.readLine()) != null)
94 response.append(inputLine);
95 } catch (Exception ex) {
96 logger.error("getSessionSlotCheckInterval failed to read stream", ex);
98 return response.toString();
99 } catch (Exception e) {
100 logger.error("getSessionSlotCheckInterval: failed to fetch the session slot check", e);
107 * Calls the ECOMP Portal to request an extension of the current session.
109 * @param ecompRestURL
112 * application user name used for authentication at Portal
114 * application password used for authentication at Portal
116 * application UEB key (basically application ID) used for
117 * authentication at Portal
118 * @param sessionTimeoutMap
119 * Session timeout map
120 * @return Content read from the remote REST endpoint
122 public static String requestPortalSessionTimeoutExtension(String ecompRestURL, String userName, String password,
123 String uebKey, String sessionTimeoutMap) {
126 String url = ecompRestURL + "/extendSessionTimeOuts";
127 URL obj = new URL(url);
129 HttpURLConnection con = (HttpURLConnection) obj.openConnection();
131 con.setRequestMethod("POST");
132 con.setConnectTimeout(3000);
133 con.setReadTimeout(15000);
135 // add request header
136 con.setRequestProperty("username", userName);
137 con.setRequestProperty("password", password);
138 con.setRequestProperty("uebkey", uebKey);
139 con.setRequestProperty("sessionMap", sessionTimeoutMap);
140 con.setDoInput(true);
141 con.setDoOutput(true);
142 con.getOutputStream().write(sessionTimeoutMap.getBytes());
143 con.getOutputStream().flush();
144 con.getOutputStream().close();
146 int responseCode = con.getResponseCode();
147 if (logger.isDebugEnabled()) {
148 logger.debug("requestPortalSessionTimeoutExtension: Sending 'GET' request to URL : " + url);
149 logger.debug("requestPortalSessionTimeoutExtension: Response Code : " + responseCode);
152 StringBuilder response = new StringBuilder();
153 try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
155 while ((inputLine = in.readLine()) != null) {
156 response.append(inputLine);
158 } catch (Exception ex) {
159 logger.error("requestPortalSessionTimeoutExtension failed", ex);
161 return response.toString();
162 } catch (Exception e) {
163 logger.error("requestPortalSessionTimeoutExtension: failed to request Portal to extend time out ", e);