List of usage examples for javax.servlet ServletContextEvent ServletContextEvent
public ServletContextEvent(ServletContext source)
From source file:org.jasig.springframework.web.portlet.context.PortletContextLoaderTests.java
@Test public void testContextLoaderListenerWithRegisteredContextInitializer() { MockServletContext sc = new MockServletContext(""); sc.addInitParameter(PortletContextLoader.CONFIG_LOCATION_PARAM, "org/springframework/web/context/WEB-INF/ContextLoaderTests-acc-context.xml"); sc.addInitParameter(PortletContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM, StringUtils.arrayToCommaDelimitedString(new Object[] { TestContextInitializer.class.getName(), TestWebContextInitializer.class.getName() })); PortletContextLoaderListener listener = new PortletContextLoaderListener(); listener.contextInitialized(new ServletContextEvent(sc)); //initialize the portlet application context, needed because PortletContextLoaderListener.contextInitialized doesn't actually create //the portlet app context due to lack of PortletContext reference MockPortletContext pc = new MockPortletContext(sc); PortletApplicationContextUtils2.getPortletApplicationContext(pc); PortletApplicationContext pac = PortletContextLoader.getCurrentPortletApplicationContext(); TestBean testBean = pac.getBean(TestBean.class); assertThat(testBean.getName(), equalTo("testName")); // assertThat(pac.getServletContext().getAttribute("initialized"), notNullValue()); assertThat(pac.getPortletContext().getAttribute("initialized"), notNullValue()); }
From source file:org.grails.plugin.batch.Launcher.java
public void destroy() { logDebug("destroy(): begin"); synchronized (destroyLock) { if (!this.destroyed) { GrailsApplication grailsApplication = ApplicationHolder.getApplication(); if (grailsApplication != null) { DefaultGrailsMainClass main = getMainClass(grailsApplication); if (main != null) { main.callDestroy();/* w w w.ja va2s. c om*/ } GrailsClass[] bootstraps = grailsApplication.getArtefacts(BootstrapArtefactHandler.TYPE); for (int i = bootstraps.length - 1; i >= 0; i--) { GrailsClass bootstrap = bootstraps[i]; ((GrailsBootstrapClass) bootstrap).callDestroy(); } } { ServletContextEvent event = new ServletContextEvent(servletContext); for (int i = servletContextListeners.length - 1; i >= 0; i--) { ServletContextListener l = servletContextListeners[i]; l.contextDestroyed(event); } } if (shutdownHook != null) { if (!shutdownHook.isAlive()) { Runtime.getRuntime().removeShutdownHook(this.shutdownHook); logDebug(true, "destroy(): shutdown hook removed"); } this.shutdownHook = null; } servletContext = null; } this.destroyed = true; logDebug(true, "destroy(): end"); } }
From source file:org.jasig.springframework.web.portlet.context.PortletContextLoaderTests.java
@Test public void testRegisteredContextInitializerCanAccessServletContextParamsViaEnvironment() { MockServletContext sc = new MockServletContext(""); // config file doesn't matter. just a placeholder sc.addInitParameter(PortletContextLoader.CONFIG_LOCATION_PARAM, "/org/springframework/web/context/WEB-INF/empty-context.xml"); sc.addInitParameter("someProperty", "someValue"); sc.addInitParameter(PortletContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM, EnvApplicationContextInitializer.class.getName()); PortletContextLoaderListener listener = new PortletContextLoaderListener(); listener.contextInitialized(new ServletContextEvent(sc)); //initialize the portlet application context, needed because PortletContextLoaderListener.contextInitialized doesn't actually create //the portlet app context due to lack of PortletContext reference MockPortletContext pc = new MockPortletContext(sc); PortletApplicationContextUtils2.getPortletApplicationContext(pc); }
From source file:org.jasig.springframework.web.portlet.context.PortletContextLoaderTests.java
@Test public void testContextLoaderListenerWithUnkownContextInitializer() { MockServletContext sc = new MockServletContext(""); // config file doesn't matter. just a placeholder sc.addInitParameter(PortletContextLoader.CONFIG_LOCATION_PARAM, "/org/springframework/web/context/WEB-INF/empty-context.xml"); sc.addInitParameter(PortletContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM, StringUtils .arrayToCommaDelimitedString(new Object[] { UnknownContextInitializer.class.getName() })); PortletContextLoaderListener listener = new PortletContextLoaderListener(); listener.contextInitialized(new ServletContextEvent(sc)); try {//www .j av a 2 s. c o m //initialize the portlet application context, needed because PortletContextLoaderListener.contextInitialized doesn't actually create //the portlet app context due to lack of PortletContext reference MockPortletContext pc = new MockPortletContext(sc); PortletApplicationContextUtils2.getPortletApplicationContext(pc); fail("expected exception"); } catch (IllegalArgumentException ex) { assertTrue(ex.getMessage().contains("not assignable")); } }
From source file:org.openmeetings.cli.Admin.java
private ClassPathXmlApplicationContext getApplicationContext(final String ctxName) { if (ctx == null) { OMContextListener omcl = new OMContextListener(); omcl.contextInitialized(new ServletContextEvent(new ServletContext() { public void setAttribute(String arg0, Object arg1) { }/* ww w . j a v a 2 s .c o m*/ public void removeAttribute(String arg0) { } public void log(String arg0, Throwable arg1) { } public void log(Exception arg0, String arg1) { } public void log(String arg0) { } @SuppressWarnings("rawtypes") public Enumeration getServlets() { return null; } @SuppressWarnings("rawtypes") public Enumeration getServletNames() { return null; } public String getServletContextName() { return null; } public Servlet getServlet(String arg0) throws ServletException { return null; } public String getServerInfo() { return null; } @SuppressWarnings("rawtypes") public Set getResourcePaths(String arg0) { return null; } public InputStream getResourceAsStream(String arg0) { return null; } public URL getResource(String arg0) throws MalformedURLException { return null; } public RequestDispatcher getRequestDispatcher(String arg0) { return null; } public String getRealPath(String arg0) { return null; } public RequestDispatcher getNamedDispatcher(String arg0) { return null; } public int getMinorVersion() { return 0; } public String getMimeType(String arg0) { return null; } public int getMajorVersion() { return 0; } @SuppressWarnings("rawtypes") public Enumeration getInitParameterNames() { return null; } public String getInitParameter(String arg0) { return null; } public String getContextPath() { return ctxName; } public ServletContext getContext(String arg0) { return null; } @SuppressWarnings("rawtypes") public Enumeration getAttributeNames() { return null; } public Object getAttribute(String arg0) { return null; } })); try { ctx = new ClassPathXmlApplicationContext("openmeetings-applicationContext.xml"); } catch (Exception e) { handleError("Unable to obtain application context", e); } } return ctx; }
From source file:org.jasig.springframework.web.portlet.context.PortletContextLoaderTests.java
@Test public void testContextLoaderWithCustomContextAndParent() throws Exception { MockServletContext sc = new MockServletContext(""); sc.addInitParameter(ContextLoader.CONTEXT_CLASS_PARAM, StaticWebApplicationContext.class.getName()); sc.addInitParameter(PortletContextLoader.CONTEXT_CLASS_PARAM, SimplePortletApplicationContext.class.getName()); ContextLoaderListener servletListener = new ContextLoaderListener(); ServletContextListener listener = new PortletContextLoaderListener(); ServletContextEvent event = new ServletContextEvent(sc); servletListener.contextInitialized(event); listener.contextInitialized(event);/*from w w w.j a va 2s . c om*/ //initialize the portlet application context, needed because PortletContextLoaderListener.contextInitialized doesn't actually create //the portlet app context due to lack of PortletContext reference MockPortletContext pc = new MockPortletContext(sc); PortletApplicationContextUtils2.getPortletApplicationContext(pc); PortletApplicationContext wc = (PortletApplicationContext) pc .getAttribute(PortletApplicationContext.ROOT_PORTLET_APPLICATION_CONTEXT_ATTRIBUTE); assertTrue("Correct PortletApplicationContext exposed in PortletContext", wc instanceof SimplePortletApplicationContext); }
From source file:org.jasig.springframework.web.portlet.context.PortletContextLoaderTests.java
@Test public void testContextLoaderWithInvalidLocation() throws Exception { MockServletContext sc = new MockServletContext(""); sc.addInitParameter(PortletContextLoader.CONFIG_LOCATION_PARAM, "/WEB-INF/myContext.xml"); ServletContextListener listener = new PortletContextLoaderListener(); ServletContextEvent event = new ServletContextEvent(sc); listener.contextInitialized(event);//from www . j av a 2 s . com try { //initialize the portlet application context, needed because PortletContextLoaderListener.contextInitialized doesn't actually create //the portlet app context due to lack of PortletContext reference MockPortletContext pc = new MockPortletContext(sc); PortletApplicationContextUtils2.getPortletApplicationContext(pc); fail("Should have thrown BeanDefinitionStoreException"); } catch (BeanDefinitionStoreException ex) { // expected assertTrue(ex.getCause() instanceof FileNotFoundException); } }
From source file:org.jasig.springframework.web.portlet.context.PortletContextLoaderTests.java
@Test public void testContextLoaderWithInvalidContext() throws Exception { MockServletContext sc = new MockServletContext(""); sc.addInitParameter(PortletContextLoader.CONTEXT_CLASS_PARAM, "org.springframework.web.context.support.InvalidWebApplicationContext"); ServletContextListener listener = new PortletContextLoaderListener(); ServletContextEvent event = new ServletContextEvent(sc); listener.contextInitialized(event);//from w w w. j a v a 2s . c om try { //initialize the portlet application context, needed because PortletContextLoaderListener.contextInitialized doesn't actually create //the portlet app context due to lack of PortletContext reference MockPortletContext pc = new MockPortletContext(sc); PortletApplicationContextUtils2.getPortletApplicationContext(pc); fail("Should have thrown ApplicationContextException"); } catch (ApplicationContextException ex) { // expected assertTrue(ex.getCause() instanceof ClassNotFoundException); } }
From source file:org.jasig.springframework.web.portlet.context.PortletContextLoaderTests.java
@Test public void testContextLoaderWithDefaultLocation() throws Exception { MockServletContext sc = new MockServletContext(""); ServletContextListener listener = new PortletContextLoaderListener(); ServletContextEvent event = new ServletContextEvent(sc); listener.contextInitialized(event);// ww w. ja va 2s. co m try { //initialize the portlet application context, needed because PortletContextLoaderListener.contextInitialized doesn't actually create //the portlet app context due to lack of PortletContext reference MockPortletContext pc = new MockPortletContext(sc); PortletApplicationContextUtils2.getPortletApplicationContext(pc); fail("Should have thrown BeanDefinitionStoreException"); } catch (BeanDefinitionStoreException ex) { // expected assertTrue(ex.getCause() instanceof IOException); assertTrue(ex.getCause().getMessage().contains("/WEB-INF/portletApplicationContext.xml")); } }