use of org.springframework.core.io.DefaultResourceLoader in project opennms by OpenNMS.
the class DroolsTicketerServiceLayerTest method setUp.
@Before
public void setUp() throws Exception {
m_eventIpcManager = new MockEventIpcManager();
EventIpcManagerFactory.setIpcManager(m_eventIpcManager);
MockLogAppender.setupLogging();
ResourceLoader loader = new DefaultResourceLoader();
Resource resource = loader.getResource("classpath:/drools-ticketer-rules.drl");
m_easyMockUtils = new EasyMockUtils();
m_configDao = m_easyMockUtils.createMock(DroolsTicketerConfigDao.class);
EasyMock.expect(m_configDao.getRulesFile()).andReturn(resource.getFile()).times(1);
EasyMock.replay(m_configDao);
m_alarmDao = m_easyMockUtils.createMock(AlarmDao.class);
m_ticketerPlugin = m_easyMockUtils.createMock(Plugin.class);
m_droolsTicketerServiceLayer = new DroolsTicketerServiceLayer(m_configDao);
m_droolsTicketerServiceLayer.setAlarmDao(m_alarmDao);
m_droolsTicketerServiceLayer.setTicketerPlugin(m_ticketerPlugin);
EasyMock.reset(m_configDao);
m_alarm = new OnmsAlarm();
m_alarm.setId(1);
m_alarm.setLogMsg("Test Logmsg");
m_alarm.setDescription("Test Description");
m_alarm.setUei("uei.opennms.org/nodes/nodeDown");
m_ticket = new Ticket();
m_ticket.setId("4");
}
use of org.springframework.core.io.DefaultResourceLoader in project chassis by Kixeye.
the class JettyConnectorRegistry method registerHttpsConnector.
/**
* Register to listen to HTTPS.
*
* @param server
* @param address
* @throws Exception
*/
public static void registerHttpsConnector(Server server, InetSocketAddress address, boolean selfSigned, boolean mutualSsl, String keyStorePath, String keyStoreData, String keyStorePassword, String keyManagerPassword, String trustStorePath, String trustStoreData, String trustStorePassword, String[] excludedCipherSuites) throws Exception {
// SSL Context Factory
SslContextFactory sslContextFactory = new SslContextFactory();
if (selfSigned) {
char[] passwordChars = UUID.randomUUID().toString().toCharArray();
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null, passwordChars);
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
keyPairGenerator.initialize(1024);
KeyPair keyPair = keyPairGenerator.generateKeyPair();
X509V3CertificateGenerator v3CertGen = new X509V3CertificateGenerator();
v3CertGen.setSerialNumber(BigInteger.valueOf(new SecureRandom().nextInt()).abs());
v3CertGen.setIssuerDN(new X509Principal("CN=" + "kixeye.com" + ", OU=None, O=None L=None, C=None"));
v3CertGen.setNotBefore(new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24 * 30));
v3CertGen.setNotAfter(new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 365 * 10)));
v3CertGen.setSubjectDN(new X509Principal("CN=" + "kixeye.com" + ", OU=None, O=None L=None, C=None"));
v3CertGen.setPublicKey(keyPair.getPublic());
v3CertGen.setSignatureAlgorithm("MD5WithRSAEncryption");
X509Certificate privateKeyCertificate = v3CertGen.generateX509Certificate(keyPair.getPrivate());
keyStore.setKeyEntry("selfSigned", keyPair.getPrivate(), passwordChars, new java.security.cert.Certificate[] { privateKeyCertificate });
ByteArrayOutputStream keyStoreBaos = new ByteArrayOutputStream();
keyStore.store(keyStoreBaos, passwordChars);
keyStoreData = new String(Hex.encode(keyStoreBaos.toByteArray()), Charsets.UTF_8);
keyStorePassword = new String(passwordChars);
keyManagerPassword = keyStorePassword;
sslContextFactory.setTrustAll(true);
}
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
if (StringUtils.isNotBlank(keyStoreData)) {
keyStore.load(new ByteArrayInputStream(Hex.decode(keyStoreData)), keyStorePassword.toCharArray());
} else if (StringUtils.isNotBlank(keyStorePath)) {
try (InputStream inputStream = new DefaultResourceLoader().getResource(keyStorePath).getInputStream()) {
keyStore.load(inputStream, keyStorePassword.toCharArray());
}
}
sslContextFactory.setKeyStore(keyStore);
sslContextFactory.setKeyStorePassword(keyStorePassword);
if (StringUtils.isBlank(keyManagerPassword)) {
keyManagerPassword = keyStorePassword;
}
sslContextFactory.setKeyManagerPassword(keyManagerPassword);
KeyStore trustStore = null;
if (StringUtils.isNotBlank(trustStoreData)) {
trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(new ByteArrayInputStream(Hex.decode(trustStoreData)), trustStorePassword.toCharArray());
} else if (StringUtils.isNotBlank(trustStorePath)) {
trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
try (InputStream inputStream = new DefaultResourceLoader().getResource(trustStorePath).getInputStream()) {
trustStore.load(inputStream, trustStorePassword.toCharArray());
}
}
if (trustStore != null) {
sslContextFactory.setTrustStore(trustStore);
sslContextFactory.setTrustStorePassword(trustStorePassword);
}
sslContextFactory.setNeedClientAuth(mutualSsl);
sslContextFactory.setExcludeCipherSuites(excludedCipherSuites);
// SSL Connector
ServerConnector connector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.toString()), new HttpConnectionFactory());
connector.setHost(address.getHostName());
connector.setPort(address.getPort());
server.addConnector(connector);
}
use of org.springframework.core.io.DefaultResourceLoader in project spring-boot by spring-projects.
the class SpringApplication method printBanner.
private Banner printBanner(ConfigurableEnvironment environment) {
if (this.bannerMode == Banner.Mode.OFF) {
return null;
}
ResourceLoader resourceLoader = this.resourceLoader != null ? this.resourceLoader : new DefaultResourceLoader(getClassLoader());
SpringApplicationBannerPrinter bannerPrinter = new SpringApplicationBannerPrinter(resourceLoader, this.banner);
if (this.bannerMode == Mode.LOG) {
return bannerPrinter.print(environment, this.mainApplicationClass, logger);
}
return bannerPrinter.print(environment, this.mainApplicationClass, System.out);
}
use of org.springframework.core.io.DefaultResourceLoader in project spring-boot by spring-projects.
the class SpringApplicationTests method customResourceLoaderFromConstructor.
@Test
public void customResourceLoaderFromConstructor() throws Exception {
ResourceLoader resourceLoader = new DefaultResourceLoader();
TestSpringApplication application = new TestSpringApplication(resourceLoader, ExampleWebConfig.class);
this.context = application.run();
verify(application.getLoader()).setResourceLoader(resourceLoader);
}
use of org.springframework.core.io.DefaultResourceLoader in project spring-boot by spring-projects.
the class SpringApplicationTests method customResourceLoader.
@Test
public void customResourceLoader() throws Exception {
TestSpringApplication application = new TestSpringApplication(ExampleConfig.class);
application.setWebApplicationType(WebApplicationType.NONE);
ResourceLoader resourceLoader = new DefaultResourceLoader();
application.setResourceLoader(resourceLoader);
this.context = application.run();
verify(application.getLoader()).setResourceLoader(resourceLoader);
}
Aggregations