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();
}
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);
}
}
}
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);
}
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();
}
}
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;
}
Aggregations