diff --git a/webui/src/main/java/io/meeds/portal/permlink/web/PermanentLinkRequestHandler.java b/webui/src/main/java/io/meeds/portal/permlink/web/PermanentLinkRequestHandler.java index 904e24faba..b8d82451de 100644 --- a/webui/src/main/java/io/meeds/portal/permlink/web/PermanentLinkRequestHandler.java +++ b/webui/src/main/java/io/meeds/portal/permlink/web/PermanentLinkRequestHandler.java @@ -26,18 +26,21 @@ import org.exoplatform.commons.exception.ObjectNotFoundException; import org.exoplatform.container.ExoContainerContext; +import org.exoplatform.portal.config.UserPortalConfigService; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; import org.exoplatform.services.security.ConversationState; import org.exoplatform.services.security.Identity; import org.exoplatform.services.security.IdentityConstants; import org.exoplatform.web.ControllerContext; +import org.exoplatform.web.WebAppController; import org.exoplatform.web.WebRequestHandler; import org.exoplatform.web.controller.QualifiedName; import org.exoplatform.web.security.sso.SSOHelper; import io.meeds.portal.permlink.service.PermanentLinkService; +import jakarta.servlet.ServletConfig; import jakarta.servlet.http.HttpServletResponse; public class PermanentLinkRequestHandler extends WebRequestHandler { @@ -48,6 +51,8 @@ public class PermanentLinkRequestHandler extends WebRequestHandler { private PermanentLinkService permanentLinkService; + private UserPortalConfigService userPortalConfigService; + @Override public String getHandlerName() { return "permanent-link"; @@ -58,12 +63,18 @@ protected boolean getRequiresLifeCycle() { return true; } + @Override + public void onInit(WebAppController controller, ServletConfig sConfig) throws Exception { + permanentLinkService = ExoContainerContext.getService(PermanentLinkService.class); + userPortalConfigService = ExoContainerContext.getService(UserPortalConfigService.class); + } + @Override public boolean execute(ControllerContext context) throws Exception { String requestPath = context.getParameter(REQUEST_PATH); Identity currentIdentity = getCurrentIdentity(); try { - String directAccessUrl = getPermanentLinkService().getDirectAccessUrl(requestPath, currentIdentity); + String directAccessUrl = permanentLinkService.getDirectAccessUrl(requestPath, currentIdentity); HttpServletResponse res = context.getResponse(); // Use HTTP 302 response instead of 301 to not // allow to cache the redirect directive in routers @@ -74,12 +85,16 @@ public boolean execute(ControllerContext context) throws Exception { String loginPath = getAuthenticationUrl(context.getRequest().getRequestURI()); context.getResponse().sendRedirect(loginPath); } else { - LOG.error("Error while handling permanent link '{}' redirecting to not found page", requestPath, e); - context.getResponse().sendRedirect("/portal/public/page-not-found"); + LOG.warn("Error while handling permanent link '{}' redirecting to not found page", requestPath, e); + context.getResponse() + .sendRedirect(String.format("/portal/%s/page-not-found", + userPortalConfigService.getMetaPortal())); } } catch (ObjectNotFoundException e) { - LOG.error("Error while handling permanent link '{}'", requestPath, e); - context.getResponse().sendRedirect("/portal/public/page-not-found"); + LOG.warn("Error while handling permanent link '{}'", requestPath, e); + context.getResponse() + .sendRedirect(String.format("/portal/%s/page-not-found", + userPortalConfigService.getMetaPortal())); } return true; } @@ -103,11 +118,4 @@ private Identity getCurrentIdentity() { return conversationState == null ? null : conversationState.getIdentity(); } - private PermanentLinkService getPermanentLinkService() { - if (permanentLinkService == null) { - permanentLinkService = ExoContainerContext.getService(PermanentLinkService.class); - } - return permanentLinkService; - } - }