Search in sources :

Example 16 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class PageServiceImpl method buildKey.

protected String buildKey(String identifier, Locale locale, Boolean secure) {
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    Site site = context.getNonPersistentSite();
    Long siteId = (site != null) ? site.getId() : null;
    locale = findLanguageOnlyLocale(locale);
    StringBuilder key = new StringBuilder(identifier);
    if (locale != null) {
        key.append("-").append(locale.getLocaleCode());
    }
    if (secure != null) {
        key.append("-").append(secure);
    }
    if (siteId != null) {
        key.append("-").append(siteId);
    }
    return key.toString();
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 17 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class PageServiceImpl method addPageMapCacheEntry.

@SuppressWarnings("unchecked")
protected void addPageMapCacheEntry(String identifier, String key) {
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    Site site = context.getNonPersistentSite();
    Long siteId = (site != null) ? site.getId() : null;
    String mapKey = getPageMapCacheKey(identifier, siteId);
    if (mapKey != null) {
        Element e = getPageMapCache().get(mapKey);
        if (e == null || e.getObjectValue() == null) {
            List<String> keys = new ArrayList<>();
            keys.add(key);
            getPageMapCache().put(new Element(mapKey, keys));
        } else {
            ((List<String>) e.getObjectValue()).add(mapKey);
        }
    }
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) Element(net.sf.ehcache.Element) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class PageServiceImpl method buildPageDTOList.

/*
     * Converts a list of pages to a list of pageDTOs, and caches the list.
     */
@Override
public List<PageDTO> buildPageDTOList(List<Page> pageList, boolean secure, String identifier, Locale locale) {
    List<PageDTO> dtoList = new ArrayList<>();
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    if (context.isProductionSandBox()) {
        dtoList = buildPageDTOListUsingCache(pageList, identifier, locale, secure);
    } else {
        // no caching actions needed if not production sandbox
        addPageListToPageDTOList(pageList, secure, dtoList);
    }
    return copyDTOList(dtoList);
}
Also used : NullPageDTO(org.broadleafcommerce.common.page.dto.NullPageDTO) PageDTO(org.broadleafcommerce.common.page.dto.PageDTO) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) ArrayList(java.util.ArrayList)

Example 19 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext 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)

Example 20 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class MultiTenantCopyContext method createOrRetrieveCopyInstance.

/**
 * Create a new instance of the polymorphic entity type - could be an extended type outside of Broadleaf.
 *
 * @param instance the object instance for the actual entity type (could be extended)
 * @param <G>
 * @return the new, empty instance of the entity
 * @throws java.lang.CloneNotSupportedException
 */
public <G> CreateResponse<G> createOrRetrieveCopyInstance(Object instance) throws CloneNotSupportedException {
    CreateResponse<G> createResponse;
    BroadleafRequestContext context = setupContext();
    validateOriginal(instance);
    Class<?> instanceClass = instance.getClass();
    createResponse = handleEmbedded(instanceClass);
    if (createResponse == null) {
        createResponse = handleStandardEntity(instance, context, instanceClass);
    }
    tearDownContext(context);
    return createResponse;
}
Also used : BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Aggregations

BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)78 Site (org.broadleafcommerce.common.site.domain.Site)16 HashMap (java.util.HashMap)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 Locale (org.broadleafcommerce.common.locale.domain.Locale)8 SandBox (org.broadleafcommerce.common.sandbox.domain.SandBox)5 StructuredContentDTO (org.broadleafcommerce.common.structure.dto.StructuredContentDTO)5 MessageSource (org.springframework.context.MessageSource)5 List (java.util.List)4 StructuredContent (org.broadleafcommerce.cms.structure.domain.StructuredContent)4 Field (java.lang.reflect.Field)3 HashSet (java.util.HashSet)3 Locale (java.util.Locale)3 Catalog (org.broadleafcommerce.common.site.domain.Catalog)3 BroadleafAttributeModifier (org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 File (java.io.File)2 PrintWriter (java.io.PrintWriter)2