Search in sources :

Example 1 with StatusExposingServletResponse

use of org.broadleafcommerce.common.web.util.StatusExposingServletResponse in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafProcessURLFilter method doFilterInternal.

/**
 * (non-Javadoc)
 *
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
 */
@Override
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException {
    if (!shouldProcessURL(request, request.getRequestURI())) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Process URL not processing URL " + request.getRequestURI());
        }
        filterChain.doFilter(request, response);
        return;
    }
    final String requestURIWithoutContext;
    if (request.getContextPath() != null) {
        requestURIWithoutContext = request.getRequestURI().substring(request.getContextPath().length());
    } else {
        requestURIWithoutContext = request.getRequestURI();
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("Process URL Filter Begin " + requestURIWithoutContext);
    }
    if (request.getAttribute(REQUEST_DTO) == null) {
        request.setAttribute(REQUEST_DTO, new RequestDTOImpl(request));
    }
    Site site = determineSite(request);
    SandBox currentSandbox = determineSandbox(request, site);
    BroadleafRequestContext brc = new BroadleafRequestContext();
    brc.setLocale(determineLocale(request, site));
    brc.setSandBox(currentSandbox);
    brc.setRequest(request);
    brc.setResponse(response);
    BroadleafRequestContext.setBroadleafRequestContext(brc);
    try {
        URLProcessor urlProcessor = null;
        if (isProduction(currentSandbox)) {
            try {
                urlProcessor = lookupProcessorFromCache(requestURIWithoutContext);
            } catch (ExecutionException e) {
                LOG.error(e);
            }
        }
        if (urlProcessor == null) {
            urlProcessor = determineURLProcessor(requestURIWithoutContext);
        }
        if (urlProcessor instanceof NullURLProcessor) {
            // Pass request down the filter chain
            if (LOG.isTraceEnabled()) {
                LOG.trace("URL not being processed by a Broadleaf URLProcessor " + requestURIWithoutContext);
            }
            StatusExposingServletResponse sesResponse = new StatusExposingServletResponse(response);
            filterChain.doFilter(request, sesResponse);
            if (sesResponse.getStatus() == sesResponse.SC_NOT_FOUND) {
                if (LOG.isWarnEnabled()) {
                    LOG.warn("Page not found.  Unable to render " + requestURIWithoutContext);
                }
                urlCache.invalidate(requestURIWithoutContext);
            }
        } else {
            if (LOG.isTraceEnabled()) {
                LOG.trace("URL about to be processed by a Broadleaf URLProcessor " + requestURIWithoutContext);
            }
            urlProcessor.processURL(requestURIWithoutContext);
        }
    } finally {
        // If the system-time was overridden, set it back to normal
        SystemTime.resetLocalTimeSource();
    }
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) SandBox(org.broadleafcommerce.common.sandbox.domain.SandBox) StatusExposingServletResponse(org.broadleafcommerce.common.web.util.StatusExposingServletResponse) RequestDTOImpl(org.broadleafcommerce.common.RequestDTOImpl) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)1 RequestDTOImpl (org.broadleafcommerce.common.RequestDTOImpl)1 SandBox (org.broadleafcommerce.common.sandbox.domain.SandBox)1 Site (org.broadleafcommerce.common.site.domain.Site)1 BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)1 StatusExposingServletResponse (org.broadleafcommerce.common.web.util.StatusExposingServletResponse)1