[jboss-cvs] JBossAS SVN: r109884 - branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Dec 13 17:13:04 EST 2010


Author: thauser at redhat.com
Date: 2010-12-13 17:13:03 -0500 (Mon, 13 Dec 2010)
New Revision: 109884

Added:
   branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/EndOfMibViewException.java
   branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/NoSuchOidException.java
   branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/VariableTypeException.java
Modified:
   branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java
   branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpRequest.java
Log:
Changed all errors in RequestHandlerImpl to be thrown exceptions rather than special return values. 

Added: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/EndOfMibViewException.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/EndOfMibViewException.java	                        (rev 0)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/EndOfMibViewException.java	2010-12-13 22:13:03 UTC (rev 109884)
@@ -0,0 +1,23 @@
+package org.jboss.jmx.adaptor.snmp.agent;
+
+/** This exception is thrown when a GETNEXT or GETBULK operation
+ *  attempts to read out of the Tree it is in. 
+ *  Example: 4 OID MIB with 1.2.3.4.1, 1.2.3.4.2, 1.2.3.4.3, and 1.3.7.1.1
+ *  This exception will be thrown when the GETNEXT(1.2.3.4.3) is called, because 1.3.7.1.1
+ *  is part of a different tree.
+ *  
+ * @author Thomas Hauser <a href="mailto:thauser at redhat.com"></a>
+ *
+ */
+
+public class EndOfMibViewException extends Exception {
+	
+	public EndOfMibViewException(){
+		super("Traversal of the tree left the subtree.");
+			
+	}
+
+	public EndOfMibViewException(String m){
+		super(m);
+	}
+}

Added: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/NoSuchOidException.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/NoSuchOidException.java	                        (rev 0)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/NoSuchOidException.java	2010-12-13 22:13:03 UTC (rev 109884)
@@ -0,0 +1,20 @@
+package org.jboss.jmx.adaptor.snmp.agent;
+
+import org.snmp4j.smi.OID;
+
+/** This exception is thrown when a manager attempts to retrieve information 
+ *  about an OID that does not exist in the attributes.xml
+ *  
+ *  @author Thomas Hauser <a href="mailto:thauser at redhat.com"></a>
+ */
+
+public class NoSuchOidException extends Exception {
+	
+	public NoSuchOidException(){
+		super("Error: Requested an OID that does not exist.");
+	}
+
+	public NoSuchOidException(OID oid){
+		super("Error: The following OID does not exist: "+oid);
+	}
+}

Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java	2010-12-13 21:12:21 UTC (rev 109883)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java	2010-12-13 22:13:03 UTC (rev 109884)
@@ -151,7 +151,7 @@
 
    /** 
     * <P>
-    * This method handles SNMP GetBulk requests recieved in this session. Request
+    * This method handles SNMP GetBulk requests received in this session. Request
     * is already validated. Builds a response and passes it back.
     * A GetBulk request has two additional fields: 
     * nonRepeaters: the amount of scalar objects in the PDU
@@ -166,7 +166,9 @@
     * 		a list of OIDs 
     * 		an Integer > 0 indicating the number of non-repeaters (set with PDU.setNonRepeaters())
     * 		an Integer >= 0 indicating the number of repetitions   (set with PDU.setMaxRepetitions())
-    * @return a PDU filled with the appropriate values, and statuses indicating errors.
+    * @return a PDU filled with the appropriate values, and if values were not found, null for those values. GetBulk
+    * 		  will rarely error out completely if non-zero list of VariableBindings is provided in the parameter PDU.
+    * 		  It may be filled with no useful data, but will always return a PDU with some content. 
     * 
     */
    
@@ -196,48 +198,91 @@
 		if (pdu != null){
 			int nonRepeaters = pdu.getNonRepeaters();
 			int maxRepetitions = pdu.getMaxRepetitions();
-			Vector it = pdu.getVariableBindings();
-			VariableBinding vb;
-			Variable var;
+			Vector<VariableBinding> it = pdu.getVariableBindings();
+			VariableBinding vb = null;
+			Variable var = null;
 			
 			if (it.size() == 0){ // we were given an empty list in the PDU
 				log.debug("snmpReceivedGetBulk: No VariableBindings in received PDU");
-				response.setErrorStatus(SnmpConstants.SNMP_ERROR_GENERAL_ERROR);
-				return response;
+				return makeErrorPdu(null, SnmpConstants.SNMP_ERROR_GENERAL_ERROR, 0);
 			}
 			// for the first nonRepeater Bindings, we simply get their value. if nonRepeaters is 0, 
 			// we do a GET on every element, and ignore the next loop.
 			for (int i=0; i < Math.min(nonRepeaters, it.size());i++){
 				vb = (VariableBinding)it.get(i);
 				OID oid = vb.getOid();
-				var = getValueFor(oid);
-				
-				if (var instanceof Null){
+				try {
+					var = getValueFor(oid);
+				} 
+				catch (NoSuchOidException e) {
+					// getBulk allows Null values and errors in it's return. 
+					log.debug("snmpReceivedGetBulk: An OID didn't exist. Null substituted in it's place.");
+					response.add(new VariableBinding(null, new Null()));
 					continue;
+				} 
+				catch (VariableTypeException e){
+					log.debug("snmpReceivedGetBulk: Couldn't convert a Variable to a correct type. adding a null value instead.");
+					response.add(new VariableBinding(oid, new Null()));
+					continue;
 				}
-				
 				response.add(new VariableBinding(oid,var));	
 			}
 			
 			// for the remaining it.size() bindings, we perform maxRepetitions successive getNext calls
 			for (int i = nonRepeaters; i < it.size(); i++){
 				vb = (VariableBinding)it.get(i);
-				OID noid = getNextOid(vb.getOid(),true);
+				OID noid = null;
+				try {
+					noid = getNextOid(vb.getOid(),true);
+				}
+				catch (NoSuchOidException e) {
+					// if this OID didn't exist, the GETNEXT surely does not exist. try the next one.
+					log.debug("snmpReceivedGetBulk: An OID didn't exist. Null value given.");
+					response.add(new VariableBinding(noid, Null.noSuchObject));
+					continue;
+				}
+				catch (EndOfMibViewException e) {
+					//not an error here. we skip this one and go to the next Repeater.
+					continue;
+				}
 								
 				//FIXME: returns null when maxReptitions goes into OIDs that don't exist. 
 				for (int j = 0; j < maxRepetitions; j++){
-					if (noid == null){ // reached the end of the repitions.
+				/*	if (noid == null){ // reached the end of the repitions.
 						log.debug("snmpReceivedGetBulk: Attempt to GETBULK on non-existent non-scalar OID.");
 						continue;
-/*						response.setErrorStatus(PDU.noSuchName);
+						response.setErrorStatus(PDU.noSuchName);
 						response.setErrorIndex(i+1);
 						response.add(new VariableBinding(new OID(), Null.noSuchObject));
 						// TODO: should we fail out here?
-						return response;*/
+						return response;
+					}*/
+					try {
+						var = getValueFor(noid);
+					} 
+					catch (NoSuchOidException e) {
+						log.debug("snmpReceivedGetBulk: An OID didn't exist. Null substituted in it's place.");
+						var = Null.noSuchObject;						
+					} 
+					catch (VariableTypeException e) {
+						log.debug("snmpReceivedGetBulk: Couldn't convert a Variable to a correct type. adding a null value instead.");
+						var = Null.noSuchInstance;						
 					}
-					var = getValueFor(noid);
+					
 					response.add(new VariableBinding(noid,var));
-					noid = getNextOid(noid,true);
+					
+					try {
+						noid = getNextOid(noid,true);
+					} 
+					catch (NoSuchOidException e) {
+						// error. break out and try the next one
+						log.debug("snmpReceivedGetBulk: An OID didn't exist. Null substituted in it's place.");
+						break;
+					} 
+					catch (EndOfMibViewException e) {
+					// not an error. we're finished with the repeaters here. 
+						break;
+					}
 				}
 			}
 				
@@ -255,8 +300,9 @@
 	 * @param pdu
 	 *            The SNMP pdu.           
 	 * 
-	 * @return a PDU filled in with the proper response, or null if
-	 *         cannot process NOTE: this might be changed to throw an exception.
+	 * @return a PDU filled in with the proper response, or a PDU filled with appropriate 
+	 * 		   error indications. Both the error type (ErrorStatus) and error index (the binding in the 
+	 * 		   PDU being processed that caused the error are returned.)
 	 */
 	public PDU snmpReceivedGet(PDU pdu)
 	{
@@ -285,37 +331,75 @@
 			Iterator it = pdu.getVariableBindings().iterator();
 			VariableBinding newVB;
 			Variable var;
+			OID noid = null;
 			
 			while (it.hasNext()){
 				VariableBinding vb = (VariableBinding)it.next();
 				OID oid = vb.getOid();
 				
-				if (pdu.getType()==PDU.GETNEXT){	
+				if (pdu.getType()==PDU.GETNEXT){
 					// we get the lexically next OID from the given one.
-					OID noid = getNextOid(oid,true);
+					try{
+					noid = getNextOid(oid,true);
 					// if noid is null, there is no OID > the one given. so we change response's errorStatus.
-					// we also abort here. 
-					if (noid == null){
-						log.debug("snmpReceivedGet: getNextOid operation returned null. No such OID.");
+					// we also abort here.
+					}
+					catch(NoSuchOidException e){
+						log.debug("snmpReceivedGet: GETNEXT operation couldn't find given oid.");
+						return makeErrorPdu(noid,PDU.noSuchName,counter);
+					}
+					catch(EndOfMibViewException e){
+						log.debug("snmpReceivedGet: GETNEXT operation left the OID subtree");
+						continue;
+					}
+/*					if (noid == null){
+						// this reaction should be factored out.
+						log.debug("snmpReceivedGet: GETNEXT operation returned null. No such OID.");
 						response.setErrorStatus(PDU.noSuchName);
 						response.setErrorIndex(counter);
 						response.add(new VariableBinding(noid, Null.noSuchObject));
 						return response;
+					}*/
+					newVB = new VariableBinding(noid);
+					try {
+						var = getValueFor(noid);
 					}
-					newVB = new VariableBinding(noid);
-					var = getValueFor(noid);	
+					catch (NoSuchOidException e) {
+						log.debug("snmpReceivedGet: GETNEXT operation returned null. No such OID.");
+						return makeErrorPdu(noid, PDU.noSuchName, counter);
+					}
+					catch (VariableTypeException e) {
+						log.debug("snmpReceivedGet: GETNEXT operation could not convert the returned value for " + noid + " into an appropriate type.");
+						return makeErrorPdu(noid,PDU.badValue, counter);
+						
+					}		
+				
+					
 				}
 				else {
 					newVB = new VariableBinding(oid);
-					var = getValueFor(oid);
+				
+					try {
+						var = getValueFor(oid);
+					}
+					catch (NoSuchOidException e) {
+						log.debug("snmpReceivedGet: GET operation returned null. No such OID.");
+						return makeErrorPdu(oid, PDU.noSuchName, counter);
+					}
+					catch (VariableTypeException e) {
+						log.debug("snmpReceivedGet: GET operation could not convert the returned value for " + oid + " into an appropriate type.");
+						return makeErrorPdu(oid, PDU.badValue, counter);
+					}
 					// the OID we are looking for has no BindEntry. Indicate this in the returned pdu.
 					// and abort immediately.
-					if (var instanceof Null){
+					//* probably no longer needed *//
+/*					if (var instanceof Null){
+						log.debug("snmpReceivedGet: GET operation returned null. No such OID.");
 						response.setErrorStatus(PDU.noSuchName);
 						response.setErrorIndex(counter);
-						response.add(newVB);
+						response.add(new VariableBinding(oid, Null.noSuchObject));
 						return response;
-					}
+					}*/
 				}
 					newVB.setVariable(var);
 					response.add(newVB);
@@ -343,10 +427,12 @@
 	public PDU snmpReceivedSet(PDU pdu)
    {
 		PDU response;
-		HashMap modified = new HashMap(); // the modified OID entries so far. 
+		// the modified OID entries so far.  
+		HashSet<VariableBinding> modified = new HashSet<VariableBinding>(); // modified variable values so far
 		// this counter is so we can indicate which entry in the given VB list caused an error, if any
 		int counter = 1;
-		Variable var = null;
+		Variable var, oldVar = null; // oldVar variable for storing into modified
+		
 		if (pdu instanceof ScopedPDU){
 			response = DefaultPDUFactory.createPDU(SnmpConstants.version3);
 		} else if (pdu instanceof PDUv1){
@@ -357,7 +443,7 @@
 		response.setType(PDU.RESPONSE);
 		
 		final boolean trace = log.isTraceEnabled();
-		
+		// TODO: why is this before a null check? if the pdu is null, pdu.getRequestID() and pdu.size() will both fail.
 		if (trace) {
 			log.trace("requestID=" + pdu.getRequestID() + ", elementCount="
 					+ pdu.size());
@@ -380,28 +466,35 @@
 				//some errorchecking ....
 				//else is good and do:
 				try{
+				oldVar = getValueFor(oid);
+				modified.add(new VariableBinding(oid, oldVar)); // keep a record of the old variable binding.
 				var = setValueFor(oid,newVal);
 				}
+				catch (NoSuchOidException e){
+					log.debug("snmpReceivedSet: attempt to set a non-existent OID " + oid);
+					undoSets(modified);
+					return makeErrorPdu(oid, PDU.noSuchName,counter);
+					//maybe factor out later: pdu = makeErrorPdu(oid, errorIndex, errorStatus, vb);
+				}
+				catch (VariableTypeException e){
+					log.debug("snmpReceievedSet: could not convert the given value into an appropriate type: " +newVal);
+					undoSets(modified);
+					return makeErrorPdu(oid, PDU.badValue, counter);
+				}
 				catch (ReadOnlyException e){
 					// this reaction needs to be turned into an exception in all cases.
 					log.debug("snmpReceivedSet: attempt to set a read-only attribute: " + newVB);
-					response.setErrorIndex(counter);
-					response.setErrorStatus(PDU.readOnly);
 					undoSets(modified);
-		//			response.add(newVB);
-					return response;
+					return makeErrorPdu(oid, PDU.readOnly, counter);
 				}
 				
-				if (var != null){
+				//this can probably be removed entirely
+/*				if (var != null){
 					log.debug("snmpReceivedSet: attempt to set value resulted in a null PDU being returned");
-					response.setErrorStatus(PDU.noSuchName);
-					response.setErrorIndex(counter);
-					response.add(new VariableBinding(oid, Null.noSuchObject));
 					undoSets(modified);
-					return response;
-				}
+					return makeErrorPdu(oid, PDU.noSuchName, counter);
+				}*/
 				// if we get here, we modified the value successfully. 
-				modified.put(oid,newVal);
 				response.add(newVB);
 				counter++;
 			}
@@ -620,7 +713,7 @@
 	 *            The oid we want a value for
 	 * @return Null if no value present
 	 */
-	private Variable getValueFor(final OID oid) {
+	private Variable getValueFor(final OID oid) throws NoSuchOidException, VariableTypeException {
 
 		BindEntry be = findBindEntryForOid(oid);
 		Variable ssy = null;
@@ -638,7 +731,10 @@
 					log.info("getValueFor: Unknown type for " + be);
 				}
 		}
-
+		catch (VariableTypeException e){
+			log.debug("setValueFor: didn't find a suitable data type for the requested data");
+			throw e;
+		}
         catch (Exception e)
         {
 				log.warn("getValueFor: (" + be.mbean.toString() + ", "
@@ -646,35 +742,16 @@
         }
      }
      else
-     {
-			ssy = Null.noSuchObject;
-			log.info("getValueFor: " + NO_ENTRY_FOUND_FOR_OID + oid);
+     {		
+    	 	
+			log.debug("getValueFor: " + NO_ENTRY_FOUND_FOR_OID + oid);
+			throw new NoSuchOidException();
 		}
 		return ssy;
 	}
 
-	/** This method is used by snmpReceivedSet to reverse any changes in a 
-	 * SET PDU if an error is encountered before finishing.
-	 * 
-	 * @param modified HashMap containing OID,Val mappings
-	 */
-	private void undoSets(HashMap modified){
-		HashSet keys = (HashSet)modified.keySet();
-		Iterator iter = keys.iterator();
-		
-		while (iter.hasNext()){
-			try{
-			OID oid = (OID) iter.next();
-			setValueFor(oid,(Variable)modified.get(oid));// this will not fail, because it succeeded earlier.
-			}
-			catch(Exception e){
-				//impossible;
-			}
-		}		
-	}
 	
 	
-	
 	/**This method takes an Object that is typically going to be 
 	 * put into a VariableBinding for use in a PDU, and thus must be converted
 	 * into an SNMP type based on it's type. This Object is usually read 
@@ -682,10 +759,12 @@
 	 *  
 	 * @param val The value needing conversion. 
 	 * @return the converted value. null on failure.
+	 * @throws VariableTypeException if the method was unable to convert val's type into an 
+	 * equivalent SMI type.
 	 * 
 	 */
 	
-	private Variable prepForPdu(final Object val){
+	private Variable prepForPdu(final Object val) throws VariableTypeException{
 		Variable result = null;
 		//TODO: all types managed by the PDU 
 		if (val instanceof Long)
@@ -716,7 +795,7 @@
         }
         else
         {
-        	result = Null.noSuchInstance; // no instance of an SNMP Variable could be crated for type
+        	throw new VariableTypeException(); // no instance of an SNMP Variable could be created for type
         }
 		return result;
 	}	
@@ -724,10 +803,13 @@
 	/** 
 	 * Takes an instance of org.snmp4j.smi.Variable and returns a Java primitive
 	 * representation. This is used to set mbean values given a PDU.
+	 * 
 	 * @param val the value to be converted
 	 * @return an Object created with the proper type. null if failure
+	 * @throws VariableTypeException if the method was unable to convert the type of val into
+	 * a type compatible with the MBean server.
 	 */
-	private Object convertVariableToValue(final Variable val){
+	private Object convertVariableToValue(final Variable val) throws VariableTypeException{
 		Object result = null;
 		if (val instanceof OctetString)
 		{	
@@ -746,7 +828,7 @@
 			result = new Long(((Counter64)val).getValue());
 		}
 		else{
-			result = Null.noSuchInstance; //no instance could be created.
+			throw new VariableTypeException(); //no instance could be created.
 		}
 		// TODO do more mumbo jumbo for type casting / changing
 		return result;
@@ -764,9 +846,11 @@
 	//TODO: currently, if one accesses a String and attempts to set it to an Int or Double value,
 	// the response is success, but the result is failure. This must be changed by investigating 
 	// what value is given from this method when such a situation arises, and then either throwing an exception 
-	// or handling that value in the caller.
-	private Variable setValueFor(final OID oid, final Variable newVal) throws ReadOnlyException
-   {
+	// or handling that value in the caller. /** THIS HAS BEEN IMPLEMENTED. AN EXCEPTION SHOULD BE THROWN. **/
+	//TODO: decide what to do in the case of a non writeable entry. (Exception thrown)
+	
+	private Variable setValueFor(final OID oid, final Variable newVal) 
+	throws ReadOnlyException, VariableTypeException, NoSuchOidException {
 		final boolean trace = log.isTraceEnabled();
 		
 		BindEntry be = findBindEntryForOid(oid);
@@ -789,13 +873,12 @@
 			}
 			try
 			{		
+				Object other = server.getAttribute(be.mbean, be.attr.getName());
 				Object val = convertVariableToValue(newVal);
-		
-				if (val instanceof Null)
-				{ 
-					log.debug("setValueFor: did not find a suitable data type for newVal " + newVal);
+				
+				if (val.getClass() != other.getClass() ){
+					log.debug("setValueFor: attempt to set an MBean Attribute with the wrong type.");
 					ssy = newVal;
-
 				}
 				
 				Attribute at = new Attribute(be.attr.getName(), val);
@@ -804,21 +887,54 @@
 				if (trace)
 					log.trace("setValueFor: set attribute in mbean server");
 			}
-			catch (Exception e )
+			catch (VariableTypeException e){
+				log.debug("setValueFor: didn't find a suitable data type for newVal " + newVal);
+				throw e;
+			}
+			catch (Exception e)
 			{
 				log.debug("setValueFor: exception " + e.getMessage());
-				ssy = null;
+				ssy = newVal;
 			}
 		}
 		else
 		{
-			ssy = newVal;
-			log.info("setValueFor: " + NO_ENTRY_FOUND_FOR_OID + oid + " on the mbean server");
+			throw new NoSuchOidException();
+			/*ssy = newVal;
+			log.info("setValueFor: " + NO_ENTRY_FOUND_FOR_OID + oid + " on the mbean server");*/
 		}
 		return ssy;
 	}
 
 
+	/** This method is used by snmpReceivedSet to reverse any changes in a 
+	 * SET PDU if an error is encountered before finishing.
+	 * 
+	 * @param modified HashMap containing OID,Val mappings
+	 */
+	private void undoSets(HashSet modified){
+		Iterator<VariableBinding> iter = modified.iterator();
+		
+		while (iter.hasNext()){
+			try{
+			VariableBinding vb = iter.next();
+			OID oid = vb.getOid();
+			Variable var = vb.getVariable();
+			setValueFor(oid,var);// this will not fail, because it succeeded earlier.
+			}
+			catch(NoSuchOidException e){
+				//impossible
+			}
+			catch(VariableTypeException e){
+				//impossible
+			}
+			catch(ReadOnlyException e){
+				//impossible;
+			}
+		}		
+	}
+	
+
 	/**
 	 * Lookup a BindEntry on the given oid. If the oid ends in .0,
 	 * then the .0 will be stripped of before the search.
@@ -865,7 +981,7 @@
 	 * @param stayInSubtree if true, the next oid will not have a different prefix than the one of oid.
 	 * @return the next oid or null if none found.
 	 */
-	private OID getNextOid(final OID oid, boolean stayInSubtree) {
+	private OID getNextOid(final OID oid, boolean stayInSubtree) throws NoSuchOidException, EndOfMibViewException {
 		OID coid = new OID(oid);
 
 
@@ -892,7 +1008,7 @@
 		//log.debug("getNextOid: Placeholder. The OID did not exist");
 		else{
 			log.debug("getNextOid: Placeholder. The OID did not exist");
-			return null;
+			throw new NoSuchOidException();
 		}	
 		
 		if (roid.compareTo(coid)==0) // input elment
@@ -907,7 +1023,7 @@
 			{
 				log.debug("getNextOid: Placeholder. There is no lexically larger OID than the input.");
 				// end of list
-				return null;
+				throw new EndOfMibViewException();
 			}
 		}
  		
@@ -919,13 +1035,50 @@
 			// this emulates the functionality of the "isRoot" in SnmpObjectId from joesnmp
 			if (coid.leftMostCompare((coid.size()-1), roid) != 0){
 				log.debug("getNextOid: Placeholder. The traversal has left the subtree.");
-				roid = null;
+				throw new EndOfMibViewException();
 			}
 		}
 
 		return roid;
 	}
 
+	/** This utility method is used to construct an error PDU. This code
+	 * was repeated so many times it was prudent to give it it's own method.
+	 *
+	 */
+	private PDU makeErrorPdu(OID oid, int errNo, int errInd){
+		PDU retVal = new PDU();
+		retVal.setErrorStatus(errNo);
+		retVal.setErrorIndex(errInd);
+		switch (errNo){
+			case PDU.noSuchName:
+				retVal.add(new VariableBinding(oid, Null.noSuchObject));
+				break;
+			case PDU.badValue:
+			case PDU.wrongValue:
+				retVal.add(new VariableBinding(oid, Null.noSuchInstance));
+				break;
+			case PDU.readOnly:
+				retVal.add(new VariableBinding(oid, Null.instance));
+				break;
+			case PDU.noError:
+			case PDU.tooBig:
+			case PDU.genErr:
+			case PDU.noAccess:
+			case PDU.wrongType:
+			case PDU.wrongLength:
+			case PDU.wrongEncoding:
+			case PDU.resourceUnavailable:
+			case PDU.commitFailed:
+			case PDU.undoFailed:
+			case PDU.authorizationError:
+			case PDU.notWritable:
+			case PDU.inconsistentName:
+				retVal.add(new VariableBinding(oid, Null.instance));
+				break;
+		}
+		return retVal;		
+	}
 
    // Inner Class ---------------------------------------------------
    
@@ -1041,6 +1194,8 @@
 
 	}
 
+	
+	
 }
 
 /** Brian Shim commented this out for reference i'm guessing **/

Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpRequest.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpRequest.java	2010-12-13 21:12:21 UTC (rev 109883)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpRequest.java	2010-12-13 22:13:03 UTC (rev 109884)
@@ -51,7 +51,6 @@
 				break;
 			case PDU.GETBULK:
 				//TODO maybe make a method called snmpReceivedGetBulk in requesthandler 
-				// requestHandler.snmpReceivedGet(pdu);
 				response = requestHandler.snmpReceivedGetBulk(pdu);
 				break;
 			case PDU.SET:

Added: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/VariableTypeException.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/VariableTypeException.java	                        (rev 0)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/VariableTypeException.java	2010-12-13 22:13:03 UTC (rev 109884)
@@ -0,0 +1,22 @@
+package org.jboss.jmx.adaptor.snmp.agent;
+
+/**	
+ * This exception is thrown when a client attempts to either GET a variable that 
+ * is of a type not supported by our SNMP adaptor (hopefully very few types eventually),
+ * or if the client attempts to SET an attribute of type T to something of a type that is not T 
+ * (ie a String to an int)
+ * 
+ * @author Thomas Hauser <a href="mailto:thauser at redhat.com"></a>
+ *
+ */
+
+public class VariableTypeException extends Exception{
+	
+	public VariableTypeException(){
+		super("Error: Variable type mismatch.");
+	}
+
+	public VariableTypeException(String m){
+		super(m);
+	}
+}



More information about the jboss-cvs-commits mailing list