/**
  * Redirect the user to the 404 page
  *
  * @param response the Hst response
  */
 public void redirectToNotFoundPage(HstResponse response) {
   try {
     response.forward("/404");
   } catch (IOException e) {
     throw new HstComponentException(e);
   }
 }
예제 #2
0
 /**
  * Sets {@code HttpServletResponse.SC_NOT_FOUND} error code onto request.
  *
  * @param response
  * @see javax.servlet.http.HttpServletResponse#SC_NOT_FOUND
  */
 public void pageNotFound(HstResponse response) {
   final HstRequestContext context = RequestContextProvider.get();
   String pageNotFoundPath = getComponentParameter(PAGE_404);
   if (Strings.isNullOrEmpty(pageNotFoundPath)) {
     pageNotFoundPath = PAGE_404;
   }
   final HippoBean bean =
       context.getSiteContentBaseBean().getBean(pageNotFoundPath, HippoBean.class);
   response.setStatus(HttpServletResponse.SC_NOT_FOUND);
   if (bean != null) {
     final HstLinkCreator hstLinkCreator = context.getHstLinkCreator();
     final HstLink hstLink = hstLinkCreator.create(bean.getNode(), context);
     try {
       response.sendRedirect(hstLink.toUrlForm(context, false));
     } catch (IOException e) {
       log.warn("Error redirecting to 404 page: [{}]", PAGE_404);
     }
   } else {
     // check if we have pagenotfound config
     final ResolvedSiteMapItem resolvedSiteMapItem =
         RequestContextProvider.get().getResolvedSiteMapItem();
     if (resolvedSiteMapItem == null) {
       return;
     }
     final HstSiteMap siteMap = resolvedSiteMapItem.getHstSiteMapItem().getHstSiteMap();
     final HstSiteMapItem pagenotfound = siteMap.getSiteMapItemByRefId(PAGE_NOT_FOUND);
     if (pagenotfound != null) {
       String link = pagenotfound.getValue();
       try {
         response.forward('/' + link);
       } catch (IOException e) {
         log.error("Error forwarding to " + PAGE_NOT_FOUND + " page", e);
       }
     }
   }
 }