Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-734

Undertow does not call the init() method of servlets that implements SingleThreadModel even when load-on-startup is set

    XMLWordPrintable

Details

    Description

      Found that some of the servlets did not have the init() invoked on start up. Found that if the servlet implements javax.servlet.SingleThreadModel, their init() methods are not called.

      Sample snippnet from web.xml

      	<servlet>
      		<servlet-name>testServlet</servlet-name>
      		<servlet-class>TestServlet</servlet-class>
      		<load-on-startup>1</load-on-startup>
      	</servlet>
      

      Sample servlet

      @Slf4j
      public class TestServlet extends HttpServlet implements SingleThreadModel {
      
      	@Override
      	public void init(ServletConfig config) throws ServletException {
      		log.info("init() in TestServlet");
      		super.init(config);
      	}
      
      	@Override
      	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      		log.info("doGet() in TestServlet");
      	}
      
      	@Override
      	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      		log.info("doPost() in TestServlet");
      	}
      }
      

      If the servlet does not implements SingleThreadModel , the init() method is called on start up.

      Attachments

        Issue Links

          Activity

            People

              sdouglas1@redhat.com Stuart Douglas
              lamshing Shing Lam (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: