\r
import com.indexdata.masterkey.pazpar2.client.Pazpar2HttpResponse;\r
\r
+/**\r
+ * Contains one HTTP response to a command executed against a Pazpar2 service in such a \r
+ * way as to give the response parser a common interface to responses, whether \r
+ * they are from Pazpar2, from the Service Proxy, or are error messages created \r
+ * by the JSF application during processing.\r
+ * \r
+ * @author Niels Erik\r
+ *\r
+ */\r
public class ClientCommandResponse implements HttpResponseWrapper {\r
\r
private int statusCode;\r
private String contentString = null;\r
private byte[] bytesForParsing = null;\r
\r
+ /**\r
+ * Used for storing Pazpar2 based response\r
+ * \r
+ * @param pz2response\r
+ * @param content\r
+ */\r
public ClientCommandResponse(Pazpar2HttpResponse pz2response, ByteArrayOutputStream content) { \r
this.content = content.toByteArray();\r
this.statusCode = pz2response.getStatusCode();\r
this.contentType = pz2response.getContentType();\r
}\r
\r
+ /**\r
+ * Used for storing error response\r
+ * \r
+ * @param statusCode\r
+ * @param content\r
+ * @param contentType\r
+ */\r
public ClientCommandResponse(int statusCode, String content, String contentType) {\r
this.statusCode = statusCode;\r
this.contentString = content;\r
this.contentType = contentType;\r
}\r
\r
+ /**\r
+ * Used for storing Service Proxy based response\r
+ * \r
+ * @param statusCode\r
+ * @param content\r
+ * @param contentType\r
+ */\r
public ClientCommandResponse(int statusCode, byte[] content, String contentType) {\r
this.statusCode = statusCode;\r
this.content = content;\r
return contentType;\r
}\r
\r
+ /**\r
+ * Gets the response as a String - unless the response is marked as binary\r
+ */\r
@Override\r
public String getResponseString() {\r
if (content == null) {\r
return contentString;\r
+ } else if (isBinary()) {\r
+ return "[binary response]";\r
} else {\r
try {\r
return new String(content,"UTF-8");\r
return content;\r
}\r
\r
+ /**\r
+ * Overrides the original response with a modified response. Used for\r
+ * one instance of a response that is not named by the command that \r
+ * created it - such as the parser expects. \r
+ * \r
+ * @param parseString\r
+ */\r
public void setResponseToParse(String parseString) { \r
try {\r
this.bytesForParsing = parseString.getBytes("UTF-8");\r
}\r
}\r
\r
+ /**\r
+ * Used by the parser to get the response for further processing. \r
+ * @return\r
+ */\r
public byte[] getResponseToParse() {\r
if (bytesForParsing != null) {\r
return bytesForParsing;\r