Show the error messages for parser exception similar to the other exceptions.
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/APIServlet.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/APIServlet.java
index fcea1ea..bb03dc3 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/APIServlet.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/APIServlet.java
@@ -1,23 +1,20 @@
package edu.uci.ics.asterix.api.http.servlet;
+import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
import java.io.PrintWriter;
-import java.io.File;
-import java.io.FileInputStream;
import java.util.List;
import java.util.logging.Level;
-import java.awt.image.BufferedImage;
+import javax.imageio.ImageIO;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import javax.activation.MimetypesFileTypeMap;
-import javax.imageio.ImageIO;
import edu.uci.ics.asterix.api.common.APIFramework.DisplayFormat;
import edu.uci.ics.asterix.api.common.SessionConfig;
@@ -88,10 +85,7 @@
out.println("<PRE>Duration of all jobs: " + duration + " sec</PRE>");
} catch (ParseException | TokenMgrError | edu.uci.ics.asterix.aqlplus.parser.TokenMgrError pe) {
GlobalConfig.ASTERIX_LOGGER.log(Level.INFO, pe.toString(), pe);
- out.println("<pre class=\"error\">");
- String errorMessage = ResultUtils.buildParseExceptionMessage(pe, query);
- out.println(errorMessage);
- out.println("</pre>");
+ ResultUtils.webUIParseExceptionHandler(out, pe, query);
} catch (Exception e) {
GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, e.getMessage(), e);
ResultUtils.webUIErrorHandler(out, e);
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultUtils.java b/asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultUtils.java
index 44a54e0..012b7b2 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultUtils.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultUtils.java
@@ -89,29 +89,20 @@
}
public static void webUIErrorHandler(PrintWriter out, Exception e) {
- String errorTemplate = "%s\n%s\n%s";
- try {
- String resourcePath = "/webui/errortemplate.html";
- InputStream is = APIServlet.class.getResourceAsStream(resourcePath);
- InputStreamReader isr = new InputStreamReader(is);
- StringBuilder sb = new StringBuilder();
- BufferedReader br = new BufferedReader(isr);
- String line = br.readLine();
-
- while (line != null) {
- sb.append(line);
- line = br.readLine();
- }
- errorTemplate = sb.toString();
- } catch (IOException ioe) {
- // If there is an IOException reading the error template html file, default value of error template is used.
- }
+ String errorTemplate = readTemplateFile("/webui/errortemplate.html", "%s\n%s\n%s");
String errorOutput = String.format(errorTemplate, extractErrorMessage(e), extractErrorSummary(e),
extractFullStackTrace(e));
out.println(errorOutput);
}
+ public static void webUIParseExceptionHandler(PrintWriter out, Throwable e, String query) {
+ String errorTemplate = readTemplateFile("/webui/errortemplate_message.html", "<pre class=\"error\">%s\n</pre>");
+
+ String errorOutput = String.format(errorTemplate, buildParseExceptionMessage(e, query));
+ out.println(errorOutput);
+ }
+
public static void apiErrorHandler(PrintWriter out, Exception e) {
int errorCode = 99;
if (e instanceof ParseException) {
@@ -211,4 +202,35 @@
e.printStackTrace(printWriter);
return stringWriter.toString();
}
+
+ /**
+ * Read the template file which is stored as a resource and return its content. If the file does not exist or is
+ * not readable return the default template string.
+ *
+ * @param path
+ * The path to the resource template file
+ * @param defaultTemplate
+ * The default template string if the template file does not exist or is not readable
+ * @return The template string to be used to render the output.
+ */
+ private static String readTemplateFile(String path, String defaultTemplate) {
+ String errorTemplate = defaultTemplate;
+ try {
+ String resourcePath = "/webui/errortemplate_message.html";
+ InputStream is = APIServlet.class.getResourceAsStream(resourcePath);
+ InputStreamReader isr = new InputStreamReader(is);
+ StringBuilder sb = new StringBuilder();
+ BufferedReader br = new BufferedReader(isr);
+ String line = br.readLine();
+
+ while (line != null) {
+ sb.append(line);
+ line = br.readLine();
+ }
+ errorTemplate = sb.toString();
+ } catch (IOException ioe) {
+ // If there is an IOException reading the error template html file, default value of error template is used.
+ }
+ return errorTemplate;
+ }
}
diff --git a/asterix-app/src/main/resources/webui/errortemplate_message.html b/asterix-app/src/main/resources/webui/errortemplate_message.html
new file mode 100644
index 0000000..ea95ccf
--- /dev/null
+++ b/asterix-app/src/main/resources/webui/errortemplate_message.html
@@ -0,0 +1,14 @@
+<div class="accordion" id="errorblock">
+ <div class="accordion-group">
+ <div class="accordion-heading">
+ <a class="accordion-toggle" data-toggle="collapse" data-parent="#errorblock" href="#levelOne">
+ Message
+ </a>
+ </div>
+ <div id="levelOne" class="accordion-body collapse in">
+ <div class="accordion-inner">
+ <pre class="error">%s</pre>
+ </div>
+ </div>
+ </div>
+</div>