Search in sources :

Example 1 with RuntimeInitializationException

use of com.adeptj.runtime.exception.RuntimeInitializationException in project adeptj-runtime by AdeptJ.

the class Server method start.

/**
 * Bootstrap Undertow Server and OSGi Framework.
 */
@Override
public void start(String[] args) {
    Config undertowConf = Configs.of().undertow();
    Config httpConf = undertowConf.getConfig(KEY_HTTP);
    int port = this.resolvePort(httpConf);
    LOGGER.info("Starting AdeptJ Runtime @port: [{}]", port);
    this.printBanner();
    try {
        this.deploymentManager = Servlets.defaultContainer().addDeployment(this.deploymentInfo(undertowConf));
        this.deploymentManager.deploy();
        this.createOrUpdateServerConfFile();
        // Now the Felix is completely initialized, therefore set the System Bundle's BundleContext
        // as a ServletContext attribute per the Felix HttpBridge Specification.
        ServletContext servletContext = this.deploymentManager.getDeployment().getServletContext();
        servletContext.setAttribute(ATTRIBUTE_BUNDLE_CONTEXT, BundleContextHolder.getInstance().getBundleContext());
        HttpHandler httpContinueReadHandler = this.deploymentManager.start();
        this.rootHandler = this.createHandlerChain(httpContinueReadHandler, undertowConf);
        Undertow.Builder undertowBuilder = Undertow.builder();
        this.setWorkerOptions(undertowBuilder, undertowConf);
        new SocketOptions().setOptions(undertowBuilder, undertowConf);
        new ServerOptions().setOptions(undertowBuilder, undertowConf);
        this.undertow = this.addHttpsListener(undertowBuilder, undertowConf).addHttpListener(port, httpConf.getString(KEY_HOST)).setHandler(this.rootHandler).build();
        this.undertow.start();
        this.populateCredentialsStore(undertowConf);
    } catch (Exception ex) {
        // NOSONAR
        throw new RuntimeInitializationException(ex);
    }
}
Also used : HttpHandler(io.undertow.server.HttpHandler) RuntimeInitializationException(com.adeptj.runtime.exception.RuntimeInitializationException) ServletSessionConfig(io.undertow.servlet.api.ServletSessionConfig) Config(com.typesafe.config.Config) CrawlerSessionManagerConfig(io.undertow.servlet.api.CrawlerSessionManagerConfig) ServletContext(javax.servlet.ServletContext) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) Undertow(io.undertow.Undertow) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) RuntimeInitializationException(com.adeptj.runtime.exception.RuntimeInitializationException)

Example 2 with RuntimeInitializationException

use of com.adeptj.runtime.exception.RuntimeInitializationException in project adeptj-runtime by AdeptJ.

the class RuntimeInitializer method onStartup.

/**
 * {@inheritDoc}
 */
@Override
public void onStartup(Set<Class<?>> startupAwareClasses, ServletContext context) {
    ServletContextHolder.getInstance().setServletContext(context);
    Logger logger = LoggerFactory.getLogger(this.getClass());
    for (Class<?> startupAwareClass : startupAwareClasses) {
        logger.info("@HandlesTypes: [{}]", startupAwareClass);
        try {
            ((StartupAware) startupAwareClass.getConstructor().newInstance()).onStartup(context);
        } catch (Exception ex) {
            // NOSONAR
            logger.error("Exception while executing StartupAware#onStartup!!", ex);
            throw new RuntimeInitializationException(ex);
        }
    }
    context.addListener(FrameworkShutdownHandler.class);
    this.handleServiceLoaderBasedStartupAware(context, logger);
}
Also used : RuntimeInitializationException(com.adeptj.runtime.exception.RuntimeInitializationException) Logger(org.slf4j.Logger) RuntimeInitializationException(com.adeptj.runtime.exception.RuntimeInitializationException)

Example 3 with RuntimeInitializationException

use of com.adeptj.runtime.exception.RuntimeInitializationException in project adeptj-runtime by AdeptJ.

the class KeyStores method getKeyStore.

static KeyStore getKeyStore(boolean p12FileExternal, String type, String p12Loc, char[] p12Pwd) {
    try (InputStream is = p12FileExternal ? Files.newInputStream(Paths.get(p12Loc)) : KeyStores.class.getResourceAsStream(p12Loc)) {
        KeyStore keyStore = KeyStore.getInstance(type);
        keyStore.load(is, p12Pwd);
        return keyStore;
    } catch (IOException | GeneralSecurityException ex) {
        throw new RuntimeInitializationException(ex);
    }
}
Also used : RuntimeInitializationException(com.adeptj.runtime.exception.RuntimeInitializationException) InputStream(java.io.InputStream) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) KeyStore(java.security.KeyStore)

Aggregations

RuntimeInitializationException (com.adeptj.runtime.exception.RuntimeInitializationException)3 IOException (java.io.IOException)2 GeneralSecurityException (java.security.GeneralSecurityException)2 Config (com.typesafe.config.Config)1 Undertow (io.undertow.Undertow)1 HttpHandler (io.undertow.server.HttpHandler)1 CrawlerSessionManagerConfig (io.undertow.servlet.api.CrawlerSessionManagerConfig)1 SecurityConstraint (io.undertow.servlet.api.SecurityConstraint)1 ServletSessionConfig (io.undertow.servlet.api.ServletSessionConfig)1 InputStream (java.io.InputStream)1 KeyStore (java.security.KeyStore)1 ServletContext (javax.servlet.ServletContext)1 Logger (org.slf4j.Logger)1