use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpMibTable method checkRowStatusFail.
// ---------------------------------------------------------------------
//
// Register an exception when checking the RowStatus variable
//
// ---------------------------------------------------------------------
static void checkRowStatusFail(SnmpMibSubRequest req, int errorStatus) throws SnmpStatusException {
final SnmpVarBind statusvb = req.getRowStatusVarBind();
final SnmpStatusException x = new SnmpStatusException(errorStatus);
req.registerCheckException(statusvb, x);
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpV3Message method getRequestId.
/**
* Returns the associated request Id.
* @param data The flat message.
* @return The request Id.
*/
public int getRequestId(byte[] data) throws SnmpStatusException {
BerDecoder bdec = null;
int msgId = 0;
try {
bdec = new BerDecoder(data);
bdec.openSequence();
bdec.fetchInteger();
bdec.openSequence();
msgId = bdec.fetchInteger();
} catch (BerException x) {
throw new SnmpStatusException("Invalid encoding");
}
try {
bdec.closeSequence();
} catch (BerException x) {
}
return msgId;
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpV3Message method decodeMessage.
/**
* Decodes the specified bytes and initializes this message.
* For internal use only.
*
* @param inputBytes The bytes to be decoded.
*
* @exception SnmpStatusException If the specified bytes are not a valid encoding.
*/
public void decodeMessage(byte[] inputBytes, int byteCount) throws SnmpStatusException {
try {
BerDecoder bdec = new BerDecoder(inputBytes);
bdec.openSequence();
version = bdec.fetchInteger();
bdec.openSequence();
msgId = bdec.fetchInteger();
msgMaxSize = bdec.fetchInteger();
msgFlags = bdec.fetchOctetString()[0];
msgSecurityModel = bdec.fetchInteger();
bdec.closeSequence();
msgSecurityParameters = bdec.fetchOctetString();
if ((msgFlags & SnmpDefinitions.privMask) == 0) {
bdec.openSequence();
contextEngineId = bdec.fetchOctetString();
contextName = bdec.fetchOctetString();
data = bdec.fetchAny();
dataLength = data.length;
bdec.closeSequence();
} else {
encryptedPdu = bdec.fetchOctetString();
}
bdec.closeSequence();
} catch (BerException x) {
x.printStackTrace();
throw new SnmpStatusException("Invalid encoding");
}
if (SNMP_LOGGER.isLoggable(Level.FINER)) {
final StringBuilder strb = new StringBuilder().append("Unmarshalled message : \n").append("version : ").append(version).append("\n").append("msgId : ").append(msgId).append("\n").append("msgMaxSize : ").append(msgMaxSize).append("\n").append("msgFlags : ").append(msgFlags).append("\n").append("msgSecurityModel : ").append(msgSecurityModel).append("\n").append("contextEngineId : ").append(contextEngineId == null ? null : SnmpEngineId.createEngineId(contextEngineId)).append("\n").append("contextName : ").append(contextName).append("\n").append("data : ").append(data).append("\n").append("dat len : ").append((data == null) ? 0 : data.length).append("\n").append("encryptedPdu : ").append(encryptedPdu).append("\n");
SNMP_LOGGER.logp(Level.FINER, SnmpV3Message.class.getName(), "decodeMessage", strb.toString());
}
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpV3Message method encodeSnmpPdu.
/**
* Initializes this message with the specified <CODE>pdu</CODE>.
* <P>
* This method initializes the data field with an array of
* <CODE>maxDataLength</CODE> bytes. It encodes the <CODE>pdu</CODE>.
* The resulting encoding is stored in the data field
* and the length of the encoding is stored in <CODE>dataLength</CODE>.
* <p>
* If the encoding length exceeds <CODE>maxDataLength</CODE>,
* the method throws an exception.
*
* @param p The PDU to be encoded.
* @param maxDataLength The maximum length permitted for the data field.
*
* @exception SnmpStatusException If the specified <CODE>pdu</CODE>
* is not valid.
* @exception SnmpTooBigException If the resulting encoding does not fit
* into <CODE>maxDataLength</CODE> bytes.
* @exception ArrayIndexOutOfBoundsException If the encoding exceeds
* <CODE>maxDataLength</CODE>.
*/
public void encodeSnmpPdu(SnmpPdu p, int maxDataLength) throws SnmpStatusException, SnmpTooBigException {
SnmpScopedPduPacket pdu = (SnmpScopedPduPacket) p;
if (SNMP_LOGGER.isLoggable(Level.FINER)) {
final StringBuilder strb = new StringBuilder().append("PDU to marshall: \n").append("security parameters : ").append(pdu.securityParameters).append("\n").append("type : ").append(pdu.type).append("\n").append("version : ").append(pdu.version).append("\n").append("requestId : ").append(pdu.requestId).append("\n").append("msgId : ").append(pdu.msgId).append("\n").append("msgMaxSize : ").append(pdu.msgMaxSize).append("\n").append("msgFlags : ").append(pdu.msgFlags).append("\n").append("msgSecurityModel : ").append(pdu.msgSecurityModel).append("\n").append("contextEngineId : ").append(pdu.contextEngineId).append("\n").append("contextName : ").append(pdu.contextName).append("\n");
SNMP_LOGGER.logp(Level.FINER, SnmpV3Message.class.getName(), "encodeSnmpPdu", strb.toString());
}
version = pdu.version;
address = pdu.address;
port = pdu.port;
msgId = pdu.msgId;
msgMaxSize = pdu.msgMaxSize;
msgFlags = pdu.msgFlags;
msgSecurityModel = pdu.msgSecurityModel;
contextEngineId = pdu.contextEngineId;
contextName = pdu.contextName;
securityParameters = pdu.securityParameters;
//
// Allocate the array to receive the encoding.
//
data = new byte[maxDataLength];
try {
BerEncoder benc = new BerEncoder(data);
benc.openSequence();
encodeVarBindList(benc, pdu.varBindList);
switch(pdu.type) {
case pduGetRequestPdu:
case pduGetNextRequestPdu:
case pduInformRequestPdu:
case pduGetResponsePdu:
case pduSetRequestPdu:
case pduV2TrapPdu:
case pduReportPdu:
SnmpPduRequestType reqPdu = (SnmpPduRequestType) pdu;
benc.putInteger(reqPdu.getErrorIndex());
benc.putInteger(reqPdu.getErrorStatus());
benc.putInteger(pdu.requestId);
break;
case pduGetBulkRequestPdu:
SnmpPduBulkType bulkPdu = (SnmpPduBulkType) pdu;
benc.putInteger(bulkPdu.getMaxRepetitions());
benc.putInteger(bulkPdu.getNonRepeaters());
benc.putInteger(pdu.requestId);
break;
default:
throw new SnmpStatusException("Invalid pdu type " + String.valueOf(pdu.type));
}
benc.closeSequence(pdu.type);
dataLength = benc.trim();
} catch (ArrayIndexOutOfBoundsException x) {
throw new SnmpTooBigException();
}
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpMibTable method setRowStatusFail.
// ---------------------------------------------------------------------
//
// Register an exception when checking the RowStatus variable
//
// ---------------------------------------------------------------------
static void setRowStatusFail(SnmpMibSubRequest req, int errorStatus) throws SnmpStatusException {
final SnmpVarBind statusvb = req.getRowStatusVarBind();
final SnmpStatusException x = new SnmpStatusException(errorStatus);
req.registerSetException(statusvb, x);
}
Aggregations