@Before public void setup() { this.servletContext = new MockServletContext(); this.webAppContext = new AnnotationConfigWebApplicationContext(); this.webAppContext.register(Config.class); this.contextLoader = new ContextLoader(this.webAppContext); this.contextLoader.initWebApplicationContext(this.servletContext); this.configurator = new SpringConfigurator(); }
public void registerSubContext(String webAppKey) { // get the sub contexts - servlet context ServletContext ctx = servletContext.getContext(webAppKey); if (ctx == null) { ctx = servletContext; } ContextLoader loader = new ContextLoader(); ConfigurableWebApplicationContext appCtx = (ConfigurableWebApplicationContext) loader.initWebApplicationContext(ctx); appCtx.setParent(applicationContext); appCtx.refresh(); ctx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appCtx); ConfigurableBeanFactory appFactory = appCtx.getBeanFactory(); logger.debug("About to grab Webcontext bean for {}", webAppKey); Context webContext = (Context) appCtx.getBean("web.context"); webContext.setCoreBeanFactory(parentFactory); webContext.setClientRegistry(clientRegistry); webContext.setServiceInvoker(globalInvoker); webContext.setScopeResolver(globalResolver); webContext.setMappingStrategy(globalStrategy); WebScope scope = (WebScope) appFactory.getBean("web.scope"); scope.setServer(server); scope.setParent(global); scope.register(); scope.start(); // register the context so we dont try to reinitialize it registeredContexts.add(ctx); }
@Test public void updateTargetUrlWithContextLoader() throws Exception { StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class); MockServletContext servletContext = new MockServletContext(); ContextLoader contextLoader = new ContextLoader(wac); contextLoader.initWebApplicationContext(servletContext); try { RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class); wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor); RedirectView rv = new RedirectView(); rv.setUrl("/path"); given(mockProcessor.processUrl(request, "/path")).willReturn("/path?key=123"); rv.render(new ModelMap(), request, response); verify(mockProcessor).processUrl(request, "/path"); } finally { contextLoader.closeWebApplicationContext(servletContext); } }
/**`` * Do everything to get openmrs going. * * @param servletContext the servletContext from the filterconfig * @see Listener#startOpenmrs(ServletContext) */ private void startOpenmrs(ServletContext servletContext) throws Exception { // start spring // after this point, all errors need to also call: contextLoader.closeWebApplicationContext(event.getServletContext()) // logic copied from org.springframework.web.context.ContextLoaderListener ContextLoader contextLoader = new ContextLoader(); contextLoader.initWebApplicationContext(servletContext); try { WebDaemon.startOpenmrs(servletContext); } catch (Exception exception) { contextLoader.closeWebApplicationContext(servletContext); throw exception; } }
/** * Create the ContextLoader to use. Can be overridden in subclasses. * @return the new ContextLoader */ protected ContextLoader createContextLoader() { return new ContextLoader(); }
/** * Create the ContextLoader to use. Can be overridden in subclasses. * @return the new ContextLoader */ protected ContextLoader createContextLoader() { return new ContextLoader(); }
ContextLoader contextLoader = new ContextLoader(); contextLoader.initWebApplicationContext(filterConfig.getServletContext());
public BeanFactory loadBeanFactory() { new ContextLoader().initWebApplicationContext(servletContext); return WebApplicationContextUtils.getWebApplicationContext(servletContext); }
public void init(ServletConfig config) { sc = config.getServletContext(); Logger.log.warn("ReasonableSpringServlet starting up for context " + sc.getRealPath("")); contextLoader = new ContextLoader(); WebApplicationContext wac = contextLoader.initWebApplicationContext(sc); rsacbeanlocator = (RSACBeanLocator) wac .getBean(RSACBeanLocator.RSAC_BEAN_LOCATOR_NAME); }
@Override protected void setUp() throws Exception { super.setUp(); ContextLoader contextLoader = new ContextLoader(); servletContext = new MockServletContext(); servletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, getApplicationContextPath()); applicationContext = contextLoader.initWebApplicationContext(servletContext); }
/** * Crea e restituisce il Contesto dell'Applicazione. * * @param srvCtx Il Contesto della Servlet. * @return Il Contesto dell'Applicazione. */ public ApplicationContext createApplicationContext(ServletContext srvCtx) { this.createNamingContext(); XmlWebApplicationContext applicationContext = new XmlWebApplicationContext(); applicationContext.setConfigLocations(this.getSpringConfigFilePaths()); applicationContext.setServletContext(srvCtx); ContextLoader contextLoader = new ContextLoader(applicationContext); contextLoader.initWebApplicationContext(srvCtx); applicationContext.refresh(); return applicationContext; }