Added support for using service names in connection strings with format
host:port/servicename:username:password
Showing
4 changed files
with
36 additions
and
9 deletions
No preview for this file type
| ... | @@ -47,17 +47,31 @@ public class OraMonRESTgetData extends HttpServlet { | ... | @@ -47,17 +47,31 @@ public class OraMonRESTgetData extends HttpServlet { |
| 47 | if(request.getParameterMap().containsKey("connectionString")) { | 47 | if(request.getParameterMap().containsKey("connectionString")) { |
| 48 | // We have a connection string, find the monitor or create it and call getData() on the monitor | 48 | // We have a connection string, find the monitor or create it and call getData() on the monitor |
| 49 | 49 | ||
| 50 | // Check that we have a valid connection string | 50 | // Check that we have a valid connection string (added support to handle diffrent kinds of connection strings) |
| 51 | String[] conStrParamArray = request.getParameter("connectionString").split(":"); | 51 | String[] conStrParamArray = request.getParameter("connectionString").split(":"); |
| 52 | if(conStrParamArray.length != 5) { | 52 | Boolean serviceName = false; |
| 53 | if(conStrParamArray.length == 4) { | ||
| 54 | // Check if service name is used ( / instead of : ) | ||
| 55 | if(conStrParamArray[1].indexOf("/") >= 0) { | ||
| 56 | serviceName = true; | ||
| 57 | } | ||
| 58 | } | ||
| 59 | if(conStrParamArray.length != 5 && serviceName == false) { | ||
| 53 | // Error, we need 5 parts in the connection string | 60 | // Error, we need 5 parts in the connection string |
| 54 | response.setStatus(400); | 61 | response.setStatus(400); |
| 55 | response.getWriter().println("{\"error\":true,\"msg\":\"connectionString needs to be in format host:port:sid:username:password\"}"); | 62 | response.getWriter().println("{\"error\":true,\"msg\":\"connectionString needs to be in format host:port:sid:username:password or host:port/servicename:username:password\"}"); |
| 56 | return; | 63 | return; |
| 57 | } | 64 | } |
| 58 | String conStr = "jdbc:oracle:thin:@" + conStrParamArray[0] + ":" + conStrParamArray[1] + ":" + conStrParamArray[2]; | 65 | String conStr, usrStr, pwdStr; |
| 59 | String usrStr = conStrParamArray[3]; | 66 | if(serviceName) { |
| 60 | String pwdStr = conStrParamArray[4]; | 67 | conStr = "jdbc:oracle:thin:@" + conStrParamArray[0] + ":" + conStrParamArray[1]; |
| 68 | usrStr = conStrParamArray[2]; | ||
| 69 | pwdStr = conStrParamArray[3]; | ||
| 70 | } else { | ||
| 71 | conStr = "jdbc:oracle:thin:@" + conStrParamArray[0] + ":" + conStrParamArray[1] + ":" + conStrParamArray[2]; | ||
| 72 | usrStr = conStrParamArray[3]; | ||
| 73 | pwdStr = conStrParamArray[4]; | ||
| 74 | } | ||
| 61 | 75 | ||
| 62 | // Try to find the monitor in our list | 76 | // Try to find the monitor in our list |
| 63 | OraMon monitor = Registry.findOrCreate(conStr, usrStr, pwdStr); | 77 | OraMon monitor = Registry.findOrCreate(conStr, usrStr, pwdStr); | ... | ... |
| ... | @@ -40,13 +40,25 @@ public class OraMonRESTgetMetrics extends HttpServlet { | ... | @@ -40,13 +40,25 @@ public class OraMonRESTgetMetrics extends HttpServlet { |
| 40 | // We have a connection string, find the monitor and report only on that monitor | 40 | // We have a connection string, find the monitor and report only on that monitor |
| 41 | // Check that we have a valid connection string | 41 | // Check that we have a valid connection string |
| 42 | String[] conStrParamArray = request.getParameter("connectionString").split(":"); | 42 | String[] conStrParamArray = request.getParameter("connectionString").split(":"); |
| 43 | if(conStrParamArray.length < 3) { | 43 | Boolean serviceName = false; |
| 44 | if(conStrParamArray.length > 1) { | ||
| 45 | // Check if service name is used ( / instead of : ) | ||
| 46 | if(conStrParamArray[1].indexOf("/") >= 0) { | ||
| 47 | serviceName = true; | ||
| 48 | } | ||
| 49 | } | ||
| 50 | if(conStrParamArray.length < 3 && serviceName == false) { | ||
| 44 | // Error, we need at least 3 parts in the connection string | 51 | // Error, we need at least 3 parts in the connection string |
| 45 | response.setStatus(HttpServletResponse.SC_BAD_REQUEST); | 52 | response.setStatus(HttpServletResponse.SC_BAD_REQUEST); |
| 46 | response.getWriter().println("{\"error\":true,\"msg\":\"connectionString needs to be in format host:port:sid\"}"); | 53 | response.getWriter().println("{\"error\":true,\"msg\":\"connectionString needs to be in format host:port:sid or host:port/servicename\"}"); |
| 47 | return; | 54 | return; |
| 48 | } | 55 | } |
| 49 | String conStr = "jdbc:oracle:thin:@" + conStrParamArray[0] + ":" + conStrParamArray[1] + ":" + conStrParamArray[2]; | 56 | String conStr; |
| 57 | if(serviceName) { | ||
| 58 | conStr = "jdbc:oracle:thin:@" + conStrParamArray[0] + ":" + conStrParamArray[1]; | ||
| 59 | } else { | ||
| 60 | conStr = "jdbc:oracle:thin:@" + conStrParamArray[0] + ":" + conStrParamArray[1] + ":" + conStrParamArray[2]; | ||
| 61 | } | ||
| 50 | 62 | ||
| 51 | // Try to find the monitor in our list | 63 | // Try to find the monitor in our list |
| 52 | OraMon monitor = null; | 64 | OraMon monitor = null; | ... | ... |
-
Please register or sign in to post a comment