Search in sources :

Example 16 with ConfigurableWebApplicationContext

use of org.springframework.web.context.ConfigurableWebApplicationContext in project spring-boot by spring-projects.

the class MappingsEndpointTests method servletWebMappings.

@Test
void servletWebMappings() {
    Supplier<ConfigurableWebApplicationContext> contextSupplier = prepareContextSupplier();
    new WebApplicationContextRunner(contextSupplier).withUserConfiguration(EndpointConfiguration.class, ServletWebConfiguration.class).run((context) -> {
        ContextMappings contextMappings = contextMappings(context);
        assertThat(contextMappings.getParentId()).isNull();
        assertThat(contextMappings.getMappings()).containsOnlyKeys("dispatcherServlets", "servletFilters", "servlets");
        Map<String, List<DispatcherServletMappingDescription>> dispatcherServlets = mappings(contextMappings, "dispatcherServlets");
        assertThat(dispatcherServlets).containsOnlyKeys("dispatcherServlet");
        List<DispatcherServletMappingDescription> handlerMappings = dispatcherServlets.get("dispatcherServlet");
        assertThat(handlerMappings).hasSize(1);
        List<ServletRegistrationMappingDescription> servlets = mappings(contextMappings, "servlets");
        assertThat(servlets).hasSize(1);
        List<FilterRegistrationMappingDescription> filters = mappings(contextMappings, "servletFilters");
        assertThat(filters).hasSize(1);
    });
}
Also used : ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) FilterRegistrationMappingDescription(org.springframework.boot.actuate.web.mappings.servlet.FilterRegistrationMappingDescription) DispatcherServletMappingDescription(org.springframework.boot.actuate.web.mappings.servlet.DispatcherServletMappingDescription) ContextMappings(org.springframework.boot.actuate.web.mappings.MappingsEndpoint.ContextMappings) ServletRegistrationMappingDescription(org.springframework.boot.actuate.web.mappings.servlet.ServletRegistrationMappingDescription) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 17 with ConfigurableWebApplicationContext

use of org.springframework.web.context.ConfigurableWebApplicationContext in project spring-boot by spring-projects.

the class MappingsEndpointTests method servletWebMappingsWithAdditionalDispatcherServlets.

@Test
void servletWebMappingsWithAdditionalDispatcherServlets() {
    Supplier<ConfigurableWebApplicationContext> contextSupplier = prepareContextSupplier();
    new WebApplicationContextRunner(contextSupplier).withUserConfiguration(EndpointConfiguration.class, ServletWebConfiguration.class, CustomDispatcherServletConfiguration.class).run((context) -> {
        ContextMappings contextMappings = contextMappings(context);
        Map<String, List<DispatcherServletMappingDescription>> dispatcherServlets = mappings(contextMappings, "dispatcherServlets");
        assertThat(dispatcherServlets).containsOnlyKeys("dispatcherServlet", "customDispatcherServletRegistration", "anotherDispatcherServletRegistration");
        assertThat(dispatcherServlets.get("dispatcherServlet")).hasSize(1);
        assertThat(dispatcherServlets.get("customDispatcherServletRegistration")).hasSize(1);
        assertThat(dispatcherServlets.get("anotherDispatcherServletRegistration")).hasSize(1);
    });
}
Also used : ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) ContextMappings(org.springframework.boot.actuate.web.mappings.MappingsEndpoint.ContextMappings) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 18 with ConfigurableWebApplicationContext

use of org.springframework.web.context.ConfigurableWebApplicationContext in project spring-framework by spring-projects.

the class MessageTagTests method nullMessageSource.

@Test
void nullMessageSource() throws JspException {
    PageContext pc = createPageContext();
    ConfigurableWebApplicationContext ctx = (ConfigurableWebApplicationContext) RequestContextUtils.findWebApplicationContext((HttpServletRequest) pc.getRequest(), pc.getServletContext());
    ctx.close();
    MessageTag tag = new MessageTag();
    tag.setPageContext(pc);
    tag.setCode("test");
    tag.setVar("testvar2");
    tag.doStartTag();
    assertThat(tag.doEndTag()).as("Correct doEndTag return value").isEqualTo(Tag.EVAL_PAGE);
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) PageContext(jakarta.servlet.jsp.PageContext) Test(org.junit.jupiter.api.Test)

Example 19 with ConfigurableWebApplicationContext

use of org.springframework.web.context.ConfigurableWebApplicationContext in project pentaho-platform by pentaho.

the class JAXRSServlet method getAppContext.

@VisibleForTesting
protected ApplicationContext getAppContext() {
    ConfigurableWebApplicationContext wac = new XmlWebApplicationContext() {

        @Override
        protected Resource getResourceByPath(String path) {
            return new FileSystemResource(new File(path));
        }
    };
    wac.setServletContext(getServletContext());
    wac.setServletConfig(getServletConfig());
    wac.setNamespace(getServletName());
    String springFile = PentahoSystem.getApplicationContext().getSolutionPath(// $NON-NLS-1$ //$NON-NLS-2$
    "system" + File.separator + "pentahoServices.spring.xml");
    wac.setConfigLocations(new String[] { springFile });
    wac.addBeanFactoryPostProcessor(new PentahoBeanScopeValidatorPostProcessor());
    wac.refresh();
    return wac;
}
Also used : ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) XmlWebApplicationContext(org.springframework.web.context.support.XmlWebApplicationContext) PentahoBeanScopeValidatorPostProcessor(org.pentaho.platform.engine.core.system.objfac.spring.PentahoBeanScopeValidatorPostProcessor) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 20 with ConfigurableWebApplicationContext

use of org.springframework.web.context.ConfigurableWebApplicationContext in project pentaho-platform by pentaho.

the class SystemGwtRpc method createAppContext.

// Visible For Testing
@NonNull
ApplicationContext createAppContext() {
    WebApplicationContext parent = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
    ConfigurableWebApplicationContext wac = new XmlWebApplicationContext() {

        @Override
        protected Resource getResourceByPath(@NonNull String path) {
            return new FileSystemResource(new File(path));
        }
    };
    wac.setParent(parent);
    wac.setServletContext(getServletContext());
    // This code was previously part of the GwtRpcProxyServlet class.
    // There were/are really no known uses of this class.
    // The only declared System, GWT-RPC service is /ws/gwt/unifiedRepository and is not used by any Pentaho code.
    // 
    // No access to servlet config. Used to be passed, when this code was part of GwtRpcProxyServlet class.
    // The GwtRpcProxyServlet servlet had no init parameters configured.
    // wac.setServletConfig( getServletConfig() );
    // J.I.C. Used to be created with getServerName(), in the GwtRpcProxyServlet class.
    wac.setNamespace("GwtRpcProxyServlet");
    String springFile = PentahoSystem.getApplicationContext().getSolutionPath("system" + File.separator + "pentahoServices.spring.xml");
    wac.setConfigLocations(springFile);
    wac.refresh();
    return wac;
}
Also used : ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) XmlWebApplicationContext(org.springframework.web.context.support.XmlWebApplicationContext) NonNull(edu.umd.cs.findbugs.annotations.NonNull) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) WebApplicationContext(org.springframework.web.context.WebApplicationContext) ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) XmlWebApplicationContext(org.springframework.web.context.support.XmlWebApplicationContext) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Aggregations

ConfigurableWebApplicationContext (org.springframework.web.context.ConfigurableWebApplicationContext)20 XmlWebApplicationContext (org.springframework.web.context.support.XmlWebApplicationContext)7 Test (org.junit.jupiter.api.Test)6 File (java.io.File)4 FileSystemResource (org.springframework.core.io.FileSystemResource)4 CubaXmlWebApplicationContext (com.haulmont.cuba.core.sys.CubaXmlWebApplicationContext)3 List (java.util.List)3 ContextMappings (org.springframework.boot.actuate.web.mappings.MappingsEndpoint.ContextMappings)3 ReactiveWebApplicationContextRunner (org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner)3 WebApplicationContextRunner (org.springframework.boot.test.context.runner.WebApplicationContextRunner)3 MockServletContext (org.springframework.mock.web.MockServletContext)3 WebApplicationContext (org.springframework.web.context.WebApplicationContext)3 SingleAppResourcePatternResolver (com.haulmont.cuba.core.sys.SingleAppResourcePatternResolver)2 DispatcherServletMappingDescription (org.springframework.boot.actuate.web.mappings.servlet.DispatcherServletMappingDescription)2 FilterRegistrationMappingDescription (org.springframework.boot.actuate.web.mappings.servlet.FilterRegistrationMappingDescription)2 ServletRegistrationMappingDescription (org.springframework.boot.actuate.web.mappings.servlet.ServletRegistrationMappingDescription)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 PageContext (jakarta.servlet.jsp.PageContext)1