Rev 187 | Rev 198 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
/**
*
*/
package net.brutex.xservices.util;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.jcs.JCS;
import org.apache.commons.jcs.access.exception.CacheException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import net.brutex.mgmt.openair.OpenAirRestConnection;
/**
* @author brosenberger
*
*/
public final class OpenAirConnection {
private final static Logger logger = LogManager.getLogger();
public static OpenAirRestConnection getOpenAirConnection() {
final PropertiesConfiguration props;
try {
final String config = "../openair.properties";
logger.info("Loading Open Air connection details from {}", config.toString());
final URL configloc = OpenAirConnection.class.getClassLoader().getResource(config);
logger.debug("Loading Open Air connection details from {}", configloc.toString());
props = new PropertiesConfiguration();
props.read( new InputStreamReader( new BufferedInputStream(configloc.openStream())) );
final String user = props.getString("user");
final String password = props.getString("password");
final String company = props.getString("company");
final String apikey = props.getString("apikey", "_PUT_HERE_");
final String namespace = props.getString("namespace", "");
final OpenAirRestConnection con;
con = new OpenAirRestConnection(JCS.getInstance("OACache"), company, user, password);
return con;
} catch (CacheException e) {
logger.error(e.getMessage(), e);
e.printStackTrace();
} catch (ConfigurationException e) {
logger.error(e.getMessage(), e);
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
return null;
}
}