X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fcom%2Findexdata%2Fmkjsf%2Fpazpar2%2FPz2Client.java;h=cbdcf6bd4a09814fd42f8145484f48b8d8460a4f;hb=bcb39bd9bde8071ac3a6741ce5d51ed9e763ba9c;hp=a68e67fe245fb0f71545e994ddd2a7a4541c3a4c;hpb=249aba186bb25b673bc701f4614cfe1981cd6767;p=mkjsf-moved-to-github.git diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java index a68e67f..cbdcf6b 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java @@ -35,9 +35,10 @@ public class Pz2Client implements SearchClient { private Pazpar2ClientConfiguration cfg = null; public static final String MODULENAME = "pz2client"; public static Map DEFAULTS = new HashMap(); - Configuration config = null; + Configuration config = null; static { + DEFAULTS.put("PAZPAR2_URL", ""); DEFAULTS.put("PROXY_MODE","1"); DEFAULTS.put("SERIALIZE_REQUESTS", "false"); DEFAULTS.put("STREAMBUFF_SIZE", "4096"); @@ -50,7 +51,7 @@ public class Pz2Client implements SearchClient { public void configure(ConfigurationReader configReader) throws ConfigurationException { logger.info(Utils.objectId(this) + " is configuring using the provided " + Utils.objectId(configReader)); try { - config = configReader.getConfiguration(this); + config = configReader.getConfiguration(this); cfg = new Pazpar2ClientConfiguration(new ConfigurationGetter(config)); } catch (ProxyErrorException pe) { logger.error("Could not configure Pazpar2 client: " + pe.getMessage()); @@ -88,8 +89,8 @@ public class Pz2Client implements SearchClient { } @Override - public CommandResponse executeCommand(Pazpar2Command command) { - Pz2CommandResponse commandResponse = null; + public HttpResponseWrapper executeCommand(Pazpar2Command command) { + ClientCommandResponse commandResponse = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); ClientCommand clientCommand = new ClientCommand(command.getCommandName(), command.getEncodedQueryString()); Pazpar2HttpResponse pz2HttpResponse = null; @@ -97,25 +98,25 @@ public class Pz2Client implements SearchClient { try { pz2HttpResponse = client.executeCommand(clientCommand, baos); if (pz2HttpResponse.getStatusCode()==200) { - commandResponse = new Pz2CommandResponse(pz2HttpResponse,baos); + commandResponse = new ClientCommandResponse(pz2HttpResponse,baos); } else if (pz2HttpResponse.getStatusCode()==417) { logger.error("Pazpar2 status code 417: " + baos.toString("UTF-8")); - commandResponse = new Pz2CommandResponse(pz2HttpResponse.getStatusCode(),CommandError.insertPazpar2ErrorXml(command.getCommandName(), "Pazpar2: Expectation failed (417)", baos.toString("UTF-8")),"text/xml"); + commandResponse = new ClientCommandResponse(pz2HttpResponse.getStatusCode(),CommandError.insertPazpar2ErrorXml(command.getCommandName(), "Pazpar2: Expectation failed (417)", baos.toString("UTF-8")),"text/xml"); } else { String resp = baos.toString("UTF-8"); logger.error("Pazpar2 status code was " + pz2HttpResponse.getStatusCode() + ": " + resp); - commandResponse = new Pz2CommandResponse(pz2HttpResponse.getStatusCode(),CommandError.insertPazpar2ErrorXml(command.getCommandName(), "Pazpar2 error occurred", baos.toString("UTF-8")),"text/xml"); + commandResponse = new ClientCommandResponse(pz2HttpResponse.getStatusCode(),CommandError.insertPazpar2ErrorXml(command.getCommandName(), "Pazpar2 error occurred", baos.toString("UTF-8")),"text/xml"); throw new Pazpar2ErrorException(resp,pz2HttpResponse.getStatusCode(),resp,null); } } catch (IOException e) { logger.error(e.getMessage()); e.printStackTrace(); - commandResponse = new Pz2CommandResponse(-1,CommandError.createErrorXml(command.getCommandName(), "io", e.getMessage()),"text/xml"); + commandResponse = new ClientCommandResponse(-1,CommandError.createErrorXml(command.getCommandName(), "io", e.getMessage()),"text/xml"); } catch (Pazpar2ErrorException e) { logger.error(e.getMessage()); e.printStackTrace(); logger.error("Creating error XML"); - commandResponse = new Pz2CommandResponse(-1,CommandError.createErrorXml(command.getCommandName(), "io", e.getMessage()),"text/xml"); + commandResponse = new ClientCommandResponse(-1,CommandError.createErrorXml(command.getCommandName(), "io", e.getMessage()),"text/xml"); } long end = System.currentTimeMillis(); logger.debug("Executed " + command.getCommandName() + " in " + (end-start) + " ms." ); @@ -175,4 +176,20 @@ public class Pz2Client implements SearchClient { return config; } + @Override + public String getServiceUrl() { + return cfg.PAZPAR2_URL; + } + + @Override + public boolean hasServiceUrl() { + return cfg.PAZPAR2_URL != null && cfg.PAZPAR2_URL.length()>0; + } + + @Override + public void setServiceUrl (String serviceUrl) { + cfg.PAZPAR2_URL = serviceUrl; + + } + }