return;
}
// we have a good action and path so lets load the sql based on path and then call the appropriate sql action
if (dsPath.equalsIgnoreCase("/_system/connections")) {
Configuration configuration = ConfigurationHandler.getConfiguration("/connections");
if (configuration == null) {
response.sendError(404, "Configuration error: /connections configuration was not found!");
return;
}
if (action.equalsIgnoreCase("query"))
response.getOutputStream().println(ConnectionHandler.toJSON());
else {
// attempt to execute the connection requested action
try {response.getOutputStream().println(configuration.execute(request, _action));}
catch (Throwable ex)
{
ex.printStackTrace();
response.sendError(500, ex.toString());
}
}
}
else if (dsPath.equalsIgnoreCase("/_system/connections/test")) {
// attempt to get the parameters (assume always GET)
try {
String name = request.getParameter("name");
String type = request.getParameter("type");
if (name == null || name.length() == 0 || type == null || type.length() == 0)
throw new RuntimeException("name or type parameter was not passed! connection is invalid!");
ConnectionHandler.test(name, type, request.getParameter("jndi-context"),
request.getParameter("jndi-name"), request.getParameter("driver"), request.getParameter("url"),
request.getParameter("login"), request.getParameter("password"));
}
catch (Exception ex) {throw new ServletException(ex);}
response.getOutputStream().print("true");
response.flushBuffer();
}
else if (dsPath.equalsIgnoreCase("/_system/connections/refresh")) {
try {ConnectionHandler.destroy(); ConnectionHandler.init();}
catch (Exception ex) {log.fatal("Exception trying to refresh connection list: " + ex);}
response.getOutputStream().print("refreshed");
response.flushBuffer();
}
else if (dsPath.equalsIgnoreCase("/_system/connections/download")) {
try {
response.setContentType("application/xml");
String xml = ConnectionHandler.toXML();
response.setHeader("Content-Disposition", "attachment; filename=\"connections.xml\"");
response.setContentLength(xml.length());
response.getOutputStream().print(xml);
response.flushBuffer();
}
catch (Exception ex) {
ex.printStackTrace();
response.sendError(500, "Exception downloading connections: " + ex);
}
}
else if (dsPath.equalsIgnoreCase("/_system/connections/upload")) {
try {
// read in and parse the body content
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
XMLConnectionUploader handler = new XMLConnectionUploader();
String xml = request.getParameter("file");
// log.debug("using string: " + xml);
InputSource is = new InputSource(new StringReader(xml));
is.setEncoding("UTF-8");
saxParser.parse(is, handler);
response.getOutputStream().print(handler.getStatus());
response.flushBuffer();
}
catch (SAXParseException err) {
err.printStackTrace();
response.sendError(500, "Exception parsing connections upload file: " + err);
}
catch (Throwable t) {
t.printStackTrace();
response.sendError(500, "Exception uploading connections: " + t);
}
}
else if (dsPath.equalsIgnoreCase("/_system/configurations")) {
Configuration configuration = ConfigurationHandler.getConfiguration("/configurations");
if (configuration == null) {
response.sendError(404, "Configuration error: /configurations configuration was not found!");
return;
}
try {response.getOutputStream().println(configuration.execute(request, _action));}
catch (Throwable ex)
{
ex.printStackTrace();
response.sendError(500, ex.toString());
}