List of usage examples for org.springframework.web.context.support WebApplicationContextUtils getRequiredWebApplicationContext
public static WebApplicationContext getRequiredWebApplicationContext(ServletContext sc) throws IllegalStateException
From source file:com.nec.harvest.servlet.listener.WebApplicationContextLoaderListener.java
/** * Initialize the root web application context *//*from www . j a va 2s . c o m*/ @Override public void contextInitialized(ServletContextEvent event) { super.contextInitialized(event); // Starting Harvest environment initialization... if (logger.isDebugEnabled()) { logger.debug("Starting Harvest environment initialization..."); } /// You can get Servlet Context ServletContext servletContext = event.getServletContext(); WebApplicationContext webApplicationContext = WebApplicationContextUtils .getRequiredWebApplicationContext(servletContext); String jasperReportPath = getReportPath(webApplicationContext); // Create new a folder to store all of reports logger.info("Trying to create a new local storage {} folder for all reports", jasperReportPath); File folder = new File(jasperReportPath); if (!folder.exists()) { folder.mkdirs(); } // ???? logger.info("Successfully created a report storage folder to store all of temporary reports"); // logger.info("Context instance: {}", webApplicationContext); logger.info("Application name: {} && path: {}", webApplicationContext.getApplicationName(), servletContext.getContextPath()); }
From source file:com.sbu.controller.ServletSaveJobController.java
@Override public void init() throws ServletException { WebApplicationContext context = WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()); employerService = context.getBean(EmployerManager.class); jobPositionService = context.getBean(JobPositionManager.class); projectService = context.getBean(ProjectManager.class); skillsService = context.getBean(SkillsManager.class); employeeService = context.getBean(EmployeeManager.class); feedService = context.getBean(FeedManager.class); }
From source file:org.soulwing.cas.filter.FilterToBeanProxy.java
public void init(FilterConfig filterConfig) throws ServletException { target = getTargetBean(/*from ww w . j a v a2 s . c om*/ WebApplicationContextUtils.getRequiredWebApplicationContext(filterConfig.getServletContext()), getTargetBeanName(filterConfig)); }
From source file:org.efs.openreports.util.displaytag.SpringDecoratorFactory.java
@Override public DisplaytagColumnDecorator loadColumnDecorator(PageContext pageContext, String name) throws DecoratorInstantiationException { if (StringUtils.isBlank(name)) return null; ApplicationContext appContext = WebApplicationContextUtils .getRequiredWebApplicationContext(pageContext.getServletContext()); Object decorator = null;//from www. ja v a 2 s . co m try { decorator = appContext.getBean(name, DisplaytagColumnDecorator.class); } catch (NoSuchBeanDefinitionException e) { log.debug("Decorator " + name + " not found in Spring ApplicationContext. Using DefaultDecoratorFactory.loadTableDecorator. "); } if (decorator != null && decorator instanceof DisplaytagColumnDecorator) return (DisplaytagColumnDecorator) decorator; return super.loadColumnDecorator(pageContext, name); }
From source file:com.morevaadin.vaadin7.springsecurity.service.AuthenticationService.java
public void handleAuthentication(String login, String password, HttpServletRequest httpRequest) { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(login, password); token.setDetails(new WebAuthenticationDetails(httpRequest)); ServletContext servletContext = httpRequest.getSession().getServletContext(); WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); AuthenticationManager authManager = wac.getBean(AuthenticationManager.class); Authentication authentication = authManager.authenticate(token); SecurityContextHolder.getContext().setAuthentication(authentication); }
From source file:com.artofsolving.jodconverter.web.DocumentConverterServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { ApplicationContext applicationContext = WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()); ServletFileUpload fileUpload = (ServletFileUpload) applicationContext.getBean("fileUpload"); DocumentConverter converter = (DocumentConverter) applicationContext.getBean("documentConverter"); DocumentFormatRegistry registry = (DocumentFormatRegistry) applicationContext .getBean("documentFormatRegistry"); if (!ServletFileUpload.isMultipartContent(request)) { throw new IllegalArgumentException("request is not multipart"); }// w w w . j a va 2s . co m // determine output format based on the request uri String outputExtension = FilenameUtils.getExtension(request.getRequestURI()); DocumentFormat outputFormat = registry.getFormatByFileExtension(outputExtension); if (outputFormat == null) { throw new IllegalArgumentException("invalid outputFormat: " + outputExtension); } FileItem inputFileUpload = getInputFileUpload(request, fileUpload); if (inputFileUpload == null) { throw new IllegalArgumentException("inputDocument is null"); } String inputExtension = FilenameUtils.getExtension(inputFileUpload.getName()); DocumentFormat inputFormat = registry.getFormatByFileExtension(inputExtension); response.setContentType(outputFormat.getMimeType()); String fileName = FilenameUtils.getBaseName(inputFileUpload.getName()) + "." + outputFormat.getFileExtension(); response.setHeader("Content-Disposition", "inline; filename=" + fileName); //response.setContentLength(???); converter.convert(inputFileUpload.getInputStream(), inputFormat, response.getOutputStream(), outputFormat); }
From source file:org.hdiv.context.RedirectExternalContext.java
/** * ExternalContext constructor/*from w w w . j a v a 2 s . c om*/ * * @param wrapped * original ExternalContext */ public RedirectExternalContext(ExternalContext wrapped) { ServletContext servletContext = (ServletContext) wrapped.getContext(); this.redirectHelper = (RedirectHelper) WebApplicationContextUtils .getRequiredWebApplicationContext(servletContext).getBean("redirectHelper"); Assert.notNull(this.redirectHelper); this.wrapped = wrapped; }
From source file:org.openxdata.server.servlet.ReportServlet.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); ServletContext sctx = this.getServletContext(); WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(sctx); reportService = (ReportService) ctx.getBean("reportService"); }
From source file:com.sbu.controller.Feed_Form_Startup_Edit_Contorller.java
@Override public void init() throws ServletException { WebApplicationContext context = WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()); startupService = context.getBean(StartupManager.class); memberService = context.getBean(MemberManager.class); }
From source file:net.sf.appstatus.demo.batch.LaunchClassicBatchSampleServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // launch the batch ExecutorService executorService = Executors.newCachedThreadPool(); BatchSample batch = (BatchSample) WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()).getBean("batch"); executorService.execute(batch);/*from ww w . j a v a 2 s . c o m*/ BatchSample2 batch2 = (BatchSample2) WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()).getBean("batch2"); executorService.execute(batch2); ServletOutputStream os = resp.getOutputStream(); os.write("<html><head".getBytes(ENCODING)); os.write("<body>".getBytes(ENCODING)); os.write("<h1>Ok</h1>".getBytes(ENCODING)); os.write("</body></html>".getBytes(ENCODING)); }