@Override
  public Answer processRequest(Request request) {
    dumpMessage(request,false);
    if (request.getCommandCode() != commandCode) {
      log.error("Received bad answer: " + request.getCommandCode());
      return null;
    }
    AvpSet requestAvpSet = request.getAvps();

    Avp exchangeTypeAvp = requestAvpSet.getAvp(exchangeTypeCode, vendorID);
    Avp exchangeDataAvp = requestAvpSet.getAvp(exchangeDataCode, vendorID);
    if (exchangeTypeAvp == null) {
      log.error("Request does not have Exchange-Type");

      Answer answer = createAnswer(request, 5004, EXCHANGE_TYPE_TERMINATING);
      dumpMessage(answer,true);
      return answer; // set
                                      // exchange
                                      // type
                                      // to
                                      // terminating
    }
    if (exchangeDataAvp == null) {
      log.error("Request does not have Exchange-Data");
      Answer answer = createAnswer(request, 5004, EXCHANGE_TYPE_TERMINATING);
      dumpMessage(answer,true);
      return answer; // set
                                      // exchange
                                      // type
                                      // to
                                      // terminating
    }
    // cast back to int(Enumerated is Unsigned32, and API represents it as
    // long so its easier
    // to manipulate
    try {
      switch ((int) exchangeTypeAvp.getUnsigned32()) {
      case EXCHANGE_TYPE_INITIAL:
        // JIC check;
        String data = exchangeDataAvp.getUTF8String();
        this.session = this.factory.getNewSession(request.getSessionId());
        if (data.equals(TO_RECEIVE[toReceiveIndex])) {
          // create session;

          Answer answer = createAnswer(request, 2001, EXCHANGE_TYPE_INITIAL); // set
                                                // exchange
                                                // type
                                                // to
                                                // terminating
          toReceiveIndex++;
          dumpMessage(answer,true);
          return answer;
        } else {
          log.error("Received wrong Exchange-Data: " + data);
          Answer answer = request.createAnswer(6000);
        }
        break;
      case EXCHANGE_TYPE_INTERMEDIATE:
        // JIC check;
        data = exchangeDataAvp.getUTF8String();
        if (data.equals(TO_RECEIVE[toReceiveIndex])) {

          Answer answer = createAnswer(request, 2001, EXCHANGE_TYPE_INTERMEDIATE); // set
                                                // exchange
                                                // type
                                                // to
                                                // terminating
          toReceiveIndex++;
          dumpMessage(answer,true);
          return answer;
        } else {
          log.error("Received wrong Exchange-Data: " + data);
        }
        break;
      case EXCHANGE_TYPE_TERMINATING:
        data = exchangeDataAvp.getUTF8String();
        if (data.equals(TO_RECEIVE[toReceiveIndex])) {
          // good, we reached end of FSM.
          finished = true;
          // release session and its resources.
          Answer answer = createAnswer(request, 2001, EXCHANGE_TYPE_TERMINATING); // set
                                              // exchange
                                              // type
                                              // to
                                              // terminating
          toReceiveIndex++;
          this.session.release();
          finished = true;
          this.session = null;
          dumpMessage(answer,true);
          return answer;

        } else {
          log.error("Received wrong Exchange-Data: " + data);
        }
        break;
      default:
        log.error("Bad value of Exchange-Type avp: " + exchangeTypeAvp.getUnsigned32());
        break;
      }
    } catch (AvpDataException e) {
      // thrown when interpretation of byte[] fails
      e.printStackTrace();
    } catch (InternalException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    //error, something bad happened.
    finished = true;
    return null;
  }
@ Override public Answer processRequest ( Request request ) { dumpMessage ( request , false ) ; if ( request . getCommandCode ( ) != commandCode ) { log . error ( "Received bad answer: " + request . getCommandCode ( ) ) ; return null ; } AvpSet requestAvpSet = request . getAvps ( ) ; Avp exchangeTypeAvp = requestAvpSet . getAvp ( exchangeTypeCode , vendorID ) ; Avp exchangeDataAvp = requestAvpSet . getAvp ( exchangeDataCode , vendorID ) ; if ( exchangeTypeAvp == null ) { log . error ( "Request does not have Exchange-Type" ) ; Answer answer = createAnswer ( request , 5004 , EXCHANGE_TYPE_TERMINATING ) ; dumpMessage ( answer , true ) ; return answer ; } if ( exchangeDataAvp == null ) { log . error ( "Request does not have Exchange-Data" ) ; Answer answer = createAnswer ( request , 5004 , EXCHANGE_TYPE_TERMINATING ) ; dumpMessage ( answer , true ) ; return answer ; } try { switch ( ( int ) exchangeTypeAvp . getUnsigned32 ( ) ) { case EXCHANGE_TYPE_INITIAL : String data = exchangeDataAvp . getUTF8String ( ) ; this . session = this . factory . getNewSession ( request . getSessionId ( ) ) ; if ( data . equals ( TO_RECEIVE [ toReceiveIndex ] ) ) { Answer answer = createAnswer ( request , 2001 , EXCHANGE_TYPE_INITIAL ) ; toReceiveIndex ++ ; dumpMessage ( answer , true ) ; return answer ; } else { log . error ( "Received wrong Exchange-Data: " + data ) ; Answer answer = request . createAnswer ( 6000 ) ; } break ; case EXCHANGE_TYPE_INTERMEDIATE : data = exchangeDataAvp . getUTF8String ( ) ; if ( data . equals ( TO_RECEIVE [ toReceiveIndex ] ) ) { Answer answer = createAnswer ( request , 2001 , EXCHANGE_TYPE_INTERMEDIATE ) ; toReceiveIndex ++ ; dumpMessage ( answer , true ) ; return answer ; } else { log . error ( "Received wrong Exchange-Data: " + data ) ; } break ; case EXCHANGE_TYPE_TERMINATING : data = exchangeDataAvp . getUTF8String ( ) ; if ( data . equals ( TO_RECEIVE [ toReceiveIndex ] ) ) { finished = true ; Answer answer = createAnswer ( request , 2001 , EXCHANGE_TYPE_TERMINATING ) ; toReceiveIndex ++ ; this . session . release ( ) ; finished = true ; this . session = null ; dumpMessage ( answer , true ) ; return answer ; } else { log . error ( "Received wrong Exchange-Data: " + data ) ; } break ; default : log . error ( "Bad value of Exchange-Type avp: " + exchangeTypeAvp . getUnsigned32 ( ) ) ; break ; } } catch ( AvpDataException e ) { e . printStackTrace ( ) ; } catch ( InternalException e ) { e . printStackTrace ( ) ; } finished = true ; return null ; }
/*
(non-Javadoc)

@see
org.jdiameter.api.NetworkReqListener#processRequest(org.jdiameter.api
.Request)