Skip to content
Snippets Groups Projects
Commit 42ce1377 authored by Eduardo L. Buratti's avatar Eduardo L. Buratti
Browse files

webservice: Move ws config to a separate properties file (instead of being hardcoded)

parent 734e162c
No related branches found
No related tags found
No related merge requests found
...@@ -44,30 +44,52 @@ import javax.xml.validation.SchemaFactory; ...@@ -44,30 +44,52 @@ import javax.xml.validation.SchemaFactory;
import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamSource;
public class DataSID { public class DataSID {
// enum does not work as expected inside an axis web service
// using simple constants instead
private static final int LINUX = 0; private static final int LINUX = 0;
private static final int WINDOWS = 1; private static final int WINDOWS = 1;
private static final String SA_INVENTORY = "telecenter_inventory";
private static final String SA_NET_USAGE = "net_usage";
private static final String SA_USER_HISTORY = "telecenter_user";
private static final File XML_INVENTORY_SCHEMA = new File("/home/datasid/conf/collected-data.xsd");
private static final File XML_NET_USAGE_SCHEMA = new File("/home/datasid/conf/net-collected-data.xsd");
private static final String AGENT_VERSION = "1.0.1";
private static final String AGENT_UPDATE_LINK = "http://bisimmcdev.c3sl.ufpr.br/download/datasid-1.0.1-update.run";
private static final String WINDOWS_AGENT_VERSION = "1.0.0";
private static final String WINDOWS_UPDATE_LINK = "http://bisimmcdev.c3sl.ufpr.br/download/datasid-1.0.0-update.exe";
// enum does not work as expected inside an axis web service
// using simple constants instead
private static final int ERROR = 0; private static final int ERROR = 0;
private static final int WARNING = 1; private static final int WARNING = 1;
private static final int INFO = 2; private static final int INFO = 2;
private static final int DEBUG = 3; private static final int DEBUG = 3;
private Properties prop;
private File xml_inventory_schema;
private File xml_net_usage_schema;
private String linux_agent_version;
private String linux_agent_update_link;
private String windows_agent_version;
private String windows_agent_update_link;
public DataSID() throws IOException {
try {
this.prop = new Properties();
this.prop.load(new FileInputStream("../conf/webservice.properties"));
}
catch (IOException e) {
System.err.println("Failed to load webservice.properties.");
throw e;
}
this.xml_inventory_schema = new File(this.prop.getProperty("xml_inventory_schema",
"../conf/collected-data.xsd"));
this.xml_net_usage_schema = new File(this.prop.getProperty("xml_net_usage_schema",
"../conf/net-collected-data.xsd"));
this.linux_agent_version = this.prop.getProperty("linux_agent_version", "1.0.0");
this.linux_agent_update_link = this.prop.getProperty("linux_agent_update_link",
"http://bisimmcdev.c3sl.ufpr.br/download/datasid-1.0.0-update.run");
this.windows_agent_version = this.prop.getProperty("windows_agent_version", "1.0.0");
this.windows_agent_update_link = this.prop.getProperty("windows_agent_update_link",
"http://bisimmcdev.c3sl.ufpr.br/download/datasid-1.0.0-update.exe");
}
/** /**
* Returns the name of the log level * Returns the name of the log level
* *
...@@ -135,12 +157,12 @@ public class DataSID { ...@@ -135,12 +157,12 @@ public class DataSID {
* @param OS Integer of OS Type * @param OS Integer of OS Type
* @return String * @return String
*/ */
public static String getAgentVersion(int OS) { public String getAgentVersion(int OS) {
switch(OS){ switch(OS){
case LINUX: case LINUX:
return AGENT_VERSION; return this.linux_agent_version;
case WINDOWS: case WINDOWS:
return WINDOWS_AGENT_VERSION; return this.windows_agent_version;
default: default:
return "ERROR: invalid OS"; return "ERROR: invalid OS";
} }
...@@ -155,13 +177,13 @@ public class DataSID { ...@@ -155,13 +177,13 @@ public class DataSID {
* @param OS Integer of OS Type * @param OS Integer of OS Type
* @return String * @return String
*/ */
public static String getUpdateLink(int OS) public String getUpdateLink(int OS)
{ {
switch(OS){ switch(OS){
case LINUX: case LINUX:
return AGENT_UPDATE_LINK; return this.linux_agent_update_link;
case WINDOWS: case WINDOWS:
return WINDOWS_UPDATE_LINK; return this.windows_agent_update_link;
default: default:
return "ERROR: invalid OS"; return "ERROR: invalid OS";
} }
...@@ -176,7 +198,7 @@ public class DataSID { ...@@ -176,7 +198,7 @@ public class DataSID {
* @param xmlData XML string of inventory * @param xmlData XML string of inventory
* @return String * @return String
*/ */
public static String setInventory(String xmlData) { public String setInventory(String xmlData) {
try { try {
InitialContext cxt = new InitialContext(); InitialContext cxt = new InitialContext();
DataSource ds = (DataSource) cxt.lookup("java:/comp/env/jdbc/simmc"); DataSource ds = (DataSource) cxt.lookup("java:/comp/env/jdbc/simmc");
...@@ -188,7 +210,7 @@ public class DataSID { ...@@ -188,7 +210,7 @@ public class DataSID {
throw new Exception("Failed to get a database connection!"); throw new Exception("Failed to get a database connection!");
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = factory.newSchema(XML_INVENTORY_SCHEMA); Schema schema = factory.newSchema(this.xml_inventory_schema);
JAXBContext context = JAXBContext.newInstance(CollectedData.class); JAXBContext context = JAXBContext.newInstance(CollectedData.class);
Unmarshaller unmarshaller = context.createUnmarshaller(); Unmarshaller unmarshaller = context.createUnmarshaller();
...@@ -235,8 +257,8 @@ public class DataSID { ...@@ -235,8 +257,8 @@ public class DataSID {
} }
} }
private static PreparedStatement createInventoryStatement(Connection con, CollectedData collectedData, java.sql.Date contactDate) throws SQLException, ParseException { private PreparedStatement createInventoryStatement(Connection con, CollectedData collectedData, java.sql.Date contactDate) throws SQLException, ParseException {
final String query = "INSERT INTO " + SA_INVENTORY + " " + final String query = "INSERT INTO telecenter_inventory " +
"(contact_date, machine_type, id_point, macaddr, agent_version, " + "(contact_date, machine_type, id_point, macaddr, agent_version, " +
" os_type, os_distro, os_kernel, " + " os_type, os_distro, os_kernel, " +
" processor, memory, " + " processor, memory, " +
...@@ -345,9 +367,9 @@ public class DataSID { ...@@ -345,9 +367,9 @@ public class DataSID {
return st; return st;
} }
private static PreparedStatement createUserHistoryStatement(Connection con, java.sql.Date contactDate, private PreparedStatement createUserHistoryStatement(Connection con, java.sql.Date contactDate,
int id_point, Object macaddr, String name, String login, String logout) throws SQLException { int id_point, Object macaddr, String name, String login, String logout) throws SQLException {
final String query = "INSERT INTO " + SA_USER_HISTORY + " " + final String query = "INSERT INTO telecenter_user " +
"(contact_date, id_point, macaddr, name, login, logout) VALUES " + "(contact_date, id_point, macaddr, name, login, logout) VALUES " +
"(?, ?, ?, ?, ?, ?);"; "(?, ?, ?, ?, ?, ?);";
...@@ -385,7 +407,7 @@ public class DataSID { ...@@ -385,7 +407,7 @@ public class DataSID {
* @param xmlData XML string of inventory * @param xmlData XML string of inventory
* @return String * @return String
*/ */
public static String setNetUsage(String xmlData) public String setNetUsage(String xmlData)
{ {
try { try {
InitialContext cxt = new InitialContext(); InitialContext cxt = new InitialContext();
...@@ -398,7 +420,7 @@ public class DataSID { ...@@ -398,7 +420,7 @@ public class DataSID {
throw new Exception("Failed to get a database connection!"); throw new Exception("Failed to get a database connection!");
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = factory.newSchema(XML_NET_USAGE_SCHEMA); Schema schema = factory.newSchema(this.xml_net_usage_schema);
JAXBContext context = JAXBContext.newInstance(NetCollectedData.class); JAXBContext context = JAXBContext.newInstance(NetCollectedData.class);
Unmarshaller unmarshaller = context.createUnmarshaller(); Unmarshaller unmarshaller = context.createUnmarshaller();
...@@ -446,10 +468,10 @@ public class DataSID { ...@@ -446,10 +468,10 @@ public class DataSID {
} }
} }
private static PreparedStatement createNetUsageStatement(Connection con, java.sql.Date contactDate, private PreparedStatement createNetUsageStatement(Connection con, java.sql.Date contactDate,
BigInteger idpoint, Object macaddr, String collect_date, String collect_time, long down_kbits, BigInteger idpoint, Object macaddr, String collect_date, String collect_time, long down_kbits,
BigInteger down_packages, long up_kbits, BigInteger up_packages) throws SQLException { BigInteger down_packages, long up_kbits, BigInteger up_packages) throws SQLException {
final String query = "INSERT INTO " + SA_NET_USAGE + " " + final String query = "INSERT INTO net_usage " +
"(contact_date, id_point, macaddr, collect_date, collect_time, " + "(contact_date, id_point, macaddr, collect_date, collect_time, " +
"down_kbits, down_packages, up_kbits, up_packages, ip, city_code) VALUES " + "down_kbits, down_packages, up_kbits, up_packages, ip, city_code) VALUES " +
"(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
......
xml_inventory_schema=../conf/collected-data.xsd
xml_net_usage_schema=../conf/net-collected-data.xsd
linux_agent_version=1.0.1
linux_agent_update_link=http://bisimmcdev.c3sl.ufpr.br/download/datasid-1.0.1-update.run
windows_agent_version=1.0.0
windows_agent_update_link=http://bisimmcdev.c3sl.ufpr.br/download/datasid-1.0.0-update.exe
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment