org.springframework.http.server.reactive.ServletHttpHandlerAdapter Java Examples

The following examples show how to use org.springframework.http.server.reactive.ServletHttpHandlerAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TomcatHttpServer.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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());
	}
}
 
Example #2
Source File: ExploreSpring5URLPatternUsingRouterFunctions.java    From tutorials with MIT License 6 votes vote down vote up
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);
    Wrapper servletWrapper = Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
    servletWrapper.setAsyncSupported(true);
    rootContext.addServletMappingDecoded("/", "httpHandlerServlet");

    TomcatWebServer server = new TomcatWebServer(tomcat);
    server.start();
    return server;

}
 
Example #3
Source File: FunctionalWebApplication.java    From tutorials with MIT License 6 votes vote down vote up
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;

}
 
Example #4
Source File: FunctionalWebApplication.java    From tutorials with MIT License 6 votes vote down vote up
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);
    Wrapper servletWrapper = Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
    servletWrapper.setAsyncSupported(true);
    rootContext.addServletMappingDecoded("/", "httpHandlerServlet");

    TomcatWebServer server = new TomcatWebServer(tomcat);
    server.start();
    return server;

}
 
Example #5
Source File: NettyTcpServerFactory.java    From spring-boot-protocol with Apache License 2.0 6 votes vote down vote up
/**
 * Reactive container (temporarily replaced by servlets)
 * @param httpHandler httpHandler
 * @return NettyTcpServer
 */
@Override
public WebServer getWebServer(HttpHandler httpHandler) {
    try {
        ServletContext servletContext = getServletContext();
        if(servletContext != null) {
            ServletRegistration.Dynamic servletRegistration = servletContext.addServlet("default", new ServletHttpHandlerAdapter(httpHandler));
            servletRegistration.setAsyncSupported(true);
            servletRegistration.addMapping("/");
        }

        //Server port
        InetSocketAddress serverAddress = getServerSocketAddress(getAddress(),getPort());
        return new NettyTcpServer(serverAddress, properties, protocolHandlers,serverListeners,channelHandlerSupplier);
    }catch (Exception e){
        throw new IllegalStateException(e.getMessage(),e);
    }
}
 
Example #6
Source File: JettyHttpServer.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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.start();

	ServerConnector connector = new ServerConnector(this.jettyServer);
	connector.setHost(getHost());
	connector.setPort(getPort());
	this.jettyServer.addConnector(connector);
}
 
Example #7
Source File: AbstractReactiveWebInitializer.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
	String servletName = getServletName();
	Assert.hasLength(servletName, "getServletName() must not return null or empty");

	ApplicationContext applicationContext = createApplicationContext();
	Assert.notNull(applicationContext, "createApplicationContext() must not return null");

	refreshApplicationContext(applicationContext);
	registerCloseListener(servletContext, applicationContext);

	HttpHandler httpHandler = WebHttpHandlerBuilder.applicationContext(applicationContext).build();
	ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);

	ServletRegistration.Dynamic registration = servletContext.addServlet(servletName, servlet);
	if (registration == null) {
		throw new IllegalStateException("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);
}
 
Example #8
Source File: AbstractReactiveWebInitializer.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
	String servletName = getServletName();
	Assert.hasLength(servletName, "getServletName() must not return null or empty");

	ApplicationContext applicationContext = createApplicationContext();
	Assert.notNull(applicationContext, "createApplicationContext() must not return null");

	refreshApplicationContext(applicationContext);
	registerCloseListener(servletContext, applicationContext);

	HttpHandler httpHandler = WebHttpHandlerBuilder.applicationContext(applicationContext).build();
	ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);

	ServletRegistration.Dynamic registration = servletContext.addServlet(servletName, servlet);
	if (registration == null) {
		throw new IllegalStateException("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);
}
 
Example #9
Source File: JettyHttpServer.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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.start();

	ServerConnector connector = new ServerConnector(this.jettyServer);
	connector.setHost(getHost());
	connector.setPort(getPort());
	this.jettyServer.addConnector(connector);
}
 
Example #10
Source File: TomcatHttpServer.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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());
	}
}
 
Example #11
Source File: HttpServerConfig.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
public ServletRegistrationBean routeServlet1(RouterFunction<?> routerFunction) throws Exception {
HttpHandler httpHandler = RouterFunctions.toHttpHandler(routerFunction );
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);

     ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(servlet, "/flux" + "/*");
     registrationBean.setLoadOnStartup(1);
     registrationBean.setAsyncSupported(true);
     
 	System.out.println("starts server");		
     return registrationBean;
 }
 
Example #12
Source File: HttpServerConfig.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
public ServletRegistrationBean routeServlet1(RouterFunction<?> routerFunction) throws Exception {
HttpHandler httpHandler = RouterFunctions.toHttpHandler(routerFunction );
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);

     ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(servlet, "/flux" + "/*");
     registrationBean.setLoadOnStartup(1);
     registrationBean.setAsyncSupported(true);
     
 	System.out.println("starts server");		
     return registrationBean;
 }
 
Example #13
Source File: HttpServerConfig.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
public ServletRegistrationBean routeServlet1(RouterFunction<?> routerFunction) throws Exception {
HttpHandler httpHandler = RouterFunctions.toHttpHandler(routerFunction );
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);

     ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(servlet, "/flux" + "/*");
     registrationBean.setLoadOnStartup(1);
     registrationBean.setAsyncSupported(true);
     
 	System.out.println("starts server");		
     return registrationBean;
 }
 
Example #14
Source File: HttpServerConfig.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
public ServletRegistrationBean routeServlet1(RouterFunction<?> routerFunction) throws Exception {
HttpHandler httpHandler = RouterFunctions.toHttpHandler(routerFunction );
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);

     ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(servlet, "/flux" + "/*");
     registrationBean.setLoadOnStartup(1);
     registrationBean.setAsyncSupported(true);
     
 	System.out.println("starts server");		
     return registrationBean;
 }
 
Example #15
Source File: HttpServerConfig.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
public ServletRegistrationBean routeServlet1(RouterFunction<?> routerFunction) throws Exception {
HttpHandler httpHandler = RouterFunctions.toHttpHandler(routerFunction );
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);

     ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(servlet, "/flux" + "/*");
     registrationBean.setLoadOnStartup(1);
     registrationBean.setAsyncSupported(true);
     
 	System.out.println("starts server");		
     return registrationBean;
 }
 
Example #16
Source File: HttpServerConfig.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
public ServletRegistrationBean routeServlet1(RouterFunction<?> routerFunction) throws Exception {
HttpHandler httpHandler = RouterFunctions.toHttpHandler(routerFunction );
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);

     ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(servlet, "/flux" + "/*");
     registrationBean.setLoadOnStartup(1);
     registrationBean.setAsyncSupported(true);
     
 	System.out.println("starts server");		
     return registrationBean;
 }
 
Example #17
Source File: HttpServerConfig.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
public ServletRegistrationBean routeServlet1(RouterFunction<?> routerFunction) throws Exception {
HttpHandler httpHandler = RouterFunctions.toHttpHandler(routerFunction );
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);

     ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(servlet, "/flux" + "/*");
     registrationBean.setLoadOnStartup(1);
     registrationBean.setAsyncSupported(true);
     
 	System.out.println("starts server");		
     return registrationBean;
 }
 
Example #18
Source File: HttpServerConfig.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
public ServletRegistrationBean routeServlet1(RouterFunction<?> routerFunction) throws Exception {
HttpHandler httpHandler = RouterFunctions.toHttpHandler(routerFunction );
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);

     ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(servlet, "/flux" + "/*");
     registrationBean.setLoadOnStartup(1);
     registrationBean.setAsyncSupported(true);
     
 	System.out.println("starts server");		
     return registrationBean;
 }
 
Example #19
Source File: HttpServerConfig.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
public ServletRegistrationBean routeServlet1(RouterFunction<?> routerFunction) throws Exception {
HttpHandler httpHandler = RouterFunctions.toHttpHandler(routerFunction );
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);

     ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(servlet, "/flux" + "/*");
     registrationBean.setLoadOnStartup(1);
     registrationBean.setAsyncSupported(true);
     
 	System.out.println("starts server");		
     return registrationBean;
 }
 
Example #20
Source File: HttpServerConfig.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
public ServletRegistrationBean routeServlet1(RouterFunction<?> routerFunction) throws Exception {
HttpHandler httpHandler = RouterFunctions.toHttpHandler(routerFunction );
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);

     ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(servlet, "/flux" + "/*");
     registrationBean.setLoadOnStartup(1);
     registrationBean.setAsyncSupported(true);
     
 	System.out.println("starts server");		
     return registrationBean;
 }
 
Example #21
Source File: HttpServerConfig.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
public ServletRegistrationBean routeServlet1(RouterFunction<?> routerFunction) throws Exception {
HttpHandler httpHandler = RouterFunctions.toHttpHandler(routerFunction );
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);

     ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(servlet, "/flux" + "/*");
     registrationBean.setLoadOnStartup(1);
     registrationBean.setAsyncSupported(true);
     
 	System.out.println("starts server");		
     return registrationBean;
 }
 
Example #22
Source File: HttpServerConfig.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
public ServletRegistrationBean routeServlet1(RouterFunction<?> routerFunction) throws Exception {
HttpHandler httpHandler = RouterFunctions.toHttpHandler(routerFunction );
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);

     ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(servlet, "/flux" + "/*");
     registrationBean.setLoadOnStartup(1);
     registrationBean.setAsyncSupported(true);
     
 	System.out.println("starts server");		
     return registrationBean;
 }
 
Example #23
Source File: JettyHttpServer.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private ServletHttpHandlerAdapter createServletAdapter() {
	return new JettyHttpHandlerAdapter(resolveHttpHandler());
}
 
Example #24
Source File: ServerlessReactiveServletEmbeddedServerFactory.java    From aws-serverless-java-container with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressFBWarnings("MTIA_SUSPECT_SERVLET_INSTANCE_FIELD")
public WebServer getWebServer(HttpHandler httpHandler) {
    handler = new ServletHttpHandlerAdapter(httpHandler);
    return this;
}
 
Example #25
Source File: JettyHttpServer.java    From java-technology-stack with MIT License 4 votes vote down vote up
private ServletHttpHandlerAdapter createServletAdapter() {
	return new JettyHttpHandlerAdapter(resolveHttpHandler());
}
 
Example #26
Source File: TomcatHttpServer.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private ServletHttpHandlerAdapter initServletAdapter() {
	return new TomcatHttpHandlerAdapter(resolveHttpHandler());
}
 
Example #27
Source File: TomcatHttpServer.java    From java-technology-stack with MIT License 4 votes vote down vote up
private ServletHttpHandlerAdapter initServletAdapter() {
	return new TomcatHttpHandlerAdapter(resolveHttpHandler());
}