コード例 #1
0
  /**
   * This is an helper class to redirect the customer to another page
   *
   * @param request the HstRequest
   * @param response the HstResponse
   * @param refId the refId
   */
  public void redirectByRefId(HstRequest request, HstResponse response, String refId) {

    HstLinkCreator linkCreator = request.getRequestContext().getHstLinkCreator();

    HstLink link =
        linkCreator.createByRefId(refId, request.getRequestContext().getResolvedMount().getMount());

    HstResponseUtils.sendRedirectOrForward(request, response, link.getPath());
  }
コード例 #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);
       }
     }
   }
 }