Example usage for javax.servlet ServletContext getServletRegistration

List of usage examples for javax.servlet ServletContext getServletRegistration

Introduction

In this page you can find the example usage for javax.servlet ServletContext getServletRegistration.

Prototype

public ServletRegistration getServletRegistration(String servletName);

Source Link

Document

Gets the ServletRegistration corresponding to the servlet with the given servletName.

Usage

From source file:org.joinfaces.primefaces.PrimefacesFileUploadServletContextInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    ServletRegistration servletRegistration = servletContext.getServletRegistration(FACES_SERVLET_NAME);
    if (servletRegistration instanceof ServletRegistration.Dynamic) {
        ((ServletRegistration.Dynamic) servletRegistration).setMultipartConfig(this.multipartConfigElement);
    }/*ww  w.  ja v  a  2s  .c om*/
}

From source file:org.joinfaces.primefaces.PrimefacesFileUploadServletContextInitializerIT.java

@Test
public void testOnStartup() throws ServletException {
    PrimefacesFileUploadServletContextInitializer primefacesServletContextInitializer = new PrimefacesFileUploadServletContextInitializer(
            multipartConfigElement);//w w w. j  a v a 2 s  .  c  o m

    MockServletRegistrationDynamic servletRegistration = new MockServletRegistrationDynamic();
    ServletContext servletContext = Mockito.mock(ServletContext.class);
    Mockito.when(servletContext.getServletRegistration("FacesServlet")).thenReturn(servletRegistration);

    primefacesServletContextInitializer.onStartup(servletContext);

    assertThat(servletRegistration.getMultipartConfig()).isEqualTo(multipartConfigElement);
}

From source file:org.joinfaces.primefaces.PrimefacesFileUploadServletContextInitializerIT.java

@Test
public void testOnStartup2() throws ServletException {
    PrimefacesFileUploadServletContextInitializer primefacesServletContextInitializer = new PrimefacesFileUploadServletContextInitializer(
            multipartConfigElement);//  w  w w.  j  ava2s  .  c  o  m

    MockServletRegistration servletRegistration = new MockServletRegistration();
    ServletContext servletContext = Mockito.mock(ServletContext.class);
    Mockito.when(servletContext.getServletRegistration("FacesServlet")).thenReturn(servletRegistration);

    primefacesServletContextInitializer.onStartup(servletContext);

    assertThat(servletRegistration.getMultipartConfig()).isNotEqualTo(multipartConfigElement);
}

From source file:org.openmrs.web.WebComponentRegistrar.java

@Override
public void setServletContext(ServletContext servletContext) {

    try {// ww w. j ava2s . com
        ServletRegistration openmrsServletReg = servletContext.getServletRegistration("openmrs");
        addMappings(openmrsServletReg, "*.htm", "*.form", "*.list", "*.json", "*.field", "*.portlet", "*.page",
                "*.action");

        addMappings(servletContext.getServletRegistration("jsp"), "*.withjstl");

        ServletRegistration servletReg = servletContext.addServlet("logoutServlet", new LogoutServlet());
        servletReg.addMapping("/logout");

        Dynamic filter = servletContext.addFilter("forcePasswordChangeFilter", new ForcePasswordChangeFilter());
        filter.setInitParameter("changePasswordForm", "/admin/users/changePassword.form");
        filter.setInitParameter("excludeURL", "changePasswordForm,logout,.js,.css,.gif,.jpg,.jpeg,.png");
        filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");

        filter = servletContext.addFilter("adminPageFilter", new AdminPageFilter());
        filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/admin");

        servletContext.addListener(new SessionListener());
        /*
         * EfficientShutdownServletContextAttributeListener is used instead of
         * EfficientShutdownServletContextListener since the latter implements ServletContextListener,
         * which is not supported by ServletContext.addListener.
        */
        servletContext.addListener(new EfficientShutdownServletContextAttributeListener());
    } catch (Exception ex) {
        //TODO not yet looked into what caused this to fail.
    }
}

From source file:com.indeed.imhotep.web.config.WebApp.java

protected void initJSPMapping(ServletContext servletContext) {
    // Map jsp files to jsp servlet
    servletContext.getServletRegistration("jsp").addMapping("*.jsp");
}

From source file:org.openmrs.module.uiframework.UrlMappingsRegistrar.java

@Override
public void setServletContext(ServletContext servletContext) {
    log.debug("Registering URL mappings");

    //Dynamic servlet registration can only be done once i.e. at application startup
    //In theory it means this module can only be installed at application startup
    if (!skipAddMappings) {
        servletContext.getServletRegistration("openmrs").addMapping("*.page", "*.action");
        servletContext.getFilterRegistration("compressionFilter").addMappingForUrlPatterns(null, true, "*.page",
                "*.action");
        skipAddMappings = true;/*  w  ww .  j a v  a 2 s. c  om*/
    }
}

From source file:org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration.java

@Override
public void setServletContext(ServletContext servletContext) {
    String servletRegistrationName = getServletRegistrationName();
    ServletRegistration registration = servletContext.getServletRegistration(servletRegistrationName);
    if (registration != null) {
        if (logger.isInfoEnabled()) {
            logger.info(//from  w ww  . j  a  v  a  2s  .c o  m
                    "Configuring existing registration for Jersey servlet '" + servletRegistrationName + "'");
        }
        registration.setInitParameters(this.jersey.getInit());
        registration.setInitParameter(CommonProperties.METAINF_SERVICES_LOOKUP_DISABLE,
                Boolean.TRUE.toString());
    }
}