use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpMib method getGetNextHandlers.
/**
* This method builds the temporary request-tree that will be used to
* perform the SNMP GET-NEXT request associated with the given vector
* of varbinds `list'.
*
* @param req The SnmpMibRequest object holding the varbind list
* concerning this MIB.
*
* @return The request-tree where the original varbind list has been
* dispatched to the appropriate nodes, and where the original
* OIDs have been replaced with the correct "next" OID.
*/
private SnmpRequestTree getGetNextHandlers(SnmpMibRequest req) throws SnmpStatusException {
// Creates an empty request tree, no entry creation is allowed (false)
SnmpRequestTree handlers = new SnmpRequestTree(req, false, SnmpDefinitions.pduGetNextRequestPdu);
// Sets the getNext flag: if version=V2, status exception are
// transformed in endOfMibView
handlers.setGetNextFlag();
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "getGetNextHandlers", "Received MIB request : " + req);
}
AcmChecker checker = new AcmChecker(req);
int index = 0;
SnmpVarBind var = null;
final int ver = req.getVersion();
SnmpOid original = null;
// follows.
for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); index++) {
var = e.nextElement();
SnmpOid result;
try {
//ACM loop.
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "getGetNextHandlers", " Next OID of : " + var.oid);
}
result = new SnmpOid(root.findNextHandlingNode(var, var.oid.longValue(false), 0, 0, handlers, checker));
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "getGetNextHandlers", " is : " + result);
}
// We replace the varbind original OID with the OID of the
// leaf object we have to return.
var.oid = result;
} catch (SnmpStatusException x) {
if (ver == SnmpDefinitions.snmpVersionOne) {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "getGetNextHandlers", "\tThrowing exception " + x.toString());
}
//
throw new SnmpStatusException(x, index + 1);
}
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "getGetNextHandlers", "Exception : " + x.getStatus());
}
var.setSnmpValue(SnmpVarBind.endOfMibView);
}
}
return handlers;
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpErrorHandlerAgent method getBulk.
/**
* Processes a <CODE>getBulk</CODE> operation. It will throw an exception if the request is a V1 one or it will set exceptions within the list for V2 ones.
*
* @param inRequest The SnmpMibRequest object holding the list of variable to be retrieved.
*
* @exception SnmpStatusException An error occurred during the operation.
*/
@Override
public void getBulk(SnmpMibRequest inRequest, int nonRepeat, int maxRepeat) throws SnmpStatusException {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpErrorHandlerAgent.class.getName(), "getBulk", "GetBulk in Exception");
if (inRequest.getVersion() == SnmpDefinitions.snmpVersionOne)
throw new SnmpStatusException(SnmpDefinitions.snmpRspGenErr, 0);
Enumeration<SnmpVarBind> l = inRequest.getElements();
while (l.hasMoreElements()) {
SnmpVarBind varbind = l.nextElement();
varbind.setEndOfMibView();
}
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpErrorHandlerAgent method get.
/**
* Processes a <CODE>get</CODE> operation. It will throw an exception for V1 requests or it will set exceptions within the list for V2 requests.
*
* @param inRequest The SnmpMibRequest object holding the list of variable to be retrieved.
*
* @exception SnmpStatusException An error occurred during the operation.
*/
@Override
public void get(SnmpMibRequest inRequest) throws SnmpStatusException {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpErrorHandlerAgent.class.getName(), "get", "Get in Exception");
if (inRequest.getVersion() == SnmpDefinitions.snmpVersionOne)
throw new SnmpStatusException(SnmpStatusException.noSuchName);
Enumeration<SnmpVarBind> l = inRequest.getElements();
while (l.hasMoreElements()) {
SnmpVarBind varbind = l.nextElement();
varbind.setNoSuchObject();
}
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpGenericObjectServer method get.
/**
* Get the value of an SNMP variable.
*
* <p><b><i>
* You should never need to use this method directly.
* </i></b></p>
*
* @param meta The impacted metadata object
* @param name The ObjectName of the impacted MBean
* @param id The OID arc identifying the variable we're trying to set.
* @param data User contextual data allocated through the
* {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}
*
* @return The value of the variable.
*
* @exception SnmpStatusException whenever an SNMP exception must be
* raised. Raising an exception will abort the request. <br>
* Exceptions should never be raised directly, but only by means of
* <code>
* req.registerGetException(<i>VariableId</i>,<i>SnmpStatusException</i>)
* </code>
**/
public SnmpValue get(SnmpGenericMetaServer meta, ObjectName name, long id, Object data) throws SnmpStatusException {
final String attname = meta.getAttributeName(id);
Object result = null;
try {
result = server.getAttribute(name, attname);
} catch (MBeanException m) {
Exception t = m.getTargetException();
if (t instanceof SnmpStatusException)
throw (SnmpStatusException) t;
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
} catch (Exception e) {
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
return meta.buildSnmpValue(id, result);
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpGenericObjectServer method check.
/**
* Checks whether an SNMP SET request can be successfully performed.
*
* <p>
* For each variable in the subrequest, this method calls
* checkSetAccess() on the meta object, and then tries to invoke the
* check<i>AttributeName</i>() method on the MBean. If this method
* is not defined then it is assumed that the SET won't fail.
* </p>
*
* <p><b><i>
* This method is called internally by <code>mibgen</code> generated
* objects and you should never need to call it directly.
* </i></b></p>
*
* @param meta The metadata object impacted by the subrequest
* @param name The ObjectName of the MBean impacted by this subrequest
* @param req The SNMP subrequest to execute on the MBean
* @param depth The depth of the SNMP object in the OID tree.
*
* @exception SnmpStatusException if the requested SET operation must
* be rejected. Raising an exception will abort the request. <br>
* Exceptions should never be raised directly, but only by means of
* <code>
* req.registerCheckException(<i>VariableId</i>,<i>SnmpStatusException</i>)
* </code>
*
**/
public void check(SnmpGenericMetaServer meta, ObjectName name, SnmpMibSubRequest req, int depth) throws SnmpStatusException {
final Object data = req.getUserData();
for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
final SnmpVarBind var = e.nextElement();
try {
final long id = var.oid.getOidArc(depth);
// call meta.check() here, and meta.check will call check()
check(meta, name, var.value, id, data);
} catch (SnmpStatusException x) {
req.registerCheckException(var, x);
}
}
}
Aggregations