private static URL find(String resource, ClassLoader... loaders) { for (ClassLoader loader : loaders) { if (loader != null) { URL url = FileLookupFactory.newInstance().lookupFileLocation(resource, loader); if (url != null) { return url; } } } throw new IllegalArgumentException(String.format("Failed to locate %s", resource)); }
@Test public void testSchema() throws Exception { FileLookup lookup = FileLookupFactory.newInstance(); String schemaFilename = String.format("schema/infinispan-config-%s.xsd", Version.getMajorMinor()); URL schemaFile = lookup.lookupFileLocation(schemaFilename, Thread.currentThread().getContextClassLoader()); if (schemaFile == null) { throw new NullPointerException("Failed to find a schema file " + schemaFilename); } Source xmlFile = new StreamSource(lookup.lookupFile(String.format("configs/unified/%s.xml", Version.getMajorMinor()), Thread.currentThread().getContextClassLoader())); SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaFile).newValidator().validate(xmlFile); }
private static InputStream lookupFile(String configFile, ClassLoader classLoader, ClassLoader strictClassLoader) throws FileNotFoundException { FileLookup fileLookup = FileLookupFactory.newInstance(); InputStream input = fileLookup.lookupFile(configFile, classLoader); // when it's not a user-provided configuration file, it might be a default configuration file, // and if that's included in [this] module might not be visible to the ClassLoaderService: if (input == null) { // This time use lookupFile*Strict* so to provide an exception if we can't find it yet: input = fileLookup.lookupFileStrict(configFile, strictClassLoader); } return input; }
private Properties loadPropertiesFile(ClassLoader classLoader, PooledConnectionFactoryConfiguration poolConfig) { if (classLoader == null) return new Properties(); FileLookup fileLookup = FileLookupFactory.newInstance(); String propertyPath = poolConfig.propertyFile(); InputStream is = null; try { if (propertyPath != null) { is = fileLookup.lookupFileStrict(propertyPath, classLoader); } else if (classLoader.getResource(HIKARI_PROPERTIES) != null) { is = fileLookup.lookupFileStrict(HIKARI_PROPERTIES, classLoader); } if (is != null) { Properties properties = new Properties(); properties.load(is); return properties; } } catch (IOException e) { log.errorLoadingHikariCPProperties(PooledConnectionFactoryConfiguration.class.getName()); } return new Properties(); }
private InputStream findPropertiesFile() { ClassLoader cl = Thread.currentThread().getContextClassLoader(); return FileLookupFactory.newInstance() .lookupFile(RemoteCacheManager.HOTROD_CLIENT_PROPERTIES, cl); }
public static EmbeddedCacheManager fromXml(String xmlFile, boolean keepJmxDomainName) throws IOException { InputStream is = FileLookupFactory.newInstance().lookupFileStrict( xmlFile, Thread.currentThread().getContextClassLoader()); return fromStream(is, keepJmxDomainName); }
public Properties getProperties(ClassLoader cl) { InputStream is = FileLookupFactory.newInstance().lookupFile("hotrod-client.properties", cl); Properties testProperties = new Properties(); try { testProperties.load(is); return testProperties; } catch (IOException e) { throw new AssertionError(e); } }
private void logFileOverride(ClassLoader classLoader) { FileLookup fileLookup = FileLookupFactory.newInstance(); URL c3p0Props = fileLookup.lookupFileLocation(C3P0_PROPERTIES, classLoader); URL c3p0Xml = fileLookup.lookupFileLocation(C3P0_CONFIG, classLoader); if (log.isDebugEnabled()) { if (c3p0Props != null) log.debugf("Found '%s' in classpath: %s", C3P0_PROPERTIES, c3p0Props); if (c3p0Xml != null) log.debugf("Found '%s' in classpath: %s", C3P0_CONFIG, c3p0Xml); } }
public static EmbeddedCacheManager fromXml(String xmlFile, boolean keepJmxDomainName, boolean defaultParserOnly) throws IOException { InputStream is = FileLookupFactory.newInstance().lookupFileStrict( xmlFile, Thread.currentThread().getContextClassLoader()); return fromStream(is, keepJmxDomainName, defaultParserOnly, true); }
@Test public void testTimestampValidation() { final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache"; Properties p = createProperties(); InputStream configStream = FileLookupFactory.newInstance().lookupFile(DEF_INFINISPAN_CONFIG_RESOURCE, getClass().getClassLoader()); ConfigurationBuilderHolder cbh = new ParserRegistry().parse(configStream); ConfigurationBuilder builder = cbh.getNamedConfigurationBuilders().get( DEF_TIMESTAMPS_RESOURCE ); builder.clustering().cacheMode(CacheMode.INVALIDATION_SYNC); DefaultCacheManager manager = new DefaultCacheManager(cbh, true); try { TestRegionFactory factory = createRegionFactory(manager, p, null); factory.start(ServiceRegistryTestingImpl.forUnitTesting(), p); // Should have failed saying that invalidation is not allowed for timestamp caches. Exceptions.expectException(CacheException.class, () -> factory.buildTimestampsRegion(timestamps)); } finally { TestingUtil.killCacheManagers( manager ); } }
@Override public synchronized void updated(String pid, @SuppressWarnings("rawtypes") Dictionary properties) throws ConfigurationException { String config = (String) properties.get(PROP_CONFIG); if (config == null) { throw new ConfigurationException(PROP_CONFIG, "Property must be set"); } String instanceId = (String) properties.get(PROP_INSTANCE_ID); if (instanceId == null) { throw new ConfigurationException(PROP_INSTANCE_ID, "Property must be set"); } try { URL configURL = FileLookupFactory.newInstance().lookupFileLocation(config, Thread.currentThread().getContextClassLoader()); if (configURL == null) { throw new ConfigurationException(PROP_CONFIG, String.format("Failed to find the specified config '%s'.", config)); } /* Unregister and destroy the old object. */ deleted(pid); InputStream configStream = configURL.openStream(); DefaultCacheManager cacheManager = new DefaultCacheManager(configStream); cacheManager.start(); Hashtable<String, String> ht = new Hashtable<String, String>(); ht.put(PROP_INSTANCE_ID, instanceId); ht.put(PROP_CONFIG, config); ServiceRegistration<EmbeddedCacheManager> serviceRegistration = bundleContext.registerService(EmbeddedCacheManager.class, cacheManager, ht); managedRegistrations.put(pid, serviceRegistration); cacheManagers.put(pid, cacheManager); } catch (Exception e) { throw new ConfigurationException(null, "Cannot start the CacheManager", e); } }
public static EmbeddedCacheManager fromXml(String xmlFile, boolean keepJmxDomainName, boolean defaultParserOnly, boolean start) throws IOException { InputStream is = FileLookupFactory.newInstance().lookupFileStrict( xmlFile, Thread.currentThread().getContextClassLoader()); return fromStream(is, keepJmxDomainName, defaultParserOnly, start); }
JChannel channel = new JChannel(fileLookup.lookupFileLocation("default-configs/default-jgroups-udp.xml", this.getClass().getClassLoader())); channel.setName(nodeName); JGroupsTransport transport = new JGroupsTransport(channel);
@Test(dataProvider = "configurationFiles") public void testParseAndConstructUnifiedXmlFile(Path config) throws IOException { String[] parts = config.getFileName().toString().split("\\."); int major = Integer.parseInt(parts[0]); int minor = Integer.parseInt(parts[1]); ParserRegistry parserRegistry = new ParserRegistry(Thread.currentThread().getContextClassLoader(), false); try (InputStream is = FileLookupFactory.newInstance().lookupFileStrict(config.toString(), Thread.currentThread().getContextClassLoader())) { ConfigurationBuilderHolder holder = parserRegistry.parse(is); for(ParserVersionCheck check : ParserVersionCheck.values()) { if (check.isIncludedBy(major, minor)) { check.check(holder); } } } }
@Override public void run() { try { URL resource = FileLookupFactory.newInstance().lookupFileLocation(cacheConfigFile, getClass().getClassLoader()); if (resource == null) resource = new URL(cacheConfigFile);
private EmbeddedCacheManager createCacheManager(int nodeIndex) throws Exception { InputStream is = FileLookupFactory.newInstance().lookupFileStrict("async-jdbc-store-config.xml", Thread.currentThread().getContextClassLoader()); ParserRegistry parserRegistry = new ParserRegistry(Thread.currentThread().getContextClassLoader()); ConfigurationBuilderHolder holder = parserRegistry.parse(is); is.close(); for (ConfigurationBuilder builder : holder.getNamedConfigurationBuilders().values()) { for (StoreConfigurationBuilder storeBuilder : builder.persistence().stores()) { if (storeBuilder instanceof AbstractJdbcStoreConfigurationBuilder) { AbstractJdbcStoreConfigurationBuilder jdbcStoreBuilder = (AbstractJdbcStoreConfigurationBuilder) storeBuilder; jdbcStoreBuilder.simpleConnection() .driverClass("org.h2.Driver") .connectionUrl("jdbc:h2:mem:infinispan_string_based_" + nodeIndex + ";DB_CLOSE_DELAY=-1") .username("sa"); } } } return TestCacheManagerFactory.createClusteredCacheManager(holder); }
@Override protected void createCacheManagers() throws Throwable { server = PerThreadMBeanServerLookup.getThreadMBeanServer(); for (int i = 0; i < NUM_NODES; i++) { InputStream is = FileLookupFactory.newInstance().lookupFileStrict( "dynamic-indexing-distribution.xml", Thread.currentThread().getContextClassLoader()); ParserRegistry parserRegistry = new ParserRegistry( Thread.currentThread().getContextClassLoader()); ConfigurationBuilderHolder holder = parserRegistry.parse(is); // Each cache manager should use a different jmx domain and // a parallel-testsuite friendly mbean server holder.getGlobalConfigurationBuilder().globalJmxStatistics() .jmxDomain(BASE_JMX_DOMAIN + i) .mBeanServerLookup(new PerThreadMBeanServerLookup()); EmbeddedCacheManager cm = TestCacheManagerFactory .createClusteredCacheManager(holder, true); registerCacheManager(cm); Cache cache = cm.getCache(); caches.add(cache); } waitForClusterToForm(neededCacheNames); }
@Test(dataProvider="configurationFiles") public void configurationSerializationTest(Path config) throws Exception { ParserRegistry registry = new ParserRegistry(); InputStream is = FileLookupFactory.newInstance().lookupFileStrict(config.toString(), Thread.currentThread().getContextClassLoader()); ConfigurationBuilderHolder holderBefore = registry.parse(is); Map<String, Configuration> configurations = new HashMap<>();