1 package ca.uhn.hl7v2.hoh.encoder;
2
3 import java.nio.charset.Charset;
4 import java.nio.charset.StandardCharsets;
5 import java.util.LinkedHashMap;
6 import java.util.Map;
7
8 import ca.uhn.hl7v2.hoh.sign.ISigner;
9 import ca.uhn.hl7v2.hoh.util.StringUtils;
10 import ca.uhn.hl7v2.hoh.util.VersionLogger;
11
12 abstract class AbstractHl7OverHttp {
13 public static final String HTTP_HEADER_HL7_SIGNATURE = "HL7-Signature";
14 public static final String HTTP_HEADER_HL7_SIGNATURE_LC = HTTP_HEADER_HL7_SIGNATURE.toLowerCase();
15
16 protected static final Charset ourDefaultCharset;
17
18 static {
19 ourDefaultCharset = StandardCharsets.UTF_8;
20 VersionLogger.init();
21 }
22
23 private Charset myCharset;
24 private boolean myCharsetExplicitlySet;
25 private byte[] myData;
26 private LinkedHashMap<String, String> myHeaders;
27 private String myMessage;
28 private String myPassword;
29 private ISigner mySigner;
30 private String myPath;
31 private boolean myUsed;
32 private String myUsername;
33
34
35
36
37 public AbstractHl7OverHttp() {
38 myCharset = ourDefaultCharset;
39 }
40
41
42
43
44 public Charset getCharset() {
45 return myCharset;
46 }
47
48
49
50
51 public byte[] getData() {
52 return myData;
53 }
54
55
56
57
58 public Map<String, String> getHeaders() {
59 return myHeaders;
60 }
61
62
63
64
65 public String getMessage() {
66 return myMessage;
67 }
68
69
70
71
72
73 public String getPassword() {
74 return myPassword;
75 }
76
77
78
79
80 public ISigner getSigner() {
81 return mySigner;
82 }
83
84
85
86
87 public String getPath() {
88
89 return myPath;
90 }
91
92
93
94
95 public String getPathRaw() {
96 return myPath;
97 }
98
99
100
101
102 public String getUsername() {
103 return myUsername;
104 }
105
106
107
108
109
110 public boolean isCharsetExplicitlySet() {
111 return myCharsetExplicitlySet;
112 }
113
114
115
116
117
118
119 @Deprecated
120 public void setCharset(Charset theCharset) {
121 if (theCharset == null) {
122 throw new NullPointerException("Charset can not be null");
123 }
124 myCharsetExplicitlySet = true;
125 myCharset = theCharset;
126 }
127
128
129
130
131
132 protected void setData(byte[] theData) {
133 myData = theData;
134 }
135
136
137
138
139
140 public void setHeaders(LinkedHashMap<String, String> theHeaders) {
141 myHeaders = theHeaders;
142 }
143
144
145
146
147
148 public void setMessage(String theMessage) {
149 myMessage = theMessage;
150 }
151
152
153
154
155
156 public void setPassword(String thePassword) {
157 myPassword = thePassword;
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 }