org.springframework.boot.context.embedded.EmbeddedServletContainerException Java Examples

The following examples show how to use org.springframework.boot.context.embedded.EmbeddedServletContainerException. 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
Source File: DiscoveryClientRegistrationInvoker.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Override
public void customize(ConfigurableApplicationContext context) {
    if (context instanceof EmbeddedWebApplicationContext
            && !AdminEndpointApplicationRunListener.isEmbeddedServletServer(context.getEnvironment())) {
        MetaDataProvider metaDataProvider = context.getBean(MetaDataProvider.class);
        EmbeddedServletContainer embeddedServletContainer = new EmbeddedServletContainer() {

            @Override
            public void start() throws EmbeddedServletContainerException {

            }

            @Override
            public void stop() throws EmbeddedServletContainerException {

            }

            @Override
            public int getPort() {
                return metaDataProvider.getServerPort();
            }
        };
        context.publishEvent(new EmbeddedServletContainerInitializedEvent((EmbeddedWebApplicationContext) context, embeddedServletContainer));
    }
}
 
Example #2
Source File: NettyEmbeddedServletContainer.java    From Jinx with Apache License 2.0 6 votes vote down vote up
@Override
public void stop() throws EmbeddedServletContainerException {
    try {
        if (null != bossGroup) {
            bossGroup.shutdownGracefully().await();
        }
        if (null != workerGroup) {
            workerGroup.shutdownGracefully().await();
        }
        if (null != servletExecutor) {
            servletExecutor.shutdownGracefully().await();
        }
    } catch (InterruptedException e) {
        throw new EmbeddedServletContainerException("Container stop interrupted", e);
    }
}
 
Example #3
Source File: NettyContainer.java    From spring-boot-starter-netty with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 优雅地关闭各种资源
 * @throws EmbeddedServletContainerException
 */
@Override
public void stop() throws EmbeddedServletContainerException {
    log.info("Embedded Netty Servlet Container(by Leibniz.Hu) is now shuting down.");
    try {
        if (null != bossGroup) {
            bossGroup.shutdownGracefully().await();
        }
        if (null != workerGroup) {
            workerGroup.shutdownGracefully().await();
        }
        if (null != servletExecutor) {
            servletExecutor.shutdownGracefully().await();
        }
    } catch (InterruptedException e) {
        throw new EmbeddedServletContainerException("Container stop interrupted", e);
    }
}
 
Example #4
Source File: NettyEmbeddedServletContainer.java    From spring-boot-starter-netty with Apache License 2.0 6 votes vote down vote up
@Override
public void start() throws EmbeddedServletContainerException {
    ServerBootstrap b = new ServerBootstrap();
    groups(b);
    servletExecutor = new DefaultEventExecutorGroup(50);
    b.childHandler(new NettyEmbeddedServletInitializer(servletExecutor, context));

    // Don't yet need the complexity of lifecycle state, listeners etc, so tell the context it's initialised here
    context.setInitialised(true);

    ChannelFuture future = b.bind(address).awaitUninterruptibly();
    //noinspection ThrowableResultOfMethodCallIgnored
    Throwable cause = future.cause();
    if (null != cause) {
        throw new EmbeddedServletContainerException("Could not start Netty server", cause);
    }
    logger.info(context.getServerInfo() + " started on port: " + getPort());
}
 
Example #5
Source File: NettyEmbeddedServletContainer.java    From spring-boot-starter-netty with Apache License 2.0 6 votes vote down vote up
@Override
public void stop() throws EmbeddedServletContainerException {
    try {
        if (null != bossGroup) {
            bossGroup.shutdownGracefully().await();
        }
        if (null != workerGroup) {
            workerGroup.shutdownGracefully().await();
        }
        if (null != servletExecutor) {
            servletExecutor.shutdownGracefully().await();
        }
    } catch (InterruptedException e) {
        throw new EmbeddedServletContainerException("Container stop interrupted", e);
    }
}
 
Example #6
Source File: ServerlessServletEmbeddedServerFactory.java    From aws-serverless-java-container with Apache License 2.0 5 votes vote down vote up
@Override
public void start() throws EmbeddedServletContainerException {
    for (ServletContextInitializer i : initializers) {
        try {
            if (handler.getServletContext() == null) {
                throw new EmbeddedServletContainerException("Attempting to initialize ServletEmbeddedWebServer without ServletContext in Handler", null);
            }
            i.onStartup(handler.getServletContext());
        } catch (ServletException e) {
            throw new EmbeddedServletContainerException("Could not initialize Servlets", e);
        }
    }
}
 
Example #7
Source File: ServerlessServletEmbeddedServerFactoryTest.java    From aws-serverless-java-container with Apache License 2.0 5 votes vote down vote up
@Test
public void start_throwsException() {
    ServerlessServletEmbeddedServerFactory factory = new ServerlessServletEmbeddedServerFactory();
    TestServlet initializer = new TestServlet(true);
    EmbeddedServletContainer container = factory.getEmbeddedServletContainer(initializer);
    try {
        container.start();
    } catch (EmbeddedServletContainerException e) {
        assertTrue(ServletException.class.isAssignableFrom(e.getCause().getClass()));
        assertEquals(TestServlet.EXCEPTION_MESSAGE, e.getCause().getMessage());
        return;
    }
    fail("Did not throw the expected exception");
}
 
Example #8
Source File: MockServer.java    From funcatron with Apache License 2.0 4 votes vote down vote up
@Override
public void start() throws EmbeddedServletContainerException {
}
 
Example #9
Source File: ServerlessServletEmbeddedServerFactory.java    From aws-serverless-java-container with Apache License 2.0 2 votes vote down vote up
@Override
public void stop() throws EmbeddedServletContainerException {

}