Subversion Repositories XServices

Rev

Rev 198 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
187 brianR 1
/**
2
 *
3
 */
4
package net.brutex.xservices.util;
5
 
197 brianR 6
import java.io.BufferedInputStream;
7
import java.io.BufferedReader;
8
import java.io.IOException;
9
import java.io.InputStreamReader;
187 brianR 10
import java.net.URL;
11
 
199 brianR 12
import lombok.extern.slf4j.Slf4j;
197 brianR 13
import org.apache.commons.configuration2.ex.ConfigurationException;
14
import org.apache.commons.configuration2.PropertiesConfiguration;
187 brianR 15
import org.apache.commons.jcs.JCS;
16
import org.apache.commons.jcs.access.exception.CacheException;
17
 
199 brianR 18
 
187 brianR 19
import net.brutex.mgmt.openair.OpenAirRestConnection;
20
 
21
/**
22
 * @author brosenberger
23
 *
24
 */
199 brianR 25
@Slf4j
187 brianR 26
public final class OpenAirConnection {
199 brianR 27
 
187 brianR 28
 
29
	public static OpenAirRestConnection getOpenAirConnection() {
30
		final PropertiesConfiguration props;
31
		try {
32
			final String config = "../openair.properties";
199 brianR 33
			log.info("Loading Open Air connection details from {}", config.toString());
187 brianR 34
			final URL configloc = OpenAirConnection.class.getClassLoader().getResource(config);
199 brianR 35
			log.debug("Loading Open Air connection details from {}", configloc.toString());
187 brianR 36
 
197 brianR 37
			props = new PropertiesConfiguration();
38
			props.read( new InputStreamReader( new BufferedInputStream(configloc.openStream())) );
39
 
187 brianR 40
			final String user = props.getString("user");
41
			final String password = props.getString("password");
42
			final String company = props.getString("company");
43
			final String apikey = props.getString("apikey", "_PUT_HERE_");
44
			final String namespace = props.getString("namespace", "");
45
 
46
			final OpenAirRestConnection con;
47
 
48
			con = new OpenAirRestConnection(JCS.getInstance("OACache"), company, user, password);
49
			return con;
199 brianR 50
		} catch (CacheException | ConfigurationException e) {
51
			log.error(e.getMessage(), e);
187 brianR 52
			e.printStackTrace();
197 brianR 53
		} catch (IOException e) {
54
			e.printStackTrace();
187 brianR 55
		} finally {
56
 
57
		}
58
		return null;
59
	}
60
 
61
 
62
}