|
|
@ -1,3 +1,21 @@
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
|
|
|
|
|
|
|
* Version 2.0 (the "License"); you may not use this file except
|
|
|
|
|
|
|
|
* in compliance with the License.
|
|
|
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
|
|
|
|
* under the License.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
package io.entgra.ui.request.interceptor;
|
|
|
|
package io.entgra.ui.request.interceptor;
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
@ -51,12 +69,10 @@ public class HubspotHandler extends HttpServlet {
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
log.error("Error occurred when processing POST request.", e);
|
|
|
|
log.error("Error occurred when processing POST request.", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
|
|
|
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (validateRequest(req, resp)) {
|
|
|
|
if (validateRequest(req, resp)) {
|
|
|
|
HttpGet getRequest = new HttpGet(HandlerUtil.generateBackendRequestURL(req,hubspotEndpoint));
|
|
|
|
HttpGet getRequest = new HttpGet(HandlerUtil.generateBackendRequestURL(req,hubspotEndpoint));
|
|
|
@ -80,29 +96,25 @@ public class HubspotHandler extends HttpServlet {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private boolean validateRequest(HttpServletRequest req, HttpServletResponse resp)
|
|
|
|
private boolean validateRequest(HttpServletRequest req, HttpServletResponse resp)
|
|
|
|
throws IOException {
|
|
|
|
throws IOException {
|
|
|
|
|
|
|
|
if (httpSession == null) {
|
|
|
|
httpSession = req.getSession(false);
|
|
|
|
log.error("Unauthorized, You are not logged in. Please log in to the portal");
|
|
|
|
gatewayUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR)
|
|
|
|
HandlerUtil.handleError(resp, HttpStatus.SC_UNAUTHORIZED);
|
|
|
|
+ HandlerConstants.COLON + HandlerUtil.getGatewayPort(req.getScheme());
|
|
|
|
return false;
|
|
|
|
iotsCoreUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR)
|
|
|
|
}
|
|
|
|
+ HandlerConstants.COLON + HandlerUtil.getCorePort(req.getScheme());
|
|
|
|
if (req.getMethod() == null) {
|
|
|
|
String uiConfigUrl = iotsCoreUrl + HandlerConstants.UI_CONFIG_ENDPOINT;
|
|
|
|
log.error("Bad Request, Request method is empty");
|
|
|
|
uiConfigJsonObject = HandlerUtil.getUIConfigAndPersistInSession(uiConfigUrl, gatewayUrl, httpSession, resp);
|
|
|
|
HandlerUtil.handleError(resp, HttpStatus.SC_BAD_REQUEST);
|
|
|
|
chatConfig = uiConfigJsonObject.get("chatConfig").getAsString();
|
|
|
|
return false;
|
|
|
|
hubspotEndpoint = HandlerConstants.HTTPS_PROTOCOL + HandlerConstants.SCHEME_SEPARATOR + HandlerConstants.HUBSPOT_CHAT_URL;
|
|
|
|
}
|
|
|
|
|
|
|
|
httpSession = req.getSession(false);
|
|
|
|
if (httpSession == null) {
|
|
|
|
gatewayUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR)
|
|
|
|
log.error("Unauthorized, You are not logged in. Please log in to the portal");
|
|
|
|
+ HandlerConstants.COLON + HandlerUtil.getGatewayPort(req.getScheme());
|
|
|
|
HandlerUtil.handleError(resp, HttpStatus.SC_UNAUTHORIZED);
|
|
|
|
iotsCoreUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR)
|
|
|
|
return false;
|
|
|
|
+ HandlerConstants.COLON + HandlerUtil.getCorePort(req.getScheme());
|
|
|
|
}
|
|
|
|
String uiConfigUrl = iotsCoreUrl + HandlerConstants.UI_CONFIG_ENDPOINT;
|
|
|
|
|
|
|
|
uiConfigJsonObject = HandlerUtil.getUIConfigAndPersistInSession(uiConfigUrl, gatewayUrl, httpSession, resp);
|
|
|
|
if (req.getMethod() == null) {
|
|
|
|
chatConfig = uiConfigJsonObject.get("chatConfig").getAsString();
|
|
|
|
log.error("Bad Request, Request method is empty");
|
|
|
|
hubspotEndpoint = HandlerConstants.HTTPS_PROTOCOL + HandlerConstants.SCHEME_SEPARATOR + HandlerConstants.HUBSPOT_CHAT_URL;
|
|
|
|
HandlerUtil.handleError(resp, HttpStatus.SC_BAD_REQUEST);
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|