+ /**\r
+ * Executes the command and parses the response to create data objects.\r
+ * If the parsed response is of a known type it will be cached in 'pzresp'\r
+ * \r
+ * @param commandName The command to be executed\r
+ * @return An XML response parsed to form a response data object\r
+ */\r
+ protected ResponseDataObject doCommand(String commandName) {\r
+ if (pzreq.getCommand(commandName).spOnly() && isPazpar2Service()) {\r
+ logger.warn("Skipping " + commandName + " - SP-only command, un-supported by Pazpar2");\r
+ return new ResponseDataObject();\r
+ } else {\r
+ ResponseDataObject responseObject = null; \r
+ logger.info("Request "+commandName + ": "+ pzreq.getCommand("search").toString());\r
+ Pazpar2Command command = pzreq.getCommand(commandName);\r
+ long start = System.currentTimeMillis();\r
+ HttpResponseWrapper commandResponse = searchClient.executeCommand(command);\r
+ long end = System.currentTimeMillis();\r
+ logger.debug("Executed " + command.getCommandName() + " in " + (end-start) + " ms." );\r
+ responseLogger.debug("Response was: " + commandResponse.getResponseString());\r
+ if (commandResponse.getContentType().contains("xml")) {\r
+ responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse)commandResponse);\r
+ if (ResponseParser.docTypes.contains(responseObject.getType())) {\r
+ logger.debug("Storing " + responseObject.getType() + " in pzresp. ");\r
+ pzresp.put(commandName, responseObject);\r
+ } else {\r
+ if (commandName.equals("record")) {\r
+ logger.debug("Command was 'record' but response not '<record>' - assuming raw record response.");\r
+ ResponseDataObject recordResponse = new RecordResponse(); \r
+ recordResponse.setType("record");\r
+ recordResponse.setXml(responseObject.getXml()); \r
+ recordResponse.setAttribute("activeclients", "0");\r
+ pzresp.put("record", recordResponse); \r
+ } \r
+ }\r
+ } else if (commandResponse.isBinary()) {\r
+ responseObject = new RecordResponse(); \r
+ responseObject.setType(commandName);\r
+ logger.info("Binary response");\r
+ responseObject.setAttribute("activeclients", "0");\r
+ responseObject.setXml("<record>binary response</record>");\r
+ responseObject.setBinary(commandResponse.getBytes());\r
+ pzresp.put("record", responseObject);\r
+ } else {\r
+ logger.error("Response was not found to be XML or binary. The response was not handled.");\r
+ }\r
+ return responseObject;\r
+ }\r