Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package test.tck.msgflow.callflows.prack;
  
  import javax.sip.*;
  import javax.sip.header.*;
  
  
 
 import java.util.*;

This class is a UAC template. Shootist is the guy that shoots and shootme is the guy that gets shot.

Author(s):
M. Ranganathan
 
 
 public class Shootme implements SipListener {
 
     protected static final int PRACK_CODE = 183;
 
     private static SipProvider sipProvider;
 
     private static AddressFactory addressFactory;
 
     private static MessageFactory messageFactory;
 
     private static HeaderFactory headerFactory;
 
     private static SipStack sipStack;
 
     private static final String myAddress = "127.0.0.1";
 
     protected ServerTransaction inviteTid;
 
     private Request inviteRequest;
 
     private Dialog dialog;
 
     private String toTag;
 
     private String transport;
 
     private boolean prackRequestReceived;
 
     private boolean inviteReceived;
 
     public static final int myPort = 5080;
 
     private static Logger logger = Logger.getLogger("test.tck");
 
     public Shootme(ProtocolObjects protObjects) {
          = protObjects.addressFactory;
          = protObjects.messageFactory;
          = protObjects.headerFactory;
          = protObjects.sipStack;
          = protObjects.transport;
     }
 
     public void processRequest(RequestEvent requestEvent) {
         Request request = requestEvent.getRequest();
         ServerTransaction serverTransactionId = requestEvent
                 .getServerTransaction();
 
         .info("\n\nRequest " + request.getMethod() + " received at "
                 + .getStackName() + " with server transaction id "
                 + serverTransactionId);
 
         if (request.getMethod().equals(.)) {
             processInvite(requestEventserverTransactionId);
         } else if (request.getMethod().equals(.)) {
             processAck(requestEventserverTransactionId);
         } else if (request.getMethod().equals(.)) {
             processBye(requestEventserverTransactionId);
         } else if (request.getMethod().equals(.)) {
             processPrack(requestEventserverTransactionId);
         }
 
     }
 
     private void processPrack(RequestEvent requestEvent,
             ServerTransaction serverTransactionId) {
          = true;
         try {
             .info("shootme: got an PRACK! ");
             .info("Dialog State = " + .getState());

            
JvB: First, send 200 OK for PRACK
 
             Request prack = requestEvent.getRequest();
             Response prackOk = .createResponse(200, prack);
             serverTransactionId.sendResponse(prackOk);

            
Send a 200 OK response to complete the 3 way handshake for the INIVTE.
            Response response = .createResponse(200,
                    );
            ToHeader to = (ToHeaderresponse.getHeader(.);
            to.setTag(this.);
            Address address = .createAddress("Shootme <sip:"
                    +  + ":" +  + ">");
            ContactHeader contactHeader = 
                    .createContactHeader(address);
            response.addHeader(contactHeader);
            .sendResponse(response);
        } catch (Exception ex) {
            TestHarness.fail(ex.getMessage());
        }
    }
    public void processResponse(ResponseEvent responseEvent) {
    }

    
Process the ACK request. Send the bye and complete the call flow.
    public void processAck(RequestEvent requestEvent,
            ServerTransaction serverTransaction) {
        try {
            .info("shootme: got an ACK! Sending  a BYE");
            .info("Dialog State = " + .getState());
            // JvB: there should not be a transaction for ACKs; requestEvent
            // can be used to get it instead
            // Dialog dialog = serverTransaction.getDialog();
            Dialog dialog = requestEvent.getDialog();
            SipProvider provider = (SipProviderrequestEvent.getSource();
            Request byeRequest = dialog.createRequest(.);
            ClientTransaction ct = provider.getNewClientTransaction(byeRequest);
            dialog.sendRequest(ct);
        } catch (Exception ex) {
            ex.printStackTrace();
            TestHarness.fail(ex.getMessage());
        }
    }

    
Process the invite request.
    public void processInvite(RequestEvent requestEvent,
            ServerTransaction serverTransaction) {
         = true;
        SipProvider sipProvider = (SipProviderrequestEvent.getSource();
        Request request = requestEvent.getRequest();
        try {
            .info("shootme: got an Invite sending Trying");
            // logger.info("shootme: " + request);
            Response response = .createResponse(.,
                    request);
            ServerTransaction st = requestEvent.getServerTransaction();
            if (st == null) {
                st = sipProvider.getNewServerTransaction(request);
            }
             = st.getDialog();
            st.sendResponse(response);
            // reliable provisional response.
            Response okResponse = .createResponse(,
                    request);
            ToHeader toHeader = (ToHeaderokResponse.getHeader(.);
            this. = "4321";
            toHeader.setTag(); // Application is supposed to set.
            this. = st;
            this. = request;
            .info("sending reliable provisional response.");
            RequireHeader requireHeader = 
                    .createRequireHeader("100rel");
            okResponse.addHeader(requireHeader);
            .sendReliableProvisionalResponse(okResponse);
        } catch (Exception ex) {
          ex.printStackTrace();
            TestHarness.fail(ex.getMessage());
        }
    }

    
Process the bye request.
    public void processBye(RequestEvent requestEvent,
            ServerTransaction serverTransactionId) {
        Request request = requestEvent.getRequest();
        try {
            .info("shootme:  got a bye sending OK.");
            Response response = .createResponse(200, request);
            serverTransactionId.sendResponse(response);
            .info("Dialog State is "
                    + serverTransactionId.getDialog().getState());
        } catch (Exception ex) {
            TestHarness.fail(ex.getMessage());
            System.exit(0);
        }
    }
    public void processTimeout(javax.sip.TimeoutEvent timeoutEvent) {
        Transaction transaction;
        if (timeoutEvent.isServerTransaction()) {
            transaction = timeoutEvent.getServerTransaction();
        } else {
            transaction = timeoutEvent.getClientTransaction();
        }
        .info("state = " + transaction.getState());
        .info("dialog = " + transaction.getDialog());
        .info("dialogState = " + transaction.getDialog().getState());
        .info("Transaction Time out");
    }
    public SipProvider createProvider() throws Exception {
        ListeningPoint lp = .createListeningPoint("127.0.0.1",
                );
         = .createSipProvider(lp);
        .info( + " SIP provider " + );
        return ;
    }
    public void processIOException(IOExceptionEvent exceptionEvent) {
        .info("IOException");
    }
    public void processTransactionTerminated(
            TransactionTerminatedEvent transactionTerminatedEvent) {
        .info("Transaction terminated event recieved");
    }
    public void processDialogTerminated(
            DialogTerminatedEvent dialogTerminatedEvent) {
        .info("Dialog terminated event recieved");
    }
    public void checkState() {
        TestHarness.assertTrue( && );
    }
New to GrepCode? Check out our FAQ X