use of org.springframework.web.context.request.ServletRequestAttributes in project irida by phac-nml.
the class UnitTestListener method testRunStarted.
/**
* {@inheritDoc}
*/
public void testRunStarted(Description description) throws Exception {
logger.debug("Configuring Spring MockHTTPServletRequest.");
// fake out the servlet response so that the URI builder will work.
RequestAttributes ra = new ServletRequestAttributes(new MockHttpServletRequest());
RequestContextHolder.setRequestAttributes(ra);
}
use of org.springframework.web.context.request.ServletRequestAttributes in project irida by phac-nml.
the class RootControllerTest method setUp.
@Before
public void setUp() {
// fake out the servlet response so that the URI builder will work.
RequestAttributes ra = new ServletRequestAttributes(new MockHttpServletRequest());
RequestContextHolder.setRequestAttributes(ra);
controller.initLinks();
}
use of org.springframework.web.context.request.ServletRequestAttributes in project BroadleafCommerce by BroadleafCommerce.
the class FrameworkMvcUriComponentsBuilder method getWebApplicationContext.
private static WebApplicationContext getWebApplicationContext() {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes == null) {
logger.debug("No request bound to the current thread: not in a DispatcherServlet request?");
return null;
}
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
WebApplicationContext wac = (WebApplicationContext) request.getAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE);
if (wac == null) {
logger.debug("No WebApplicationContext found: not in a DispatcherServlet request?");
return null;
}
return wac;
}
use of org.springframework.web.context.request.ServletRequestAttributes in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafContextUtil method establishThinRequestContextInternal.
/**
* Adds request and site to the BroadleafRequestContext
*
* If includeTheme is true then also adds the Theme.
* If includeSandBox is true then also adds the SandBox.
*
* @param includeTheme
* @param includeSandBox
*/
protected void establishThinRequestContextInternal(boolean includeTheme, boolean includeSandBox) {
BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
if (brc.getRequest() == null) {
HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
HttpSession session = req.getSession(false);
SecurityContext ctx = readSecurityContextFromSession(session);
if (ctx != null) {
SecurityContextHolder.setContext(ctx);
}
brc.setRequest(req);
}
WebRequest wr = brc.getWebRequest();
if (brc.getNonPersistentSite() == null) {
brc.setNonPersistentSite(siteResolver.resolveSite(wr, true));
if (includeSandBox) {
brc.setSandBox(sbResolver.resolveSandBox(wr, brc.getNonPersistentSite()));
}
brc.setDeployBehavior(deployBehaviorUtil.isProductionSandBoxMode() ? DeployBehavior.CLONE_PARENT : DeployBehavior.OVERWRITE_PARENT);
}
if (includeTheme) {
if (brc.getTheme() == null) {
brc.setTheme(themeResolver.resolveTheme(wr));
}
}
}
use of org.springframework.web.context.request.ServletRequestAttributes in project BroadleafCommerce by BroadleafCommerce.
the class BLCJSResourceResolver method convertResource.
protected Resource convertResource(Resource origResource, String resourceFileName) throws IOException {
byte[] bytes = FileCopyUtils.copyToByteArray(origResource.getInputStream());
String content = new String(bytes, DEFAULT_CHARSET);
String newContent = content;
if (!StringUtils.isEmpty(content)) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
newContent = newContent.replace("//BLC-SERVLET-CONTEXT", request.getContextPath());
String siteBaseUrl = urlResolver.getSiteBaseUrl();
if (!StringUtils.isEmpty(siteBaseUrl)) {
newContent = newContent.replace("//BLC-SITE-BASEURL", siteBaseUrl);
}
}
return new GeneratedResource(newContent.getBytes(), resourceFileName);
}
Aggregations