private SnmpMessage makeResponseMessage(SnmpMessage reqMsg){
  SnmpMessage respMsg=null;
  SnmpPduPacket reqPdu;
  Object userData=null;
  try {
    reqPdu=(SnmpPduPacket)pduFactory.decodeSnmpPdu(reqMsg);
    if (reqPdu != null && userDataFactory != null)     userData=userDataFactory.allocateUserData(reqPdu);
  }
 catch (  SnmpStatusException x) {
    reqPdu=null;
    SnmpAdaptorServer snmpServer=(SnmpAdaptorServer)adaptorServer;
    snmpServer.incSnmpInASNParseErrs(1);
    if (x.getStatus() == SnmpDefinitions.snmpWrongSnmpVersion)     snmpServer.incSnmpInBadVersions(1);
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
      SNMP_ADAPTOR_LOGGER.logp(Level.FINEST,dbgTag,"makeResponseMessage","message decoding failed",x);
    }
  }
  SnmpPduPacket respPdu=null;
  if (reqPdu != null) {
    respPdu=makeResponsePdu(reqPdu,userData);
    try {
      if (userDataFactory != null)       userDataFactory.releaseUserData(userData,respPdu);
    }
 catch (    SnmpStatusException x) {
      respPdu=null;
    }
  }
  if (respPdu != null) {
    try {
      respMsg=(SnmpMessage)pduFactory.encodeSnmpPdu(respPdu,packet.getData().length);
    }
 catch (    SnmpStatusException x) {
      respMsg=null;
      if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST,dbgTag,"makeResponseMessage","failure when encoding the response message",x);
      }
    }
catch (    SnmpTooBigException x) {
      if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST,dbgTag,"makeResponseMessage","response message is too big");
      }
      try {
        if (packet.getData().length <= 32)         throw x;
        int pos=x.getVarBindCount();
        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
          SNMP_ADAPTOR_LOGGER.logp(Level.FINEST,dbgTag,"makeResponseMessage","fail on element" + pos);
        }
        int old;
        while (true) {
          try {
            respPdu=reduceResponsePdu(reqPdu,respPdu,pos);
            respMsg=(SnmpMessage)pduFactory.encodeSnmpPdu(respPdu,packet.getData().length - 32);
            break;
          }
 catch (          SnmpTooBigException xx) {
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
              SNMP_ADAPTOR_LOGGER.logp(Level.FINEST,dbgTag,"makeResponseMessage","response message is still too big");
            }
            old=pos;
            pos=xx.getVarBindCount();
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
              SNMP_ADAPTOR_LOGGER.logp(Level.FINEST,dbgTag,"makeResponseMessage","fail on element" + pos);
            }
            if (pos == old) {
              throw xx;
            }
          }
        }
      }
 catch (      SnmpStatusException xx) {
        respMsg=null;
        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
          SNMP_ADAPTOR_LOGGER.logp(Level.FINEST,dbgTag,"makeResponseMessage","failure when encoding the response message",xx);
        }
      }
catch (      SnmpTooBigException xx) {
        try {
          respPdu=newTooBigPdu(reqPdu);
          respMsg=(SnmpMessage)pduFactory.encodeSnmpPdu(respPdu,packet.getData().length);
        }
 catch (        SnmpTooBigException xxx) {
          respMsg=null;
          if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINEST,dbgTag,"makeResponseMessage","'too big' is 'too big' !!!");
          }
          adaptor.incSnmpSilentDrops(1);
        }
catch (        Exception xxx) {
          if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINEST,dbgTag,"makeResponseMessage","Got unexpected exception",xxx);
          }
          respMsg=null;
        }
      }
catch (      Exception xx) {
        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
          SNMP_ADAPTOR_LOGGER.logp(Level.FINEST,dbgTag,"makeResponseMessage","Got unexpected exception",xx);
        }
        respMsg=null;
      }
    }
  }
  return respMsg;
}

private SnmpMessage makeResponseMessage ( SnmpMessage reqMsg ) { SnmpMessage respMsg = null ; SnmpPduPacket reqPdu ; Object userData = null ; try { reqPdu = ( SnmpPduPacket ) pduFactory . decodeSnmpPdu ( reqMsg ) ; if ( reqPdu != null && userDataFactory != null ) userData = userDataFactory . allocateUserData ( reqPdu ) ; } catch ( SnmpStatusException x ) { reqPdu = null ; SnmpAdaptorServer snmpServer = ( SnmpAdaptorServer ) adaptorServer ; snmpServer . incSnmpInASNParseErrs ( 1 ) ; if ( x . getStatus ( ) == SnmpDefinitions . snmpWrongSnmpVersion ) snmpServer . incSnmpInBadVersions ( 1 ) ; if ( SNMP_ADAPTOR_LOGGER . isLoggable ( Level . FINEST ) ) { SNMP_ADAPTOR_LOGGER . logp ( Level . FINEST , dbgTag , "makeResponseMessage" , "message decoding failed" , x ) ; } } SnmpPduPacket respPdu = null ; if ( reqPdu != null ) { respPdu = makeResponsePdu ( reqPdu , userData ) ; try { if ( userDataFactory != null ) userDataFactory . releaseUserData ( userData , respPdu ) ; } catch ( SnmpStatusException x ) { respPdu = null ; } } if ( respPdu != null ) { try { respMsg = ( SnmpMessage ) pduFactory . encodeSnmpPdu ( respPdu , packet . getData ( ) . length ) ; } catch ( SnmpStatusException x ) { respMsg = null ; if ( SNMP_ADAPTOR_LOGGER . isLoggable ( Level . FINEST ) ) { SNMP_ADAPTOR_LOGGER . logp ( Level . FINEST , dbgTag , "makeResponseMessage" , "failure when encoding the response message" , x ) ; } } catch ( SnmpTooBigException x ) { if ( SNMP_ADAPTOR_LOGGER . isLoggable ( Level . FINEST ) ) { SNMP_ADAPTOR_LOGGER . logp ( Level . FINEST , dbgTag , "makeResponseMessage" , "response message is too big" ) ; } try { if ( packet . getData ( ) . length <= 32 ) throw x ; int pos = x . getVarBindCount ( ) ; if ( SNMP_ADAPTOR_LOGGER . isLoggable ( Level . FINEST ) ) { SNMP_ADAPTOR_LOGGER . logp ( Level . FINEST , dbgTag , "makeResponseMessage" , "fail on element" + pos ) ; } int old ; while ( true ) { try { respPdu = reduceResponsePdu ( reqPdu , respPdu , pos ) ; respMsg = ( SnmpMessage ) pduFactory . encodeSnmpPdu ( respPdu , packet . getData ( ) . length - 32 ) ; break ; } catch ( SnmpTooBigException xx ) { if ( SNMP_ADAPTOR_LOGGER . isLoggable ( Level . FINEST ) ) { SNMP_ADAPTOR_LOGGER . logp ( Level . FINEST , dbgTag , "makeResponseMessage" , "response message is still too big" ) ; } old = pos ; pos = xx . getVarBindCount ( ) ; if ( SNMP_ADAPTOR_LOGGER . isLoggable ( Level . FINEST ) ) { SNMP_ADAPTOR_LOGGER . logp ( Level . FINEST , dbgTag , "makeResponseMessage" , "fail on element" + pos ) ; } if ( pos == old ) { throw xx ; } } } } catch ( SnmpStatusException xx ) { respMsg = null ; if ( SNMP_ADAPTOR_LOGGER . isLoggable ( Level . FINEST ) ) { SNMP_ADAPTOR_LOGGER . logp ( Level . FINEST , dbgTag , "makeResponseMessage" , "failure when encoding the response message" , xx ) ; } } catch ( SnmpTooBigException xx ) { try { respPdu = newTooBigPdu ( reqPdu ) ; respMsg = ( SnmpMessage ) pduFactory . encodeSnmpPdu ( respPdu , packet . getData ( ) . length ) ; } catch ( SnmpTooBigException xxx ) { respMsg = null ; if ( SNMP_ADAPTOR_LOGGER . isLoggable ( Level . FINEST ) ) { SNMP_ADAPTOR_LOGGER . logp ( Level . FINEST , dbgTag , "makeResponseMessage" , "'too big' is 'too big' !!!" ) ; } adaptor . incSnmpSilentDrops ( 1 ) ; } catch ( Exception xxx ) { if ( SNMP_ADAPTOR_LOGGER . isLoggable ( Level . FINEST ) ) { SNMP_ADAPTOR_LOGGER . logp ( Level . FINEST , dbgTag , "makeResponseMessage" , "Got unexpected exception" , xxx ) ; } respMsg = null ; } } catch ( Exception xx ) { if ( SNMP_ADAPTOR_LOGGER . isLoggable ( Level . FINEST ) ) { SNMP_ADAPTOR_LOGGER . logp ( Level . FINEST , dbgTag , "makeResponseMessage" , "Got unexpected exception" , xx ) ; } respMsg = null ; } } } return respMsg ; }
here we make a response message from a request message . we return null if there is no message to reply .
