/** * Returns * {@link com.redhat.lightblue.client.PropertiesLightblueClientConfiguration#fromDefault()} * by default if no context parameter with key * {@link #LIGHTBLUE_CLIENT_PROPERTIES_PATH_KEY} is specified. Otherwise, * the path is used with * {@link com.redhat.lightblue.client.PropertiesLightblueClientConfiguration#fromPath(java.nio.file.Path)}. */ protected LightblueClientConfiguration baseLightblueClientConfiguration() { String propertiesFilePath = context.getInitParameter(LIGHTBLUE_CLIENT_PROPERTIES_PATH_KEY); if (propertiesFilePath == null) { return PropertiesLightblueClientConfiguration.fromDefault(); } return PropertiesLightblueClientConfiguration.fromPath(Paths.get(propertiesFilePath)); }
/** * Assumes a lightblue-client.properties file at the root of the classpath. * * <p> * For client configuration property keys, see * {@link com.redhat.lightblue.client.PropertiesLightblueClientConfiguration}. */ public static LightblueClientConfiguration fromDefault() { return fromResource(DEFAULT_CONFIG_FILE); }
/** * 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); } }
/** * 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); }
/** * For client configuration property keys, see * {@link com.redhat.lightblue.client.PropertiesLightblueClientConfiguration}. */ public static LightblueClientConfiguration fromInputStream(InputStream propertiesStream) { try { Properties properties = new Properties(); properties.load(loadInputStream(propertiesStream)); return fromObject(properties); } catch (IOException e) { LOGGER.error(propertiesStream + " could not be read", e); throw new LightblueClientConfigurationException("Could not read properties file from " + "input stream, " + propertiesStream, e); } }
/** * This constructor will attempt to read the configuration from the * specified properties file on the file system. * * @see com.redhat.lightblue.client.PropertiesLightblueClientConfiguration */ public LightblueHttpClient(String configFilePath) { this(PropertiesLightblueClientConfiguration.fromPath(Paths.get(configFilePath))); }
/** * This constructor will attempt to read the configuration from the default * properties file on the classpath. * * @see com.redhat.lightblue.client.PropertiesLightblueClientConfiguration */ public LightblueHttpClient() { this(PropertiesLightblueClientConfiguration.fromDefault()); }
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; }
public static void main(String[] args) throws LightblueException { .fromPath(Paths.get("/home/mpatercz/redhat/lightblue-certs/client/lightblue-client-dev.properties"));
/** * Returns a resource found using the current thread's context class loader. * * <p> * 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 (/). * * @see Thread#currentThread() * @see Thread#getContextClassLoader() */ public static LightblueClientConfiguration fromResource(String resourcePath) { return fromResource(resourcePath, Thread.currentThread().getContextClassLoader()); }