90d4f2e908b50fd8faaf926eae94681d44b375b3
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / sp / ServiceProxyCommandResponse.java
1 package com.indexdata.mkjsf.pazpar2.sp;\r
2 \r
3 import java.io.UnsupportedEncodingException;\r
4 \r
5 import com.indexdata.mkjsf.pazpar2.CommandResponse;\r
6 \r
7 public class ServiceProxyCommandResponse implements CommandResponse {\r
8 \r
9   private int statusCode = 0;\r
10   private byte[] content = null;\r
11   private String responseString = null;\r
12   private String contentType = "";\r
13   \r
14   public ServiceProxyCommandResponse(int statusCode, byte[] content, String contentType) {\r
15     this.statusCode = statusCode;\r
16     this.content = content;\r
17     this.contentType = contentType;\r
18   }\r
19   \r
20   public ServiceProxyCommandResponse(int statusCode, String contentString, String contentType) {\r
21     this.statusCode = statusCode;\r
22     this.contentType = contentType;\r
23     this.responseString = contentString;\r
24   }\r
25     \r
26   @Override\r
27   public int getStatusCode() {\r
28     return statusCode;\r
29   }\r
30 \r
31   @Override\r
32   public String getContentType() {\r
33     return contentType;    \r
34   }\r
35 \r
36   @Override\r
37   public String getResponseString() {\r
38     if (content == null) {\r
39       return responseString;\r
40     } else {\r
41       try {\r
42         return new String(content,"UTF-8");\r
43       } catch (UnsupportedEncodingException e) {      \r
44         e.printStackTrace();\r
45         return "<applicationerror><error>unsupported encoding</error></applicationerror>";\r
46       }\r
47     }\r
48   }\r
49 \r
50   @Override\r
51   public byte[] getBytes() {    \r
52     return content;\r
53   }\r
54 \r
55   @Override\r
56   public boolean isBinary() {\r
57     // TODO Auto-generated method stub\r
58     return false;\r
59   }\r
60 \r
61 }\r