Example usage for org.springframework.boot.testsupport.web.servlet ExampleServlet ExampleServlet

List of usage examples for org.springframework.boot.testsupport.web.servlet ExampleServlet ExampleServlet

Introduction

In this page you can find the example usage for org.springframework.boot.testsupport.web.servlet ExampleServlet ExampleServlet.

Prototype

public ExampleServlet() 

Source Link

Usage

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  a v a 2  s  . c  o  m*/
        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   ww  w. j av  a2  s.  co m*/
        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;
}