use of org.springframework.core.io.InputStreamResource in project cas by apereo.
the class X509CredentialFactory method fromRequestBody.
@Override
public Credential fromRequestBody(final MultiValueMap<String, String> requestBody) {
final String cert = requestBody.getFirst(CERTIFICATE);
LOGGER.trace("cert: {}", cert);
if (cert == null) {
LOGGER.debug("cert is null fallback to username/passwd");
return super.fromRequestBody(requestBody);
}
final InputStream is = new ByteArrayInputStream(cert.getBytes());
final InputStreamSource iso = new InputStreamResource(is);
final X509Certificate certificate = CertUtils.readCertificate(iso);
final X509CertificateCredential credential = new X509CertificateCredential(new X509Certificate[] { certificate });
credential.setCertificate(certificate);
return credential;
}
use of org.springframework.core.io.InputStreamResource in project spring-framework by spring-projects.
the class HttpRangeTests method toResourceRegionInputStreamResource.
@Test(expected = IllegalArgumentException.class)
public void toResourceRegionInputStreamResource() {
InputStreamResource resource = mock(InputStreamResource.class);
HttpRange range = HttpRange.createByteRange(0, 9);
range.toResourceRegion(resource);
}
use of org.springframework.core.io.InputStreamResource in project opennms by OpenNMS.
the class DefaultStatisticsDaemonConfigDaoTest method testGetReports.
public void testGetReports() throws Exception {
DefaultStatisticsDaemonConfigDao dao = new DefaultStatisticsDaemonConfigDao();
InputStream in = ConfigurationTestUtils.getInputStreamForConfigFile("statsd-configuration.xml");
dao.setConfigResource(new InputStreamResource(in));
dao.afterPropertiesSet();
List<Report> reports = dao.getReports();
assertNotNull("reports list should not be null", reports);
assertTrue("at least two reports should be present but found " + reports.size(), reports.size() > 1);
assertNotNull("first report should non-null", reports.get(0));
}
use of org.springframework.core.io.InputStreamResource in project opennms by OpenNMS.
the class CollectorConfigDaoImplIT method initialize.
private void initialize() throws IOException, Exception {
System.setProperty("opennms.home", ConfigurationTestUtils.getDaemonEtcDirectory().getParentFile().getAbsolutePath());
InputStream stream = null;
stream = getInputStreamForFile("/org/opennms/netmgt/config/test-database-schema.xml");
DatabaseSchemaConfigFactory.setInstance(new DatabaseSchemaConfigFactory(stream));
stream.close();
stream = getInputStreamForFile("/org/opennms/netmgt/config/snmp-config.xml");
SnmpPeerFactory.setInstance(new SnmpPeerFactory(new InputStreamResource(stream)));
stream.close();
stream = getInputStreamForFile("/org/opennms/netmgt/config/datacollection-config.xml");
DefaultDataCollectionConfigDao dataCollectionDao = new DefaultDataCollectionConfigDao();
dataCollectionDao.setConfigResource(new InputStreamResource(stream));
dataCollectionDao.afterPropertiesSet();
DataCollectionConfigFactory.setInstance(dataCollectionDao);
stream.close();
stream = getInputStreamForFile("/org/opennms/netmgt/config/collectd-testdata.xml");
try {
new CollectdConfigFactory(stream, "localhost", false);
} finally {
stream.close();
}
}
use of org.springframework.core.io.InputStreamResource in project opennms by OpenNMS.
the class DataCollectionConfigParserTest method testPrecedence.
@Test
public void testPrecedence() throws Exception {
// Create DatacollectionConfig
Resource resource = new InputStreamResource(this.getClass().getResourceAsStream("datacollection-config-hybrid-precedence.xml"));
DatacollectionConfig config = JaxbUtils.unmarshal(DatacollectionConfig.class, resource, false);
// Validate default datacollection content
SnmpCollection collection = config.getSnmpCollections().get(0);
Assert.assertEquals(1, collection.getIncludeCollections().size());
Assert.assertEquals(0, collection.getResourceTypes().size());
Assert.assertEquals(1, collection.getSystems().getSystemDefs().size());
Assert.assertEquals(1, collection.getGroups().getGroups().size());
// Execute Parser
executeParser(collection);
// Validate SNMP Collection
// Resource Types should live on a special collection
Assert.assertEquals(0, collection.getResourceTypes().size());
Assert.assertEquals(71, collection.getSystems().getSystemDefs().size());
Assert.assertEquals(14, collection.getGroups().getGroups().size());
// This is a way to "override" the content of a specific datacollection-group.
for (Group group : collection.getGroups().getGroups()) {
if (group.getName().equals("cisco-frame-relay")) {
Assert.assertEquals(4, group.getMibObjs().size());
}
}
for (SystemDef systemDef : collection.getSystems().getSystemDefs()) {
if (systemDef.getName().equals("Cisco Routers")) {
Assert.assertEquals(3, systemDef.getCollect().getIncludeGroups().size());
}
}
}
Aggregations