List of usage examples for org.springframework.web.context WebApplicationContext getServletContext
@Nullable ServletContext getServletContext();
From source file:grails.util.GrailsWebUtil.java
/** * Binds a Mock implementation of a GrailsWebRequest object to the current thread. The mock version uses * instances of the Spring MockHttpServletRequest, MockHttpServletResponse and MockServletContext classes. * * @param ctx The WebApplicationContext to use * * @see org.springframework.mock.web.MockHttpServletRequest * @see org.springframework.mock.web.MockHttpServletResponse * @see org.springframework.mock.web.MockServletContext * * @return The GrailsWebRequest instance *//* w w w . j a v a 2 s.c om*/ public static GrailsWebRequest bindMockWebRequest(WebApplicationContext ctx) { return bindMockWebRequest(ctx, new MockHttpServletRequest(ctx.getServletContext()), new MockHttpServletResponse()); }
From source file:grails.util.GrailsWebUtil.java
/** * Binds a Mock implementation of a GrailsWebRequest object to the current thread. The mock version uses * instances of the Spring MockHttpServletRequest, MockHttpServletResponse and MockServletContext classes. * * @param ctx The WebApplicationContext to use * @param request The request//from w ww . j a va2 s. c om * @param response The response * * @see org.springframework.mock.web.MockHttpServletRequest * @see org.springframework.mock.web.MockHttpServletResponse * @see org.springframework.mock.web.MockServletContext * * @return The GrailsWebRequest instance */ public static GrailsWebRequest bindMockWebRequest(WebApplicationContext ctx, MockHttpServletRequest request, MockHttpServletResponse response) { GrailsWebRequest webRequest = new GrailsWebRequest(request, response, ctx.getServletContext(), ctx); request.setAttribute(GrailsApplicationAttributes.WEB_REQUEST, webRequest); for (ParameterCreationListener listener : ctx.getBeansOfType(ParameterCreationListener.class).values()) { webRequest.addParameterListener(listener); } RequestContextHolder.setRequestAttributes(webRequest); return webRequest; }
From source file:com.ineunet.knife.upload.WebPaths.java
/** * @return e.g. /Workspace/iNeunet/ioo/src/main/webapp *///from w ww . j a v a 2s . c o m public static String getRootPath() { if (rootPath == null) { WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext(); if (webApplicationContext == null) { rootPath = System.getProperty(WebUtils.DEFAULT_WEB_APP_ROOT_KEY); } else { ServletContext servletContext = webApplicationContext.getServletContext(); rootPath = servletContext.getRealPath("/"); } } return rootPath; }
From source file:org.frat.common.security.BaseSecurityContext.java
/** * .//from ww w .java 2 s .c om * * @param username */ public static void kickOutUnLogin() { try { WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext(); ServletContext servletContext = webApplicationContext.getServletContext(); // applicationHashSet?session @SuppressWarnings("unchecked") HashSet<HttpSession> sessions = (HashSet<HttpSession>) servletContext.getAttribute("loginSessions"); List<HttpSession> sessionList = new ArrayList<HttpSession>(); if (StringUtil.isObjNotNull(sessions)) { for (HttpSession session : sessions) { SysUserDto user = (SysUserDto) session.getAttribute("shiro.user"); if (null != session && StringUtil.isObjNull(user)) { // LOGGER.debug("getLastAccessedTime="+ new // Date(session.getLastAccessedTime())); // LOGGER.debug("now="+ new Date()); int diffTime = DateUtil.diffTime(new Date(), new Date(session.getLastAccessedTime())); // LOGGER.debug("diffTime="+diffTime); if (diffTime > 300) { sessionList.add(session); } } } for (HttpSession session : sessionList) { session.invalidate(); LOGGER.debug("success kick out UnLogin session [" + session.getId() + "]"); } } } catch (Exception e) { LOGGER.error(""); LOGGER.error(StackTraceUtil.getStackTrace(e)); } }
From source file:com.laxser.blitz.web.impl.module.ModuleAppContext.java
public static ModuleAppContext createModuleContext(WebApplicationContext parent, // List<URL> contextResources, String[] messageBasenames, String uniqueId, String namespace) throws IOException { long startTime = System.currentTimeMillis(); String loadingMsg = "[moduleContext.create] Loading Spring '" + namespace + "' WebApplicationContext"; logger.info(loadingMsg);/*w ww . j a v a 2 s . co m*/ Assert.notNull(parent); ServletContext servletContext = parent.getServletContext(); Assert.notNull(servletContext); ModuleAppContext wac = new ModuleAppContext(); wac.setParent(parent); wac.setServletContext(servletContext); wac.setContextResources(toResources(contextResources)); wac.setId(uniqueId); wac.setNamespace(namespace); wac.setMessageBaseNames(messageBasenames); wac.refresh(); // ? if (logger.isDebugEnabled()) { long elapsedTime = System.currentTimeMillis() - startTime; logger.debug("[moduleContext.create] Using context class [" + wac.getClass().getName() + "] for " + namespace + " WebApplicationContext"); logger.info("[moduleContext.create] " + namespace + " WebApplicationContext: initialization completed in " + elapsedTime + " ms"); } return wac; }
From source file:org.vaadin.spring.config.VaadinExtensionsConfiguration.java
/** * Allows injection of the {@link ServletContext}. *//*from ww w. j av a2s . co m*/ @Bean ServletContext servletContext(WebApplicationContext applicationContext) { return applicationContext.getServletContext(); }
From source file:org.appcomponents.platform.impl.EmbeddedWebApplication.java
private void refreshChildWebApplicationContext(WebApplicationContext parent, WebApplicationContext child) { ServletContext servletContext = parent.getServletContext(); ((ConfigurableWebApplicationContext) child).setServletContext(servletContext); ((ConfigurableWebApplicationContext) child).refresh(); }
From source file:edu.internet2.middleware.shibboleth.common.config.service.ServletContextAttributeExporter.java
/** {@inheritDoc} */ public void initialize() throws ServiceException { if (!(appCtx instanceof WebApplicationContext)) { log.warn("This service may only be used when services are loaded within a web application context."); return;/*w w w .j a v a2 s . c o m*/ } Object bean; if (exportedBeans != null) { WebApplicationContext webAppCtx = (WebApplicationContext) appCtx; ServletContext servletCtx = webAppCtx.getServletContext(); for (String beanId : exportedBeans) { bean = webAppCtx.getBean(beanId); if (bean != null) { log.debug("Exporting bean {} to servlet context.", beanId); servletCtx.setAttribute(beanId, bean); } else { log.warn("No {} bean located, unable to export it to the servlet context", beanId); } } } initialized = true; }
From source file:eu.europa.ejusticeportal.dss.demo.web.view.TemplateViewResolver.java
/** * {@inheritDoc}//from w ww.j a v a 2s .c o m */ @Override protected boolean canHandle(String viewName, Locale locale) { if (viewName.startsWith(REDIRECT_URL_PREFIX)) { return true; } else if (viewName.startsWith(FORWARD_URL_PREFIX)) { return true; } else { String contentUrl = getPrefix() + viewName + getSuffix(); WebApplicationContext webApplicationContext = (WebApplicationContext) getApplicationContext(); return webApplicationContext.getServletContext().getResourceAsStream(contentUrl) != null; } }
From source file:org.jboss.arquillian.spring.integration.inject.container.WebApplicationContextProducer.java
/** * <p>Retrieves the application context for the given servlet.</p> * * @param rootContext the root web application context * @param servletName the servlet name/*from w w w . j av a2s .c o m*/ * * @return the retrieved application context */ private ApplicationContext getServletApplicationContext(WebApplicationContext rootContext, String servletName) { // retrieves the servlet context from web application context ServletContext servletContext = rootContext.getServletContext(); // retrieves the application context for the given servlet using it's name return (ApplicationContext) servletContext .getAttribute(MessageFormat.format(SpringInjectConstants.SERVLET_APPLICATION_CONTEXT, servletName)); }