|
|
@ -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 {
|
|
|
|
|
|
|
|
|
|
|
|
httpSession = req.getSession(false);
|
|
|
|
|
|
|
|
gatewayUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR)
|
|
|
|
|
|
|
|
+ HandlerConstants.COLON + HandlerUtil.getGatewayPort(req.getScheme());
|
|
|
|
|
|
|
|
iotsCoreUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR)
|
|
|
|
|
|
|
|
+ HandlerConstants.COLON + HandlerUtil.getCorePort(req.getScheme());
|
|
|
|
|
|
|
|
String uiConfigUrl = iotsCoreUrl + HandlerConstants.UI_CONFIG_ENDPOINT;
|
|
|
|
|
|
|
|
uiConfigJsonObject = HandlerUtil.getUIConfigAndPersistInSession(uiConfigUrl, gatewayUrl, httpSession, resp);
|
|
|
|
|
|
|
|
chatConfig = uiConfigJsonObject.get("chatConfig").getAsString();
|
|
|
|
|
|
|
|
hubspotEndpoint = HandlerConstants.HTTPS_PROTOCOL + HandlerConstants.SCHEME_SEPARATOR + HandlerConstants.HUBSPOT_CHAT_URL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (httpSession == null) {
|
|
|
|
if (httpSession == null) {
|
|
|
|
log.error("Unauthorized, You are not logged in. Please log in to the portal");
|
|
|
|
log.error("Unauthorized, You are not logged in. Please log in to the portal");
|
|
|
|
HandlerUtil.handleError(resp, HttpStatus.SC_UNAUTHORIZED);
|
|
|
|
HandlerUtil.handleError(resp, HttpStatus.SC_UNAUTHORIZED);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (req.getMethod() == null) {
|
|
|
|
if (req.getMethod() == null) {
|
|
|
|
log.error("Bad Request, Request method is empty");
|
|
|
|
log.error("Bad Request, Request method is empty");
|
|
|
|
HandlerUtil.handleError(resp, HttpStatus.SC_BAD_REQUEST);
|
|
|
|
HandlerUtil.handleError(resp, HttpStatus.SC_BAD_REQUEST);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
httpSession = req.getSession(false);
|
|
|
|
|
|
|
|
gatewayUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR)
|
|
|
|
|
|
|
|
+ HandlerConstants.COLON + HandlerUtil.getGatewayPort(req.getScheme());
|
|
|
|
|
|
|
|
iotsCoreUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR)
|
|
|
|
|
|
|
|
+ HandlerConstants.COLON + HandlerUtil.getCorePort(req.getScheme());
|
|
|
|
|
|
|
|
String uiConfigUrl = iotsCoreUrl + HandlerConstants.UI_CONFIG_ENDPOINT;
|
|
|
|
|
|
|
|
uiConfigJsonObject = HandlerUtil.getUIConfigAndPersistInSession(uiConfigUrl, gatewayUrl, httpSession, resp);
|
|
|
|
|
|
|
|
chatConfig = uiConfigJsonObject.get("chatConfig").getAsString();
|
|
|
|
|
|
|
|
hubspotEndpoint = HandlerConstants.HTTPS_PROTOCOL + HandlerConstants.SCHEME_SEPARATOR + HandlerConstants.HUBSPOT_CHAT_URL;
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|