public class RpcBroker extends java.lang.Object implements IPulseHandler, ITimerHandler
The RpcBroker
class provides VistA application developers with client/server-related
functionality for software written in the Java programming language.
Using an instance of RpcBroker
, an application can connect to the server by simply
calling the connect
method passing the server host and port. Remote procedures on the
server can be executed by invoking one of the overloaded lCall
, tCall
, or
sCall
methods.
RpcBroker rpcBroker = new RpcBroker(); rpcBroker.connect("test.lom.med.va.gov", 9100); long duz = rpcBroker.doSignon("access", "verify"); if (duz > 0) { String s = rpcBroker.sCall("OR CPRS GUI CHART, "ORWU USERINFO"); }
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
RPC_BROKER |
Constructor and Description |
---|
RpcBroker()
Constructs an instance of RpcBroker using the default version of the
RPC broker protocol.
|
RpcBroker(int rpcProtocolVersion)
Constructs an instance of RpcBroker using the version of the protocol specified.
|
RpcBroker(int rpcProtocolVersion,
java.lang.String server,
int port)
Constructs an instance of RpcBroker and connects to the server
at the specified server host/ip and port using the version of the
broker protocol that is specified .
|
RpcBroker(java.lang.String server,
int port)
Constructs an instance of RpcBroker and connects to the server
at the specified server host/ip and port using the Version 2
broker protocol.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
call()
Makes the call on the broker server using the current context and current RPC API.
|
java.lang.String |
call(java.lang.String api)
Makes the call on the broker server using the current context.
|
java.lang.String |
call(java.lang.String api,
java.lang.Object[] paramArray)
Makes the call on the broker server.
|
java.lang.String |
call(java.lang.String api,
Params params)
Makes the call on the broker server using the current context.
|
java.lang.String |
call(java.lang.String api,
java.lang.String ien)
Makes the call on the broker server using the current context.
|
void |
callOnRpcBrokerSignon()
Calls the onRpcBrokerSignon event handler.
|
boolean |
connect()
Connect to the broker server using the previously set server host/ip and port.
|
boolean |
connect(java.lang.String server,
int port)
Connect to the broker server.
|
BrokerException |
createBrokerException(java.lang.Exception e,
java.lang.String action,
int code)
Creates a broker exception.
|
boolean |
createContext(java.lang.String aContext)
Creates and sets the context on the broker server.
|
boolean |
disconnect()
Disconnects from the broker server.
|
void |
doClearParams()
Clears the
params property. |
void |
doClearResults()
Clears the results.
|
void |
doPulse() |
java.lang.String |
doSignon()
Performs a signon setup and signon using the cached access and verify codes.
|
java.lang.String |
doSignon(java.lang.String avCode)
Performs a signon setup and signon using the supplied
semicolon delimited access and verify codes.
|
java.lang.String |
doSignon(java.lang.String accessCode,
java.lang.String verifyCode)
Performs a signon setup and signon using the supplied
access and verify codes.
|
java.lang.String |
getAppHandle()
Gets a token that can be used to sign-on a new process.
|
java.lang.String |
getApplicationSegment()
Gets the application segment of the last inbound message.
|
BrokerException |
getBrokerException()
Gets the last broker exception.
|
int |
getBrokerInfo()
Gets info from the server regarding setup and parameters of the broker.
|
boolean |
getClearParams()
Tests whether or not to clear the parameter list between calls.
|
boolean |
getClearResults()
Tests whether the results are to be cleared between calls.
|
java.lang.String |
getCurrentContext()
Gets the current broker context.
|
java.lang.String |
getDataSegment()
Gets the data segment of the last inbound message.
|
java.lang.String |
getDomain()
Gets the domain of the signed-on user.
|
java.lang.String |
getErrorMessage()
Gets the message property associated with the exception or error that was encountered.
|
IRpcBrokerEventHandler |
getEventHandler()
Gets the event handler object that implements IRpcBrokerEventHandler interface.
|
java.lang.String |
getHashedAVCodes()
Returns the hashed access;verify code pair.
|
int |
getInactiveTimeout()
Returns the timeout duration (in msec) in which RpcBroker will log off
of VistA if a connection has been idle for a period of time.
|
java.util.Date |
getLastMessageTime()
Returns the timestamp of the last (non-pulse) message sent to VistA.
|
int |
getListenerPort()
Gets the listener port on the broker server.
|
static LogChannel |
getLogChannel()
The log channel is used to write messages to a logging facility.
|
java.lang.String |
getLoginHandle()
The login handle property holds the application handle for doing a silent login.
|
Params |
getParams()
Params is an object that holds all of the parameters that the
application needs to pass to the remote procedure. |
java.lang.String |
getRemoteProcedure()
Gets the remote procedure property to the name of the remote procedure call entry in the REMOTE PROCEDURE file (#8994).
|
java.lang.StringBuffer |
getResults()
Gets the results as a StringBuffer.
|
IRpcProtocol |
getRpcProtocol()
The Rpc Protocol is the implementation of the RPC Broker protocol used.
|
int |
getRpcProtocolVersion()
The Rpc protocol version is the version of the RPC protocol used.
|
java.lang.String |
getRpcVersion()
Returns the RPC version
|
java.lang.String |
getSecuritySegment()
Gets the security segment of the last inbound message.
|
java.lang.String |
getServer()
The server property contains the name or Internet Protocol (IP) address of the server computer.
|
java.lang.String |
getService()
Gets the service ID of the signed-on user.
|
java.lang.String |
getServiceSection()
Gets the service/section of the signed-on user.
|
java.lang.String |
getStation()
Gets the station of the signed-on user.
|
java.lang.String |
getStationIen()
Gets the station IEN of the signed-on user.
|
java.lang.String |
getStationNo()
Gets the station number of the signed-on user.
|
java.lang.String |
getTitle()
Gets the title of the signed-on user.
|
java.lang.String |
getUserClass()
Gets the class of the signed-on user.
|
java.lang.String |
getUserDuz()
Gets the duz of the signed-on user.
|
java.lang.String |
getUserName()
Gets the name of the signed-on user.
|
boolean |
isConnected()
Tests if a connection is established, and allows you to branch accordingly depending
on whether a connection is established or not.
|
boolean |
isConnecting()
Tests whether the broker client is currently in the process of connecting to the server.
|
boolean |
isKernelLogin()
Tests whether the login type is kernel login.
|
protected void |
lockCallMonitor() |
void |
log(int level,
java.lang.Exception e)
Writes the exception message to the logging facility.
|
void |
log(int level,
java.lang.String msg)
Writes the message to the logging facility.
|
static void |
main(java.lang.String[] args) |
void |
onTimerEvent() |
void |
setClearParameters(boolean value)
The clear parameters design-time property gives the developer the option to clear the
params property following
every invocation of the call methods. |
void |
setClearResults(boolean value)
Setting clear results to
true clears the results property. |
boolean |
setConnected(boolean value)
If
value is true , connects to the broker server using the
previously set server host/ip and port. |
void |
setContext(java.lang.String context)
Sets the current context without creating the context on the server.
|
boolean |
setCurrentContext(java.lang.String currentContext)
Sets the current broker context and creates the context on the server.
|
void |
setDomain(java.lang.String domain)
Sets the domain of the signed-on user.
|
void |
setEventHandler(IRpcBrokerEventHandler eventHandler)
Gets the event handler object.
|
void |
setHashedAVCodes(java.lang.String avCode)
Sets the hashed access;verify code pair for the user.
|
void |
setInactiveTimeout(int inactiveTimeout)
Sets the timeout duration (in msec) for inactivity, after which RpcBroker
will log off of VistA.
|
void |
setKernelLogin(boolean kernelLogin)
If
kernelLogin is true , sets the login type to kernel login. |
void |
setListenerPort(int listenerPort)
Sets the port on which the broker server is listening.
|
static void |
setLogChannel(LogChannel logChannel)
Sets the static log channel used for writing messages to the logging facility.
|
void |
setParams(Params params)
Sets the
Params object, which holds all of the parameters that the
application needs to pass to the remote procedure. |
void |
setRemoteProcedure(java.lang.String remoteProcedure)
Sets the remote procedure property to the name of the remote procedure call entry in the REMOTE PROCEDURE file (#8994).
|
void |
setRpcProtocol(IRpcProtocol rpcProtocol)
Sets the RPC version number
|
void |
setRpcProtocolVersion(int rpcProtocolVersion)
Sets the RPC broker protocol version number
|
void |
setRpcVersion(java.lang.String rpcVersion)
The RPC version property is used to pass the version of the RPC.
|
void |
setServer(java.lang.String server)
Changing the name of the server while the RpcBroker is connected disconnects the RpcBroker from the previous server.
|
void |
setService(java.lang.String service)
Sets the service ID of the signed-on user.
|
void |
setServiceSection(java.lang.String serviceSection)
Sets the service/section of the signed-on user.
|
void |
setStation(java.lang.String station)
Sets the station of the signed-on user.
|
void |
setStationIen(java.lang.String stationIen)
Sets the station IEN of the signed-on user.
|
void |
setStationNo(java.lang.String stationNo)
Sets the station number of the signed-on user.
|
void |
setTitle(java.lang.String title)
Sets the title of the signed-on user.
|
void |
setUserClass(java.lang.String userClass)
Sets the class of the signed-on user.
|
void |
setUserDuz(java.lang.String duz)
Sets the duz of the signed-on user.
|
void |
setUserName(java.lang.String userName)
Sets the name of the signed-on user.
|
protected void |
unlockCallMonitor() |
public static final java.lang.String RPC_BROKER
public RpcBroker() throws BrokerException
server
- the host/ip of the serverport
- the listening port on the serverBrokerException
public RpcBroker(int rpcProtocolVersion) throws BrokerException
rpcProtocolVersion
- the version of the rpc broker protocol to useBrokerException
public RpcBroker(java.lang.String server, int port) throws BrokerException
server
- the host/ip of the serverport
- the listening port on the serverBrokerException
public RpcBroker(int rpcProtocolVersion, java.lang.String server, int port) throws BrokerException
server
- the host/ip of the serverport
- the listening port on the serverBrokerException
public IRpcBrokerEventHandler getEventHandler()
public void setEventHandler(IRpcBrokerEventHandler eventHandler)
eventHandler
- object that implements IRpcBrokerEventHandler interface.public java.lang.String getRpcVersion()
public void setRpcVersion(java.lang.String rpcVersion)
The RPC version property is used to pass the version of the RPC. This can be useful for backward compatibility.
As you introduce new functionality into an existing RPC, your RPC can branch into different parts of the code based on the value of the RPC version property. The broker sets the XWBAPVER variable on the server to the contents of the RPC version property. This property cannot be empty and defaults to "0" (zero).
rpcVersion
- the version of the RPC to set.public boolean getClearParams()
true
if the list of parameters should be cleared between calls, false
otherwise.public void setClearParameters(boolean value)
The clear parameters design-time property gives the developer the option to clear the params
property following
every invocation of the call methods. Setting clear parameters to true
clears the params
property.
Simple assignment of true
to this property clears the Pparam
property after every invocation of the
call methods. Thus, the parameters need only be prepared for the next call without being concerned about
what was remaining from the previous call. By setting clear parameters to false
, the programmer can
make multiple calls with the same params
property. It is also appropriate to set this property to false when a
majority of the parameters in the params
property should remain the same between calls.
However, minor changes to the parameters can still be made.
If value
is true
, clears the parameter list and clears parameters between all calls.
Otherwise, if value
is false
, the parameters will not be cleared between calls.
value
- public void doClearParams()
params
property.setClearParameters(boolean value)
public boolean getClearResults()
true
if the results have been cleared, false
otherwise.setClearResults(boolean)
public void setClearResults(boolean value)
Setting clear results to true
clears the results
property.
If this property is true
, then the results
property is cleared before every
invocation of the call methods, thus, assuring that only the results of the last call are returned.
Conversely, a setting of
property.false
results
value
- true
if results are to be cleared between calls, false
otherwisepublic void doClearResults()
setClearResults(boolean)
public boolean isConnecting()
true
if the broker client is connecting, false
otherwise.public BrokerException createBrokerException(java.lang.Exception e, java.lang.String action, int code)
e
- the exception that this broker exception encapsulatesaction
- the action for which this exception occurredcode
- the integer code representing this exceptionpublic BrokerException getBrokerException()
public java.lang.String getCurrentContext()
public boolean setCurrentContext(java.lang.String currentContext) throws BrokerException
currentContext
- the current context to setBrokerException
public void setContext(java.lang.String context)
context
- the context to setpublic boolean isKernelLogin()
true
if login type is kernel login, false
otherwise.public void setKernelLogin(boolean kernelLogin)
kernelLogin
is true
, sets the login type to kernel login.kernelLogin
- true
if login type is kernel login, false
otherwise.public int getListenerPort()
public void setListenerPort(int listenerPort)
listenerPort
- the port on which the broker server is listeningpublic Params getParams()
Params
is an object that holds all of the parameters that the
application needs to pass to the remote procedure.public void setParams(Params params)
Params
object, which holds all of the parameters that the
application needs to pass to the remote procedure.params
- the params that the application needs to pass to the remote procedurepublic java.lang.String getRemoteProcedure()
public void setRemoteProcedure(java.lang.String remoteProcedure)
remoteProcedure
- the current remote procedure APIpublic java.lang.StringBuffer getResults()
public java.lang.String getHashedAVCodes()
public void setHashedAVCodes(java.lang.String avCode)
avCode
- the hashed access;verify code pairpublic java.lang.String getErrorMessage()
public java.lang.String getSecuritySegment()
public java.lang.String getApplicationSegment()
public java.lang.String getDataSegment()
public java.lang.String getUserDuz()
public void setUserDuz(java.lang.String duz)
duz
- signed-on user's duzpublic java.lang.String getDomain()
public void setDomain(java.lang.String domain)
domain
- signed-on user's domainpublic java.lang.String getService()
public void setService(java.lang.String service)
service
- signed-on user's service IDpublic java.lang.String getServiceSection()
public void setServiceSection(java.lang.String serviceSection)
serviceSection
- signed-on user's service/sectionpublic java.lang.String getStation()
public void setStation(java.lang.String station)
station
- signed-on user's stationpublic java.lang.String getStationIen()
public void setStationIen(java.lang.String stationIen)
stationIen
- signed-on user's station IENpublic java.lang.String getStationNo()
public void setStationNo(java.lang.String stationNo)
stationNo
- signed-on user's station numberpublic java.lang.String getTitle()
public void setTitle(java.lang.String title)
title
- signed-on user's titlepublic java.lang.String getUserClass()
public void setUserClass(java.lang.String userClass)
userClass
- signed-on user's classpublic java.lang.String getUserName()
public void setUserName(java.lang.String userName)
userName
- signed-on user's namepublic IRpcProtocol getRpcProtocol()
public void setRpcProtocol(IRpcProtocol rpcProtocol)
rpcProtocol
- the Rpc protocol implementation to usegetRpcProtocol()
public int getRpcProtocolVersion()
public void setRpcProtocolVersion(int rpcProtocolVersion)
rpcProtocolVersion
- the Rpc protocol version being usedgetRpcProtocolVersion()
public java.lang.String getServer()
public void setServer(java.lang.String server) throws BrokerException
Changing the name of the server while the RpcBroker is connected disconnects the RpcBroker from the previous server.
If the name is used instead of the IP address, it should be resolved by the socket through the Domain Name Service (DNS).
server
- the server host/IP address to setBrokerException
getServer()
public java.lang.String getLoginHandle()
getAppHandle
method.
The login handle may be passed as a command line argument to an application that is being started. The new application must know to look for the handle, and if present, set up the silent login.
Note: The app handle that is obtained via the getAppHandle
function is only valid
for approximately 20 seconds, after which the silent login would fail.
getAppHandle
getAppHandle()
public int getInactiveTimeout()
public void setInactiveTimeout(int inactiveTimeout)
inactiveTimeout
- the duration of inactivity in msec.public java.util.Date getLastMessageTime()
public static LogChannel getLogChannel()
public static void setLogChannel(LogChannel logChannel)
logChannel
- the log channel to use for logginggetLogChannel()
public void log(int level, java.lang.String msg)
level
- the logging level (e.g. Logger.ERROR)msg
- the messge to logpublic void log(int level, java.lang.Exception e)
level
- the logging level (e.g. Logger.ERROR)msg
- the exception to logpublic boolean isConnected()
true
if connected to the broker server, false
otherwisepublic boolean setConnected(boolean value) throws BrokerException
value
is true
, connects to the broker server using the
previously set server host/ip and port. Otherwise, if value
is false
disconnects from the broker server.true
if connected to the broker server, false
otherwiseBrokerException
public boolean connect() throws BrokerException
true
if connected to the broker server, false
otherwiseBrokerException
public boolean connect(java.lang.String server, int port) throws BrokerException
server
- the host name or IP address of the broker serverport
- the listener port on the broker servertrue
if connected to the broker server, false
otherwiseBrokerException
public boolean disconnect() throws BrokerException
true
if successfully disconnected, false
otherwiseBrokerException
public boolean createContext(java.lang.String aContext) throws BrokerException
Creates and sets the context on the broker server.
You can use the createContext
method to create a context for your application.
To create context, pass an option name as a parameter. If the function returns true
,
a context was created, and your application can use all RPCs entered in the option's RPC multiple.
If the RpcBroker is not connected at the time context is created, a connection will be established.
If for some reason a context could not be created, the createContext
method will return False.
Since context is nothing more than a client/server 'B'-type option in the OPTION file (#19), standard MenuMan security is applied in establishing a context. Therefore, a context option can be granted to user(s) exactly the same way as regular options are done using MenuMan. Before any RPC can run, it must have a context established for it to on the server. Thus, all RPCs must be registered to one or more 'B'-type option(s). This plays a major role in Broker security.
A context cannot be established for the following reasons:context
- the context to createtrue
if the context was created, false
otherwiseBrokerException
public java.lang.String doSignon(java.lang.String avCode) throws BrokerException
avCode
- semicolon-delimited access and verify codesBrokerException
public java.lang.String doSignon(java.lang.String accessCode, java.lang.String verifyCode) throws BrokerException
accessCode
- the user's access codeverifyCode
- the user's verify codeBrokerException
doSignon(String)
public java.lang.String doSignon() throws BrokerException
BrokerException
doSignon(String)
public int getBrokerInfo() throws BrokerException
BrokerException
public java.lang.String getAppHandle() throws BrokerException
BrokerException
public void doPulse()
doPulse
in interface IPulseHandler
public void onTimerEvent()
onTimerEvent
in interface ITimerHandler
public java.lang.String call() throws BrokerException
BrokerException
public java.lang.String call(java.lang.String api, java.lang.Object[] paramArray) throws BrokerException
api
- the RPC API to callparamArray
- the array of parameters to pass to the callBrokerException
public java.lang.String call(java.lang.String api, java.lang.String ien) throws BrokerException
api
- the RPC API to callien
- the internal entry number of the record to retrieveBrokerException
public java.lang.String call(java.lang.String api, Params params) throws BrokerException
api
- the RPC API to callparams
- the Params object containing the list of paramsBrokerException
public java.lang.String call(java.lang.String api) throws BrokerException
api
- the RPC API to callBrokerException
public void callOnRpcBrokerSignon()
protected void lockCallMonitor()
protected void unlockCallMonitor()
public static void main(java.lang.String[] args)