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);
}
}
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);
}
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);
}
}
Aggregations