List of usage examples for org.springframework.web.context.support WebApplicationContextUtils getWebApplicationContext
@Nullable public static WebApplicationContext getWebApplicationContext(ServletContext sc)
From source file:org.cometd.oort.spring.OortSpringAnnotationTest.java
@Test public void testSpringWiringOfOort() throws Exception { Server server = new Server(); ServletContextHandler context = new ServletContextHandler(server, "/"); WebSocketServerContainerInitializer.configureContext(context); context.addEventListener(new ContextLoaderListener()); context.getInitParams().put(ContextLoader.CONFIG_LOCATION_PARAM, "classpath:/applicationContext.xml"); server.start();//www. jav a 2 s.com ApplicationContext applicationContext = WebApplicationContextUtils .getWebApplicationContext(context.getServletContext()); String beanName = Introspector.decapitalize(OortService.class.getSimpleName()); String[] beanNames = applicationContext.getBeanDefinitionNames(); assertTrue(Arrays.asList(beanNames).contains(beanName)); OortService service = (OortService) applicationContext.getBean(beanName); assertNotNull(service); Seti seti = service.seti; assertNotNull(seti); Oort oort = seti.getOort(); assertNotNull(oort); BayeuxServer bayeux = oort.getBayeuxServer(); assertNotNull(bayeux); SecurityPolicy policy = bayeux.getSecurityPolicy(); assertNotNull(policy); assertTrue(policy instanceof OortSecurityPolicy); server.stop(); }
From source file:org.onebusaway.nyc.vehicle_tracking.webapp.servlets.VehicleLocationCollectionServlet.java
@Override public void init() { _xstream = new XStream(); _xstream.processAnnotations(Siri.class); _xstream.processAnnotations(VehicleActivity.class); WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); context.getAutowireCapableBeanFactory().autowireBean(this); }
From source file:org.addsimplicity.anicetus.web.TelemetryServletFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filter) throws IOException, ServletException { ApplicationContext curCtx = WebApplicationContextUtils.getWebApplicationContext(m_servletContext); TelemetryHttpContext curHttpCtx = (TelemetryHttpContext) curCtx.getBean(m_sessionContextName); TelemetryHttpSession curSess = (TelemetryHttpSession) curHttpCtx.getSession(); setRequestOnSession(curSess, (HttpServletRequest) request); TelemetryProxyResponse proxyResp = new TelemetryProxyResponse((HttpServletResponse) response, curSess); filter.doFilter(request, proxyResp); }
From source file:org.apache.ftpserver.example.springwar.FtpServerListener.java
public void contextInitialized(ServletContextEvent sce) { System.out.println("Starting FtpServer"); WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()); FtpServer server = (FtpServer) ctx.getBean("myServer"); sce.getServletContext().setAttribute(FTPSERVER_CONTEXT_NAME, server); try {// w ww . java 2 s . co m server.start(); System.out.println("FtpServer started"); } catch (Exception e) { throw new RuntimeException("Failed to start FtpServer", e); } }
From source file:org.geomajas.gwt.server.GeomajasServiceImpl.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); // register the controller object applicationContext = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext()); if (applicationContext instanceof ConfigurableApplicationContext) { ((ConfigurableApplicationContext) applicationContext).addApplicationListener(this); }/*from www . jav a2s . c o m*/ initDispatcher(); }
From source file:org.red5.server.net.servlet.StatisticsServlet.java
/** {@inheritDoc} */ @Override/*from w w w .j a va 2 s .c om*/ public void init() throws ServletException { webAppCtx = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); if (webAppCtx == null) { webAppCtx = (WebApplicationContext) getServletContext() .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); } if (webAppCtx == null) { throw new ServletException("No web application context found."); } webContext = (IContext) webAppCtx.getBean("web.context"); // Register handlers in XML-RPC server server.addHandler("scopes", new XmlRpcScopeStatistics(webContext.getGlobalScope())); }
From source file:com.telefonica.euro_iaas.sdc.bootstrap.PropertiesMBeanRegisterBootstrap.java
/** * Unregister the mbean.// ww w.ja va 2 s. c o m */ public void contextDestroyed(ServletContextEvent event) { WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext()); PropertiesProvider propertiesUtil = new PropertiesProviderFactoryImpl() .createPropertiesProvider((EntityManagerFactory) ctx.getBean("entityManagerFactory")); try { for (String namespace : propertiesUtil.getNamespaces()) { log.info("Unregistering mbean " + namespace); MBeanUtils.unregister( event.getServletContext().getContextPath() + ":service=SystemConfiguration-" + namespace); } } catch (Exception e) { throw new SdcRuntimeException(e); } }
From source file:org.tsm.concharto.web.filter.NotificationFilter.java
public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; ServletContext ctx = filterConfig.getServletContext(); WebApplicationContext webAppContext = WebApplicationContextUtils.getWebApplicationContext(ctx); notificationDao = (NotificationDao) webAppContext.getBean("notificationDao"); }
From source file:org.blanco.gae.blog.BlogServlet.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); ctx = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext()); }
From source file:com.hgsoft.example.hello.web.HelloServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("doPost"); WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); // String[] beanNames = context.getBeanDefinitionNames(); // if(beanNames != null) // {//from w w w . j a v a2s. c o m // for(String beanName:beanNames) // { // System.out.println("bean name >> "+beanName); // } // } // HelloWorldBusiness helloWorldBusiness = context.getBean("helloWorldBusiness",HelloWorldBusiness.class); // helloWorldBusiness.hello(); // BlueprintContainer container = (BlueprintContainer) getServletContext().getAttribute(BlueprintContextListener.CONTAINER_ATTRIBUTE); // // System.out.println("BlueprintContainer "+container); // // Set<String> componentIds = container.getComponentIds(); // if(componentIds != null) // { // for(String componentId:componentIds) // { // System.out.println("componentId >> "+componentId); // } // } //jndi? HelloWorldService helloWorldService = (HelloWorldService) JNDIHelper.getHelloWorldService(); helloWorldService.hello(); EntityManagerFactory emf = (EntityManagerFactory) context.getBean("entityManagerFactory"); Metamodel model = emf.getMetamodel(); resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" This is the result of test: "); if (null != model) { if (null != model.getEntities()) { for (EntityType type : model.getEntities()) { out.print(type.getName()); } } } out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); }