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 | 5 | 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 | 5 | ourDefaultCharset = Charset.forName("UTF-8"); |
19 | 5 | VersionLogger.init(); |
20 | 5 | } |
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 | 900 | public AbstractHl7OverHttp() { |
37 | 900 | myCharset = ourDefaultCharset; |
38 | 900 | } |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
public Charset getCharset() { |
44 | 1340 | return myCharset; |
45 | |
} |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
public byte[] getData() { |
51 | 1080 | return myData; |
52 | |
} |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
public Map<String, String> getHeaders() { |
58 | 5935 | return myHeaders; |
59 | |
} |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
public String getMessage() { |
65 | 2020 | return myMessage; |
66 | |
} |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public String getPassword() { |
73 | 645 | return myPassword; |
74 | |
} |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
public ISigner getSigner() { |
80 | 1240 | return mySigner; |
81 | |
} |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
public String getPath() { |
87 | |
|
88 | 665 | return myPath; |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public String getPathRaw() { |
95 | 125 | return myPath; |
96 | |
} |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
public String getUsername() { |
102 | 1015 | return myUsername; |
103 | |
} |
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
public boolean isCharsetExplicitlySet() { |
110 | 60 | return myCharsetExplicitlySet; |
111 | |
} |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
@Deprecated |
119 | |
public void setCharset(Charset theCharset) { |
120 | 660 | if (theCharset == null) { |
121 | 0 | throw new NullPointerException("Charset can not be null"); |
122 | |
} |
123 | 660 | myCharsetExplicitlySet = true; |
124 | 660 | myCharset = theCharset; |
125 | 660 | } |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
protected void setData(byte[] theData) { |
132 | 390 | myData = theData; |
133 | 390 | } |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
public void setHeaders(LinkedHashMap<String, String> theHeaders) { |
140 | 805 | myHeaders = theHeaders; |
141 | 805 | } |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
public void setMessage(String theMessage) { |
148 | 690 | myMessage = theMessage; |
149 | 690 | } |
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
public void setPassword(String thePassword) { |
156 | 455 | myPassword = thePassword; |
157 | 455 | } |
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
public void setSigner(ISigner theSigner) { |
167 | 420 | mySigner = theSigner; |
168 | 420 | } |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
public void setPath(String thePath) { |
175 | 455 | myPath = thePath; |
176 | 455 | } |
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
public void setUsername(String theUsername) { |
183 | 455 | if (StringUtils.isNotBlank(theUsername)) { |
184 | 455 | if (theUsername.contains(":")) { |
185 | 0 | throw new IllegalArgumentException("Username contains illegal characters"); |
186 | |
} |
187 | |
} |
188 | 455 | myUsername = theUsername; |
189 | 455 | } |
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
protected void verifyNotUsed() { |
195 | 900 | if (myUsed) { |
196 | 0 | throw new IllegalStateException(getClass().getSimpleName() + " may not be reused"); |
197 | |
} |
198 | 900 | myUsed = true; |
199 | 900 | } |
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
public static Charset getDefaultCharset() { |
205 | 250 | return ourDefaultCharset; |
206 | |
} |
207 | |
|
208 | |
} |