use of org.platformlayer.HttpPlatformLayerClient in project platformlayer by platformlayer.
the class ConfigurationOptions method buildPlatformLayerClient.
public PlatformLayerClient buildPlatformLayerClient() throws IOException, OpsException {
HttpPlatformLayerClient client;
if (configFile == null) {
throw new IllegalArgumentException("Config file is required");
}
InputStream is = null;
try {
if (configFile.equals("-")) {
// Read from stdin
// Don't auto-close it: that terminates nailgun
is = new NoCloseInputStream(System.in);
} else {
if (isServerMode()) {
throw new IllegalArgumentException("Must pass config file over stdin in server mode");
}
File file = IoUtils.resolve(configFile);
if (!file.exists()) {
throw new FileNotFoundException("Configuration file not found: " + file);
}
is = new FileInputStream(file);
}
final Properties properties = new Properties();
try {
properties.load(is);
} catch (IOException e) {
throw new IOException("Error reading configuration file", e);
}
if (properties.getProperty("platformlayer.username") == null) {
throw new CliException("User property not set in configuration file");
}
if (debug) {
client = buildPlatformLayerClient(properties, debug);
} else {
String propertiesKey = PropertyUtils.serialize(properties);
try {
client = platformLayerClientCache.get(propertiesKey, new Callable<HttpPlatformLayerClient>() {
@Override
public HttpPlatformLayerClient call() throws Exception {
return buildPlatformLayerClient(properties, false);
}
});
} catch (ExecutionException e) {
throw new CliException("Error building platformlayer client", e);
}
}
} finally {
if (is != System.in) {
Closeables.closeQuietly(is);
}
}
return client;
}
use of org.platformlayer.HttpPlatformLayerClient in project platformlayer by platformlayer.
the class ConfigurationOptions method buildPlatformLayerClient.
private HttpPlatformLayerClient buildPlatformLayerClient(Properties properties, boolean debug) {
HttpStrategy httpStrategy = new JreHttpStrategy();
// HttpStrategy httpStrategy = new ApacheCommonsHttpStrategy();
HttpPlatformLayerClient client = HttpPlatformLayerClient.buildUsingProperties(httpStrategy, properties);
if (debug) {
client.setDebug(System.err);
} else {
// We don't want debug messages to interfere with our output
// TODO: Fix this so debug output doesn't interfere (stderr?)
// TODO: Maybe output the debug info only in case of failure?
ByteArrayOutputStream baos = new ByteArrayOutputStream();
client.setDebug(new PrintStream(baos));
}
return client;
}
Aggregations