1 package ca.uhn.hl7v2.hoh.encoder;
2
3 import java.nio.charset.Charset;
4 import java.util.LinkedHashMap;
5 import java.util.Map;
6
7 import ca.uhn.hl7v2.hoh.sign.ISigner;
8 import ca.uhn.hl7v2.hoh.util.StringUtils;
9 import ca.uhn.hl7v2.hoh.util.VersionLogger;
10
11 abstract class AbstractHl7OverHttp {
12 public static final String HTTP_HEADER_HL7_SIGNATURE = "HL7-Signature";
13 public static final String HTTP_HEADER_HL7_SIGNATURE_LC = HTTP_HEADER_HL7_SIGNATURE.toLowerCase();
14
15 protected static final Charset ourDefaultCharset;
16
17 static {
18 ourDefaultCharset = Charset.forName("UTF-8");
19 VersionLogger.init();
20 }
21
22 private Charset myCharset;
23 private boolean myCharsetExplicitlySet;
24 private byte[] myData;
25 private LinkedHashMap<String, String> myHeaders;
26 private String myMessage;
27 private String myPassword;
28 private ISigner mySigner;
29 private String myPath;
30 private boolean myUsed;
31 private String myUsername;
32
33
34
35
36 public AbstractHl7OverHttp() {
37 myCharset = ourDefaultCharset;
38 }
39
40
41
42
43 public Charset getCharset() {
44 return myCharset;
45 }
46
47
48
49
50 public byte[] getData() {
51 return myData;
52 }
53
54
55
56
57 public Map<String, String> getHeaders() {
58 return myHeaders;
59 }
60
61
62
63
64 public String getMessage() {
65 return myMessage;
66 }
67
68
69
70
71
72 public String getPassword() {
73 return myPassword;
74 }
75
76
77
78
79 public ISigner getSigner() {
80 return mySigner;
81 }
82
83
84
85
86 public String getPath() {
87
88 return myPath;
89 }
90
91
92
93
94 public String getPathRaw() {
95 return myPath;
96 }
97
98
99
100
101 public String getUsername() {
102 return myUsername;
103 }
104
105
106
107
108
109 public boolean isCharsetExplicitlySet() {
110 return myCharsetExplicitlySet;
111 }
112
113
114
115
116
117
118 @Deprecated
119 public void setCharset(Charset theCharset) {
120 if (theCharset == null) {
121 throw new NullPointerException("Charset can not be null");
122 }
123 myCharsetExplicitlySet = true;
124 myCharset = theCharset;
125 }
126
127
128
129
130
131 protected void setData(byte[] theData) {
132 myData = theData;
133 }
134
135
136
137
138
139 public void setHeaders(LinkedHashMap<String, String> theHeaders) {
140 myHeaders = theHeaders;
141 }
142
143
144
145
146
147 public void setMessage(String theMessage) {
148 myMessage = theMessage;
149 }
150
151
152
153
154
155 public void setPassword(String thePassword) {
156 myPassword = thePassword;
157 }
158
159
160
161
162
163
164
165
166 public void setSigner(ISigner theSigner) {
167 mySigner = theSigner;
168 }
169
170
171
172
173
174 public void setPath(String thePath) {
175 myPath = thePath;
176 }
177
178
179
180
181
182 public void setUsername(String theUsername) {
183 if (StringUtils.isNotBlank(theUsername)) {
184 if (theUsername.contains(":")) {
185 throw new IllegalArgumentException("Username contains illegal characters");
186 }
187 }
188 myUsername = theUsername;
189 }
190
191
192
193
194 protected void verifyNotUsed() {
195 if (myUsed) {
196 throw new IllegalStateException(getClass().getSimpleName() + " may not be reused");
197 }
198 myUsed = true;
199 }
200
201
202
203
204 public static Charset getDefaultCharset() {
205 return ourDefaultCharset;
206 }
207
208 }