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

The following examples show how to use org.springframework.http.server.reactive.ServletHttpHandlerAdapter. These examples are extracted from open source projects. 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
@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 2
Source Project: spring-analysis-note   Source File: TomcatHttpServer.java    License: 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 3
Source Project: spring-analysis-note   Source File: JettyHttpServer.java    License: 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 4
@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 5
Source Project: java-technology-stack   Source File: TomcatHttpServer.java    License: 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 6
Source Project: java-technology-stack   Source File: JettyHttpServer.java    License: 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
/**
 * 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 8
Source Project: tutorials   Source File: FunctionalWebApplication.java    License: 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 9
Source Project: tutorials   Source File: FunctionalWebApplication.java    License: 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 10
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 11
Source Project: Spring-5.0-Cookbook   Source File: HttpServerConfig.java    License: 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 Project: Spring-5.0-Cookbook   Source File: HttpServerConfig.java    License: 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 Project: Spring-5.0-Cookbook   Source File: HttpServerConfig.java    License: 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 Project: Spring-5.0-Cookbook   Source File: HttpServerConfig.java    License: 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 Project: Spring-5.0-Cookbook   Source File: HttpServerConfig.java    License: 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 Project: Spring-5.0-Cookbook   Source File: HttpServerConfig.java    License: 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 Project: Spring-5.0-Cookbook   Source File: HttpServerConfig.java    License: 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 Project: Spring-5.0-Cookbook   Source File: HttpServerConfig.java    License: 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 Project: Spring-5.0-Cookbook   Source File: HttpServerConfig.java    License: 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 Project: Spring-5.0-Cookbook   Source File: HttpServerConfig.java    License: 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 Project: Spring-5.0-Cookbook   Source File: HttpServerConfig.java    License: 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 Project: Spring-5.0-Cookbook   Source File: HttpServerConfig.java    License: 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 Project: spring-analysis-note   Source File: TomcatHttpServer.java    License: MIT License 4 votes vote down vote up
private ServletHttpHandlerAdapter initServletAdapter() {
	return new TomcatHttpHandlerAdapter(resolveHttpHandler());
}
 
Example 24
Source Project: spring-analysis-note   Source File: JettyHttpServer.java    License: MIT License 4 votes vote down vote up
private ServletHttpHandlerAdapter createServletAdapter() {
	return new JettyHttpHandlerAdapter(resolveHttpHandler());
}
 
Example 25
Source Project: java-technology-stack   Source File: TomcatHttpServer.java    License: MIT License 4 votes vote down vote up
private ServletHttpHandlerAdapter initServletAdapter() {
	return new TomcatHttpHandlerAdapter(resolveHttpHandler());
}
 
Example 26
Source Project: java-technology-stack   Source File: JettyHttpServer.java    License: MIT License 4 votes vote down vote up
private ServletHttpHandlerAdapter createServletAdapter() {
	return new JettyHttpHandlerAdapter(resolveHttpHandler());
}
 
Example 27
@Override
@SuppressFBWarnings("MTIA_SUSPECT_SERVLET_INSTANCE_FIELD")
public WebServer getWebServer(HttpHandler httpHandler) {
    handler = new ServletHttpHandlerAdapter(httpHandler);
    return this;
}