Search in sources :

Example 1 with WebServer

use of cn.taketoday.framework.web.server.WebServer in project today-framework by TAKETODAY.

the class JettyReactiveWebServerFactory method getWebServer.

@Override
public WebServer getWebServer(HttpHandler httpHandler) {
    JettyHttpHandlerAdapter servlet = new JettyHttpHandlerAdapter(httpHandler);
    Server server = createJettyServer(servlet);
    return new JettyWebServer(server, getPort() >= 0);
}
Also used : WebServer(cn.taketoday.framework.web.server.WebServer) Server(org.eclipse.jetty.server.Server) JettyHttpHandlerAdapter(cn.taketoday.http.server.reactive.JettyHttpHandlerAdapter)

Example 2 with WebServer

use of cn.taketoday.framework.web.server.WebServer in project today-framework by TAKETODAY.

the class ServletWebServerApplicationContext method createWebServer.

private void createWebServer() {
    WebServer webServer = this.webServer;
    ServletContext servletContext = getServletContext();
    if (webServer == null && servletContext == null) {
        ServletWebServerFactory factory = getWebServerFactory();
        webServer = factory.getWebServer(getSelfInitializer());
        StandardBeanFactory beanFactory = getBeanFactory();
        beanFactory.registerSingleton("webServerStartStop", new WebServerStartStopLifecycle(this, webServer));
        beanFactory.registerSingleton("webServerGracefulShutdown", new WebServerGracefulShutdownLifecycle(webServer));
        this.webServer = webServer;
    } else if (servletContext != null) {
        try {
            getSelfInitializer().onStartup(servletContext);
        } catch (ServletException ex) {
            throw new ApplicationContextException("Cannot initialize servlet context", ex);
        }
    }
    initPropertySources();
}
Also used : ServletException(jakarta.servlet.ServletException) ServletWebServerFactory(cn.taketoday.framework.web.servlet.server.ServletWebServerFactory) WebServer(cn.taketoday.framework.web.server.WebServer) WebServerGracefulShutdownLifecycle(cn.taketoday.framework.web.context.WebServerGracefulShutdownLifecycle) ServletContext(jakarta.servlet.ServletContext) StandardBeanFactory(cn.taketoday.beans.factory.support.StandardBeanFactory) ApplicationContextException(cn.taketoday.context.ApplicationContextException)

Example 3 with WebServer

use of cn.taketoday.framework.web.server.WebServer in project today-framework by TAKETODAY.

the class WebServerPortFileWriterTests method mockEvent.

private WebServerInitializedEvent mockEvent(String namespace, int port) {
    WebServer webServer = mock(WebServer.class);
    given(webServer.getPort()).willReturn(port);
    WebServerApplicationContext applicationContext = mock(WebServerApplicationContext.class);
    given(applicationContext.getServerNamespace()).willReturn(namespace);
    given(applicationContext.getWebServer()).willReturn(webServer);
    WebServerInitializedEvent event = mock(WebServerInitializedEvent.class);
    given(event.getApplicationContext()).willReturn(applicationContext);
    given(event.getWebServer()).willReturn(webServer);
    return event;
}
Also used : WebServer(cn.taketoday.framework.web.server.WebServer)

Example 4 with WebServer

use of cn.taketoday.framework.web.server.WebServer in project today-infrastructure by TAKETODAY.

the class WebServerPortFileWriterTests method mockEvent.

private WebServerInitializedEvent mockEvent(String namespace, int port) {
    WebServer webServer = mock(WebServer.class);
    given(webServer.getPort()).willReturn(port);
    WebServerApplicationContext applicationContext = mock(WebServerApplicationContext.class);
    given(applicationContext.getServerNamespace()).willReturn(namespace);
    given(applicationContext.getWebServer()).willReturn(webServer);
    WebServerInitializedEvent event = mock(WebServerInitializedEvent.class);
    given(event.getApplicationContext()).willReturn(applicationContext);
    given(event.getWebServer()).willReturn(webServer);
    return event;
}
Also used : WebServer(cn.taketoday.framework.web.server.WebServer)

Example 5 with WebServer

use of cn.taketoday.framework.web.server.WebServer in project today-infrastructure by TAKETODAY.

the class ServletWebServerApplicationContext method createWebServer.

private void createWebServer() {
    WebServer webServer = this.webServer;
    ServletContext servletContext = getServletContext();
    if (webServer == null && servletContext == null) {
        ServletWebServerFactory factory = getWebServerFactory();
        webServer = factory.getWebServer(getSelfInitializer());
        StandardBeanFactory beanFactory = getBeanFactory();
        beanFactory.registerSingleton("webServerStartStop", new WebServerStartStopLifecycle(this, webServer));
        beanFactory.registerSingleton("webServerGracefulShutdown", new WebServerGracefulShutdownLifecycle(webServer));
        this.webServer = webServer;
    } else if (servletContext != null) {
        try {
            getSelfInitializer().onStartup(servletContext);
        } catch (ServletException ex) {
            throw new ApplicationContextException("Cannot initialize servlet context", ex);
        }
    }
    initPropertySources();
}
Also used : ServletException(jakarta.servlet.ServletException) ServletWebServerFactory(cn.taketoday.framework.web.servlet.server.ServletWebServerFactory) WebServer(cn.taketoday.framework.web.server.WebServer) WebServerGracefulShutdownLifecycle(cn.taketoday.framework.web.context.WebServerGracefulShutdownLifecycle) ServletContext(jakarta.servlet.ServletContext) StandardBeanFactory(cn.taketoday.beans.factory.support.StandardBeanFactory) ApplicationContextException(cn.taketoday.context.ApplicationContextException)

Aggregations

WebServer (cn.taketoday.framework.web.server.WebServer)6 StandardBeanFactory (cn.taketoday.beans.factory.support.StandardBeanFactory)2 ApplicationContextException (cn.taketoday.context.ApplicationContextException)2 WebServerGracefulShutdownLifecycle (cn.taketoday.framework.web.context.WebServerGracefulShutdownLifecycle)2 ServletWebServerFactory (cn.taketoday.framework.web.servlet.server.ServletWebServerFactory)2 JettyHttpHandlerAdapter (cn.taketoday.http.server.reactive.JettyHttpHandlerAdapter)2 ServletContext (jakarta.servlet.ServletContext)2 ServletException (jakarta.servlet.ServletException)2 Server (org.eclipse.jetty.server.Server)2