|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.Observable
com.adventnet.snmp.snmp2.SASClient
public class SASClient
The SASClient class enables applet services for applets that are limited by the security sandbox that Java applets often run within. In addition to sending and receiving SNMP data, the services available through SASClient allow saving files, creating and deleting directories and files, etc., on the web server that loaded the applet, provided the SAS server is run on the server.
You can also do all these operations using HTTP instead of TCP/IP by setting the value of protocol in SnmpSession using setSASProtocol() to 2 or by using the constructor SASClient(applet,debug, protocol). For using HTTP protocol, you don't have to start the SAServer.
The SASClient class is needed on account of browser security which prevents Java applets from sending data to any host but the applet host when loaded over the network.
This class will not need to be used directly for SNMP operations as the use of SASClient class use will not be transparent to the user. The SNMP library will by default attempt to use SAS if available, or use HTTP if the protocol value is set to 2 but will otherwise use direct socket connections if SAS is unavailable. The file access methods of this class may be used if file operation are required by an applet. For example the applet may use the saveFile method or appendFile method to save data on the applet host.
If the protocol value is 1,which is the default value, this class implements a client to send/receive PDUs from any SNMP peer via a deamon (SAS) on the Applet Host, i.e. Web server. While using Java enabled browsers that do not permit socket connections to anything but the applet host ,your applet will automatically instantiate this class to communicate with an SNMP entity.
If the protocol value is 2,this class uses the servlet loaded with the web-server to send/receive requests.
Use the open method on your session instance to specify whether the SAS or HTTP function needs to be used by your applet. For each session, you will call the open method with your applet instance as an argument. If the connection to the SAS daemon fails(if the value of protocol specified is 1) or if the protocol is not set to 2, the session will try and open a direct local UDP port for SNMP operations.
Enable CALLBACKTHREAD to use the SASClient calls from callback. By default it is disabled.
SnmpSession,
Serialized Form| Field Summary | |
|---|---|
(package private) java.applet.Applet |
app
|
(package private) int |
CALL_TIMEOUT
|
(package private) byte[] |
callData
|
(package private) boolean |
closeSocket
|
(package private) boolean |
connected
|
(package private) byte[] |
data
|
(package private) static boolean |
fileWrite
|
(package private) boolean |
gotResponse
Some parameters to implement the clientCall |
(package private) boolean |
gotUserResponse
|
(package private) static int |
HTTP_ADDRESS_LOOKUP
|
(package private) static int |
HTTP_ALIVE
|
(package private) static int |
HTTP_APPEND
|
(package private) static int |
HTTP_ASYNC_RESPONSE
|
(package private) static int |
HTTP_CLIENT_CALL
|
(package private) static int |
HTTP_CLIENT_RESPONSE
|
(package private) static int |
HTTP_CLOSE
|
(package private) static int |
HTTP_CREATE_DIR
|
(package private) static int |
HTTP_DELETE_DIR
|
(package private) static int |
HTTP_DELETE_FILE
|
(package private) static int |
HTTP_ERROR
|
(package private) static int |
HTTP_GETCLIENTID
|
(package private) static int |
HTTP_NAME_LOOKUP
|
(package private) static int |
HTTP_OPEN
|
static int |
HTTP_PROTOCOL
|
(package private) static int |
HTTP_RECEIVED
|
(package private) static int |
HTTP_SAVE
|
(package private) static int |
HTTP_SEND
|
(package private) static int |
HTTP_TRAP_REQUEST
|
(package private) int |
len
Some necessary parameters used to pick up datagrams |
(package private) ServletCommunication |
msg
|
(package private) static java.lang.String |
ONE
|
(package private) int |
port
Some necessary parameters used to pick up datagrams |
(package private) java.util.Properties |
props
|
(package private) int |
protocol
|
(package private) com.adventnet.management.transport.TransportProvider |
provider
|
(package private) java.lang.String |
remoteHost
|
(package private) java.lang.String |
remoteHostName
|
(package private) static int |
reqID
|
(package private) static int |
SAS_ADDRESS_LOOKUP
|
(package private) static int |
SAS_ALIVE
|
(package private) static int |
SAS_APPEND
|
(package private) static int |
SAS_ASYNC_RESPONSE
|
(package private) static int |
SAS_CLIENT_CALL
|
(package private) static int |
SAS_CLIENT_RESPONSE
|
(package private) static int |
SAS_CLOSE
|
(package private) static int |
SAS_CREATE_DIR
|
(package private) static int |
SAS_DB_CLOSE
|
(package private) static int |
SAS_DB_CONNECT
|
(package private) static int |
SAS_DB_FAILURE
|
(package private) static int |
SAS_DB_QUERY
|
(package private) static int |
SAS_DB_SUCCESS
|
(package private) static int |
SAS_DB_UPDATE
|
(package private) static int |
SAS_DELETE_DIR
|
(package private) static int |
SAS_DELETE_FILE
|
(package private) static int |
SAS_ERROR
|
(package private) static int |
SAS_INVALID_TYPE
The request types used to talk to the SNMP Applet Server |
(package private) static int |
SAS_NAME_LOOKUP
|
(package private) static int |
SAS_OPEN
|
(package private) static int |
SAS_RECEIVED
|
(package private) static int |
SAS_SAVE
|
(package private) static int |
SAS_SEND
|
(package private) static int |
SAS_TRAP_REQUEST
|
(package private) static int |
SAS_VALID_TYPES
|
(package private) com.adventnet.management.transport.SessionTransportProvider |
sock
The socket used to communicate with the SNMP Applet Server |
(package private) static java.lang.String |
STATUS
|
static int |
TCP_PROTOCOL
|
(package private) static int |
TIME
|
(package private) static java.lang.String |
TWO
|
(package private) java.net.URL |
url
|
(package private) int |
user_req_type
|
(package private) byte[] |
userRcvData
|
(package private) static java.lang.String |
ZERO
|
| Constructor Summary | |
|---|---|
SASClient(java.applet.Applet applet,
boolean debug)
By default this constructor will take the protocol value as 1 and look for the SASPort.html file in the applet html directory. |
|
SASClient(java.applet.Applet applet,
boolean debug,
int protocol)
If the protocol value is set to 1, this constructor will look for the SASPort.html file in the applet html directory. |
|
| Method Summary | |
|---|---|
void |
appendFile(java.lang.String filename,
byte[] data)
The appendFile method for appending data to a file in "SASusers" sub-directory in which SASPort.html was created by the SAServer. |
byte[] |
clientCall(byte[] bytes)
This method is used to build user defined functions around SAS. |
(package private) void |
close()
Close the remote session |
void |
closeDB()
This method is for closing the database connection which is opened through the method connectDB method. |
void |
connectDB(java.lang.String driver,
java.lang.String url,
java.lang.String user,
java.lang.String pass)
This method is for connecting with the database through SAS. |
(package private) int |
convertByteArrayToInt(byte[] bArr)
|
(package private) int |
convertByteArrayToInt(byte[] bArr,
int startIndex)
|
(package private) byte[] |
convertIntToByteArray(int i)
|
void |
createDir(java.lang.String directory)
The createDir method is for creating a directory on the applet host. |
void |
deleteDir(java.lang.String directory)
The deleteDir method for deleting a directory on the applet host. |
void |
deleteFile(java.lang.String filename)
The deleteFile method is for deleting a file on the applet host. |
(package private) static byte[] |
getBytes(java.lang.String s)
|
(package private) static java.lang.String |
getByteString(byte[] array,
int offset,
int length)
|
(package private) int |
getClientID()
|
(package private) byte[] |
getData(java.util.Vector vec)
|
java.lang.String |
getHostAddress(java.lang.String hostname,
int timeout)
The ip address lookup method is for applet clients. |
java.lang.String |
getHostName(java.lang.String address,
int timeout)
The name lookup method is for applet clients. |
int |
getMaxSasTypes()
This method returns the number of known SAS request types and users are requested to use a number greater than the returned value which will keep changing in the future. |
boolean |
isConnected()
Indicates if the connection to the SNMP Applet Server has been successfully established. |
boolean |
isDBConnected()
This method is for knowing whether the database connection has been established or not. |
static boolean |
isFileReadWrite()
Checks if the fileWrite flag is true. |
boolean |
isKnownSASType(int type)
If the value passed is one of the known request types, it returns true. |
(package private) void |
notifyWaitingThreads()
|
(package private) void |
open(int local_port)
open the socket at applet host |
(package private) void |
open(int local_port,
java.lang.String[] localAddresses)
|
java.sql.ResultSet |
queryDB(java.lang.String queryString)
This method is for doing a database query. |
(package private) void |
receive()
Used to pick up PDUs from the remote port on the SAS server Blocks until a PDU has been received |
void |
reqTraps(int port)
Method to request delivery of traps by SAServer arriving at that port. |
void |
run()
Invokes receive() method. |
void |
saveFile(java.lang.String filename,
byte[] data)
The saveFile method for saving data to a file in "SASusers" sub-directory in which SASPort.html was created by the SAServer. |
(package private) void |
send(java.lang.String hostname,
int port,
byte[] data)
The send method for sending PDUs |
(package private) void |
send(java.lang.String hostname,
int port,
byte[] data,
long timeoutmillis)
|
static void |
setFileReadWrite(boolean writeFlag)
Sets the fileWrite flag. |
void |
setTimeout(int to)
For setting the timeOut value for a synchronous SASClient operation. |
(package private) void |
setTransportProvider(java.lang.String providerName)
|
void |
start()
Starts the receiver thread. |
void |
stop()
Stops the receiver thread and closes socket connection with SAServer. |
int |
updateDB(java.lang.String updateString)
This method is for updating the database with a new value. |
byte[] |
userSyncSend(int userType,
byte[] bytes)
Using this method the user can send his own request type. |
(package private) void |
waitUntilNotification()
|
| Methods inherited from class java.util.Observable |
|---|
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
static final java.lang.String ZERO
static final java.lang.String ONE
static final java.lang.String TWO
static final java.lang.String STATUS
static final int TIME
java.net.URL url
java.util.Properties props
ServletCommunication msg
public static final int TCP_PROTOCOL
public static final int HTTP_PROTOCOL
int protocol
java.applet.Applet app
static int reqID
static boolean fileWrite
boolean connected
com.adventnet.management.transport.SessionTransportProvider sock
static final int SAS_INVALID_TYPE
static final int SAS_OPEN
static final int SAS_SEND
static final int SAS_RECEIVED
static final int SAS_CLOSE
static final int SAS_SAVE
static final int SAS_ERROR
static final int SAS_APPEND
static final int SAS_DELETE_FILE
static final int SAS_CREATE_DIR
static final int SAS_DELETE_DIR
static final int SAS_CLIENT_CALL
static final int SAS_CLIENT_RESPONSE
static final int SAS_ALIVE
static final int SAS_TRAP_REQUEST
static final int SAS_NAME_LOOKUP
static final int SAS_ADDRESS_LOOKUP
static final int SAS_ASYNC_RESPONSE
static final int SAS_DB_CONNECT
static final int SAS_DB_CLOSE
static final int SAS_DB_QUERY
static final int SAS_DB_UPDATE
static final int SAS_DB_FAILURE
static final int SAS_DB_SUCCESS
static final int SAS_VALID_TYPES
static final int HTTP_OPEN
static final int HTTP_SEND
static final int HTTP_RECEIVED
static final int HTTP_CLOSE
static final int HTTP_SAVE
static final int HTTP_ERROR
static final int HTTP_APPEND
static final int HTTP_DELETE_FILE
static final int HTTP_CREATE_DIR
static final int HTTP_DELETE_DIR
static final int HTTP_CLIENT_CALL
static final int HTTP_CLIENT_RESPONSE
static final int HTTP_ALIVE
static final int HTTP_TRAP_REQUEST
static final int HTTP_NAME_LOOKUP
static final int HTTP_ADDRESS_LOOKUP
static final int HTTP_ASYNC_RESPONSE
static final int HTTP_GETCLIENTID
int port
int len
byte[] data
java.lang.String remoteHost
java.lang.String remoteHostName
boolean closeSocket
boolean gotResponse
byte[] callData
int CALL_TIMEOUT
boolean gotUserResponse
byte[] userRcvData
int user_req_type
com.adventnet.management.transport.TransportProvider provider
| Constructor Detail |
|---|
public SASClient(java.applet.Applet applet,
boolean debug)
throws SnmpException
applet - applet refernce using this sasclient to talk to SAServer.debug - Debug messages are printed, if true.
SnmpException - is thrown whenever an error occurs.
public SASClient(java.applet.Applet applet,
boolean debug,
int protocol)
throws SnmpException
applet - applet reference using this sasclient to talk to SAServerdebug - Debug messages are printed, if true.
SnmpException - is thrown whenever an error occurs.| Method Detail |
|---|
public void setTimeout(int to)
to - the timeOut value in milliSeconds.public static boolean isFileReadWrite()
public static void setFileReadWrite(boolean writeFlag)
public boolean isConnected()
public boolean isKnownSASType(int type)
type - requestType
public int getMaxSasTypes()
void open(int local_port)
local_port - Local Port number
void open(int local_port,
java.lang.String[] localAddresses)
public void reqTraps(int port)
throws java.io.IOException,
com.adventnet.management.transport.TransportException
port - the port at which SAServer to listen for
traps and forward to this client. Multiple
client applications can request for the same
port.
java.io.IOException - on error in writing to SAServer
com.adventnet.management.transport.TransportException
void send(java.lang.String hostname,
int port,
byte[] data)
throws java.io.IOException,
com.adventnet.management.transport.TransportException
hostname - the host to which the request is to be sentport - the port to which the request is to be sentdata - the packet to be sent
java.io.IOException - on error in writing to SAServer
com.adventnet.management.transport.TransportException
void send(java.lang.String hostname,
int port,
byte[] data,
long timeoutmillis)
throws java.io.IOException,
com.adventnet.management.transport.TransportException
java.io.IOException
com.adventnet.management.transport.TransportException
public void saveFile(java.lang.String filename,
byte[] data)
throws com.adventnet.management.transport.TransportException,
java.io.IOException
filename - the file will be saved by this name at the SAServer.data - the contents of the file.
java.io.IOException - on error in writing to SAServer.
com.adventnet.management.transport.TransportException
public void appendFile(java.lang.String filename,
byte[] data)
throws com.adventnet.management.transport.TransportException,
java.io.IOException
filename - the data will be appended to file by this name at the SAServer.data - the contents to be appended to the file.
java.io.IOException - on error in writing to SAServer.
com.adventnet.management.transport.TransportException
public void connectDB(java.lang.String driver,
java.lang.String url,
java.lang.String user,
java.lang.String pass)
throws java.sql.SQLException,
java.lang.ClassNotFoundException
driver - the driver class for database.url - the url where the database existsuser - the usernamepass - the password
java.sql.SQLException - is thrown when unable to create a Connection.
java.lang.ClassNotFoundException - when the driver class specified is
not present.
public boolean isDBConnected()
throws SnmpException
SnmpException - if any error occurs.
public void closeDB()
throws java.sql.SQLException
java.sql.SQLException - thrown when unable to close the database.
public java.sql.ResultSet queryDB(java.lang.String queryString)
throws java.sql.SQLException
queryString - the actual query string that is to be performed on
the database.
java.sql.SQLException - thrown when a database access error occurs.
public int updateDB(java.lang.String updateString)
throws java.sql.SQLException
updateString - the sql query string that is to be performed on the
database.
java.sql.SQLException - if a database access error occurs.public void start()
public void run()
run in interface java.lang.Runnablepublic void stop()
static java.lang.String getByteString(byte[] array,
int offset,
int length)
static byte[] getBytes(java.lang.String s)
void receive()
throws SnmpException,
com.adventnet.management.transport.TransportException,
java.io.IOException
SnmpException - is thrown on receive errors.
java.io.IOException - is thrown on receive errors.
com.adventnet.management.transport.TransportExceptionvoid notifyWaitingThreads()
void waitUntilNotification()
void close()
public byte[] clientCall(byte[] bytes)
bytes - The byte array data to be sent
public byte[] userSyncSend(int userType,
byte[] bytes)
userType - The request type to be sent to SAServer.bytes - The byte array packet to be sent.
public java.lang.String getHostName(java.lang.String address,
int timeout)
throws com.adventnet.management.transport.TransportException
address - the ip address of the host.timeout - the time in ms to wait for the SAServer to respond.
Defaults to 2 Secs.
com.adventnet.management.transport.TransportException - on error in writing to SAServer.
public java.lang.String getHostAddress(java.lang.String hostname,
int timeout)
throws com.adventnet.management.transport.TransportException
hostname - the host whose ipaddress needs to be looked up.timeout - the time in ms to wait for the SAServer to respond.
Defaults to 2 Secs.
com.adventnet.management.transport.TransportException - on error in writing to SAServer.
public void createDir(java.lang.String directory)
throws com.adventnet.management.transport.TransportException,
java.io.IOException
directory - The name of the directory to be created
java.io.IOException - on error in Creating Directory
com.adventnet.management.transport.TransportException
public void deleteFile(java.lang.String filename)
throws com.adventnet.management.transport.TransportException,
java.io.IOException
filename - The name of the file to be deleted.
java.io.IOException - on error in Deleting File .
com.adventnet.management.transport.TransportException
public void deleteDir(java.lang.String directory)
throws com.adventnet.management.transport.TransportException,
java.io.IOException
directory - The name for the directory to be deleted.
java.io.IOException - on error in Deleting Directory.
com.adventnet.management.transport.TransportException
void setTransportProvider(java.lang.String providerName)
throws java.lang.Exception
java.lang.Exceptionbyte[] convertIntToByteArray(int i)
int convertByteArrayToInt(byte[] bArr)
throws java.io.IOException
java.io.IOException
int convertByteArrayToInt(byte[] bArr,
int startIndex)
throws java.io.IOException
java.io.IOExceptionbyte[] getData(java.util.Vector vec)
int getClientID()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||