X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fcom%2Findexdata%2Fmkjsf%2Fpazpar2%2FClientCommandResponse.java;h=ef221142a9f38f42cf8cce35a4e1b601d58b8076;hb=d237859420496f6d1f183d0f64bf2f78b0799fc0;hp=e33ce1ee67126e7e9cf70816211a93adc2db9bf0;hpb=5584e83f4b8d6c66999048dafcb9ce6999808894;p=mkjsf-moved-to-github.git diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/ClientCommandResponse.java b/src/main/java/com/indexdata/mkjsf/pazpar2/ClientCommandResponse.java index e33ce1e..ef22114 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/ClientCommandResponse.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/ClientCommandResponse.java @@ -5,6 +5,15 @@ import java.io.UnsupportedEncodingException; import com.indexdata.masterkey.pazpar2.client.Pazpar2HttpResponse; +/** + * Contains one HTTP response to a command executed against a Pazpar2 service in such a + * way as to give the response parser a common interface to responses, whether + * they are from Pazpar2, from the Service Proxy, or are error messages created + * by the JSF application during processing. + * + * @author Niels Erik + * + */ public class ClientCommandResponse implements HttpResponseWrapper { private int statusCode; @@ -13,18 +22,38 @@ public class ClientCommandResponse implements HttpResponseWrapper { private String contentString = null; private byte[] bytesForParsing = null; + /** + * Used for storing Pazpar2 based response + * + * @param pz2response + * @param content + */ public ClientCommandResponse(Pazpar2HttpResponse pz2response, ByteArrayOutputStream content) { this.content = content.toByteArray(); this.statusCode = pz2response.getStatusCode(); this.contentType = pz2response.getContentType(); } + /** + * Used for storing error response + * + * @param statusCode + * @param content + * @param contentType + */ public ClientCommandResponse(int statusCode, String content, String contentType) { this.statusCode = statusCode; this.contentString = content; this.contentType = contentType; } + /** + * Used for storing Service Proxy based response + * + * @param statusCode + * @param content + * @param contentType + */ public ClientCommandResponse(int statusCode, byte[] content, String contentType) { this.statusCode = statusCode; this.content = content; @@ -41,10 +70,15 @@ public class ClientCommandResponse implements HttpResponseWrapper { return contentType; } + /** + * Gets the response as a String - unless the response is marked as binary + */ @Override public String getResponseString() { if (content == null) { return contentString; + } else if (isBinary()) { + return "[binary response]"; } else { try { return new String(content,"UTF-8"); @@ -60,6 +94,13 @@ public class ClientCommandResponse implements HttpResponseWrapper { return content; } + /** + * Overrides the original response with a modified response. Used for + * one instance of a response that is not named by the command that + * created it - such as the parser expects. + * + * @param parseString + */ public void setResponseToParse(String parseString) { try { this.bytesForParsing = parseString.getBytes("UTF-8"); @@ -68,6 +109,10 @@ public class ClientCommandResponse implements HttpResponseWrapper { } } + /** + * Used by the parser to get the response for further processing. + * @return + */ public byte[] getResponseToParse() { if (bytesForParsing != null) { return bytesForParsing;