private Pazpar2ClientConfiguration cfg = null;\r
public static final String MODULENAME = "pz2client";\r
public static Map<String,String> DEFAULTS = new HashMap<String,String>();\r
- Configuration config = null;\r
+ Configuration config = null; \r
\r
static { \r
+ DEFAULTS.put("PAZPAR2_URL", "");\r
DEFAULTS.put("PROXY_MODE","1");\r
DEFAULTS.put("SERIALIZE_REQUESTS", "false");\r
DEFAULTS.put("STREAMBUFF_SIZE", "4096");\r
public void configure(ConfigurationReader configReader) throws ConfigurationException { \r
logger.info(Utils.objectId(this) + " is configuring using the provided " + Utils.objectId(configReader));\r
try {\r
- config = configReader.getConfiguration(this);\r
+ config = configReader.getConfiguration(this); \r
cfg = new Pazpar2ClientConfiguration(new ConfigurationGetter(config));\r
} catch (ProxyErrorException pe) {\r
logger.error("Could not configure Pazpar2 client: " + pe.getMessage());\r
}\r
\r
@Override\r
- public CommandResponse executeCommand(Pazpar2Command command) {\r
- Pz2CommandResponse commandResponse = null;\r
+ public HttpResponseWrapper executeCommand(Pazpar2Command command) {\r
+ ClientCommandResponse commandResponse = null;\r
ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
ClientCommand clientCommand = new ClientCommand(command.getCommandName(), command.getEncodedQueryString());\r
Pazpar2HttpResponse pz2HttpResponse = null;\r
try {\r
pz2HttpResponse = client.executeCommand(clientCommand, baos);\r
if (pz2HttpResponse.getStatusCode()==200) {\r
- commandResponse = new Pz2CommandResponse(pz2HttpResponse,baos);\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 Pz2CommandResponse(pz2HttpResponse.getStatusCode(),CommandError.insertPazpar2ErrorXml(command.getCommandName(), "Pazpar2: Expectation failed (417)", baos.toString("UTF-8")),"text/xml"); \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 {\r
String resp = baos.toString("UTF-8");\r
logger.error("Pazpar2 status code was " + pz2HttpResponse.getStatusCode() + ": " + resp);\r
- commandResponse = new Pz2CommandResponse(pz2HttpResponse.getStatusCode(),CommandError.insertPazpar2ErrorXml(command.getCommandName(), "Pazpar2 error occurred", baos.toString("UTF-8")),"text/xml");\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
} \r
} catch (IOException e) {\r
logger.error(e.getMessage());\r
e.printStackTrace();\r
- commandResponse = new Pz2CommandResponse(-1,CommandError.createErrorXml(command.getCommandName(), "io", e.getMessage()),"text/xml"); \r
+ commandResponse = new ClientCommandResponse(-1,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 Pz2CommandResponse(-1,CommandError.createErrorXml(command.getCommandName(), "io", e.getMessage()),"text/xml");\r
+ commandResponse = new ClientCommandResponse(-1,CommandError.createErrorXml(command.getCommandName(), String.valueOf(pz2HttpResponse.getStatusCode()), "io", e.getMessage()),"text/xml");\r
}\r
long end = System.currentTimeMillis(); \r
logger.debug("Executed " + command.getCommandName() + " in " + (end-start) + " ms." );\r
return config;\r
}\r
\r
+ @Override\r
+ public String getServiceUrl() {\r
+ return cfg.PAZPAR2_URL; \r
+ }\r
+\r
+ @Override\r
+ public boolean hasServiceUrl() {\r
+ return cfg.PAZPAR2_URL != null && cfg.PAZPAR2_URL.length()>0;\r
+ }\r
+ \r
+ @Override \r
+ public void setServiceUrl (String serviceUrl) { \r
+ cfg.PAZPAR2_URL = serviceUrl;\r
+ \r
+ }\r
+\r
}\r