Catches init doc upload errors
authorNiels Erik G. Nielsen <nielserik@indexdata.com>
Fri, 10 May 2013 20:37:10 +0000 (16:37 -0400)
committerNiels Erik G. Nielsen <nielserik@indexdata.com>
Fri, 10 May 2013 20:37:10 +0000 (16:37 -0400)
.. embeds them in init reponse, i.e. for display in UI

src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java
src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java
src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyInterface.java
src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java

index ca76a6a..79d6153 100644 (file)
@@ -260,12 +260,29 @@ public class ServiceProxyClient implements SearchClient {
     return initDocPaths;\r
   }\r
   \r
-  public ClientCommandResponse postInitDoc(byte[] initDoc, boolean includeDebug) throws IOException {\r
+  public HttpResponseWrapper postInitDoc(byte[] initDoc, boolean includeDebug) {\r
     HttpPost post = new HttpPost(serviceUrl+"?command=init" + (includeDebug? "&includeDebug=yes" : ""));\r
     post.setEntity(new ByteArrayEntity(initDoc));\r
-    byte[] response = client.execute(post, handler);\r
-    logger.debug("Response on POST was: " + new String(response,"UTF-8"));    \r
-    return new ClientCommandResponse(handler.getStatusCode(),response,handler.getContentType());    \r
+    ClientCommandResponse commandResponse = null;\r
+    byte[] response;\r
+    try {\r
+      response = client.execute(post, handler);\r
+      if (handler.getStatusCode()==200) {\r
+        commandResponse = new ClientCommandResponse(handler.getStatusCode(),response,handler.getContentType());\r
+      } else {\r
+        logger.error("Service Proxy status code: " + handler.getStatusCode());\r
+        commandResponse = new ClientCommandResponse(handler.getStatusCode(),CommandError.insertPazpar2ErrorXml("init", "Service Proxy error occurred", new String(response,"UTF-8")),"text/xml");                               \r
+      }\r
+    } catch (ClientProtocolException e) {\r
+      logger.error(e.getMessage());\r
+      e.printStackTrace();\r
+      commandResponse = new ClientCommandResponse(-1,CommandError.createErrorXml("init", "client protocol exception", e.getMessage()),"text/xml");      \r
+    } catch (IOException e) {\r
+      logger.error(e.getMessage());\r
+      e.printStackTrace();\r
+      commandResponse = new ClientCommandResponse(-1,CommandError.createErrorXml("init", "IO", e.getMessage()),"text/xml");      \r
+    }\r
+    return commandResponse;    \r
   }\r
   \r
   public void setServiceUrl (String url) {    \r
index a2e212f..560edb6 100644 (file)
@@ -100,10 +100,10 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab
   }\r
   \r
   @Override\r
-  public ClientCommandResponse postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException {    \r
+  public HttpResponseWrapper postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException {    \r
     pz2.resetSearchAndRecordCommands();\r
     pzresp.resetAllSessionData();\r
-    ClientCommandResponse response = pz2.getSpClient().postInitDoc(initDoc,includeDebug);    \r
+    HttpResponseWrapper response = pz2.getSpClient().postInitDoc(initDoc,includeDebug);    \r
     return response;\r
   }\r
 \r
index 8c31abe..c2d8c48 100644 (file)
@@ -8,7 +8,7 @@ public interface ServiceProxyInterface  {
   public String login(String navigateTo);  \r
   public void setInitFileName (String fileName);  \r
   public String getInitFileName();\r
-  public ClientCommandResponse postInit() throws UnsupportedEncodingException, IOException;\r
-  public ClientCommandResponse postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException;\r
+  public HttpResponseWrapper postInit() throws UnsupportedEncodingException, IOException;\r
+  public HttpResponseWrapper postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException;\r
   public String getInitResponse();\r
 }\r
index 71769c7..a442805 100644 (file)
@@ -12,7 +12,6 @@ import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;\r
 import javax.inject.Named;\r
 \r
-import org.apache.commons.io.FilenameUtils;\r
 import org.apache.log4j.Logger;\r
 \r
 import com.indexdata.mkjsf.errors.ErrorHelper;\r