/** * For client configuration property keys, see * {@link com.redhat.lightblue.client.PropertiesLightblueClientConfiguration}. * * @param resourcePath Follows the semantics of * {@link java.lang.ClassLoader#getResourceAsStream(String)}, which is to * say it is a relative / separated path from the root of the class path and * should <em>not</em> start with a forward slash (/). * @param classLoader The class loader to use to find the resource. */ public static LightblueClientConfiguration fromResource(String resourcePath, ClassLoader classLoader) { InputStream propertiesStream = classLoader.getResourceAsStream(resourcePath); if (propertiesStream == null) { LOGGER.error("Could not find properties resource at " + resourcePath); throw new LightblueClientConfigurationException("Could not find properties resource " + "at " + resourcePath); } return fromInputStream(propertiesStream); }
public static LightblueClient getLightblueClient(String configPath) throws IOException { LOGGER.debug("Getting client with config {}", configPath); LightblueClient cli; if (configPath == null) { cli = new LightblueHttpClient(); } else { try (InputStream is = new FileInputStream(configPath)) { LightblueClientConfiguration config = PropertiesLightblueClientConfiguration.fromInputStream(is); cli = new LightblueHttpClient(config); } } return cli; }
/** * For client configuration property keys, see * {@link com.redhat.lightblue.client.PropertiesLightblueClientConfiguration}. * * @param pathToProperties A file system path, relative to the working * directory of the java process. If the specified path has no leading * directories, try to look for it in the classpath instead */ public static LightblueClientConfiguration fromPath(Path pathToProperties) { try { //If specified path has no leading directories, look for the correponding file on the classpath if(pathToProperties.getFileName().toString().equals(pathToProperties.toString())) { return fromResource(pathToProperties.toString()); } else { InputStream inStream = Files.newInputStream(pathToProperties); return fromInputStream(inStream); } } catch (IOException e) { LOGGER.error(pathToProperties + " could not be found/read", e); throw new LightblueClientConfigurationException("Could not read properties file from " + "path, " + pathToProperties, e); } }