From 16f342276da7b336c96e285005db5c1401f2a6c6 Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Fri, 10 May 2013 16:37:10 -0400 Subject: [PATCH] Catches init doc upload errors .. embeds them in init reponse, i.e. for display in UI --- .../mkjsf/pazpar2/ServiceProxyClient.java | 25 ++++++++++++++++---- .../mkjsf/pazpar2/ServiceProxyExtensions.java | 4 ++-- .../mkjsf/pazpar2/ServiceProxyInterface.java | 4 ++-- .../indexdata/mkjsf/pazpar2/data/Responses.java | 1 - 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java index ca76a6a..79d6153 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java @@ -260,12 +260,29 @@ public class ServiceProxyClient implements SearchClient { return initDocPaths; } - public ClientCommandResponse postInitDoc(byte[] initDoc, boolean includeDebug) throws IOException { + public HttpResponseWrapper postInitDoc(byte[] initDoc, boolean includeDebug) { HttpPost post = new HttpPost(serviceUrl+"?command=init" + (includeDebug? "&includeDebug=yes" : "")); post.setEntity(new ByteArrayEntity(initDoc)); - byte[] response = client.execute(post, handler); - logger.debug("Response on POST was: " + new String(response,"UTF-8")); - return new ClientCommandResponse(handler.getStatusCode(),response,handler.getContentType()); + ClientCommandResponse commandResponse = null; + byte[] response; + try { + response = client.execute(post, handler); + if (handler.getStatusCode()==200) { + commandResponse = new ClientCommandResponse(handler.getStatusCode(),response,handler.getContentType()); + } else { + logger.error("Service Proxy status code: " + handler.getStatusCode()); + commandResponse = new ClientCommandResponse(handler.getStatusCode(),CommandError.insertPazpar2ErrorXml("init", "Service Proxy error occurred", new String(response,"UTF-8")),"text/xml"); + } + } catch (ClientProtocolException e) { + logger.error(e.getMessage()); + e.printStackTrace(); + commandResponse = new ClientCommandResponse(-1,CommandError.createErrorXml("init", "client protocol exception", e.getMessage()),"text/xml"); + } catch (IOException e) { + logger.error(e.getMessage()); + e.printStackTrace(); + commandResponse = new ClientCommandResponse(-1,CommandError.createErrorXml("init", "IO", e.getMessage()),"text/xml"); + } + return commandResponse; } public void setServiceUrl (String url) { diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java index a2e212f..560edb6 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java @@ -100,10 +100,10 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab } @Override - public ClientCommandResponse postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException { + public HttpResponseWrapper postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException { pz2.resetSearchAndRecordCommands(); pzresp.resetAllSessionData(); - ClientCommandResponse response = pz2.getSpClient().postInitDoc(initDoc,includeDebug); + HttpResponseWrapper response = pz2.getSpClient().postInitDoc(initDoc,includeDebug); return response; } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyInterface.java b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyInterface.java index 8c31abe..c2d8c48 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyInterface.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyInterface.java @@ -8,7 +8,7 @@ public interface ServiceProxyInterface { public String login(String navigateTo); public void setInitFileName (String fileName); public String getInitFileName(); - public ClientCommandResponse postInit() throws UnsupportedEncodingException, IOException; - public ClientCommandResponse postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException; + public HttpResponseWrapper postInit() throws UnsupportedEncodingException, IOException; + public HttpResponseWrapper postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException; public String getInitResponse(); } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java index 71769c7..a442805 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java @@ -12,7 +12,6 @@ import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import javax.inject.Named; -import org.apache.commons.io.FilenameUtils; import org.apache.log4j.Logger; import com.indexdata.mkjsf.errors.ErrorHelper; -- 1.7.10.4