public class HohRawClientSimple extends AbstractRawClient implements IClientSimple
Simple raw message sender using the HL7 over HTTP specification. This implementation makes use of a single connection so it is simple, but may only be used to send one message at time (per instance).
This client uses no external threads, so it is suitable for use within J2EE containers.
DEFAULT_CHARSET, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_RESPONSE_TIMEOUT
Constructor and Description |
---|
HohRawClientSimple(String theHost,
int thePort,
String theUriPath)
Constructor
|
HohRawClientSimple(URL theUrl)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
close()
If a socket exists and it is connected, closes the socket.
|
boolean |
isAutoClose() |
boolean |
isConnected() |
static void |
main(String[] args) |
protected Socket |
provideSocket()
Subclasses must override to provide a connected socket
|
protected void |
returnSocket(Socket theSocket)
Returns the socket provided by
AbstractRawClient.provideSocket() . |
IReceivable<String> |
sendAndReceive(ISendable<?> theMessageToSend)
Sends a message, waits for the response, and then returns the response if
any
|
void |
setAutoClose(boolean theAutoClose)
Sets the auto-close property.
|
closeSocket, connect, getHost, getPort, getSocketFactory, getSoTimeout, getUriPath, getUrl, getUrlString, isKeepAlive, setAuthorizationCallback, setCharset, setHost, setKeepAlive, setPort, setResponseTimeout, setSigner, setSocketFactory, setSoTimeout, setUriPath, setUrl, setUrlString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getHost, getPort, getSocketFactory, getSoTimeout, getUriPath, getUrl, getUrlString, isKeepAlive, setAuthorizationCallback, setCharset, setHost, setKeepAlive, setPort, setResponseTimeout, setSigner, setSocketFactory, setSoTimeout, setUriPath, setUrl, setUrlString
public HohRawClientSimple(String theHost, int thePort, String theUriPath)
theHost
- The HOST (name/address). E.g. "192.168.1.1"thePort
- The PORT. E.g. "8080"theUriPath
- The URI path being requested (must either be blank or start with
'/' and contain a path). E.g. "/Apps/Receiver.jsp"public HohRawClientSimple(URL theUrl)
theUrl
- The URL to connect topublic IReceivable<String> sendAndReceive(ISendable<?> theMessageToSend) throws DecodeException, IOException, EncodeException
sendAndReceive
in class AbstractRawClient
theMessageToSend
- The message to sendDecodeException
- If a problem occurs (read error, socket disconnect, etc.)
during communication, or the response is invalid in some way.
Note that IO errors in trying to connect to the remote host
or sending the message are thrown directly (i.e. as
IOException
), but IO errors in reading the response
are thrown as DecodeExceptionIOException
- If the client is unable to connect to the remote hostEncodeException
- If a failure occurs while encoding the message into a
sendable HTTP requestpublic void close()
auto close
mode is falseclose
in interface IClientSimple
public boolean isAutoClose()
isAutoClose
in interface IClientSimple
IClientSimple.setAutoClose(boolean)
public boolean isConnected()
isConnected
in interface IClientSimple
protected Socket provideSocket() throws IOException
provideSocket
in class AbstractRawClient
IOException
protected void returnSocket(Socket theSocket)
AbstractRawClient.provideSocket()
. This method will
always be called after the request is finished.returnSocket
in class AbstractRawClient
public void setAutoClose(boolean theAutoClose)
Sets the auto-close property. If set to true (which is the default), the
client will close the socket between each request. If set to
false
, the client will keep the socket open between
requests.
If auto-close is disabled, sockets will never automatically disconnect,
which some servers may not like. The socket can still be closed by
calling IClientSimple.close()
.
setAutoClose
in interface IClientSimple
Copyright © 2012–2017 University Health Network. All rights reserved.