1 package ca.uhn.hl7v2.hoh.hapi.client;
2
3 import java.io.IOException;
4 import java.net.URL;
5 import java.nio.charset.Charset;
6
7 import ca.uhn.hl7v2.HL7Exception;
8 import ca.uhn.hl7v2.hoh.api.DecodeException;
9 import ca.uhn.hl7v2.hoh.api.EncodeException;
10 import ca.uhn.hl7v2.hoh.api.IAuthorizationClientCallback;
11 import ca.uhn.hl7v2.hoh.api.IClient;
12 import ca.uhn.hl7v2.hoh.api.IReceivable;
13 import ca.uhn.hl7v2.hoh.api.ISendable;
14 import ca.uhn.hl7v2.hoh.hapi.api.MessageReceivable;
15 import ca.uhn.hl7v2.hoh.hapi.api.MessageSendable;
16 import ca.uhn.hl7v2.hoh.raw.client.AbstractRawClient;
17 import ca.uhn.hl7v2.hoh.sign.ISigner;
18 import ca.uhn.hl7v2.hoh.sockets.ISocketFactory;
19 import ca.uhn.hl7v2.hoh.util.Validate;
20 import ca.uhn.hl7v2.model.Message;
21 import ca.uhn.hl7v2.parser.EncodingNotSupportedException;
22 import ca.uhn.hl7v2.parser.Parser;
23
24 public abstract class AbstractClient<T extends AbstractRawClient> implements IClient {
25
26 private Parser myParser;
27 private final T myRawClient;
28
29
30
31
32
33
34
35 public AbstractClient(T theRawClient) {
36 this(theRawClient, null);
37 }
38
39
40
41
42 public void setKeepAlive(boolean theKeepAlive) {
43 getRawClient().setKeepAlive(theKeepAlive);
44 }
45
46
47
48
49 public boolean isKeepAlive() {
50 return getRawClient().isKeepAlive();
51 }
52
53
54
55
56 public void setSoTimeout(int theSoTimeout) {
57 getRawClient().setSoTimeout(theSoTimeout);
58 }
59
60
61
62
63 public int getSoTimeout() {
64 return getRawClient().getSoTimeout();
65 }
66
67
68
69
70
71
72
73
74
75
76 protected AbstractClient(T theRawClient, Parser theParser) {
77 Validate.notNull(theRawClient, "rawClient");
78 myRawClient = theRawClient;
79 myParser = theParser;
80 }
81
82 public String getHost() {
83 return myRawClient.getHost();
84 }
85
86
87
88
89
90 public Parser getParser() {
91 return myParser;
92 }
93
94
95
96
97 public int getPort() {
98 return myRawClient.getPort();
99 }
100
101
102
103
104 protected T getRawClient() {
105 return myRawClient;
106 }
107
108
109
110
111 public ISocketFactory getSocketFactory() {
112 return myRawClient.getSocketFactory();
113 }
114
115
116
117
118 public String getUriPath() {
119 return myRawClient.getUriPath();
120 }
121
122
123
124
125 public URL getUrl() {
126 return myRawClient.getUrl();
127 }
128
129
130
131
132 public String getUrlString() {
133 return myRawClient.getUrlString();
134 }
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 public IReceivable<Message> sendAndReceiveMessage(ISendable<Message> theMessageToSend) throws DecodeException, IOException, EncodeException, EncodingNotSupportedException, HL7Exception {
161 IReceivable<String> response = myRawClient.sendAndReceive(theMessageToSend);
162 Parser parser = myParser != null ? myParser : theMessageToSend.getMessage().getParser();
163 return new MessageReceivable(parser.parse(response.getMessage()));
164 }
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190 public IReceivable<Message> sendAndReceiveMessage(Message theMessageToSend) throws DecodeException, IOException, EncodeException, EncodingNotSupportedException, HL7Exception {
191 MessageSendable sendable = new MessageSendable(theMessageToSend);
192 return sendAndReceiveMessage(sendable);
193 }
194
195
196
197
198 public void setAuthorizationCallback(IAuthorizationClientCallback theAuthorizationCallback) {
199 myRawClient.setAuthorizationCallback(theAuthorizationCallback);
200 }
201
202
203
204
205 public void setCharset(Charset theCharset) {
206 myRawClient.setCharset(theCharset);
207 }
208
209
210
211
212 public void setHost(String theHost) {
213 myRawClient.setHost(theHost);
214 }
215
216
217
218
219
220 public void setParser(Parser theParser) {
221 Validate.notNull(theParser, "parser");
222 myParser = theParser;
223 }
224
225
226
227
228 public void setUriPath(String thePath) {
229 myRawClient.setUriPath(thePath);
230 }
231
232
233
234
235 public void setPort(int thePort) {
236 myRawClient.setPort(thePort);
237 }
238
239
240
241
242 public void setResponseTimeout(long theResponseTimeout) {
243 myRawClient.setResponseTimeout(theResponseTimeout);
244 }
245
246
247
248
249 public void setSigner(ISigner theSigner) {
250 myRawClient.setSigner(theSigner);
251 }
252
253
254
255
256 public void setSocketFactory(ISocketFactory theSocketFactory) {
257 myRawClient.setSocketFactory(theSocketFactory);
258 }
259
260
261
262
263 public void setUrl(URL theUrl) {
264 myRawClient.setUrl(theUrl);
265 }
266
267
268
269
270 public void setUrlString(String theString) {
271 myRawClient.setUrlString(theString);
272 }
273
274 }