throws IOException, FileNotFoundException, ServletException
{
Class oDriver;
Connection oConn = null;
ServletOutputStream oOut = response.getOutputStream();
QueryByForm oQBF;
String sQuerySpec;
String sColumnList;
String sWhere;
String sOrderBy;
String sShowAs;
String sStorage;
if (DebugFile.trace) {
DebugFile.writeln("Begin HttpQueryServlet.doGet(...)");
DebugFile.incIdent();
}
sStorage = Environment.getProfileVar("hipergate", "storage");
if (DebugFile.trace) DebugFile.writeln("storage=" + sStorage);
try {
oDriver = Class.forName(jdbcDriverClassName);
}
catch (ClassNotFoundException ignore) {
oDriver = null;
if (DebugFile.trace) DebugFile.writeln("Class.forName(" + jdbcDriverClassName + ") : " + ignore.getMessage());
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Database driver not found");
}
if (null==oDriver) return;
try {
sQuerySpec = request.getParameter("queryspec");
sColumnList = request.getParameter("columnlist");
if (null==sColumnList) sColumnList = "*";
sWhere = request.getParameter("where");
if (null==sWhere) sWhere = "1=1";
sOrderBy = request.getParameter("orderby");
if (null==sOrderBy) sOrderBy = "";
sShowAs = request.getParameter("showas");
if (null==sShowAs) sShowAs = "CSV";
if (DebugFile.trace) DebugFile.writeln("queryspec=" + sQuerySpec!=null ? sQuerySpec : "null");
if (DebugFile.trace) DebugFile.writeln("where=" + sWhere);
if (DebugFile.trace) DebugFile.writeln("orderby=" + sOrderBy);
if (hasSqlSignature(sColumnList)) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid Column List Syntax");
return;
}
oQBF = new QueryByForm("file://" + sStorage + "/qbf/" + sQuerySpec + ".xml");
if (DebugFile.trace) DebugFile.writeln("DriverManager.getConnection(" + jdbcURL + ",...)");
oConn = DriverManager.getConnection(jdbcURL,dbUserName,dbUserPassword);
// Send some basic http headers to support binary d/l.
if (sShowAs.equalsIgnoreCase("XLS")) {
response.setContentType("application/x-msexcel");
response.setHeader("Content-Disposition", "inline; filename=\"" + oQBF.getTitle(request.getLocale().getLanguage())+ " 1.csv\"");
}
else if (sShowAs.equalsIgnoreCase("CSV")) {
response.setContentType("text/plain");
response.setHeader("Content-Disposition","attachment; filename=\"" + oQBF.getTitle(request.getLocale().getLanguage())+ " 1.csv\"");
}
else if (sShowAs.equalsIgnoreCase("TSV")) {
response.setContentType("text/tab-separated-values");
response.setHeader("Content-Disposition","attachment; filename=\"" + oQBF.getTitle(request.getLocale().getLanguage())+ " 1.tsv\"");
}
else {
response.setContentType("text/plain");
response.setHeader("Content-Disposition", "inline; filename=\"" + oQBF.getTitle(request.getLocale().getLanguage())+ " 1.txt\"");
}
if (0==sOrderBy.length())
oQBF.queryToStream(oConn, sColumnList, oQBF.getBaseFilter(request) + " " + sWhere, oOut, sShowAs);
else
oQBF.queryToStream(oConn, sColumnList, oQBF.getBaseFilter(request) + " " + sWhere + " ORDER BY " + sOrderBy, oOut, sShowAs);
oConn.close();
oConn = null;
oOut.flush();