List of usage examples for org.springframework.core.io UrlResource UrlResource
public UrlResource(String path) throws MalformedURLException
From source file:org.jboss.fuse.wsdl2rest.util.SpringCamelContextFactory.java
/** * Create a {@link SpringCamelContext} list from the given URL *///from w ww . j a v a 2s .c o m public static List<SpringCamelContext> createCamelContextList(URL contextUrl, ClassLoader classsLoader) throws Exception { return createCamelContextList(new UrlResource(contextUrl), classsLoader); }
From source file:org.crsh.spring.SpringTestCase.java
public void testFoo() throws Exception { URL xml = SpringTestCase.class.getResource("spring.xml"); Assert.assertNotNull(xml);//ww w. ja v a2 s . co m // GenericXmlApplicationContext context = new GenericXmlApplicationContext(new UrlResource(xml)); context.start(); // SpringBootstrap bootstrap = context.getBean(SpringBootstrap.class); // Test a bit ShellFactory factory = bootstrap.getContext().getPlugin(ShellFactory.class); Shell shell = factory.create(null); assertNotNull(shell); ShellProcess process = shell.createProcess("foo_cmd"); assertNotNull(process); BaseProcessContext pc = BaseProcessContext.create(process).execute(); assertTrue(pc.getResponse() instanceof ShellResponse.Ok); String r = pc.getOutput(); assertEquals("bar", r); }
From source file:com.jbrisbin.vpc.jobsched.SpringResourceConnector.java
public URLConnection getResourceConnection(String name) throws ResourceException { Resource res = null;//from w ww. j av a2 s . co m if (name.startsWith("classpath:")) { res = new ClassPathResource(name.substring(10)); } else if (name.startsWith("http")) { try { res = new UrlResource(name); } catch (MalformedURLException e) { log.error(e.getMessage(), e); } } else { res = new FileSystemResource(name); } try { return res.getURI().toURL().openConnection(); } catch (IOException e) { log.error(e.getMessage(), e); throw new ResourceException(e); } }
From source file:com.liferay.portal.spring.extender.internal.context.ModuleApplicationContext.java
@Override public Resource[] getResources(String locationPattern) { Enumeration<URL> enumeration = _bundle.findEntries(locationPattern, "*.xml", false); List<Resource> resources = new ArrayList<>(); while (enumeration.hasMoreElements()) { resources.add(new UrlResource(enumeration.nextElement())); }/* w ww .j a v a 2 s .com*/ return resources.toArray(new Resource[resources.size()]); }
From source file:io.lavagna.common.LavagnaEnvironment.java
public LavagnaEnvironment(ConfigurableEnvironment environment) { this.environment = environment; if (environment.containsProperty(LAVAGNA_CONFIG_LOCATION) && StringUtils.isNotBlank(environment.getProperty(LAVAGNA_CONFIG_LOCATION))) { String configLocation = environment.getProperty(LAVAGNA_CONFIG_LOCATION); LOG.info("Detected config file {}, loading it", configLocation); try {/*ww w .ja v a 2s .c o m*/ environment.getPropertySources() .addFirst(new ResourcePropertySource(new UrlResource(configLocation))); } catch (IOException ioe) { throw new IllegalStateException( "error while loading external configuration file at " + configLocation, ioe); } } setSystemPropertyIfNull(environment, "datasource.dialect", "HSQLDB"); setSystemPropertyIfNull(environment, "datasource.url", "jdbc:hsqldb:mem:lavagna"); setSystemPropertyIfNull(environment, "datasource.username", "sa"); setSystemPropertyIfNull(environment, "datasource.password", ""); setSystemPropertyIfNull(environment, "spring.profiles.active", "dev"); logUse("datasource.dialect"); logUse("datasource.url"); logUse("datasource.username"); logUse("spring.profiles.active"); }
From source file:io.spring.initializr.web.project.MainControllerServiceMetadataIntegrationTests.java
@Test public void initializeRemoteConfig() throws Exception { InitializrMetadata localMetadata = metadataProvider.get(); InitializrMetadata metadata = InitializrMetadataBuilder.create() .withInitializrMetadata(new UrlResource(createUrl("/metadata/config"))).build(); // Basic assertions assertEquals(localMetadata.getDependencies().getContent().size(), metadata.getDependencies().getContent().size()); assertEquals(localMetadata.getTypes().getContent().size(), metadata.getTypes().getContent().size()); assertEquals(localMetadata.getBootVersions().getContent().size(), metadata.getBootVersions().getContent().size()); assertEquals(localMetadata.getPackagings().getContent().size(), metadata.getPackagings().getContent().size()); assertEquals(localMetadata.getJavaVersions().getContent().size(), metadata.getJavaVersions().getContent().size()); assertEquals(localMetadata.getLanguages().getContent().size(), metadata.getLanguages().getContent().size()); }
From source file:net.bioclipse.structuredb.internalbusiness.SQLMapPathBeanPostProcessor.java
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (beanName.equals("sqlMapClient") && bean instanceof SqlMapClientFactoryBean) { // path = FileLocator.toFileURL( // Structuredb.class // .getClassLoader() // .getResource("sqlMapConfig.xml") ) // .getPath(); URL url = Structuredb.class.getClassLoader().getResource("sqlMapConfig.xml"); // if( path.contains("file:") ) { // path = path.substring( 5 ); // } ((SqlMapClientFactoryBean) bean).setConfigLocation(new UrlResource(url)); }/*from www . j a v a 2 s. c o m*/ return bean; }
From source file:com.baifendian.swordfish.webserver.service.storage.FileSystemStorageService.java
@Override public Resource loadAsResource(String filename) { try {/*from ww w. j a v a 2 s .c om*/ Path file = Paths.get(filename); Resource resource = new UrlResource(file.toUri()); if (resource.exists() || resource.isReadable()) { return resource; } else { throw new StorageFileNotFoundException("Could not read file: " + filename); } } catch (MalformedURLException e) { throw new StorageFileNotFoundException("Could not read file: " + filename, e); } }
From source file:org.owasp.webgoat.i18n.LabelProvider.java
/** * <p>updatePluginResources.</p> * * @param propertyFile a {@link java.nio.file.Path} object. *///from w ww.j av a 2 s .co m public static void updatePluginResources(final Path propertyFile) { pluginLabels.setBasename("WebGoatLabels"); pluginLabels.setFallbackToSystemLocale(false); pluginLabels.setUseCodeAsDefaultMessage(true); pluginLabels.setResourceLoader(new ResourceLoader() { @Override public Resource getResource(String location) { try { return new UrlResource(propertyFile.toUri()); } catch (MalformedURLException e) { throw new RuntimeException(e); } } @Override public ClassLoader getClassLoader() { return Thread.currentThread().getContextClassLoader(); } }); pluginLabels.clearCache(); }