congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ServletContextEvent.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
javax.servlet.ServletContextEvent
constructor

Best Java code snippets using javax.servlet.ServletContextEvent.<init> (Showing top 20 results out of 828)

origin: spring-projects/spring-framework

@Override
public <T extends EventListener> void addListener(T t) {
  if (t instanceof ServletContextListener) {
    ((ServletContextListener) t).contextInitialized(new ServletContextEvent(this));
  }
}
origin: spring-projects/spring-framework

@Test
public void testContextLoaderListenerWithMixedContextInitializers() {
  MockServletContext sc = new MockServletContext("");
  sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
      "org/springframework/web/context/WEB-INF/ContextLoaderTests-acc-context.xml");
  sc.addInitParameter(ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM, TestContextInitializer.class.getName());
  sc.addInitParameter(ContextLoader.GLOBAL_INITIALIZER_CLASSES_PARAM, TestWebContextInitializer.class.getName());
  ContextLoaderListener listener = new ContextLoaderListener();
  listener.contextInitialized(new ServletContextEvent(sc));
  WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
  TestBean testBean = wac.getBean(TestBean.class);
  assertThat(testBean.getName(), equalTo("testName"));
  assertThat(wac.getServletContext().getAttribute("initialized"), notNullValue());
}
origin: spring-projects/spring-framework

@Test
public void testContextLoaderListenerWithGlobalContextInitializers() {
  MockServletContext sc = new MockServletContext("");
  sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
      "org/springframework/web/context/WEB-INF/ContextLoaderTests-acc-context.xml");
  sc.addInitParameter(ContextLoader.GLOBAL_INITIALIZER_CLASSES_PARAM, StringUtils.arrayToCommaDelimitedString(
      new Object[] {TestContextInitializer.class.getName(), TestWebContextInitializer.class.getName()}));
  ContextLoaderListener listener = new ContextLoaderListener();
  listener.contextInitialized(new ServletContextEvent(sc));
  WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
  TestBean testBean = wac.getBean(TestBean.class);
  assertThat(testBean.getName(), equalTo("testName"));
  assertThat(wac.getServletContext().getAttribute("initialized"), notNullValue());
}
origin: spring-projects/spring-framework

@Test
public void testContextLoaderListenerWithLocalContextInitializers() {
  MockServletContext sc = new MockServletContext("");
  sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
      "org/springframework/web/context/WEB-INF/ContextLoaderTests-acc-context.xml");
  sc.addInitParameter(ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM, StringUtils.arrayToCommaDelimitedString(
      new Object[] {TestContextInitializer.class.getName(), TestWebContextInitializer.class.getName()}));
  ContextLoaderListener listener = new ContextLoaderListener();
  listener.contextInitialized(new ServletContextEvent(sc));
  WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
  TestBean testBean = wac.getBean(TestBean.class);
  assertThat(testBean.getName(), equalTo("testName"));
  assertThat(wac.getServletContext().getAttribute("initialized"), notNullValue());
}
origin: spring-projects/spring-framework

@Test
public void abstractRefreshableWAC_respectsProgrammaticConfigLocations() {
  XmlWebApplicationContext ctx = new XmlWebApplicationContext();
  ctx.setConfigLocation("programmatic.xml");
  ContextLoaderListener cll = new ContextLoaderListener(ctx);
  MockServletContext sc = new MockServletContext();
  try {
    cll.contextInitialized(new ServletContextEvent(sc));
    fail("expected exception");
  }
  catch (Throwable t) {
    // assert that an attempt was made to load the correct XML
    assertTrue(t.getMessage(), t.getMessage().endsWith(
        "Could not open ServletContext resource [/programmatic.xml]"));
  }
}
origin: spring-projects/spring-framework

@Test
public void testApplicationScope() {
  WebApplicationContext ac = initApplicationContext(WebApplicationContext.SCOPE_APPLICATION);
  assertNull(ac.getServletContext().getAttribute(NAME));
  DerivedTestBean bean = ac.getBean(NAME, DerivedTestBean.class);
  assertSame(bean, ac.getServletContext().getAttribute(NAME));
  assertSame(bean, ac.getBean(NAME));
  new ContextCleanupListener().contextDestroyed(new ServletContextEvent(ac.getServletContext()));
  assertTrue(bean.wasDestroyed());
}
origin: spring-projects/spring-framework

@Test
public void testContextLoaderListenerWithProgrammaticAndGlobalInitializers() {
  MockServletContext sc = new MockServletContext("");
  sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
      "org/springframework/web/context/WEB-INF/ContextLoaderTests-acc-context.xml");
  sc.addInitParameter(ContextLoader.GLOBAL_INITIALIZER_CLASSES_PARAM, TestWebContextInitializer.class.getName());
  ContextLoaderListener listener = new ContextLoaderListener();
  listener.setContextInitializers(new TestContextInitializer());
  listener.contextInitialized(new ServletContextEvent(sc));
  WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
  TestBean testBean = wac.getBean(TestBean.class);
  assertThat(testBean.getName(), equalTo("testName"));
  assertThat(wac.getServletContext().getAttribute("initialized"), notNullValue());
}
origin: spring-projects/spring-framework

@Test
public void testContextLoaderListenerWithProgrammaticAndLocalInitializers() {
  MockServletContext sc = new MockServletContext("");
  sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
      "org/springframework/web/context/WEB-INF/ContextLoaderTests-acc-context.xml");
  sc.addInitParameter(ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM, TestContextInitializer.class.getName());
  ContextLoaderListener listener = new ContextLoaderListener();
  listener.setContextInitializers(new TestWebContextInitializer());
  listener.contextInitialized(new ServletContextEvent(sc));
  WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
  TestBean testBean = wac.getBean(TestBean.class);
  assertThat(testBean.getName(), equalTo("testName"));
  assertThat(wac.getServletContext().getAttribute("initialized"), notNullValue());
}
origin: spring-projects/spring-framework

@Test
public void testRegisteredContextInitializerCanAccessServletContextParamsViaEnvironment() {
  MockServletContext sc = new MockServletContext("");
  // config file doesn't matter - just a placeholder
  sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
      "/org/springframework/web/context/WEB-INF/empty-context.xml");
  sc.addInitParameter("someProperty", "someValue");
  sc.addInitParameter(ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM,
      EnvApplicationContextInitializer.class.getName());
  ContextLoaderListener listener = new ContextLoaderListener();
  listener.contextInitialized(new ServletContextEvent(sc));
}
origin: spring-projects/spring-framework

@Test
public void testContextLoaderListenerWithProgrammaticInitializers() {
  MockServletContext sc = new MockServletContext("");
  sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
      "org/springframework/web/context/WEB-INF/ContextLoaderTests-acc-context.xml");
  ContextLoaderListener listener = new ContextLoaderListener();
  listener.setContextInitializers(new TestContextInitializer(), new TestWebContextInitializer());
  listener.contextInitialized(new ServletContextEvent(sc));
  WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
  TestBean testBean = wac.getBean(TestBean.class);
  assertThat(testBean.getName(), equalTo("testName"));
  assertThat(wac.getServletContext().getAttribute("initialized"), notNullValue());
}
origin: spring-projects/spring-framework

@Test
public void register() throws ServletException {
  initializer.onStartup(servletContext);
  assertTrue(eventListener instanceof ContextLoaderListener);
  ContextLoaderListener cll = (ContextLoaderListener) eventListener;
  cll.contextInitialized(new ServletContextEvent(servletContext));
  WebApplicationContext applicationContext = WebApplicationContextUtils
      .getRequiredWebApplicationContext(servletContext);
  assertTrue(applicationContext.containsBean(BEAN_NAME));
  assertTrue(applicationContext.getBean(BEAN_NAME) instanceof MyBean);
}
origin: spring-projects/spring-framework

@Test
public void testContextLoaderWithDefaultLocation() throws Exception {
  MockServletContext sc = new MockServletContext("");
  ServletContextListener listener = new ContextLoaderListener();
  ServletContextEvent event = new ServletContextEvent(sc);
  try {
    listener.contextInitialized(event);
    fail("Should have thrown BeanDefinitionStoreException");
  }
  catch (BeanDefinitionStoreException ex) {
    // expected
    assertTrue(ex.getCause() instanceof IOException);
    assertTrue(ex.getCause().getMessage().contains("/WEB-INF/applicationContext.xml"));
  }
}
origin: spring-projects/spring-framework

/**
 * If a contextConfigLocation init-param has been specified for the ContextLoaderListener,
 * then it should take precedence. This is generally not a recommended practice, but
 * when it does happen, the init-param should be considered more specific than the
 * programmatic configuration, given that it still quite possibly externalized in
 * hybrid web.xml + WebApplicationInitializer cases.
 */
@Test
public void abstractRefreshableWAC_respectsInitParam_overProgrammaticConfigLocations() {
  XmlWebApplicationContext ctx = new XmlWebApplicationContext();
  ctx.setConfigLocation("programmatic.xml");
  ContextLoaderListener cll = new ContextLoaderListener(ctx);
  MockServletContext sc = new MockServletContext();
  sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "from-init-param.xml");
  try {
    cll.contextInitialized(new ServletContextEvent(sc));
    fail("expected exception");
  }
  catch (Throwable t) {
    // assert that an attempt was made to load the correct XML
    assertTrue(t.getMessage(), t.getMessage().endsWith(
        "Could not open ServletContext resource [/from-init-param.xml]"));
  }
}
origin: spring-projects/spring-framework

/**
 * If setConfigLocation has not been called explicitly against the application context,
 * then fall back to the ContextLoaderListener init-param if present.
 */
@Test
public void abstractRefreshableWAC_fallsBackToInitParam() {
  XmlWebApplicationContext ctx = new XmlWebApplicationContext();
  //ctx.setConfigLocation("programmatic.xml"); // nothing set programmatically
  ContextLoaderListener cll = new ContextLoaderListener(ctx);
  MockServletContext sc = new MockServletContext();
  sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "from-init-param.xml");
  try {
    cll.contextInitialized(new ServletContextEvent(sc));
    fail("expected exception");
  }
  catch (Throwable t) {
    // assert that an attempt was made to load the correct XML
    assertTrue(t.getMessage().endsWith(
        "Could not open ServletContext resource [/from-init-param.xml]"));
  }
}
origin: spring-projects/spring-framework

@Test
public void testContextLoaderListenerWithUnknownContextInitializer() {
  MockServletContext sc = new MockServletContext("");
  // config file doesn't matter.  just a placeholder
  sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
      "/org/springframework/web/context/WEB-INF/empty-context.xml");
  sc.addInitParameter(ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM,
      StringUtils.arrayToCommaDelimitedString(new Object[] {UnknownContextInitializer.class.getName()}));
  ContextLoaderListener listener = new ContextLoaderListener();
  try {
    listener.contextInitialized(new ServletContextEvent(sc));
    fail("expected exception");
  }
  catch (ApplicationContextException ex) {
    assertTrue(ex.getMessage().contains("not assignable"));
  }
}
origin: spring-projects/spring-framework

  /**
   * Ensure that ContextLoaderListener and AnnotationConfigApplicationContext interact nicely.
   */
  @Test
  public void annotationConfigWAC() {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();

    ctx.scan("does.not.matter");

    ContextLoaderListener cll = new ContextLoaderListener(ctx);
    cll.contextInitialized(new ServletContextEvent(new MockServletContext()));
  }
}
origin: spring-projects/spring-framework

@Test
public void testContextLoaderWithCustomContext() throws Exception {
  MockServletContext sc = new MockServletContext("");
  sc.addInitParameter(ContextLoader.CONTEXT_CLASS_PARAM,
      "org.springframework.web.servlet.SimpleWebApplicationContext");
  ServletContextListener listener = new ContextLoaderListener();
  ServletContextEvent event = new ServletContextEvent(sc);
  listener.contextInitialized(event);
  String contextAttr = WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE;
  WebApplicationContext wc = (WebApplicationContext) sc.getAttribute(contextAttr);
  assertTrue("Correct WebApplicationContext exposed in ServletContext",
      wc instanceof SimpleWebApplicationContext);
}
origin: spring-projects/spring-framework

/**
 * Ensure that ContextLoaderListener and GenericWebApplicationContext interact nicely.
 */
@Test
public void genericWAC() {
  GenericWebApplicationContext ctx = new GenericWebApplicationContext();
  ContextLoaderListener cll = new ContextLoaderListener(ctx);
  ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
  scanner.scan("bogus.pkg");
  cll.contextInitialized(new ServletContextEvent(new MockServletContext()));
}
origin: spring-projects/spring-framework

@Test
public void testContextLoaderWithInvalidLocation() throws Exception {
  MockServletContext sc = new MockServletContext("");
  sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "/WEB-INF/myContext.xml");
  ServletContextListener listener = new ContextLoaderListener();
  ServletContextEvent event = new ServletContextEvent(sc);
  try {
    listener.contextInitialized(event);
    fail("Should have thrown BeanDefinitionStoreException");
  }
  catch (BeanDefinitionStoreException ex) {
    // expected
    assertTrue(ex.getCause() instanceof FileNotFoundException);
  }
}
origin: spring-projects/spring-framework

@Test
public void testContextLoaderWithInvalidContext() throws Exception {
  MockServletContext sc = new MockServletContext("");
  sc.addInitParameter(ContextLoader.CONTEXT_CLASS_PARAM,
      "org.springframework.web.context.support.InvalidWebApplicationContext");
  ServletContextListener listener = new ContextLoaderListener();
  ServletContextEvent event = new ServletContextEvent(sc);
  try {
    listener.contextInitialized(event);
    fail("Should have thrown ApplicationContextException");
  }
  catch (ApplicationContextException ex) {
    // expected
    assertTrue(ex.getCause() instanceof ClassNotFoundException);
  }
}
javax.servletServletContextEvent<init>

Javadoc

Construct a ServletContextEvent from the given context.

Popular methods of ServletContextEvent

  • getServletContext
    Return the ServletContext that changed.
  • getClass

Popular in Java

  • Reactive rest calls using spring rest template
  • scheduleAtFixedRate (Timer)
  • onCreateOptionsMenu (Activity)
  • onRequestPermissionsResult (Fragment)
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now