public abstract class AbstractRawClient extends Object implements IClient
Modifier and Type | Field and Description |
---|---|
static Charset |
DEFAULT_CHARSET
The default charset encoding (UTF-8)
|
static int |
DEFAULT_CONNECTION_TIMEOUT
The default connection timeout in milliseconds: 10000
|
static int |
DEFAULT_RESPONSE_TIMEOUT
The default number of milliseconds to wait before timing out waiting for
a response: 60000
|
Constructor and Description |
---|
AbstractRawClient()
Constructor
|
AbstractRawClient(String theHost,
int thePort,
String thePath)
Constructor
|
AbstractRawClient(URL theUrl)
Constructor
|
Modifier and Type | Method and Description |
---|---|
protected void |
closeSocket(Socket theSocket) |
protected Socket |
connect() |
String |
getHost()
Getter for the host (e.g.
|
int |
getPort()
Getter for the port (e.g.
|
ISocketFactory |
getSocketFactory()
Returns the socket factory used by this client
|
int |
getSoTimeout()
Returns the TCP SO Timeout setting for new connections
|
String |
getUriPath()
Getter for the "Path" portion of the URL.
|
URL |
getUrl()
Getter for the URL to send messages to.
|
String |
getUrlString()
Getter for the URL to send messages to.
|
boolean |
isKeepAlive()
Returns the TCP KeepAlive flag for new connections
|
protected abstract Socket |
provideSocket()
Subclasses must override to provide a connected socket
|
protected abstract void |
returnSocket(Socket theSocket)
Returns the socket provided by
provideSocket() . |
IReceivable<String> |
sendAndReceive(ISendable<?> theMessageToSend)
Sends a message, waits for the response, and then returns the response if
any
|
void |
setAuthorizationCallback(IAuthorizationClientCallback theAuthorizationCallback)
If set, provides a callback which will be used to se the username and
password associated with the request
|
void |
setCharset(Charset theCharset)
Sets the charset to use for requests from this client.
|
void |
setHost(String theHost)
Setter for the host (e.g.
|
void |
setKeepAlive(boolean theKeepAlive)
Configures the TCP KeepAlive flag for new connections
|
void |
setPort(int thePort)
Getter for the port (e.g.
|
void |
setResponseTimeout(long theResponseTimeout)
Sets the number of milliseconds before timing out.
|
void |
setSigner(ISigner theSigner) |
void |
setSocketFactory(ISocketFactory theSocketFactory)
Sets the socket factory used by this client.
|
void |
setSoTimeout(int theSoTimeout)
Sets the TCP SO Timeout setting for new connections
|
void |
setUriPath(String thePath)
Setter for the "Path" portion of the URL.
|
void |
setUrl(URL theUrl)
Setter for the URL to send messages to.
|
void |
setUrlString(String theString)
Setter for the URL to send messages to.
|
public static final Charset DEFAULT_CHARSET
public static final int DEFAULT_CONNECTION_TIMEOUT
public static final int DEFAULT_RESPONSE_TIMEOUT
public AbstractRawClient()
public AbstractRawClient(String theHost, int thePort, String thePath)
theHost
- The HOST (name/address). E.g. "192.168.1.1"thePort
- The PORT. E.g. "8080"thePath
- The path being requested (must either be blank or start with
'/' and contain a path). E.g. "/Apps/Receiver.jsp"public AbstractRawClient(URL theUrl)
theUrl
- The URL to connect to. Note that if the URL refers to the
"https" protocol, a SocketFactory
which uses TLS will be set. If custom
certificates are used, a different factory may need to be
provided manually.protected void closeSocket(Socket theSocket)
protected Socket connect() throws IOException
IOException
public String getHost()
IClient
public int getPort()
IClient
public ISocketFactory getSocketFactory()
IClient
getSocketFactory
in interface IClient
public int getSoTimeout()
IClient
getSoTimeout
in interface IClient
Socket.getSoTimeout()
public String getUriPath()
IClient
http://somehost.com:8888/messaging/receiver.jsp
, the URI
path portion would be /messaging/receiver.jsp
getUriPath
in interface IClient
public String getUrlString()
getUrlString
in interface IClient
public boolean isKeepAlive()
IClient
isKeepAlive
in interface IClient
Socket.getKeepAlive()
protected abstract Socket provideSocket() throws IOException
IOException
protected abstract void returnSocket(Socket theSocket)
provideSocket()
. This method will
always be called after the request is finished.public IReceivable<String> sendAndReceive(ISendable<?> theMessageToSend) throws DecodeException, IOException, EncodeException
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 setAuthorizationCallback(IAuthorizationClientCallback theAuthorizationCallback)
IClient
setAuthorizationCallback
in interface IClient
public void setCharset(Charset theCharset)
Sets the charset to use for requests from this client. May be changed at any time.
Default is UTF-8
setCharset
in interface IClient
public void setKeepAlive(boolean theKeepAlive)
setKeepAlive
in interface IClient
Socket.getKeepAlive()
public void setPort(int thePort)
public void setResponseTimeout(long theResponseTimeout)
#DEFAULT_RESPONSE_TIMEOUT
setResponseTimeout
in interface IClient
theResponseTimeout
- The millis to wait before timeout.#DEFAULT_RESPONSE_TIMEOUT
public void setSigner(ISigner theSigner)
setSigner
in interface IClient
theSigner
- If provided, sets the Signature Profile signer implementation
to use. See http://hl7api.sourceforge.net/hapi-hl7overhttp/specification.
html#SIGNATURE_PROFILEpublic void setSocketFactory(ISocketFactory theSocketFactory)
StandardSocketFactory
.setSocketFactory
in interface IClient
ISocketFactory
public void setSoTimeout(int theSoTimeout)
setSoTimeout
in interface IClient
Socket.getSoTimeout()
public void setUriPath(String thePath)
http://somehost.com:8888/messaging/receiver.jsp
, the URI
path portion would be /messaging/receiver.jsp
setUriPath
in interface IClient
public void setUrl(URL theUrl)
IClient.setHost(String)
, IClient.setPort(int)
, or IClient.setUriPath(String)
public void setUrlString(String theString)
IClient.setHost(String)
, IClient.setPort(int)
, or IClient.setUriPath(String)
setUrlString
in interface IClient
Copyright © 2012–2017 University Health Network. All rights reserved.