Search in sources :

Example 6 with ServletHttpHandlerAdapter

use of org.springframework.http.server.reactive.ServletHttpHandlerAdapter in project tutorials by eugenp.

the class FunctionalWebApplication method start.

WebServer start() throws Exception {
    WebHandler webHandler = (WebHandler) toHttpHandler(routingFunction());
    HttpHandler httpHandler = WebHttpHandlerBuilder.webHandler(webHandler).filter(new IndexRewriteFilter()).build();
    Tomcat tomcat = new Tomcat();
    tomcat.setHostname("localhost");
    tomcat.setPort(9090);
    Context rootContext = tomcat.addContext("", System.getProperty("java.io.tmpdir"));
    ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);
    Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
    rootContext.addServletMappingDecoded("/", "httpHandlerServlet");
    TomcatWebServer server = new TomcatWebServer(tomcat);
    server.start();
    return server;
}
Also used : Context(org.apache.catalina.Context) RouterFunctions.toHttpHandler(org.springframework.web.reactive.function.server.RouterFunctions.toHttpHandler) HttpHandler(org.springframework.http.server.reactive.HttpHandler) Tomcat(org.apache.catalina.startup.Tomcat) TomcatWebServer(org.springframework.boot.web.embedded.tomcat.TomcatWebServer) ServletHttpHandlerAdapter(org.springframework.http.server.reactive.ServletHttpHandlerAdapter) WebHandler(org.springframework.web.server.WebHandler)

Example 7 with ServletHttpHandlerAdapter

use of org.springframework.http.server.reactive.ServletHttpHandlerAdapter in project tutorials by eugenp.

the class ExploreSpring5URLPatternUsingRouterFunctions method start.

WebServer start() throws Exception {
    WebHandler webHandler = (WebHandler) toHttpHandler(routingFunction());
    HttpHandler httpHandler = WebHttpHandlerBuilder.webHandler(webHandler).filter(new IndexRewriteFilter()).build();
    Tomcat tomcat = new Tomcat();
    tomcat.setHostname("localhost");
    tomcat.setPort(9090);
    Context rootContext = tomcat.addContext("", System.getProperty("java.io.tmpdir"));
    ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);
    Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
    rootContext.addServletMappingDecoded("/", "httpHandlerServlet");
    TomcatWebServer server = new TomcatWebServer(tomcat);
    server.start();
    return server;
}
Also used : Context(org.apache.catalina.Context) RouterFunctions.toHttpHandler(org.springframework.web.reactive.function.server.RouterFunctions.toHttpHandler) HttpHandler(org.springframework.http.server.reactive.HttpHandler) Tomcat(org.apache.catalina.startup.Tomcat) TomcatWebServer(org.springframework.boot.web.embedded.tomcat.TomcatWebServer) ServletHttpHandlerAdapter(org.springframework.http.server.reactive.ServletHttpHandlerAdapter) WebHandler(org.springframework.web.server.WebHandler)

Example 8 with ServletHttpHandlerAdapter

use of org.springframework.http.server.reactive.ServletHttpHandlerAdapter in project tutorials by eugenp.

the class FunctionalWebApplication method start.

WebServer start() throws Exception {
    WebHandler webHandler = (WebHandler) toHttpHandler(routingFunction());
    HttpHandler httpHandler = WebHttpHandlerBuilder.webHandler(webHandler).filter(new IndexRewriteFilter()).build();
    Tomcat tomcat = new Tomcat();
    tomcat.setHostname("localhost");
    tomcat.setPort(9090);
    Context rootContext = tomcat.addContext("", System.getProperty("java.io.tmpdir"));
    ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);
    Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
    rootContext.addServletMappingDecoded("/", "httpHandlerServlet");
    TomcatWebServer server = new TomcatWebServer(tomcat);
    server.start();
    return server;
}
Also used : Context(org.apache.catalina.Context) RouterFunctions.toHttpHandler(org.springframework.web.reactive.function.server.RouterFunctions.toHttpHandler) HttpHandler(org.springframework.http.server.reactive.HttpHandler) Tomcat(org.apache.catalina.startup.Tomcat) TomcatWebServer(org.springframework.boot.web.embedded.tomcat.TomcatWebServer) ServletHttpHandlerAdapter(org.springframework.http.server.reactive.ServletHttpHandlerAdapter) WebHandler(org.springframework.web.server.WebHandler)

Example 9 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);
    servletHolder.setAsyncSupported(true);
    this.contextHandler = new ServletContextHandler(this.jettyServer, "", false, false);
    this.contextHandler.addServlet(servletHolder, "/");
    this.contextHandler.addServletContainerInitializer(new JettyWebSocketServletContainerInitializer());
    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) JettyWebSocketServletContainerInitializer(org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletHttpHandlerAdapter(org.springframework.http.server.reactive.ServletHttpHandlerAdapter) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

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