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 |
|
197 |
brianR |
12 |
import org.apache.commons.configuration2.ex.ConfigurationException;
|
|
|
13 |
import org.apache.commons.configuration2.PropertiesConfiguration;
|
187 |
brianR |
14 |
import org.apache.commons.jcs.JCS;
|
|
|
15 |
import org.apache.commons.jcs.access.exception.CacheException;
|
|
|
16 |
import org.apache.logging.log4j.LogManager;
|
|
|
17 |
import org.apache.logging.log4j.Logger;
|
|
|
18 |
|
|
|
19 |
import net.brutex.mgmt.openair.OpenAirRestConnection;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* @author brosenberger
|
|
|
23 |
*
|
|
|
24 |
*/
|
|
|
25 |
public final class OpenAirConnection {
|
|
|
26 |
private final static Logger logger = LogManager.getLogger();
|
|
|
27 |
|
|
|
28 |
public static OpenAirRestConnection getOpenAirConnection() {
|
|
|
29 |
final PropertiesConfiguration props;
|
|
|
30 |
try {
|
|
|
31 |
final String config = "../openair.properties";
|
|
|
32 |
logger.info("Loading Open Air connection details from {}", config.toString());
|
|
|
33 |
final URL configloc = OpenAirConnection.class.getClassLoader().getResource(config);
|
|
|
34 |
logger.debug("Loading Open Air connection details from {}", configloc.toString());
|
|
|
35 |
|
197 |
brianR |
36 |
props = new PropertiesConfiguration();
|
|
|
37 |
props.read( new InputStreamReader( new BufferedInputStream(configloc.openStream())) );
|
|
|
38 |
|
187 |
brianR |
39 |
final String user = props.getString("user");
|
|
|
40 |
final String password = props.getString("password");
|
|
|
41 |
final String company = props.getString("company");
|
|
|
42 |
final String apikey = props.getString("apikey", "_PUT_HERE_");
|
|
|
43 |
final String namespace = props.getString("namespace", "");
|
|
|
44 |
|
|
|
45 |
final OpenAirRestConnection con;
|
|
|
46 |
|
|
|
47 |
con = new OpenAirRestConnection(JCS.getInstance("OACache"), company, user, password);
|
|
|
48 |
return con;
|
|
|
49 |
} catch (CacheException e) {
|
|
|
50 |
logger.error(e.getMessage(), e);
|
|
|
51 |
e.printStackTrace();
|
|
|
52 |
} catch (ConfigurationException e) {
|
|
|
53 |
logger.error(e.getMessage(), e);
|
|
|
54 |
e.printStackTrace();
|
197 |
brianR |
55 |
} catch (IOException e) {
|
|
|
56 |
e.printStackTrace();
|
187 |
brianR |
57 |
} finally {
|
|
|
58 |
|
|
|
59 |
}
|
|
|
60 |
return null;
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
}
|