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
IOExceptionpublic String getHost()
IClientpublic int getPort()
IClientpublic ISocketFactory getSocketFactory()
IClientgetSocketFactory in interface IClientpublic int getSoTimeout()
IClientgetSoTimeout in interface IClientSocket.getSoTimeout()public String getUriPath()
IClienthttp://somehost.com:8888/messaging/receiver.jsp, the URI
path portion would be /messaging/receiver.jspgetUriPath in interface IClientpublic String getUrlString()
getUrlString in interface IClientpublic boolean isKeepAlive()
IClientisKeepAlive in interface IClientSocket.getKeepAlive()protected abstract Socket provideSocket() throws IOException
IOExceptionprotected 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)
IClientsetAuthorizationCallback in interface IClientpublic 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 IClientpublic void setKeepAlive(boolean theKeepAlive)
setKeepAlive in interface IClientSocket.getKeepAlive()public void setPort(int thePort)
public void setResponseTimeout(long theResponseTimeout)
#DEFAULT_RESPONSE_TIMEOUTsetResponseTimeout in interface IClienttheResponseTimeout - The millis to wait before timeout.#DEFAULT_RESPONSE_TIMEOUTpublic void setSigner(ISigner theSigner)
setSigner in interface IClienttheSigner - 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 IClientISocketFactorypublic void setSoTimeout(int theSoTimeout)
setSoTimeout in interface IClientSocket.getSoTimeout()public void setUriPath(String thePath)
http://somehost.com:8888/messaging/receiver.jsp, the URI
path portion would be /messaging/receiver.jspsetUriPath in interface IClientpublic 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 IClientCopyright © 2012–2017 University Health Network. All rights reserved.