More error handling/reporting. Normalizing auth resp
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / ClientCommandResponse.java
index 6e0d9e3..e33ce1e 100644 (file)
@@ -11,6 +11,7 @@ public class ClientCommandResponse implements HttpResponseWrapper {
   private String contentType;\r
   private byte[] content = null;\r
   private String contentString = null;\r
+  private byte[] bytesForParsing = null;\r
   \r
   public ClientCommandResponse(Pazpar2HttpResponse pz2response, ByteArrayOutputStream content) {    \r
     this.content = content.toByteArray();\r
@@ -58,7 +59,30 @@ public class ClientCommandResponse implements HttpResponseWrapper {
   public byte[] getBytes() {\r
     return content;\r
   }\r
+  \r
+  public void setResponseToParse(String parseString) {    \r
+    try {\r
+      this.bytesForParsing = parseString.getBytes("UTF-8");\r
+    } catch (UnsupportedEncodingException e) {      \r
+      e.printStackTrace();\r
+    }\r
+  }\r
 \r
+  public byte[] getResponseToParse() {\r
+    if (bytesForParsing != null) {\r
+      return bytesForParsing;\r
+    } else if (content != null) {\r
+      return content;\r
+    } else {\r
+      try {\r
+        return contentString.getBytes("UTF-8");\r
+      } catch (UnsupportedEncodingException e) {\r
+        e.printStackTrace();\r
+        return null;\r
+      }\r
+    }\r
+  }\r
+  \r
   @Override\r
   public boolean isBinary() {    \r
     return !contentType.contains("xml");\r