Saturday, April 4, 2015

SnmpTooBigException

com.sun.jmx.snmp.SnmpTooBigException

SnmpTooBigException is described in the javadoc comments as:

Is used internally to signal that the size of a PDU exceeds the packet size limitation.

You will not usually need to use this class, except if you decide to implement your own {link: com.sun.jmx.snmp.SnmpPduFactory SnmPduFactory} object.

The varBindCount property contains the number of SnmpVarBind successfully encoded before the exception was thrown. Its value is 0 when this number is unknown.

This API is a Sun Microsystems internal API and is subject to change without notice.


version: 1.1 07/23/98 author: Sun Microsystems, Inc

Where is this exception thrown?

Following, is a list of exception messages cross-referenced to the source code responsible for throwing them. Click on the method link to view the code and see how the exception is thrown.

How is this exception thrown?

The following sub-sections identify where this exception is thrown, and how (or why) the code is throwing the exception.

Any source code quoted in this section is subject to the Java Research License unless stated otherwise.

com.sun.jmx.snmp.SnmpMessage.encodeMessage(byte[])

/**
     * Encodes this message and puts the result in the specified byte array.
     * For internal use only.
     * @param outputBytes An array to receive the resulting encoding.
     * @exception ArrayIndexOutOfBoundsException If the result does not fit
     *                                           into the specified array.
     */
public int encodeMessage(byte[] outputBytes) throws SnmpTooBigException {
    int encodingLength = 0;
    if (data == null) throw new IllegalArgumentException('Data field is null');
    try {
        BerEncoder benc = new BerEncoder(outputBytes);
        benc.openSequence();
        benc.putAny(data, dataLength);
        benc.putOctetString((community != null) ? community : new byte[0]);
        benc.putInteger(version);
        benc.closeSequence();
        encodingLength = benc.trim();
    } catch (ArrayIndexOutOfBoundsException x) {
        throw new SnmpTooBigException();
    }
    return encodingLength;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

com.sun.jmx.snmp.SnmpMessage.encodeSnmpPdu(SnmpPdu, int)

/**
     * 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>.
     * If the encoding length exceeds <CODE>maxDataLength</CODE>, 
     * the method throws an exception.
     * @param pdu 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>.
     * @since 1.5
     */
public void encodeSnmpPdu(SnmpPdu pdu, int maxDataLength) throws SnmpStatusException, SnmpTooBigException {
    SnmpPduPacket pdupacket = (SnmpPduPacket) pdu;
    version = pdupacket.version;
    community = pdupacket.community;
    address = pdupacket.address;
    port = pdupacket.port;
    data = new byte[maxDataLength];
    try {
        BerEncoder benc = new BerEncoder(data);
        benc.openSequence();
        encodeVarBindList(benc, pdupacket.varBindList);
        switch(pdupacket.type) {
            case pduGetRequestPdu:
            case pduGetNextRequestPdu:
            case pduInformRequestPdu:
            case pduGetResponsePdu:
            case pduSetRequestPdu:
            case pduV2TrapPdu:
            case pduReportPdu:
                SnmpPduRequest reqPdu = (SnmpPduRequest) pdupacket;
                benc.putInteger(reqPdu.errorIndex);
                benc.putInteger(reqPdu.errorStatus);
                benc.putInteger(reqPdu.requestId);
                break;
            case pduGetBulkRequestPdu:
                SnmpPduBulk bulkPdu = (SnmpPduBulk) pdupacket;
                benc.putInteger(bulkPdu.maxRepetitions);
                benc.putInteger(bulkPdu.nonRepeaters);
                benc.putInteger(bulkPdu.requestId);
                break;
            case pduV1TrapPdu:
                SnmpPduTrap trapPdu = (SnmpPduTrap) pdupacket;
                benc.putInteger(trapPdu.timeStamp, SnmpValue.TimeticksTag);
                benc.putInteger(trapPdu.specificTrap);
                benc.putInteger(trapPdu.genericTrap);
                if (trapPdu.agentAddr != null) benc.putOctetString(trapPdu.agentAddr.byteValue(), SnmpValue.IpAddressTag); else benc.putOctetString(new byte[0], SnmpValue.IpAddressTag);
                benc.putOid(trapPdu.enterprise.longValue());
                break;
            default:
                throw new SnmpStatusException('Invalid pdu type ' + String.valueOf(pdupacket.type));
        }
        benc.closeSequence(pdupacket.type);
        dataLength = benc.trim();
    } catch (ArrayIndexOutOfBoundsException x) {
        throw new SnmpTooBigException();
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

com.sun.jmx.snmp.SnmpV3Message.encodeSnmpPdu(SnmpPdu, int)

/**
     * 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>.
     * 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 (isTraceOn()) {
        trace('encodeSnmpPdu', 'Pdu to marshall: \n' + 'security parameters : ' + pdu.securityParameters + '\n' + 'type :' + pdu.type + '\n' + 'version :' + pdu.version + '\n' + 'requestId :' + pdu.requestId + '\n' + 'msgId :' + pdu.msgId + '\n' + 'msgMaxSize :' + pdu.msgMaxSize + '\n' + 'msgFlags :' + pdu.msgFlags + '\n' + 'msgSecurityModel :' + pdu.msgSecurityModel + '\n' + 'contextEngineId :' + pdu.contextEngineId + '\n' + 'contextName :' + pdu.contextName + '\n');
    }
    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;
    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();
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

com.sun.jmx.snmp.SnmpMsg.encodeVarBindList(BerEncoder, SnmpVarBind[])

/**
     * For SNMP Runtime private use only.
     */
public void encodeVarBindList(BerEncoder benc, SnmpVarBind[] varBindList) throws SnmpStatusException, SnmpTooBigException {
    int encodedVarBindCount = 0;
    try {
        benc.openSequence();
        if (varBindList != null) {
            for (int i = varBindList.length - 1; i >= 0; i--) {
                SnmpVarBind bind = varBindList[i];
                if (bind != null) {
                    benc.openSequence();
                    encodeVarBindValue(benc, bind.value);
                    benc.putOid(bind.oid.longValue());
                    benc.closeSequence();
                    encodedVarBindCount++;
                }
            }
        }
        benc.closeSequence();
    } catch (ArrayIndexOutOfBoundsException x) {
        throw new SnmpTooBigException(encodedVarBindCount);
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

com.sun.jmx.snmp.daemon.SnmpRequestHandler.reduceResponsePdu(SnmpPduPacket, SnmpPduPacket, int)

private SnmpPduPacket reduceResponsePdu(SnmpPduPacket req, SnmpPduPacket resp, int acceptedVbCount) throws SnmpTooBigException {
    if (req.type != req.pduGetBulkRequestPdu) {
        if (isDebugOn()) {
            debug('reduceResponsePdu', 'cannot remove anything');
        }
        throw new SnmpTooBigException(acceptedVbCount);
    }
    int vbCount = resp.varBindList.length;
    if (acceptedVbCount >= 3) vbCount = Math.min(acceptedVbCount - 1, resp.varBindList.length); else if (acceptedVbCount == 1) vbCount = 1; else vbCount = resp.varBindList.length / 2;
    if (vbCount < 1) {
        if (isDebugOn()) {
            debug('reduceResponsePdu', 'cannot remove anything');
        }
        throw new SnmpTooBigException(acceptedVbCount);
    } else {
        SnmpVarBind[] newVbList = new SnmpVarBind[vbCount];
        for (int i = 0; i < vbCount; i++) {
            newVbList[i] = resp.varBindList[i];
        }
        if (isDebugOn()) {
            debug('reduceResponsePdu', (resp.varBindList.length - newVbList.length) + ' items have been removed');
        }
        resp.varBindList = newVbList;
    }
    return resp;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

No comments:

Post a Comment