long start = System.currentTimeMillis();\r
try {\r
pz2HttpResponse = client.executeCommand(clientCommand, baos);\r
- if (pz2HttpResponse.getStatusCode()==200) {\r
+ if (pz2HttpResponse.getStatusCode()==200 && pz2HttpResponse.getContentType().contains("xml")) {\r
commandResponse = new ClientCommandResponse(pz2HttpResponse,baos);\r
} else if (pz2HttpResponse.getStatusCode()==417) {\r
logger.error("Pazpar2 status code 417: " + baos.toString("UTF-8"));\r
commandResponse = new ClientCommandResponse(pz2HttpResponse.getStatusCode(),CommandError.insertErrorXml(command.getCommandName(), String.valueOf(pz2HttpResponse.getStatusCode()) ,"Pazpar2: Expectation failed (417)", baos.toString("UTF-8")),"text/xml"); \r
+ } else if (pz2HttpResponse.getContentType().contains("html")) {\r
+ String resp = baos.toString("UTF-8");\r
+ logger.error("HTML response where XML was expected. Status code was " + pz2HttpResponse.getStatusCode() + ": " + resp);\r
+ 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
+ } else { \r
+ errorXml = CommandError.createErrorXml(command.getCommandName(), String.valueOf(pz2HttpResponse.getStatusCode()), "Error: Expected XML response from Pazpar2, got HTML", htmlStrippedOfTags);\r
+ } \r
+ commandResponse = new ClientCommandResponse(pz2HttpResponse.getStatusCode(),errorXml,"text/xml"); \r
} else {\r
String resp = baos.toString("UTF-8");\r
logger.error("Pazpar2 status code was " + pz2HttpResponse.getStatusCode() + ": " + resp);\r
- commandResponse = new ClientCommandResponse(pz2HttpResponse.getStatusCode(),CommandError.insertErrorXml(command.getCommandName(), String.valueOf(pz2HttpResponse.getStatusCode()), "Pazpar2 error occurred", baos.toString("UTF-8")),"text/xml");\r
- throw new Pazpar2ErrorException(resp,pz2HttpResponse.getStatusCode(),resp,null);\r
+ commandResponse = new ClientCommandResponse(pz2HttpResponse.getStatusCode(),CommandError.insertErrorXml(command.getCommandName(), String.valueOf(pz2HttpResponse.getStatusCode()), "Pazpar2 error occurred", baos.toString("UTF-8")),"text/xml"); \r
} \r
} catch (IOException e) {\r
logger.error(e.getMessage());\r
e.printStackTrace();\r
- commandResponse = new ClientCommandResponse(-1,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", 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(), String.valueOf(pz2HttpResponse.getStatusCode()), "io", e.getMessage()),"text/xml");\r
+ commandResponse = new ClientCommandResponse(-1,CommandError.createErrorXml(command.getCommandName(), "-1", "Pazpar2Error", e.getMessage()),"text/xml");\r
}\r
long end = System.currentTimeMillis(); \r
logger.debug("Executed " + command.getCommandName() + " in " + (end-start) + " ms." );\r