List of usage examples for org.springframework.web.context.support WebApplicationContextUtils getWebApplicationContext
@Nullable public static WebApplicationContext getWebApplicationContext(ServletContext sc)
From source file:com.redoute.datamap.servlet.picture.DeletePicture.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w . j a v a 2 s. c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS); try { String name = policy.sanitize(request.getParameter("id")); ApplicationContext appContext = WebApplicationContextUtils .getWebApplicationContext(this.getServletContext()); IPictureService datamapService = appContext.getBean(IPictureService.class); IFactoryPicture factoryPicture = appContext.getBean(IFactoryPicture.class); Picture sqlLib = factoryPicture.create(Integer.valueOf(name), null, null, null, null); datamapService.deletePicture(sqlLib); response.sendRedirect("Datamap.jsp"); } finally { out.close(); } }
From source file:com.redoute.datamap.servlet.datamap.DeleteDatamap.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//www .j a va 2 s . c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS); try { String name = policy.sanitize(request.getParameter("id")); ApplicationContext appContext = WebApplicationContextUtils .getWebApplicationContext(this.getServletContext()); IDatamapService datamapService = appContext.getBean(IDatamapService.class); IFactoryDatamap factoryDatamap = appContext.getBean(IFactoryDatamap.class); Datamap sqlLib = factoryDatamap.create(Integer.valueOf(name), null, null, null, null, null, null, null, null, null); datamapService.deleteDatamap(sqlLib); } finally { out.close(); } }
From source file:ru.org.linux.auth.SecurityFilter.java
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); HttpServletRequest request = (HttpServletRequest) req; request.setAttribute("configuration", ctx.getBean(Configuration.class)); request.setAttribute("template", new Template(ctx)); request.setCharacterEncoding("utf-8"); // ?? tomcat CSRFManipulation(request, (HttpServletResponse) res); forWikiManipulation(request, (HttpServletResponse) res); chain.doFilter(req, res);/*from w w w. ja v a 2s. c o m*/ }
From source file:com.thoughtworks.go.server.websocket.ConsoleLogSocketServlet.java
@Override public void init() throws ServletException { WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); socketCreator = wac.getBean(ConsoleLogSocketCreator.class); securityService = wac.getBean(SecurityService.class); super.init(); }
From source file:it.pronetics.madstore.server.test.servlet.DataServlet.java
public void init(ServletConfig config) throws ServletException { try {//from w w w .j a v a 2s. com super.init(config); ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); Map collectionRepositories = ctx.getBeansOfType(CollectionRepository.class); Map entryRepositories = ctx.getBeansOfType(EntryRepository.class); if (collectionRepositories.size() != 1 || entryRepositories.size() != 1) { throw new IllegalStateException(); } else { collectionRepository = (CollectionRepository) collectionRepositories.values().toArray()[0]; entryRepository = (EntryRepository) entryRepositories.values().toArray()[0]; } InputStream collectionStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream("entriesCollection.xml"); InputStream entryStream1 = Thread.currentThread().getContextClassLoader() .getResourceAsStream("entry1.xml"); InputStream entryStream2 = Thread.currentThread().getContextClassLoader() .getResourceAsStream("entry2.xml"); InputStream entryStream3 = Thread.currentThread().getContextClassLoader() .getResourceAsStream("entry3.xml"); byte[] bytes = new byte[collectionStream.available()]; collectionStream.read(bytes); Element collection = DomHelper.getDomFromString(new String(bytes)); bytes = new byte[entryStream1.available()]; entryStream1.read(bytes); Element entry1 = DomHelper.getDomFromString(new String(bytes)); bytes = new byte[entryStream2.available()]; entryStream2.read(bytes); Element entry2 = DomHelper.getDomFromString(new String(bytes)); bytes = new byte[entryStream3.available()]; entryStream3.read(bytes); Element entry3 = DomHelper.getDomFromString(new String(bytes)); collectionKey = collectionRepository.putIfAbsent(collection); entryRepository.put(collectionKey, entry1); entryRepository.put(collectionKey, entry2); entryRepository.put(collectionKey, entry3); } catch (Exception ex) { throw new ServletException(ex.getMessage(), ex); } }
From source file:com.dotcallservice.manager.ServiceLocator.java
@SuppressWarnings("unchecked") private <K> K getStringBean(String beanName) { ApplicationContext ctx = WebApplicationContextUtils .getWebApplicationContext(servletConfig.getServletContext()); return (K) ctx.getBean(beanName); }
From source file:br.com.caelum.vraptor.ioc.spring.DefaultSpringLocator.java
public ConfigurableWebApplicationContext getApplicationContext(ServletContext servletContext) { ConfigurableWebApplicationContext context = (ConfigurableWebApplicationContext) WebApplicationContextUtils .getWebApplicationContext(servletContext); if (context != null) { logger.info("Using a web application context: {}", context); return context; }//from w w w.j a va 2 s .c o m if (DefaultSpringLocator.class.getResource("/applicationContext.xml") != null) { logger.info("Using an XmlWebApplicationContext, searching for applicationContext.xml"); XmlWebApplicationContext ctx = new XmlWebApplicationContext(); ctx.setConfigLocation("classpath:applicationContext.xml"); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx); return ctx; } logger.info("No application context found"); ConfigurableWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.setId("VRaptor"); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx); return ctx; }
From source file:com.redoute.datamap.servlet.GenerateGraph.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w ww . j av a 2s . c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("image/png"); ServletOutputStream os = response.getOutputStream(); try { String stream = request.getParameter("stream"); ApplicationContext appContext = WebApplicationContextUtils .getWebApplicationContext(this.getServletContext()); IDatamapService datamapService = appContext.getBean(IDatamapService.class); BufferedImage graph = datamapService.dataImplementedByCriteria("stream", stream); ImageIO.write(graph, "png", os); os.close(); } finally { os.close(); } }
From source file:ar.com.allium.rules.core.listener.AlliumRuleListener.java
public void contextInitialized(ServletContextEvent servletContextEvent) { log.debug("start initialize alliumRules"); ServletContext ctx = servletContextEvent.getServletContext(); WebApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(ctx); LoadAlliumRules loadAlliumRules = new LoadAlliumRules(springContext); loadAlliumRules.loadAlliumRules();//from ww w .ja v a 2s . c o m log.debug("end initialize alliumRules"); }