Search in sources :

Example 1 with ServletHttpHandlerAdapter

use of org.springframework.http.server.reactive.ServletHttpHandlerAdapter in project spring-framework by spring-projects.

the class JettyHttpServer method initServer.

@Override
protected void initServer() throws Exception {
    this.jettyServer = new Server();
    ServletHttpHandlerAdapter servlet = createServletAdapter();
    ServletHolder servletHolder = new ServletHolder(servlet);
    this.contextHandler = new ServletContextHandler(this.jettyServer, "", false, false);
    this.contextHandler.addServlet(servletHolder, "/");
    this.contextHandler.start();
    ServerConnector connector = new ServerConnector(this.jettyServer);
    connector.setHost(getHost());
    connector.setPort(getPort());
    this.jettyServer.addConnector(connector);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletHttpHandlerAdapter(org.springframework.http.server.reactive.ServletHttpHandlerAdapter) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 2 with ServletHttpHandlerAdapter

use of org.springframework.http.server.reactive.ServletHttpHandlerAdapter in project spring-framework by spring-projects.

the class AbstractDispatcherHandlerInitializer method registerDispatcherHandler.

/**
	 * Register a {@link DispatcherHandler} against the given servlet context.
	 * <p>This method will create a {@link DispatcherHandler}, initializing it with the application
	 * context returned from {@link #createApplicationContext()}. The created handler will be
	 * wrapped in a {@link ServletHttpHandlerAdapter} servlet with the name
     * returned by {@link #getServletName()}, mapping it to the pattern
	 * returned from {@link #getServletMapping()}.
	 * <p>Further customization can be achieved by overriding {@link
	 * #customizeRegistration(ServletRegistration.Dynamic)} or
	 * {@link #createDispatcherHandler(ApplicationContext)}.
	 * @param servletContext the context to register the servlet against
	 */
protected void registerDispatcherHandler(ServletContext servletContext) {
    String servletName = getServletName();
    Assert.hasLength(servletName, "getServletName() must not return empty or null");
    ApplicationContext applicationContext = createApplicationContext();
    Assert.notNull(applicationContext, "createApplicationContext() did not return an application " + "context for servlet [" + servletName + "]");
    refreshApplicationContext(applicationContext);
    registerCloseListener(servletContext, applicationContext);
    WebHandler dispatcherHandler = createDispatcherHandler(applicationContext);
    Assert.notNull(dispatcherHandler, "createDispatcherHandler() did not return a WebHandler for servlet [" + servletName + "]");
    ServletHttpHandlerAdapter handlerAdapter = createHandlerAdapter(dispatcherHandler);
    Assert.notNull(handlerAdapter, "createHttpHandler() did not return a ServletHttpHandlerAdapter for servlet [" + servletName + "]");
    ServletRegistration.Dynamic registration = servletContext.addServlet(servletName, handlerAdapter);
    Assert.notNull(registration, "Failed to register servlet with name '" + servletName + "'." + "Check if there is another servlet registered under the same name.");
    registration.setLoadOnStartup(1);
    registration.addMapping(getServletMapping());
    registration.setAsyncSupported(true);
    customizeRegistration(registration);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ServletRegistration(javax.servlet.ServletRegistration) ServletHttpHandlerAdapter(org.springframework.http.server.reactive.ServletHttpHandlerAdapter) WebHandler(org.springframework.web.server.WebHandler)

Example 3 with ServletHttpHandlerAdapter

use of org.springframework.http.server.reactive.ServletHttpHandlerAdapter in project spring-framework by spring-projects.

the class AbstractServletHttpHandlerAdapterInitializer method registerHandlerAdapter.

/**
	 * Register a {@link ServletHttpHandlerAdapter} against the given servlet context.
	 * <p>This method will create a {@code HttpHandler} using {@link #createHttpHandler()},
	 * and use it to create a {@code ServletHttpHandlerAdapter} with the name returned by
	 * {@link #getServletName()}, and mapping it to the patterns
	 * returned from {@link #getServletMappings()}.
	 * <p>Further customization can be achieved by overriding {@link
	 * #customizeRegistration(ServletRegistration.Dynamic)} or
	 * {@link #createServlet(HttpHandler)}.
	 * @param servletContext the context to register the servlet against
	 */
protected void registerHandlerAdapter(ServletContext servletContext) {
    String servletName = getServletName();
    Assert.hasLength(servletName, "getServletName() must not return empty or null");
    HttpHandler httpHandler = createHttpHandler();
    Assert.notNull(httpHandler, "createHttpHandler() did not return a HttpHandler for servlet [" + servletName + "]");
    ServletHttpHandlerAdapter servlet = createServlet(httpHandler);
    Assert.notNull(servlet, "createHttpHandler() did not return a ServletHttpHandlerAdapter for servlet [" + servletName + "]");
    ServletRegistration.Dynamic registration = servletContext.addServlet(servletName, servlet);
    Assert.notNull(registration, "Failed to register servlet with name '" + servletName + "'." + "Check if there is another servlet registered under the same name.");
    registration.setLoadOnStartup(1);
    registration.addMapping(getServletMappings());
    registration.setAsyncSupported(true);
    customizeRegistration(registration);
}
Also used : HttpHandler(org.springframework.http.server.reactive.HttpHandler) ServletRegistration(javax.servlet.ServletRegistration) ServletHttpHandlerAdapter(org.springframework.http.server.reactive.ServletHttpHandlerAdapter)

Example 4 with ServletHttpHandlerAdapter

use of org.springframework.http.server.reactive.ServletHttpHandlerAdapter in project spring-framework by spring-projects.

the class TomcatHttpServer method initServer.

@Override
protected void initServer() throws Exception {
    this.tomcatServer = new Tomcat();
    this.tomcatServer.setBaseDir(baseDir);
    this.tomcatServer.setHostname(getHost());
    this.tomcatServer.setPort(getPort());
    ServletHttpHandlerAdapter servlet = initServletAdapter();
    File base = new File(System.getProperty("java.io.tmpdir"));
    Context rootContext = tomcatServer.addContext(this.contextPath, base.getAbsolutePath());
    Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet).setAsyncSupported(true);
    rootContext.addServletMappingDecoded(this.servletMapping, "httpHandlerServlet");
    if (wsListener != null) {
        rootContext.addApplicationListener(wsListener.getName());
    }
}
Also used : Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) ServletHttpHandlerAdapter(org.springframework.http.server.reactive.ServletHttpHandlerAdapter) File(java.io.File)

Example 5 with ServletHttpHandlerAdapter

use of org.springframework.http.server.reactive.ServletHttpHandlerAdapter in project spring-framework by spring-projects.

the class TomcatHttpServer method initServer.

@Override
protected void initServer() throws Exception {
    this.tomcatServer = new Tomcat();
    this.tomcatServer.setBaseDir(baseDir);
    this.tomcatServer.setHostname(getHost());
    this.tomcatServer.setPort(getPort());
    ServletHttpHandlerAdapter servlet = initServletAdapter();
    File base = new File(System.getProperty("java.io.tmpdir"));
    Context rootContext = tomcatServer.addContext("", base.getAbsolutePath());
    Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
    rootContext.addServletMappingDecoded("/", "httpHandlerServlet");
    if (wsListener != null) {
        rootContext.addApplicationListener(wsListener.getName());
    }
}
Also used : Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) ServletHttpHandlerAdapter(org.springframework.http.server.reactive.ServletHttpHandlerAdapter) File(java.io.File)

Aggregations

ServletHttpHandlerAdapter (org.springframework.http.server.reactive.ServletHttpHandlerAdapter)9 Context (org.apache.catalina.Context)5 Tomcat (org.apache.catalina.startup.Tomcat)5 HttpHandler (org.springframework.http.server.reactive.HttpHandler)4 WebHandler (org.springframework.web.server.WebHandler)4 TomcatWebServer (org.springframework.boot.web.embedded.tomcat.TomcatWebServer)3 RouterFunctions.toHttpHandler (org.springframework.web.reactive.function.server.RouterFunctions.toHttpHandler)3 File (java.io.File)2 ServletRegistration (javax.servlet.ServletRegistration)2 Server (org.eclipse.jetty.server.Server)2 ServerConnector (org.eclipse.jetty.server.ServerConnector)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 JettyWebSocketServletContainerInitializer (org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1