use of org.springframework.core.io.UrlResource in project spring-boot by spring-projects.
the class AutoConfigurationMetadataLoader method loadMetadata.
static AutoConfigurationMetadata loadMetadata(ClassLoader classLoader, String path) {
try {
Enumeration<URL> urls = (classLoader != null) ? classLoader.getResources(path) : ClassLoader.getSystemResources(path);
Properties properties = new Properties();
while (urls.hasMoreElements()) {
properties.putAll(PropertiesLoaderUtils.loadProperties(new UrlResource(urls.nextElement())));
}
return loadMetadata(properties);
} catch (IOException ex) {
throw new IllegalArgumentException("Unable to load @ConditionalOnClass location [" + path + "]", ex);
}
}
use of org.springframework.core.io.UrlResource in project Activiti by Activiti.
the class SpringConfigurationHelper method buildProcessEngine.
public static ProcessEngine buildProcessEngine(URL resource) {
log.debug("==== BUILDING SPRING APPLICATION CONTEXT AND PROCESS ENGINE =========================================");
ApplicationContext applicationContext = new GenericXmlApplicationContext(new UrlResource(resource));
Map<String, ProcessEngine> beansOfType = applicationContext.getBeansOfType(ProcessEngine.class);
if ((beansOfType == null) || (beansOfType.isEmpty())) {
throw new ActivitiException("no " + ProcessEngine.class.getName() + " defined in the application context " + resource.toString());
}
ProcessEngine processEngine = beansOfType.values().iterator().next();
log.debug("==== SPRING PROCESS ENGINE CREATED ==================================================================");
return processEngine;
}
use of org.springframework.core.io.UrlResource in project cas by apereo.
the class DynamicMetadataResolverAdapter method getResourceInputStream.
@Override
protected InputStream getResourceInputStream(final Resource resource, final String entityId) throws IOException {
if (resource instanceof UrlResource && resource.getURL().toExternalForm().toLowerCase().endsWith("/entities/")) {
HttpResponse response = null;
try {
val encodedId = EncodingUtils.urlEncode(entityId);
val url = resource.getURL().toExternalForm().concat(encodedId);
LOGGER.debug("Locating metadata input stream for [{}] via [{}]", encodedId, url);
val exec = HttpUtils.HttpExecutionRequest.builder().method(HttpMethod.GET).url(url).headers(Map.of("Accept", "*/*")).build();
response = HttpUtils.execute(exec);
if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
val result = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
return new ByteArrayInputStream(result.getBytes(StandardCharsets.UTF_8));
}
} catch (final Exception e) {
LoggingUtils.error(LOGGER, e);
} finally {
HttpUtils.close(response);
}
}
return ClosedInputStream.CLOSED_INPUT_STREAM;
}
use of org.springframework.core.io.UrlResource in project cas by apereo.
the class DynamicMetadataResolverAdapterTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val resource = new UrlResource(new URI("http://localhost:6622/entities/"));
val adapter = new DynamicMetadataResolverAdapter(Map.of(resource, new MetadataFilterChain()));
adapter.setConfigBean(configBean);
val entity = IOUtils.toString(new ClassPathResource("metadata.xml").getInputStream(), StandardCharsets.UTF_8);
try (val webServer = new MockWebServer(6622, new ByteArrayResource(entity.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
assertNotNull(adapter.getEntityDescriptorForEntityId("https://carmenwiki.osu.edu/shibboleth"));
}
}
use of org.springframework.core.io.UrlResource in project cas by apereo.
the class ResourceUtilsTests method verifyPrepareDir.
@Test
public void verifyPrepareDir() {
val url = getClass().getClassLoader().getResource("META-INF");
assertNotNull(url);
val resource = ResourceUtils.prepareClasspathResourceIfNeeded(new UrlResource(url), true, "MANIFEST");
assertNotNull(resource);
}
Aggregations