List of usage examples for org.springframework.boot.web.servlet ServletRegistrationBean ServletRegistrationBean
public ServletRegistrationBean(T servlet, String... urlMappings)
From source file:org.springframework.boot.web.servlet.server.AbstractServletWebServerFactoryTests.java
protected void assertForwardHeaderIsUsed(ServletWebServerFactory factory) throws IOException, URISyntaxException { this.webServer = factory .getWebServer(new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello")); this.webServer.start(); assertThat(getResponse(getLocalUrl("/hello"), "X-Forwarded-For:140.211.11.130")) .contains("remoteaddr=140.211.11.130"); }
From source file:org.springframework.boot.web.servlet.server.AbstractServletWebServerFactoryTests.java
protected ServletContextInitializer exampleServletRegistration() { return new ServletRegistrationBean<>(new ExampleServlet(), "/hello"); }
From source file:org.springframework.boot.web.servlet.server.AbstractServletWebServerFactoryTests.java
@SuppressWarnings("serial") private ServletContextInitializer errorServletRegistration() { ServletRegistrationBean<ExampleServlet> bean = new ServletRegistrationBean<>(new ExampleServlet() { @Override//from w w w .j av a 2 s.c om public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { throw new RuntimeException("Planned"); } }, "/bang"); bean.setName("error"); return bean; }
From source file:org.springframework.boot.web.servlet.server.AbstractServletWebServerFactoryTests.java
protected final ServletContextInitializer sessionServletRegistration() { ServletRegistrationBean<ExampleServlet> bean = new ServletRegistrationBean<>(new ExampleServlet() { @Override/*from w ww.j av a 2 s .c om*/ public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { HttpSession session = ((HttpServletRequest) request).getSession(true); long value = System.currentTimeMillis(); Object existing = session.getAttribute("boot"); session.setAttribute("boot", value); PrintWriter writer = response.getWriter(); writer.append(String.valueOf(existing) + ":" + value); } }, "/session"); bean.setName("session"); return bean; }
From source file:org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration.java
@Bean @ConditionalOnMissingBean(name = "jerseyServletRegistration") @ConditionalOnProperty(prefix = "spring.jersey", name = "type", havingValue = "servlet", matchIfMissing = true) public ServletRegistrationBean jerseyServletRegistration() { ServletRegistrationBean registration = new ServletRegistrationBean(new ServletContainer(this.config), this.path); addInitParameters(registration);// w ww .ja v a 2 s . c om registration.setName(getServletRegistrationName()); registration.setLoadOnStartup(this.jersey.getServlet().getLoadOnStartup()); return registration; }
From source file:org.springframework.cloud.launcher.h2.H2Application.java
@Bean public ServletRegistrationBean h2Console() { String urlMapping = "/*"; ServletRegistrationBean registration = new ServletRegistrationBean(new WebServlet(), urlMapping); registration.addInitParameter("-webAllowOthers", ""); return registration; }
From source file:org.springframework.cloud.netflix.hystrix.dashboard.HystrixDashboardConfiguration.java
@Bean public ServletRegistrationBean proxyStreamServlet() { final ProxyStreamServlet proxyStreamServlet = new ProxyStreamServlet(); proxyStreamServlet.setEnableIgnoreConnectionCloseHeader( this.dashboardProperties.isEnableIgnoreConnectionCloseHeader()); final ServletRegistrationBean registration = new ServletRegistrationBean(proxyStreamServlet, "/proxy.stream"); registration.setInitParameters(this.dashboardProperties.getInitParameters()); return registration; }