Java源码示例:org.springframework.http.server.reactive.ServletHttpHandlerAdapter
示例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);
}
示例2
@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
@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);
}
示例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);
}
示例5
@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
@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);
}
示例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);
}
}
示例8
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
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;
}
示例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;
}
示例11
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
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
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
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
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
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
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
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
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
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
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
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
private ServletHttpHandlerAdapter initServletAdapter() {
return new TomcatHttpHandlerAdapter(resolveHttpHandler());
}
示例24
private ServletHttpHandlerAdapter createServletAdapter() {
return new JettyHttpHandlerAdapter(resolveHttpHandler());
}
示例25
private ServletHttpHandlerAdapter initServletAdapter() {
return new TomcatHttpHandlerAdapter(resolveHttpHandler());
}
示例26
private ServletHttpHandlerAdapter createServletAdapter() {
return new JettyHttpHandlerAdapter(resolveHttpHandler());
}
示例27
@Override
@SuppressFBWarnings("MTIA_SUSPECT_SERVLET_INSTANCE_FIELD")
public WebServer getWebServer(HttpHandler httpHandler) {
handler = new ServletHttpHandlerAdapter(httpHandler);
return this;
}