public class RemoteApplication extends Object
The Remote Application API (RAPP) is designed to process a single or
multiple simultaneous requests to the server application using a
permanent connection or using a "state-less" connect-close connection. In
the latter case, a session ID (combined with possible calls to
getServerHostAddress
and getServerPort
) is
returned with the getSessionID
method. This session ID can then
be used to create a new instance of this class if required (otherwise
use the same instance and call the connect
method again).
When a connection has been established, the call to
isSessionIDReconnectable
indicates if the server application
supports (and is configured for) reconnection.
Requests are sent to the server (when a connection is open) and the server returns a request ID. Several requests can be sent, providing the receiving application supports this.
Replies to a request are stored in the server until the
getReply
method is called.
An application session in the server is "alive" up to the defined timeout value of the application (this timeout can also be set to zero, i.e. no session reconnection is supported). Each time a new connection, request or reply retrieval is performed using the API, the timeout is reset. The timeout can also be reset using an API call in the server application in order to keep the session alive.
Request/reply transactions are transported in an XML document using
the class RemoteTransaction
, allowing a flexible application
interaction. See the class se.entra.phantom.server.DefaultRemoteApplication
for the definition of the XML document format.
Use the class SSLRemoteApplication
is a secure socket
(using e.g. 128 bit encryption and optional "client certificate") is required.
This API is thread-safe.
Modifier and Type | Field and Description |
---|---|
static int |
CONNECTION_ALLOWED
The value for socket connection allowed.
|
static int |
EVENT_ERROR
The event class: error.
|
static int |
EVENT_INFORMATIONAL
The event class: informational.
|
static int |
EVENT_WARNING
The event class: warning.
|
static int |
RAPP_CLOSE
The transaction value for closing the application immediatly.
|
static int |
RAPP_GET_REPLY
The transaction value for getting a reply from client to server.
|
static int |
RAPP_ID_TRANS
The RAPP transaction version for initial identification.
|
static int |
RAPP_LOG_EVENT
The transaction value to produce a log event in the server.
|
static int |
RAPP_REPLY_DATA
The transaction value from the server in response to a RAPP_GET_REPLY
indicating that data is available or not.
|
static int |
RAPP_REPLY_ERROR
The transaction value from the server in response to a RAPP_GET_REPLY
indicating an error occured in the server.
|
static int |
RAPP_REQUEST_ACK
The transaction value used to ACK a client request (sent from server).
|
static int |
RAPP_REQUEST_DATA
The transaction value used to request data from the server.
|
static int |
RAPP_REQUEST_NACK
The transaction value used to NACK a client request (sent from server).
|
static int |
RAPP_STATUS_TRANS
The status transaction version used to check server redirection.
|
static int |
STATUS_ERROR
The status value for error in the connection.
|
static int |
STATUS_OK
The status value for connection OK.
|
static int |
STATUS_REDIRECTION
The status value for redirection.
|
static int |
TRANSACTION_LEVEL
The transaction level (i.e.
|
Constructor and Description |
---|
RemoteApplication(String applicationName)
Creates a new instance of the Remote Application class using the
specified
applicationName without a previous connection
(i.e. |
RemoteApplication(String applicationName,
String sessionID)
Creates a new instance of the Remote Application class using the
specified
applicationName and a previous
sessionID (if non-null). |
Modifier and Type | Method and Description |
---|---|
boolean |
close()
Closes the connection.
|
void |
connect()
Connects to the server.
|
protected String |
connect(Socket socket)
Processes the initial socket conversation to a server.
|
protected String |
connect(String hostName,
int port)
Connects to a server.
|
RemoteTransaction |
getReply(int requestID,
boolean doWait)
Gets a reply to a request transaction if available.
|
String |
getServerHostAddress()
Gets the host address (IP address, not hostName) that is
currently connected.
|
int |
getServerPort()
Gets the port number of the server that is currently connected.
|
String |
getSessionID()
Gets the current session ID for a connection.
|
boolean |
hasBlockingReply()
Call this method to check if a pending
getReply
is currently blocking. |
boolean |
inDebugMode()
Gets the debug mode flag.
|
boolean |
isConnected()
Checks if a connection is open to a server.
|
boolean |
isSessionIDReconnectable()
Flag indicating if the session can be reconnected with the same
session ID.
|
void |
logDebugOutput(String text)
Logs a string for debug mode (only printed when debug is turned on).
|
boolean |
logServerEvent(int eventClass,
String msg)
Logs an event in the server log if a connection is
present.
|
String |
paramString()
Gets the parameter string for this class for testing purposes.
|
boolean |
requestClose()
Requests immediate closure of the remote application.
|
int |
requestTransaction(RemoteTransaction transaction)
Requests a transaction in the server without waiting for a response, i.e.
|
void |
setAuthentication(String userID,
String password)
Sets up the user ID and password to use during the connect phase
to the server.
|
void |
setDebugMode(boolean inDebugMode)
Flag indicating debugging is used for the class instance.
|
void |
setServer(String hostName,
int portNumber)
Sets up the single instance of a server to contact.
|
void |
setServers(String[] hostNames,
int[] portNumbers)
Sets up a list of backup servers to contact.
|
static void |
setStaticDebugMode(boolean inDebugMode)
Sets the debugging mode used for the class statically.
|
String |
toString()
Converts this class into a string for testing purposes.
|
public static final int CONNECTION_ALLOWED
public static final int TRANSACTION_LEVEL
public static final int RAPP_ID_TRANS
public static final int RAPP_STATUS_TRANS
public static final int STATUS_OK
public static final int STATUS_ERROR
public static final int STATUS_REDIRECTION
public static final int RAPP_REQUEST_DATA
public static final int RAPP_REQUEST_ACK
public static final int RAPP_REQUEST_NACK
public static final int RAPP_GET_REPLY
public static final int RAPP_REPLY_DATA
public static final int RAPP_REPLY_ERROR
public static final int RAPP_CLOSE
public static final int RAPP_LOG_EVENT
public static final int EVENT_INFORMATIONAL
public static final int EVENT_WARNING
public static final int EVENT_ERROR
public RemoteApplication(String applicationName)
applicationName
without a previous connection
(i.e. a sessionID
).
Use the calls setServer
or setServers
to set up the servers to contact.
If user authentication is required, use the method
setAuthentication
to set it up.
After this has been done, call the connect
method
to establish a connection.
applicationName
- The application name to use.setAuthentication(java.lang.String, java.lang.String)
,
setServer(java.lang.String, int)
,
setServers(java.lang.String[], int[])
public RemoteApplication(String applicationName, String sessionID)
applicationName
and a previous
sessionID
(if non-null).
Use the calls setServer
or setServers
to set up the servers to contact.
If user authentication is required, use the method
setAuthentication
to set it up.
After this has been done, call the connect
method
to establish a connection.
applicationName
- The application name to use.sessionID
- The previously connection session ID
or null for none.setAuthentication(java.lang.String, java.lang.String)
,
setServer(java.lang.String, int)
,
setServers(java.lang.String[], int[])
,
getSessionID()
public void setDebugMode(boolean inDebugMode)
System.out
as "#RAPP: string".
Note that this mode exist in both a static or an instance version
for the class.inDebugMode
,
setStaticDebugMode(boolean)
public boolean inDebugMode()
public static void setStaticDebugMode(boolean inDebugMode)
System.out
as "#RAPP: string".
Note that this mode exist in both a static or an instance version
for the class.
When new instances of this class are created, they will inherit
the debug mode. To change a specific instance debug mode, use the
setDebugMode
method.
setDebugMode(boolean)
public void logDebugOutput(String text)
public void setServer(String hostName, int portNumber)
getServerHostAddress
and
getServerPort
to retrieve the real server to contact
if the connection is closed and later reopened using a new instance
of this class.
The new host name and port will override any previous call to
setServer
or setServers
.
hostName
- The server to contact. Preferably this should be
a raw IP address (such as 212.10.193.42) in order
to avoid DNS look-ups.portNumber
- The port number to use.setServers(java.lang.String[], int[])
,
getServerHostAddress()
,
getServerPort()
,
connect()
public final void setServers(String[] hostNames, int[] portNumbers)
Use the method getServerHostAddress
and
getServerPort
to retrieve the server to contact
if the connection is closed and later reopened using a new instance
of this class. This also applies to redirections from a server.
The new host names and ports will override any previous call to
setServer
or setServers
.
Note: The arrays hostNames
and
portNumbers
must have the same length.
hostNames
- An array of server to contact. Preferably each
String should be a raw IP address (such as
212.10.193.42) in order to avoid DNS look-ups.portNumbers
- An array of port numbers to use.setServer(java.lang.String, int)
,
getServerHostAddress()
,
getServerPort()
,
connect()
public final void setAuthentication(String userID, String password)
The authentication is processed in a similar fashion to the HTTP Digest Authentication, i.e. the password is secured. See the specification of RFC 2617 for more information of the Digest Authentication scheme.
userID
- The user ID to use.password
- The password to use.connect()
public final void connect() throws UnknownHostException, IOException
During this call, a negotiation is performed with the server to check for availability, load balancing, user authentication and possible other access control profiles imposed on the application (such as domain verification).
The method will contact all servers specified in setServer
or setServers
in turn and also check for load balancing which
would lead to a redirection of the connection to the slave server.
If two consecutive redirections are sent back for one server (primary server redirects to a slave server that also redirects), it will not be allowed and an IOException will occur if no other backup server is capable of processing the request. This scenario is virtually impossible because is is not supported at this time.
Use the method getServerHostAddress
and
getServerPort
to retrieve the real server in conjunction
with getSessionID
to contact the same server again,
if the connection is closed and later reopened using a new instance
of this class.
IOException
- if an I/O error occurs when creating the socket.UnknownHostException
- Thrown to indicate that the IP address of a host could not be determined.setAuthentication(java.lang.String, java.lang.String)
,
setServer(java.lang.String, int)
,
setServers(java.lang.String[], int[])
,
getSessionID()
,
close()
,
isConnected()
protected String connect(String hostName, int port) throws UnknownHostException, IOException
IOException
- if an I/O error occurs when creating the socket.UnknownHostException
- Thrown to indicate that the IP address of a host could not be determined.protected final String connect(Socket socket) throws UnknownHostException, IOException
IOException
- if an I/O error occurs when creating the socket.UnknownHostException
- Thrown to indicate that the IP address of a host could not be determined.public final boolean isConnected()
public final String getServerHostAddress()
connect()
,
getServerPort()
public final int getServerPort()
connect()
,
getServerHostAddress()
public final boolean isSessionIDReconnectable()
connect
and a close
.public final String getSessionID()
close
method.connect()
public final boolean close()
connect()
,
isConnected()
,
requestClose()
public final int requestTransaction(RemoteTransaction transaction) throws IOException
getReply
to check/wait for the reply transaction from the server.
Multiple pending requests are supported.
transaction
- the request to the server stored in a RemoteTransaction instance.IOException
- if an I/O error occurs when sending data to the server.public final RemoteTransaction getReply(int requestID, boolean doWait) throws IOException, SAXException
This method only blocks during the query period to the server if the
parameter doWait
is false
. If it is true
the call will wait until the server has the reply available.
Note: If this call is made with doWait = true
,
most calls to other methods will cause the calling thread to be locked
until the call to the original getReply
method returns
due to synchronization.
requestID
- the ID of the request.doWait
- true if the call should block until the reply is
available or false to return null if the reply
is not yet available.IOException
- if an I/O error occurs when sending data to the server.SAXException
- for errors in parsing the xmlDocument
to a org.w3x.dom.Document
.hasBlockingReply
public final boolean hasBlockingReply()
getReply
is currently blocking.getReply
with the doWait
parameter set to
true
.public final boolean requestClose()
When this method is called, the connection will also be closed.
close()
public final boolean logServerEvent(int eventClass, String msg)
eventClass
parameter should
one of the following:
EVENT_INFORMATIONAL informational EVENT_WARNING warning EVENT_ERROR error
EVENT_INFORMATIONAL
,
EVENT_WARNING
,
EVENT_ERROR
public String paramString()
Phantom® and NetPhantom® are registered trademarks of Mindus SARL.
© © Mindus SARL, 2024. All rights reserved.