Class WebStarter

java.lang.Object
com.bobocode.bring.web.servlet.WebStarter

public class WebStarter extends Object
The WebStarter class is responsible for initializing and running a web application using Apache Tomcat as the embedded servlet container.

This class sets up the necessary components such as the servlet container, dispatcher servlet, exception handler, and REST controller context. It also configures the servlet mappings and starts the web server.

Since:
1.0
Author:
Blyzhnytsia Team
See Also:
  • Field Details

    • BRING_CONTEXT

      public static final String BRING_CONTEXT
      Attribute key for storing the BringApplicationContext in the servlet context.
      See Also:
    • REST_CONTROLLER_PARAMS

      public static final String REST_CONTROLLER_PARAMS
      Attribute key for storing the REST controller parameters map in the servlet context.
      See Also:
    • DISPATCHER_SERVLET_NAME

      public static final String DISPATCHER_SERVLET_NAME
      Default name for the dispatcher servlet.
      See Also:
    • URL_PATTERN

      public static final String URL_PATTERN
      Default URL pattern for the dispatcher servlet.
      See Also:
    • servletWebServerFactory

      private final ServletWebServerFactory servletWebServerFactory
      The ServletWebServerFactory used to create the embedded servlet container.
    • dispatcherServlet

      private final DispatcherServlet dispatcherServlet
      The DispatcherServlet responsible for handling HTTP requests.
    • jsonExceptionHandler

      private final JsonExceptionHandler jsonExceptionHandler
      The JsonExceptionHandler for handling JSON-related exceptions.
    • restControllerContext

      private final RestControllerContext restControllerContext
      The RestControllerContext for managing REST controllers and their parameters.
    • webServer

      private TomcatWebServer webServer
      The TomcatWebServer instance representing the embedded Tomcat server.
  • Constructor Details

    • WebStarter

      public WebStarter(TomcatServletWebServerFactory tomcatServletWebServerFactory, DispatcherServlet dispatcherServlet, JsonExceptionHandler jsonExceptionHandler, RestControllerContext restControllerContext)
      Constructs a new WebStarter with the specified components.
      Parameters:
      tomcatServletWebServerFactory - The factory for creating the embedded Tomcat server.
      dispatcherServlet - The DispatcherServlet for handling HTTP requests.
      jsonExceptionHandler - The JsonExceptionHandler for handling JSON-related exceptions.
      restControllerContext - The RestControllerContext for managing REST controllers and parameters.
  • Method Details

    • run

      public void run(com.bobocode.bring.core.context.impl.BringApplicationContext bringApplicationContext)
      Runs the web application.
      Parameters:
      bringApplicationContext - The BringApplicationContext for the application.
    • stop

      public void stop()
      Stops the embedded Tomcat server.