Commit 449c7c8b 449c7c8bebbd5026f8ec43486d01fe9f1eea4fe5 by Christian Gerdes

Added support for using service names in connection strings with format

host:port/servicename:username:password
1 parent 55b12dba
/OraMonRESTgetData.class
/readme.txt
/OraMonRESTgetMetrics.class
......
......@@ -47,17 +47,31 @@ public class OraMonRESTgetData extends HttpServlet {
if(request.getParameterMap().containsKey("connectionString")) {
// We have a connection string, find the monitor or create it and call getData() on the monitor
// Check that we have a valid connection string
// Check that we have a valid connection string (added support to handle diffrent kinds of connection strings)
String[] conStrParamArray = request.getParameter("connectionString").split(":");
if(conStrParamArray.length != 5) {
Boolean serviceName = false;
if(conStrParamArray.length == 4) {
// Check if service name is used ( / instead of : )
if(conStrParamArray[1].indexOf("/") >= 0) {
serviceName = true;
}
}
if(conStrParamArray.length != 5 && serviceName == false) {
// Error, we need 5 parts in the connection string
response.setStatus(400);
response.getWriter().println("{\"error\":true,\"msg\":\"connectionString needs to be in format host:port:sid:username:password\"}");
response.getWriter().println("{\"error\":true,\"msg\":\"connectionString needs to be in format host:port:sid:username:password or host:port/servicename:username:password\"}");
return;
}
String conStr = "jdbc:oracle:thin:@" + conStrParamArray[0] + ":" + conStrParamArray[1] + ":" + conStrParamArray[2];
String usrStr = conStrParamArray[3];
String pwdStr = conStrParamArray[4];
String conStr, usrStr, pwdStr;
if(serviceName) {
conStr = "jdbc:oracle:thin:@" + conStrParamArray[0] + ":" + conStrParamArray[1];
usrStr = conStrParamArray[2];
pwdStr = conStrParamArray[3];
} else {
conStr = "jdbc:oracle:thin:@" + conStrParamArray[0] + ":" + conStrParamArray[1] + ":" + conStrParamArray[2];
usrStr = conStrParamArray[3];
pwdStr = conStrParamArray[4];
}
// Try to find the monitor in our list
OraMon monitor = Registry.findOrCreate(conStr, usrStr, pwdStr);
......
......@@ -40,13 +40,25 @@ public class OraMonRESTgetMetrics extends HttpServlet {
// We have a connection string, find the monitor and report only on that monitor
// Check that we have a valid connection string
String[] conStrParamArray = request.getParameter("connectionString").split(":");
if(conStrParamArray.length < 3) {
Boolean serviceName = false;
if(conStrParamArray.length > 1) {
// Check if service name is used ( / instead of : )
if(conStrParamArray[1].indexOf("/") >= 0) {
serviceName = true;
}
}
if(conStrParamArray.length < 3 && serviceName == false) {
// Error, we need at least 3 parts in the connection string
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().println("{\"error\":true,\"msg\":\"connectionString needs to be in format host:port:sid\"}");
response.getWriter().println("{\"error\":true,\"msg\":\"connectionString needs to be in format host:port:sid or host:port/servicename\"}");
return;
}
String conStr = "jdbc:oracle:thin:@" + conStrParamArray[0] + ":" + conStrParamArray[1] + ":" + conStrParamArray[2];
String conStr;
if(serviceName) {
conStr = "jdbc:oracle:thin:@" + conStrParamArray[0] + ":" + conStrParamArray[1];
} else {
conStr = "jdbc:oracle:thin:@" + conStrParamArray[0] + ":" + conStrParamArray[1] + ":" + conStrParamArray[2];
}
// Try to find the monitor in our list
OraMon monitor = null;
......