public void processResponse(ResponseEvent responseReceivedEvent) {
    /// System.out.println("=> BUNDLE: br.ufes.inf.ngn.televoto.client.logic | CLASS: LogicListener
    // | METOD: processResponse ");//By Ju
    try {
      Response myResponse = responseReceivedEvent.getResponse();
      logger.info("<<< " + myResponse.toString());

      ClientTransaction thisClientTransaction = responseReceivedEvent.getClientTransaction();

      int myStatusCode = myResponse.getStatusCode();

      switch (status) {
        case WAIT_PROV:
          if (!thisClientTransaction.equals(myClientTransaction))
            myClientTransaction = thisClientTransaction;

          if (myStatusCode < 200) {
            status = WAIT_FINAL;
            myDialog = thisClientTransaction.getDialog();
          } else if (myStatusCode < 300) {
            myDialog = thisClientTransaction.getDialog();
            CSeqHeader originalCSeq =
                (CSeqHeader) myClientTransaction.getRequest().getHeader(CSeqHeader.NAME);
            long numseq = originalCSeq.getSeqNumber();
            Request myAck = myDialog.createAck(numseq);
            myAck.addHeader(myContactHeader);
            myDialog.sendAck(myAck);
            // logger.info(">>> "+myAck.toString());
            status = ESTABLISHED;
            byte[] cont = (byte[]) myResponse.getContent();
            answerInfo = mySdpManager.getSdp(cont);

          } else {
            if (myStatusCode == 401) {

            } else {
              status = IDLE;
              CSeqHeader originalCSeq =
                  (CSeqHeader) myClientTransaction.getRequest().getHeader(CSeqHeader.NAME);
              long numseq = originalCSeq.getSeqNumber();
              Request myAck = myDialog.createAck(numseq);
              myAck.addHeader(myContactHeader);
              myDialog.sendAck(myAck);
              // logger.info(">>> "+myAck.toString());
            }
          }
          break;

        case WAIT_FINAL:
          if (!thisClientTransaction.equals(myClientTransaction))
            myClientTransaction = thisClientTransaction;

          if (myStatusCode < 200) {
            status = WAIT_FINAL;
            myDialog = thisClientTransaction.getDialog();
          } else if (myStatusCode < 300) {
            if (useQueue.equals("yes")) {
              status = IDLE;
            } else {
              status = ESTABLISHED;
            }

            myDialog = thisClientTransaction.getDialog();
            CSeqHeader originalCSeq =
                (CSeqHeader) myClientTransaction.getRequest().getHeader(CSeqHeader.NAME);
            long numseq = originalCSeq.getSeqNumber();
            Request myAck = myDialog.createAck(numseq); // Aquiiii
            myAck.addHeader(myContactHeader);
            myDialog.sendAck(myAck);
            // logger.info(">>> "+myAck.toString());
            byte[] cont = (byte[]) myResponse.getContent();
            answerInfo = mySdpManager.getSdp(cont);

          } else {
            // Cancelando requisição ao cliente
            Request myCancelRequest = myClientTransaction.createCancel();
            ClientTransaction myCancelClientTransaction =
                mySipProvider.getNewClientTransaction(myCancelRequest);
            myCancelClientTransaction.sendRequest();
            // logger.info(">>> " + myCancelRequest.toString());
            status = IDLE;
          }
          break;

        case REGISTERING:
          if (!thisClientTransaction.equals(myClientTransaction))
            myClientTransaction = thisClientTransaction;

          if (myStatusCode == 200) {
            status = IDLE;
            if (!Unregistring) {

              System.out.println(myName + ": Registrado");

              // inserir captura de timestamp
              // logger.info(myName + ";INVITE;" +  getTime());
              // Random gerador = new Random();
              // int temp = gerador.nextInt(10);
              // System.out.println(myName + ": Esperando " + temp + "segundos");
              // Thread.sleep(temp);

              System.out.println(myName + ": chamando " + destination);

              SdpInfo offerInfo = new SdpInfo();
              offerInfo.IpAddress = myIP;
              offerInfo.aport = myAudioPort;
              offerInfo.aformat = 0;
              byte[] content = mySdpManager.createSdp(offerInfo);

              // Via
              // ViaHeader comentei
              myViaHeader = myHeaderFactory.createViaHeader(myIP, myPort, "udp", null);
              myViaHeader.setRPort();
              ArrayList viaHeaders = new ArrayList();
              viaHeaders.add(myViaHeader);

              // From
              Address addressOfRecord = myAddressFactory.createAddress("<sip:" + myUserID + ">");
              FromHeader myFromHeader = myHeaderFactory.createFromHeader(addressOfRecord, "456249");

              // To
              String dstURI[] = destination.split("@");
              String dstSipAlias = dstURI[0];
              Address destinationAddress =
                  myAddressFactory.createAddress("<sip:" + destination + ">");
              javax.sip.address.URI myRequestURI = destinationAddress.getURI();
              ToHeader myToHeader = myHeaderFactory.createToHeader(destinationAddress, null);

              // MaxForwards
              MaxForwardsHeader myMaxForwardsHeader = myHeaderFactory.createMaxForwardsHeader(70);

              // Call-ID
              CallIdHeader myCallIdHeader = mySipProvider.getNewCallId();

              // CSeq
              Random random = new Random();
              CSeqHeader myCSeqHeader =
                  myHeaderFactory.createCSeqHeader(random.nextInt(1000) * 1L, "INVITE");

              // Create SIP request
              Request myRequest =
                  myMessageFactory.createRequest(
                      myRequestURI,
                      "INVITE",
                      myCallIdHeader,
                      myCSeqHeader,
                      myFromHeader,
                      myToHeader,
                      viaHeaders,
                      myMaxForwardsHeader);

              // Contact
              Address contactAddress =
                  myAddressFactory.createAddress(
                      "<sip:" + mySipAlias + "@" + myIP + ":" + myPort + ";transport=udp>");
              myContactHeader = myHeaderFactory.createContactHeader(contactAddress);
              myRequest.addHeader(myContactHeader);

              // Allow
              Allow myAllow = new Allow();
              myAllow.setMethod(
                  "INVITE, ACK, CANCEL, BYE, MESSAGE, OPTIONS, NOTIFY, PRACK, UPDATE, REFER");
              myRequest.addHeader(myAllow);

              // Privacy
              Privacy myPrivacy = new Privacy("none");
              myRequest.addHeader(myPrivacy);

              // PPreferredIdentity
              HeaderFactoryImpl myHeaderFactoryImpl = new HeaderFactoryImpl();
              PPreferredIdentityHeader myPPreferredIdentityHeader =
                  myHeaderFactoryImpl.createPPreferredIdentityHeader(
                      myAddressFactory.createAddress("sip:" + myName + '@' + myServer));
              myRequest.addHeader(myPPreferredIdentityHeader);

              // Route
              Address routeAddress =
                  myAddressFactory.createAddress("sip:orig@scscf." + myServer + ":6060;lr");
              // RouteHeader comentei
              myRouteHeader = myHeaderFactory.createRouteHeader(routeAddress);
              myRequest.addHeader(myRouteHeader);

              // Para proxy funcionar
              SipURI outboundProxyURI = myAddressFactory.createSipURI("proxy", myProxyIP);
              outboundProxyURI.setLrParam();
              outboundProxyURI.setPort(myProxyPort);
              myRouteHeader =
                  myHeaderFactory.createRouteHeader(
                      myAddressFactory.createAddress(outboundProxyURI));
              myRequest.addFirst(myRouteHeader);

              // Content Type
              ContentTypeHeader contentTypeHeader =
                  myHeaderFactory.createContentTypeHeader("application", "sdp");
              myRequest.setContent(content, contentTypeHeader);

              // ClientTransaction comentei aqui
              myClientTransaction = mySipProvider.getNewClientTransaction(myRequest);
              myClientTransaction.setRetransmitTimer(700);
              myClientTransaction.sendRequest();

              status = WAIT_PROV;

              logger.info(">>> " + myRequest.toString());

            } else {
              this.setOff(mySipStack);
            }
          } else {
            if (myStatusCode == 403) {

              System.out.println("Problemas com credenciais!!!!\n");
            } else if (myStatusCode == 401) {

              myName = (String) this.getLocalName();
              myUserID = (String) this.getLocalName() + "@" + myServer;

              Address contactAddress =
                  myAddressFactory.createAddress("sip:" + myName + '@' + myIP + ":" + myPort);
              myContactHeader = myHeaderFactory.createContactHeader(contactAddress);

              myViaHeader = myHeaderFactory.createViaHeader(myIP, myPort, "udp", null);

              fromAddress = myAddressFactory.createAddress(myName + " <sip:" + myUserID + ">");

              Address registrarAddress = myAddressFactory.createAddress("sip:" + myServer);
              Address registerToAddress = fromAddress;
              Address registerFromAddress = fromAddress;

              ToHeader myToHeader = myHeaderFactory.createToHeader(registerToAddress, null);
              FromHeader myFromHeader =
                  myHeaderFactory.createFromHeader(registerFromAddress, "647554");

              ArrayList myViaHeaders = new ArrayList();
              myViaHeaders.add(myViaHeader);

              // System.out.println("myClientTransaction.getRequest():"+
              // myClientTransaction.getRequest());
              CSeqHeader originalCSeq =
                  (CSeqHeader) myClientTransaction.getRequest().getHeader(CSeqHeader.NAME);
              long numseq = originalCSeq.getSeqNumber();
              MaxForwardsHeader myMaxForwardsHeader = myHeaderFactory.createMaxForwardsHeader(70);
              CSeqHeader myCSeqHeader = myHeaderFactory.createCSeqHeader(numseq + 1L, "REGISTER");

              CallIdHeader myCallID =
                  (CallIdHeader) myClientTransaction.getRequest().getHeader(CallIdHeader.NAME);
              CallIdHeader myCallIDHeader = myCallID;
              SipURI myRequestURI = (SipURI) registrarAddress.getURI();
              Request myRegisterRequest =
                  myMessageFactory.createRequest(
                      myRequestURI,
                      "REGISTER",
                      myCallIDHeader,
                      myCSeqHeader,
                      myFromHeader,
                      myToHeader,
                      myViaHeaders,
                      myMaxForwardsHeader);
              myRegisterRequest.addHeader(myContactHeader);

              // Expires
              ExpiresHeader myExpiresHeader;
              if (Unregistring) {
                myExpiresHeader = myHeaderFactory.createExpiresHeader(0);
                myContactHeader.setExpires(0);
              } else {
                myExpiresHeader = myHeaderFactory.createExpiresHeader(60000);
              }
              myRegisterRequest.addHeader(myExpiresHeader);

              // Allow
              Allow myAllow = new Allow();
              myAllow.setMethod(
                  "INVITE, ACK, CANCEL, BYE, MESSAGE, OPTIONS, NOTIFY, PRACK, UPDATE, REFER");
              myRegisterRequest.addHeader(myAllow);

              // Privacy
              Privacy myPrivacy = new Privacy("none");
              myRegisterRequest.addHeader(myPrivacy);

              // PPreferredIdentity
              HeaderFactoryImpl myHeaderFactoryImpl = new HeaderFactoryImpl();
              PPreferredIdentityHeader myPPreferredIdentityHeader =
                  myHeaderFactoryImpl.createPPreferredIdentityHeader(
                      myAddressFactory.createAddress("sip:" + myName + '@' + myServer));
              myRegisterRequest.addHeader(myPPreferredIdentityHeader);

              // Supported
              Supported mySupported = new Supported("path");
              myRegisterRequest.addHeader(mySupported);

              myWWWAuthenticateHeader =
                  Utils.makeAuthHeader(
                      myHeaderFactory, myResponse, myRegisterRequest, myUserID, myPassword);
              myRegisterRequest.addHeader(myWWWAuthenticateHeader);

              myClientTransaction = mySipProvider.getNewClientTransaction(myRegisterRequest);
              myClientTransaction.sendRequest();

              // logger.info(">>> "+myRegisterRequest.toString());
              // System.out.println(">>> " + myRegisterRequest.toString());
              status = REGISTERING;
            }
          }
          break;
      }
    } catch (Exception excep) {
      excep.printStackTrace();
    }
  }
  public void processRequest(RequestEvent requestReceivedEvent) {
    /// System.out.println("=> BUNDLE: br.ufes.inf.ngn.televoto.client.logic | CLASS: LogicListener
    // | METOD: processRequest ");//By Ju

    String method;
    Response myResponse;
    ToHeader myToHeader;
    Request myRequest = requestReceivedEvent.getRequest();
    method = myRequest.getMethod();
    // logger.info(myRequest.toString());
    if (!method.equals("CANCEL")) {
      myServerTransaction = requestReceivedEvent.getServerTransaction();
    }
    try {

      switch (status) {
        case WAIT_PROV:
          status = WAIT_ACK;
          System.out.println("Chamando....");
          break;

        case IDLE:
          if (method.equals("INVITE")) {
            if (myServerTransaction == null) {
              myServerTransaction = mySipProvider.getNewServerTransaction(myRequest);
            }
            byte[] cont = (byte[]) myRequest.getContent();
            offerInfo = mySdpManager.getSdp(cont);

            answerInfo.IpAddress = myIP;
            answerInfo.aport = myAudioPort;
            answerInfo.aformat = offerInfo.aformat;

            if (useQueue.equals("yes")) {
              status = ESTABLISHED;
            } else {
              // envio do PROVISIONAL 180
              myResponse = myMessageFactory.createResponse(180, myRequest);
              myResponse.addHeader(myContactHeader);
              myToHeader = (ToHeader) myResponse.getHeader("To");
              myToHeader.setTag("454326");
              myServerTransaction.sendResponse(myResponse);
              myDialog = myServerTransaction.getDialog();
              // logger.info(">>> "+myResponse.toString());
              status = WAIT_ACK;
            }
            // inicio do envio do ACK ao cliente em confirmacao ao PROV_180 e envio do SDP
            Request originalRequest = myServerTransaction.getRequest();
            myResponse = myMessageFactory.createResponse(200, originalRequest);
            // System.out.println(originalRequest.toString());
            myToHeader = (ToHeader) myResponse.getHeader("To");
            myResponse.addHeader(myContactHeader);

            // SEND ANSWER SDP

            ContentTypeHeader contentTypeHeader =
                myHeaderFactory.createContentTypeHeader("application", "sdp");
            byte[] content = mySdpManager.createSdp(answerInfo);
            myResponse.setContent(content, contentTypeHeader);

            // aguardando ACK do cliente
            myServerTransaction.sendResponse(myResponse);
            myDialog = myServerTransaction.getDialog();

            new Timer().schedule(new MyTimerTask(this), 500000); // Aqui!!!
            // logger.info(">>> " + myResponse.toString());

          }
          if (method.equals("OPTIONS")) {
            if (myServerTransaction == null) {
              myServerTransaction = mySipProvider.getNewServerTransaction(myRequest);
            }

            Request originalRequest = myServerTransaction.getRequest();
            myResponse = myMessageFactory.createResponse(200, originalRequest);
            myResponse.addHeader(myContactHeader);
            myServerTransaction.sendResponse(myResponse);
          }

          break;
        case ESTABLISHED:
          if (method.equals("BYE")) {
            // capturar o timestamp
            // logger.info(myName + ";BYE;" +  getTime());
            System.out.println(myName + ": BYE");
            myResponse = myMessageFactory.createResponse(200, myRequest);
            myResponse.addHeader(myContactHeader);
            myServerTransaction.sendResponse(myResponse);
            // logger.info(">>> "+myResponse.toString());
            if (ack == 1) {
              ack = 0;
              redial++;

              if (redial <= dialTimes) {
                // inserir captura timestamp
                logger.info(myName + ";BYE;" + getTime());
                System.out.println(myName + ": rediscagem " + redial + " para: " + destination);

                String dstURI[] = destination.split("@");
                String dstSipAlias = dstURI[0];
                Address destinationAddress =
                    myAddressFactory.createAddress(dstSipAlias + " <sip:" + destination + ">");
                javax.sip.address.URI myRequestURI = destinationAddress.getURI();

                Address addressOfRecord =
                    myAddressFactory.createAddress(
                        mySipAlias + " <sip:" + mySipAlias + "@" + myIP + ":" + myPort + ">");
                // HeaderFactory comentei
                myHeaderFactory = mySipFactory.createHeaderFactory();
                // ViaHeader comentei
                myViaHeader = myHeaderFactory.createViaHeader(myIP, myPort, "udp", null);
                ArrayList viaHeaders = new ArrayList();
                viaHeaders.add(myViaHeader);
                MaxForwardsHeader myMaxForwardsHeader = myHeaderFactory.createMaxForwardsHeader(70);
                CallIdHeader myCallIdHeader = mySipProvider.getNewCallId();
                CSeqHeader myCSeqHeader = myHeaderFactory.createCSeqHeader(1L, "INVITE");
                FromHeader myFromHeader =
                    myHeaderFactory.createFromHeader(addressOfRecord, "456249");
                myToHeader = myHeaderFactory.createToHeader(destinationAddress, null);

                myRequest =
                    myMessageFactory.createRequest(
                        myRequestURI,
                        "INVITE",
                        myCallIdHeader,
                        myCSeqHeader,
                        myFromHeader,
                        myToHeader,
                        viaHeaders,
                        myMaxForwardsHeader);

                Address contactAddress =
                    myAddressFactory.createAddress(
                        "<sip:" + mySipAlias + "@" + myIP + ":" + myPort + ">");
                myContactHeader = myHeaderFactory.createContactHeader(contactAddress);
                myRequest.addHeader(myContactHeader);

                SdpInfo offerInfo = new SdpInfo();

                offerInfo.IpAddress = myIP;
                offerInfo.aport = myAudioPort;

                offerInfo.aformat = 0;

                ContentTypeHeader contentTypeHeader =
                    myHeaderFactory.createContentTypeHeader("application", "sdp");
                byte[] content = mySdpManager.createSdp(offerInfo);
                myRequest.setContent(content, contentTypeHeader);

                // ClientTransaction Comentei aqui
                myClientTransaction = mySipProvider.getNewClientTransaction(myRequest);
                myClientTransaction.sendRequest();
                logger.info(myName + ";INVITE;" + getTime());
                // System.out.println(myRequest);
                status = WAIT_PROV;
              } else {
                status = IDLE;
                System.out.println(myName + ": pronto.");
              }
            } else ack++;
          }
          break;

        case RINGING:
          if (method.equals("CANCEL")) {
            ServerTransaction myCancelServerTransaction =
                requestReceivedEvent.getServerTransaction();
            Request originalRequest = myServerTransaction.getRequest();
            myResponse = myMessageFactory.createResponse(487, originalRequest);
            myServerTransaction.sendResponse(myResponse);
            Response myCancelResponse = myMessageFactory.createResponse(200, myRequest);
            myCancelServerTransaction.sendResponse(myCancelResponse);
            // logger.info(">>> "+myResponse.toString());
            // logger.info(">>> "+myCancelResponse.toString());
            status = IDLE;
          }
          break;

        case WAIT_ACK:
          if (method.equals("ACK")) {
            status = ESTABLISHED;
            System.out.println("Conectado ...");
            // SendMedia(offerInfo.IpAddress, offerInfo.aport);
          }

          break;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }