Tweaks error catching and messages.
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / data / CommandError.java
index 5e07207..7680ae5 100644 (file)
@@ -19,13 +19,13 @@ import com.indexdata.utils.XmlUtils;
  * in a new 'applicationerror' element which in turn will be embedded in a\r
  * command XML (i.e. a 'search' or a 'show' response XML)  \r
  * \r
- * The command response XML is subsequently parsed by Pazpar2ResponseParser, \r
+ * The command response XML is subsequently parsed by ResponseParser, \r
  * which will then create the CommandError object.\r
  * \r
  * @author Niels Erik\r
  *\r
  */\r
-public class CommandError extends Pazpar2ResponseData implements ErrorInterface {\r
+public class CommandError extends ResponseDataObject implements ErrorInterface {\r
 \r
   private static final long serialVersionUID = 8878776025779714122L;\r
   private static Pattern xmlDeclaration = Pattern.compile("<\\?xml.*\\?>");\r
@@ -64,19 +64,21 @@ public class CommandError extends Pazpar2ResponseData implements ErrorInterface
   \r
   /**\r
    * Creates an XML string error message, embedded in an XML string document named by the command\r
-   * This is the XML that Pazpar2ResponseParser will turn into a CommandError object. \r
+   * This is the XML that ResponseParser will turn into a CommandError object. \r
    * @param commandName\r
-   * @param exceptionName\r
+   * @param exception\r
    * @param errorMessage\r
    * @return\r
    */\r
-  public static String createErrorXml (String commandName, String exceptionName, String errorMessage) {\r
+  public static String createErrorXml (String commandName, String statusCode, String exception, String errorMessage, String response) {\r
     StringBuilder errorXml = new StringBuilder("");\r
     errorXml.append("<" + commandName + ">"+nl);\r
     errorXml.append(" <applicationerror>"+nl);\r
     errorXml.append("  <commandname>" + commandName + "</commandname>"+nl);\r
-    errorXml.append("  <exception>" + XmlUtils.escape(exceptionName) + "</exception>"+nl);    \r
-    errorXml.append("  <errormessage>" + XmlUtils.escape(errorMessage) + "</errormessage>"+nl);    \r
+    errorXml.append("  <statuscode>" + statusCode + "</statuscode>"+nl);\r
+    errorXml.append("  <exception>" + (exception != null ? XmlUtils.escape(exception) : "") + "</exception>"+nl);    \r
+    errorXml.append("  <errormessage>" + (errorMessage != null  ? XmlUtils.escape(errorMessage) : "") + "</errormessage>"+nl);\r
+    errorXml.append("  <response>" + response + "</response>" + nl);\r
     errorXml.append(" </applicationerror>"+nl);\r
     errorXml.append("</" + commandName + ">"+nl);\r
     return errorXml.toString(); \r
@@ -85,21 +87,22 @@ public class CommandError extends Pazpar2ResponseData implements ErrorInterface
   /**\r
    * Embeds a Pazpar2 (or Pazpar2 client) error response document as a child element of\r
    * a command response document (like 'search' or 'show').\r
-   * This is the XML that Pazpar2ResponseParser will turn into a CommandError object.\r
+   * This is the XML that ResponseParser will turn into a CommandError object.\r
    * \r
    * \r
    * @param commandName The name of the command during which's execution the error was encountered\r
-   * @param exceptionName The (possibly loosely defined) name of the exception that was thrown\r
+   * @param exception The (possibly loosely defined) name of the exception that was thrown\r
    * @param pazpar2ErrorXml The error document as created by Pazpar2, or the Service Proxy or \r
    *                        by the Pazpar2 client itself. \r
    * @return\r
    */\r
-  public static String insertPazpar2ErrorXml (String commandName, String exceptionName, String pazpar2ErrorXml) {\r
+  public static String insertErrorXml (String commandName, String statusCode, String exception, String pazpar2ErrorXml) {\r
     StringBuilder errorXml = new StringBuilder("");\r
     errorXml.append("<" + commandName + ">"+nl);\r
     errorXml.append(" <applicationerror>"+nl);\r
     errorXml.append("  <commandname>" + commandName + "</commandname>"+nl);\r
-    errorXml.append("  <exception>" + XmlUtils.escape(exceptionName) + "</exception>"+nl);    \r
+    errorXml.append("  <statuscode>" + statusCode + "</statuscode>"+nl);\r
+    errorXml.append("  <exception>" + XmlUtils.escape(exception) + "</exception>"+nl);    \r
     errorXml.append(xmlDeclaration.matcher(pazpar2ErrorXml).replaceAll("")+nl);    \r
     errorXml.append(" </applicationerror>"+nl);\r
     errorXml.append("</" + commandName + ">"+nl);\r