use of com.adeptj.runtime.exception.InitializationException in project adeptj-runtime by AdeptJ.
the class KeyStores method getKeyStore.
public static KeyStore getKeyStore(String keyStoreLoc, char[] keyStorePwd) {
try (InputStream is = Environment.useProvidedKeyStore() ? Files.newInputStream(Paths.get(keyStoreLoc)) : KeyStores.class.getResourceAsStream(keyStoreLoc)) {
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(is, keyStorePwd);
return keyStore;
} catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException ex) {
LoggerFactory.getLogger(SslContextFactory.class).error("Exception while loading KeyStore!!", ex);
throw new InitializationException(ex.getMessage(), ex);
}
}
use of com.adeptj.runtime.exception.InitializationException in project adeptj-runtime by AdeptJ.
the class ContainerInitializer method onStartup.
/**
* {@inheritDoc}
*/
@Override
public void onStartup(Set<Class<?>> startupAwareClasses, ServletContext context) {
Logger logger = LoggerFactory.getLogger(ContainerInitializer.class);
if (startupAwareClasses == null || startupAwareClasses.isEmpty()) {
// We can't go ahead if StartupAware implementations are not passed by container.
logger.error("No @HandlesTypes(StartupAware) on classpath!!");
throw new IllegalStateException("No @HandlesTypes(StartupAware) on classpath!!");
} else {
ServletContextHolder.INSTANCE.setServletContext(context);
startupAwareClasses.stream().sorted(new StartupAwareComparator()).peek(startupAwareClass -> logger.info("@HandlesTypes: [{}]", startupAwareClass)).forEach(startupAwareClass -> {
try {
startupAwareClass.asSubclass(StartupAware.class).getDeclaredConstructor().newInstance().onStartup(context);
} catch (Exception ex) {
// NOSONAR
logger.error("Exception while executing StartupAware#onStartup!!", ex);
throw new InitializationException("Exception while executing StartupAware#onStartup!!", ex);
}
});
// If we are here means startup went well above, register FrameworkShutdownHandler now.
context.addListener(FrameworkShutdownHandler.class);
}
}
use of com.adeptj.runtime.exception.InitializationException in project adeptj-runtime by AdeptJ.
the class SslContextFactory method createSslContext.
public static SSLContext createSslContext() {
try {
String keyStoreLoc = System.getProperty("javax.net.ssl.keyStore");
String keyStorePwd = System.getProperty("javax.net.ssl.keyStorePassword");
String keyPwd = System.getProperty("javax.net.ssl.keyPassword");
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(KeyStores.getKeyStore(keyStoreLoc, keyStorePwd.toCharArray()), keyPwd.toCharArray());
SSLContext sslContext = SSLContext.getInstance(PROTOCOL_TLS);
sslContext.init(kmf.getKeyManagers(), null, null);
return sslContext;
} catch (NoSuchAlgorithmException | KeyManagementException | UnrecoverableKeyException | KeyStoreException ex) {
LoggerFactory.getLogger(SslContextFactory.class).error("Exception while initializing SSLContext!!", ex);
throw new InitializationException("Exception while initializing SSLContext!!", ex);
}
}
Aggregations