类org.springframework.http.server.reactive.ServletHttpHandlerAdapter源码实例Demo

下面列出了怎么用org.springframework.http.server.reactive.ServletHttpHandlerAdapter的API类实例代码及写法,或者点击链接到github查看源代码。

@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);
}
 
源代码2 项目: spring-analysis-note   文件: TomcatHttpServer.java
@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());
	}
}
 
源代码3 项目: spring-analysis-note   文件: JettyHttpServer.java
@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);
}
 
@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);
}
 
源代码5 项目: java-technology-stack   文件: TomcatHttpServer.java
@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());
	}
}
 
源代码6 项目: java-technology-stack   文件: JettyHttpServer.java
@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);
}
 
/**
 * 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);
    }
}
 
源代码8 项目: tutorials   文件: FunctionalWebApplication.java
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;

}
 
源代码9 项目: tutorials   文件: FunctionalWebApplication.java
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;

}
 
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;

}
 
源代码11 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
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;
 }
 
源代码12 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
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;
 }
 
源代码13 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
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;
 }
 
源代码14 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
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;
 }
 
源代码15 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
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;
 }
 
源代码16 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
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;
 }
 
源代码17 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
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;
 }
 
源代码18 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
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;
 }
 
源代码19 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
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;
 }
 
源代码20 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
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;
 }
 
源代码21 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
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;
 }
 
源代码22 项目: Spring-5.0-Cookbook   文件: HttpServerConfig.java
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;
 }
 
源代码23 项目: spring-analysis-note   文件: TomcatHttpServer.java
private ServletHttpHandlerAdapter initServletAdapter() {
	return new TomcatHttpHandlerAdapter(resolveHttpHandler());
}
 
源代码24 项目: spring-analysis-note   文件: JettyHttpServer.java
private ServletHttpHandlerAdapter createServletAdapter() {
	return new JettyHttpHandlerAdapter(resolveHttpHandler());
}
 
源代码25 项目: java-technology-stack   文件: TomcatHttpServer.java
private ServletHttpHandlerAdapter initServletAdapter() {
	return new TomcatHttpHandlerAdapter(resolveHttpHandler());
}
 
源代码26 项目: java-technology-stack   文件: JettyHttpServer.java
private ServletHttpHandlerAdapter createServletAdapter() {
	return new JettyHttpHandlerAdapter(resolveHttpHandler());
}
 
@Override
@SuppressFBWarnings("MTIA_SUSPECT_SERVLET_INSTANCE_FIELD")
public WebServer getWebServer(HttpHandler httpHandler) {
    handler = new ServletHttpHandlerAdapter(httpHandler);
    return this;
}
 
 类所在包
 同包方法