Search in sources :

Example 6 with ServletRegistrationBean

use of org.springframework.boot.web.servlet.ServletRegistrationBean in project spring-boot by spring-projects.

the class ServletWebServerApplicationContextTests method servletContextInitializerBeansSkipsRegisteredServletsAndFilters.

@Test
public void servletContextInitializerBeansSkipsRegisteredServletsAndFilters() throws Exception {
    addWebServerFactoryBean();
    Servlet servlet = mock(Servlet.class);
    Filter filter = mock(Filter.class);
    ServletRegistrationBean<Servlet> initializer = new ServletRegistrationBean<>(servlet, "/foo");
    this.context.registerBeanDefinition("initializerBean", beanDefinition(initializer));
    this.context.registerBeanDefinition("servletBean", beanDefinition(servlet));
    this.context.registerBeanDefinition("filterBean", beanDefinition(filter));
    this.context.refresh();
    ServletContext servletContext = getWebServerFactory().getServletContext();
    verify(servletContext, atMost(1)).addServlet(anyString(), (Servlet) any());
    verify(servletContext, atMost(1)).addFilter(anyString(), (Filter) any());
}
Also used : Filter(javax.servlet.Filter) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Servlet(javax.servlet.Servlet) ServletContext(javax.servlet.ServletContext) Test(org.junit.Test)

Example 7 with ServletRegistrationBean

use of org.springframework.boot.web.servlet.ServletRegistrationBean in project camel by apache.

the class HystrixMappingAutoConfiguration method servletRegistrationBean.

@Bean
ServletRegistrationBean servletRegistrationBean(HystrixMappingConfiguration config) {
    ServletRegistrationBean mapping = new ServletRegistrationBean();
    mapping.setServlet(new HystrixEventStreamServlet());
    mapping.addUrlMappings(config.getPath());
    mapping.setName(config.getServletName());
    return mapping;
}
Also used : ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) HystrixEventStreamServlet(org.apache.camel.component.hystrix.metrics.servlet.HystrixEventStreamServlet) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 8 with ServletRegistrationBean

use of org.springframework.boot.web.servlet.ServletRegistrationBean in project camel by apache.

the class Application method servletRegistrationBean.

@Bean
ServletRegistrationBean servletRegistrationBean() {
    ServletRegistrationBean servlet = new ServletRegistrationBean(new CamelHttpTransportServlet(), "/camel-rest-jpa/*");
    servlet.setName("CamelServlet");
    return servlet;
}
Also used : ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) CamelHttpTransportServlet(org.apache.camel.component.servlet.CamelHttpTransportServlet) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 9 with ServletRegistrationBean

use of org.springframework.boot.web.servlet.ServletRegistrationBean in project libresonic by Libresonic.

the class Application method dwrServletRegistrationBean.

/**
     * Registers the DWR servlet.
     *
     * @return a registration bean.
     */
@Bean
public ServletRegistrationBean dwrServletRegistrationBean() {
    ServletRegistrationBean servlet = new ServletRegistrationBean(new DwrServlet(), "/dwr/*");
    servlet.addInitParameter("crossDomainSessionSecurity", "false");
    return servlet;
}
Also used : DwrServlet(org.directwebremoting.servlet.DwrServlet) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 10 with ServletRegistrationBean

use of org.springframework.boot.web.servlet.ServletRegistrationBean in project springboot_op by SnailFastGo.

the class DruidConfiguration method statViewServlet.

@Bean
public ServletRegistrationBean statViewServlet() {
    //创建servlet注册实体
    ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
    //设置ip白名单
    servletRegistrationBean.addInitParameter("allow", "127.0.0.1");
    //设置ip黑名单,如果allow与deny共同存在时,deny优先于allow
    servletRegistrationBean.addInitParameter("deny", "192.168.0.19");
    //设置控制台管理用户
    servletRegistrationBean.addInitParameter("loginUsername", "druid");
    servletRegistrationBean.addInitParameter("loginPassword", "123456");
    //是否可以重置数据
    servletRegistrationBean.addInitParameter("resetEnable", "false");
    return servletRegistrationBean;
}
Also used : ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) StatViewServlet(com.alibaba.druid.support.http.StatViewServlet) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)25 Bean (org.springframework.context.annotation.Bean)14 Test (org.junit.Test)8 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)7 HttpClient (org.apache.http.client.HttpClient)6 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)6 SSLContextBuilder (org.apache.http.ssl.SSLContextBuilder)6 TrustSelfSignedStrategy (org.apache.http.conn.ssl.TrustSelfSignedStrategy)5 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)4 CamelHttpTransportServlet (org.apache.camel.component.servlet.CamelHttpTransportServlet)3 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)3 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)3 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 HttpServlet (javax.servlet.http.HttpServlet)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Compression (org.springframework.boot.web.server.Compression)2 AbstractServletWebServerFactory (org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory)2 ExampleServlet (org.springframework.boot.web.servlet.server.ExampleServlet)2