List of usage examples for org.springframework.web.context.support WebApplicationContextUtils getRequiredWebApplicationContext
public static WebApplicationContext getRequiredWebApplicationContext(ServletContext sc) throws IllegalStateException
From source file:com.freebox.engeneering.application.web.common.ApplicationContextListener.java
/** * Initializes the application context by web flow xml configs. * @param servletContextEvent the servlet context event. */// w ww .j a va2s.co m public void contextInitialized(ServletContextEvent servletContextEvent) { final ServletContext servletContext = servletContextEvent.getServletContext(); final WebApplicationContext context = WebApplicationContextUtils .getRequiredWebApplicationContext(servletContext); String initParameter = servletContext.getInitParameter(CONFIG_LOCATION_PARAM); final String[] configLocations = getConfigLocations(context, initParameter); final Set<URL> xmlConfigs = new HashSet<URL>(); for (String configLocation : configLocations) { try { final Resource[] locationResources = context.getResources(configLocation); for (Resource locationResource : locationResources) { xmlConfigs.add(locationResource.getURL()); } } catch (IOException e) { if (LOGGER.isErrorEnabled()) { LOGGER.error("Could not find state chart configuration", e); } } } Assert.notEmpty(xmlConfigs, "Cannot find state chart configuration."); ApplicationContextLocator.setWebFlowConfiguration(xmlConfigs); ApplicationContextLocator.setApplicationContext(context); final FlowConfigurationLoader flowConfigurationLoader = (FlowConfigurationLoader) context .getBean("flowConfigurationLoader"); flowConfigurationLoader.init(xmlConfigs); }
From source file:com.application.model.dao.AuthenticationService.java
public void handleLogout(HttpServletRequest httpRequest) { ServletContext servletContext = httpRequest.getSession().getServletContext(); WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); LogoutHandler logoutHandler = wac.getBean(LogoutHandler.class); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); // Response should not be used? logoutHandler.logout(httpRequest, null, authentication); }
From source file:net.sourceforge.vulcan.web.struts.RestRequestProcessor.java
@Override public void init(ActionServlet servlet, ModuleConfig moduleConfig) throws ServletException { super.init(servlet, moduleConfig); final WebApplicationContext wac = WebApplicationContextUtils .getRequiredWebApplicationContext(servlet.getServletContext()); this.restRequestDetector = (RestRequestDetector) wac.getBean("restRequestDetector", RestRequestDetector.class); }
From source file:org.openxdata.server.rpc.OxdPersistentRemoteService.java
protected WebApplicationContext getApplicationContext() { ServletContext sctx = this.getServletContext(); WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(sctx); return ctx;// www. j av a 2 s . c o m }
From source file:org.atomserver.server.servlet.AtomServerServlet.java
protected void loadSpringContext() { if (appContext == null) { ServletConfig config = getServletConfig(); ServletContext context = config.getServletContext(); if (context != null) { logger.debug("LOADING: WebApplicationContextUtils.getRequiredWebApplicationContext(context))"); appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(context); } else {//from w ww. j av a2s. c o m logger.debug("LOADING: new ClassPathXmlApplicationContext( .... )"); appContext = new ClassPathXmlApplicationContext( config.getInitParameter(SPRING_APPLICATION_CONTEXT_FILE)); } if (logger.isDebugEnabled()) { logger.debug("Application context set:: appContext= " + appContext); } } }
From source file:gov.nih.nci.ncicb.cadsr.admintool.struts.action.BaseDispatchAction.java
public void setServlet(ActionServlet servlet) { super.setServlet(servlet); ServletContext servletContext = servlet.getServletContext(); WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); conceptService = (ConceptService) wac.getBean("conceptService"); contextService = (ContextService) wac.getBean("contextService"); this.printAllContexts(); }
From source file:com.cubusmail.gwtui.server.services.RetrieveAttachmentServlet.java
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { WebApplicationContext context = WebApplicationContextUtils .getRequiredWebApplicationContext(request.getSession().getServletContext()); try {/*w w w. jav a 2s. c o m*/ String messageId = request.getParameter("messageId"); String attachmentIndex = request.getParameter("attachmentIndex"); boolean view = "1".equals(request.getParameter("view")); if (messageId != null) { IMailbox mailbox = SessionManager.get().getMailbox(); Message msg = mailbox.getCurrentFolder().getMessageById(Long.parseLong(messageId)); List<MimePart> attachmentList = MessageUtils.attachmentsFromPart(msg); int index = Integer.valueOf(attachmentIndex); MimePart retrievePart = attachmentList.get(index); ContentType contentType = new ContentType(retrievePart.getContentType()); String fileName = retrievePart.getFileName(); if (StringUtils.isEmpty(fileName)) { fileName = context.getMessage("message.unknown.attachment", null, SessionManager.get().getLocale()); } StringBuffer contentDisposition = new StringBuffer(); if (!view) { contentDisposition.append("attachment; filename=\""); contentDisposition.append(fileName).append("\""); } response.setHeader("cache-control", "no-store"); response.setHeader("pragma", "no-cache"); response.setIntHeader("max-age", 0); response.setIntHeader("expires", 0); if (!StringUtils.isEmpty(contentDisposition.toString())) { response.setHeader("Content-disposition", contentDisposition.toString()); } response.setContentType(contentType.getBaseType()); // response.setContentLength( // MessageUtils.calculateSizeFromPart( retrievePart ) ); BufferedInputStream bufInputStream = new BufferedInputStream(retrievePart.getInputStream()); OutputStream outputStream = response.getOutputStream(); byte[] inBuf = new byte[1024]; int len = 0; int total = 0; while ((len = bufInputStream.read(inBuf)) > 0) { outputStream.write(inBuf, 0, len); total += len; } bufInputStream.close(); outputStream.flush(); outputStream.close(); } } catch (Exception ex) { logger.error(ex.getMessage(), ex); } }
From source file:jrouter.servlet.filter.SpringJRouterFilter.java
/** * A hook to give subclass another way to create ActionFactory * * @param filterConfig ?// ww w.j a va 2s .c o m * * @return ActionFactory bean. */ @Override protected ActionFactory createActionFactory(final FilterConfig filterConfig) { log.info("Load configuration location : " + configLocation); Configuration configuration = new Configuration(); configuration.load(configLocation); if (useSpringObjectFactory) { Map<String, Object> actionFactoryProperties = new HashMap<String, Object>(2); actionFactoryProperties.put("objectFactory", new SpringObjectFactory( WebApplicationContextUtils.getRequiredWebApplicationContext(filterConfig.getServletContext()))); configuration.addActionFactoryProperties(actionFactoryProperties); } return configuration.buildActionFactory(); }
From source file:com.clican.pluto.cms.ui.listener.StartupListener.java
public void contextInitialized(ServletContextEvent event) { super.contextInitialized(event); try {//from w w w . j a v a 2s . com Velocity.init( Thread.currentThread().getContextClassLoader().getResource("velocity.properties").getPath()); } catch (Exception e) { throw new RuntimeException(e); } ApplicationContext ctx = null; JndiUtils.setJndiFactory(MockContextFactory.class.getName()); Hashtable<String, String> ht = new Hashtable<String, String>(); ht.put(Context.INITIAL_CONTEXT_FACTORY, MockContextFactory.class.getName()); try { ctx = (ApplicationContext) JndiUtils.lookupObject(ApplicationContext.class.getName()); if (ctx == null) { log.warn("Cannot get ApplicationContext from JNDI"); } } catch (Exception e) { log.warn("Cannot get ApplicationContext from JNDI"); } if (ctx == null) { ctx = (new ClassPathXmlApplicationContext(new String[] { "classpath*:META-INF/ui-*.xml", })); } XmlWebApplicationContext wac = (XmlWebApplicationContext) WebApplicationContextUtils .getRequiredWebApplicationContext(event.getServletContext()); wac.setParent(ctx); wac.refresh(); event.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); Constants.ctx = wac; }