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);
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);
}
use of org.springframework.http.server.reactive.ServletHttpHandlerAdapter in project spring-framework by spring-projects.
the class AbstractDispatcherHandlerInitializer method registerDispatcherHandler.
/**
* Register a {@link DispatcherHandler} against the given servlet context.
* <p>This method will create a {@link DispatcherHandler}, initializing it with the application
* context returned from {@link #createApplicationContext()}. The created handler will be
* wrapped in a {@link ServletHttpHandlerAdapter} servlet with the name
* returned by {@link #getServletName()}, mapping it to the pattern
* returned from {@link #getServletMapping()}.
* <p>Further customization can be achieved by overriding {@link
* #customizeRegistration(ServletRegistration.Dynamic)} or
* {@link #createDispatcherHandler(ApplicationContext)}.
* @param servletContext the context to register the servlet against
*/
protected void registerDispatcherHandler(ServletContext servletContext) {
String servletName = getServletName();
Assert.hasLength(servletName, "getServletName() must not return empty or null");
ApplicationContext applicationContext = createApplicationContext();
Assert.notNull(applicationContext, "createApplicationContext() did not return an application " + "context for servlet [" + servletName + "]");
refreshApplicationContext(applicationContext);
registerCloseListener(servletContext, applicationContext);
WebHandler dispatcherHandler = createDispatcherHandler(applicationContext);
Assert.notNull(dispatcherHandler, "createDispatcherHandler() did not return a WebHandler for servlet [" + servletName + "]");
ServletHttpHandlerAdapter handlerAdapter = createHandlerAdapter(dispatcherHandler);
Assert.notNull(handlerAdapter, "createHttpHandler() did not return a ServletHttpHandlerAdapter for servlet [" + servletName + "]");
ServletRegistration.Dynamic registration = servletContext.addServlet(servletName, handlerAdapter);
Assert.notNull(registration, "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);
customizeRegistration(registration);
}
use of org.springframework.http.server.reactive.ServletHttpHandlerAdapter in project spring-framework by spring-projects.
the class AbstractServletHttpHandlerAdapterInitializer method registerHandlerAdapter.
/**
* Register a {@link ServletHttpHandlerAdapter} against the given servlet context.
* <p>This method will create a {@code HttpHandler} using {@link #createHttpHandler()},
* and use it to create a {@code ServletHttpHandlerAdapter} with the name returned by
* {@link #getServletName()}, and mapping it to the patterns
* returned from {@link #getServletMappings()}.
* <p>Further customization can be achieved by overriding {@link
* #customizeRegistration(ServletRegistration.Dynamic)} or
* {@link #createServlet(HttpHandler)}.
* @param servletContext the context to register the servlet against
*/
protected void registerHandlerAdapter(ServletContext servletContext) {
String servletName = getServletName();
Assert.hasLength(servletName, "getServletName() must not return empty or null");
HttpHandler httpHandler = createHttpHandler();
Assert.notNull(httpHandler, "createHttpHandler() did not return a HttpHandler for servlet [" + servletName + "]");
ServletHttpHandlerAdapter servlet = createServlet(httpHandler);
Assert.notNull(servlet, "createHttpHandler() did not return a ServletHttpHandlerAdapter for servlet [" + servletName + "]");
ServletRegistration.Dynamic registration = servletContext.addServlet(servletName, servlet);
Assert.notNull(registration, "Failed to register servlet with name '" + servletName + "'." + "Check if there is another servlet registered under the same name.");
registration.setLoadOnStartup(1);
registration.addMapping(getServletMappings());
registration.setAsyncSupported(true);
customizeRegistration(registration);
}
use of org.springframework.http.server.reactive.ServletHttpHandlerAdapter in project spring-framework by spring-projects.
the class TomcatHttpServer method initServer.
@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());
}
}
use of org.springframework.http.server.reactive.ServletHttpHandlerAdapter in project spring-framework by spring-projects.
the class TomcatHttpServer method initServer.
@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("", base.getAbsolutePath());
Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
rootContext.addServletMappingDecoded("/", "httpHandlerServlet");
if (wsListener != null) {
rootContext.addApplicationListener(wsListener.getName());
}
}
Aggregations