String htmlStrippedOfTags = resp.replaceAll("\\<[^>]*>","");\r
String errorXml = "";\r
if (htmlStrippedOfTags.toLowerCase().contains("domain")) {\r
- errorXml = CommandError.createErrorXml(command.getCommandName(), String.valueOf(pz2HttpResponse.getStatusCode()), "Error: Expected XML response from Pazpar2, got HTML with the word domain. Could be unrecognized address for Pazpar2.", htmlStrippedOfTags);\r
+ errorXml = CommandError.createErrorXml(command.getCommandName(), String.valueOf(pz2HttpResponse.getStatusCode()), "Unexpected response type from Pazpar2", "Error: Expected XML response from Pazpar2 but got HTML. The HTML contains the word domain suggesting that the Pazpar2 address was not found.", htmlStrippedOfTags);\r
} else { \r
- errorXml = CommandError.createErrorXml(command.getCommandName(), String.valueOf(pz2HttpResponse.getStatusCode()), "Error: Expected XML response from Pazpar2, got HTML", htmlStrippedOfTags);\r
+ errorXml = CommandError.createErrorXml(command.getCommandName(), String.valueOf(pz2HttpResponse.getStatusCode()), "Unexpected response type from Pazpar2: " + pz2HttpResponse.getContentType(),"Expected XML response from Pazpar2, got HTML", htmlStrippedOfTags);\r
} \r
- commandResponse = new ClientCommandResponse(pz2HttpResponse.getStatusCode(),errorXml,"text/xml"); \r
+ commandResponse = new ClientCommandResponse(pz2HttpResponse.getStatusCode(),errorXml,pz2HttpResponse.getContentType()); \r
} else {\r
String resp = baos.toString("UTF-8");\r
logger.error("Pazpar2 status code was " + pz2HttpResponse.getStatusCode() + ": " + resp);\r
} catch (IOException e) {\r
logger.error(e.getMessage());\r
e.printStackTrace();\r
- commandResponse = new ClientCommandResponse(pz2HttpResponse.getStatusCode(),CommandError.createErrorXml(command.getCommandName(), String.valueOf(pz2HttpResponse.getStatusCode()), "io", e.getMessage()),"text/xml"); \r
+ commandResponse = new ClientCommandResponse(pz2HttpResponse.getStatusCode(),CommandError.createErrorXml(command.getCommandName(), String.valueOf(pz2HttpResponse.getStatusCode()), "IO exception", e.getMessage(), ""),"text/xml"); \r
} catch (Pazpar2ErrorException e) {\r
logger.error(e.getMessage());\r
e.printStackTrace();\r
logger.error("Creating error XML");\r
- commandResponse = new ClientCommandResponse(-1,CommandError.createErrorXml(command.getCommandName(), "-1", "Pazpar2Error", e.getMessage()),"text/xml");\r
+ commandResponse = new ClientCommandResponse(500,CommandError.createErrorXml(command.getCommandName(), "", "Pazpar2Error", e.getMessage(),""),"text/xml");\r
}\r
long end = System.currentTimeMillis(); \r
logger.debug("Executed " + command.getCommandName() + " in " + (end-start) + " ms." );\r
if (handler.getContentType().contains("html")) {\r
String htmlStrippedOfTags = (new String(response,"UTF-8")).replaceAll("\\<[^>]*>","");\r
if (htmlStrippedOfTags.toLowerCase().contains("domain")) {\r
- errorXml = CommandError.createErrorXml(command.getCommandName(), String.valueOf(handler.getStatusCode()), "Error: Expected XML response from Service Proxy, got HTML with word 'domain' in, probably domain not found.", htmlStrippedOfTags); \r
+ errorXml = CommandError.createErrorXml(command.getCommandName(), String.valueOf(handler.getStatusCode()), "Unexpected response type from Service Proxy", "Expected XML from SP but got HTML. It contains the word domain suggesting that the service address was not found.", htmlStrippedOfTags); \r
} else {\r
- errorXml = CommandError.createErrorXml(command.getCommandName(), String.valueOf(handler.getStatusCode()), "Error: Expected XML response from Service Proxy, got HTML", htmlStrippedOfTags); \r
+ errorXml = CommandError.createErrorXml(command.getCommandName(), String.valueOf(handler.getStatusCode()), "Unexpected response type from Service Proxy", "Expected XML from SP but got HTML", htmlStrippedOfTags); \r
}\r
} else {\r
- errorXml = CommandError.createErrorXml(command.getCommandName(), String.valueOf(handler.getStatusCode()), "Error: Expected XML response from Service Proxy, got: "+handler.getContentType(), new String(response,"UTF-8"));\r
+ errorXml = CommandError.createErrorXml(command.getCommandName(), String.valueOf(handler.getStatusCode()), "Unexpected response type from Service Proxy: "+handler.getContentType(), "Could not process non-XML response from Service Proxy", new String(response,"UTF-8"));\r
}\r
commandResponse = new ClientCommandResponse(handler.getStatusCode(),errorXml,handler.getContentType());\r
}\r
} \r
} catch (Exception e) {\r
e.printStackTrace();\r
- commandResponse = new ClientCommandResponse(handler.getStatusCode(),CommandError.createErrorXml(command.getCommandName(), String.valueOf(handler.getStatusCode()), e.getClass().getSimpleName(), (e.getMessage()!= null ? e.getMessage() : "") + (e.getCause()!=null ? e.getCause().getMessage() : "")),handler.getContentType());\r
+ commandResponse = new ClientCommandResponse(handler.getStatusCode(),CommandError.createErrorXml(command.getCommandName(), String.valueOf(handler.getStatusCode()), e.getClass().getSimpleName(), (e.getMessage()!= null ? e.getMessage() : "") + (e.getCause()!=null ? e.getCause().getMessage() : ""), e.getStackTrace().toString()),handler.getContentType());\r
}\r
return commandResponse; \r
}\r
} catch (ClientProtocolException e) {\r
logger.error(e.getMessage());\r
e.printStackTrace();\r
- commandResponse = new ClientCommandResponse(-1,CommandError.createErrorXml("init", String.valueOf(handler.getStatusCode()), "client protocol exception", e.getMessage()),"text/xml"); \r
+ commandResponse = new ClientCommandResponse(-1,CommandError.createErrorXml("init", String.valueOf(handler.getStatusCode()), "Client protocol exception", e.getMessage(), e.getStackTrace().toString()),"text/xml"); \r
} catch (IOException e) {\r
logger.error(e.getMessage());\r
e.printStackTrace();\r
- commandResponse = new ClientCommandResponse(-1,CommandError.createErrorXml("init", String.valueOf(handler.getStatusCode()), "IO", e.getMessage()),"text/xml"); \r
+ commandResponse = new ClientCommandResponse(-1,CommandError.createErrorXml("init", String.valueOf(handler.getStatusCode()), "IO exception", e.getMessage(),e.getStackTrace().toString()),"text/xml"); \r
}\r
return commandResponse; \r
}\r
* Creates an XML string error message, embedded in an XML string document named by the command\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 statusCode, 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(" <statuscode>" + statusCode + "</statuscode>"+nl);\r
- errorXml.append(" <exception>" + (exceptionName != null ? XmlUtils.escape(exceptionName) : "") + "</exception>"+nl); \r
- errorXml.append(" <errormessage>" + (errorMessage != null ? XmlUtils.escape(errorMessage) : "") + "</errormessage>"+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
* \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 insertErrorXml (String commandName, String statusCode, 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(" <statuscode>" + statusCode + "</statuscode>"+nl);\r
- errorXml.append(" <exception>" + XmlUtils.escape(exceptionName) + "</exception>"+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