Search in sources :

Example 1 with JreHttpStrategy

use of org.platformlayer.http.jre.JreHttpStrategy 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;
}
Also used : HttpPlatformLayerClient(org.platformlayer.HttpPlatformLayerClient) PrintStream(java.io.PrintStream) JreHttpStrategy(org.platformlayer.http.jre.JreHttpStrategy) HttpStrategy(org.platformlayer.http.HttpStrategy) JreHttpStrategy(org.platformlayer.http.jre.JreHttpStrategy) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with JreHttpStrategy

use of org.platformlayer.http.jre.JreHttpStrategy in project platformlayer by platformlayer.

the class PlatformLayerTestContext method buildPlatformLayerClient.

public PlatformLayerClient buildPlatformLayerClient() throws IOException, OpsException {
    PlatformLayerClient client;
    if (configFile == null) {
        throw new IllegalArgumentException("Config file is required");
    }
    InputStream is = null;
    try {
        if (!configFile.exists()) {
            throw new FileNotFoundException("Configuration file not found: " + configFile);
        }
        is = new FileInputStream(configFile);
        Properties properties = new Properties();
        try {
            properties.load(is);
        } catch (IOException e) {
            throw new IOException("Error reading configuration file", e);
        }
        HttpStrategy httpStrategy = new JreHttpStrategy();
        client = HttpPlatformLayerClient.buildUsingProperties(httpStrategy, properties);
    } finally {
        if (is != System.in) {
            IoUtils.safeClose(is);
        }
    }
    return client;
}
Also used : HttpPlatformLayerClient(org.platformlayer.HttpPlatformLayerClient) PlatformLayerClient(org.platformlayer.PlatformLayerClient) TypedPlatformLayerClient(org.platformlayer.TypedPlatformLayerClient) JreHttpStrategy(org.platformlayer.http.jre.JreHttpStrategy) HttpStrategy(org.platformlayer.http.HttpStrategy) JreHttpStrategy(org.platformlayer.http.jre.JreHttpStrategy) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Aggregations

HttpPlatformLayerClient (org.platformlayer.HttpPlatformLayerClient)2 HttpStrategy (org.platformlayer.http.HttpStrategy)2 JreHttpStrategy (org.platformlayer.http.jre.JreHttpStrategy)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PrintStream (java.io.PrintStream)1 Properties (java.util.Properties)1 PlatformLayerClient (org.platformlayer.PlatformLayerClient)1 TypedPlatformLayerClient (org.platformlayer.TypedPlatformLayerClient)1