Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package test.unit.gov.nist.javax.sip.stack.dialog.termination;
  
  import javax.sip.*;
  import javax.sip.header.*;
  
 
 import  test.tck.msgflow.callflows.ProtocolObjects;
 
 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):
baranowb
 
 
 public class Shootme implements SipListener {
 
     class TTask extends TimerTask {
 
         RequestEvent requestEvent;
 
         ServerTransaction st;
 
         public TTask(RequestEvent requestEventServerTransaction st) {
             this. = requestEvent;
             this. = st;
         }
 
         public void run() {
             Request request = .getRequest();
             try {
                 // System.out.println("shootme: got an Invite sending OK");
                 Response response = .createResponse(180, request);
                 ToHeader toHeader = (ToHeaderresponse.getHeader(.);
                 Address address = .createAddress("Shootme <sip:" +  + ":" +  + ">");
                 ContactHeader contactHeader = .createContactHeader(address);
                 response.addHeader(contactHeader);
 
                 // System.out.println("got a server tranasaction " + st);
                 Dialog dialog = .getDialog();
 
                 .sendResponse(response); // send 180(RING)
                 response = .createResponse(200, request);
                 toHeader = (ToHeaderresponse.getHeader(.);
                 String toTag = new Integer((int) (Math.random() * 100000)).toString()+"_ResponseCode_"+;
                 toHeader.setTag(toTag); // Application is supposed to set.
                 response.addHeader(contactHeader);
 
                 .sendResponse(response);// send 200(OK)
 
             } catch (Exception ex) {
                 ex.printStackTrace();
                 DialogTerminationOn50XTest.fail("Shootme: Failed in timer task!!!"ex);
             }
 
         }
 
     }
 
 
     private static AddressFactory addressFactory;
 
     private static MessageFactory messageFactory;
 
     private static HeaderFactory headerFactory;
 
 
     private boolean stateIsOk = true;
 
     private ProtocolObjects protocolObjects;
 
     private int responseCodeToINFO = 500;
 
     // To run on two machines change these to suit.
     public static final String myAddress = "127.0.0.1";
 
     public static final int myPort = 5070;
 
     private static Logger logger = Logger.getLogger(Shootme.class);
 
     static {
         if (.getAllAppenders().equals(NullEnumeration.getInstance())) {
 
             .addAppender(new ConsoleAppender(new SimpleLayout()));
 
         }
     }
 
     public Shootme(ProtocolObjects protocolObjects) {
         this. = protocolObjects;
    }
    public boolean checkState() {
        return ;
    }
    public SipProvider createSipProvider() throws Exception {
        ListeningPoint lp = ..createListeningPoint(.);
        SipProvider sipProvider = ..createSipProvider(lp);
        return sipProvider;
    }
    public void init() {
    }

    
Process the ACK request. Send the bye and complete the call flow.
    public void processAck(RequestEvent requestEventServerTransaction serverTransaction) {
        SipProvider sipProvider = (SipProviderrequestEvent.getSource();
        try {
            // System.out.println("*** shootme: got an ACK "
            // + requestEvent.getRequest());
            if (serverTransaction == null) {
                ..println("null server transaction -- ignoring the ACK!");
                return;
            }
            Dialog dialog = serverTransaction.getDialog();
            ..println("Dialog Created = " + dialog.getDialogId() + " Dialog State = " + dialog.getState());
            ..println("Waiting for INFO");
        } catch (Exception ex) {
            ex.printStackTrace();
            DialogTerminationOn50XTest.fail("Shootme: Failed on process ACK"ex);
        }
    }
    public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) {
        Dialog dialog = dialogTerminatedEvent.getDialog();
        ..println("Dialog Terminated Event " + dialog.getDialogId());
        if ( this.>=300)
        {
            DialogTerminationOn50XTest.fail("Shootme: Got DialogTerinatedEvent, this shouldnt happen");
            =false;
        }
    }
    public void processInfo(RequestEvent requestEvent) {
        try {
            Response info500Response = .createResponse(this.requestEvent.getRequest());
            requestEvent.getServerTransaction().sendResponse(info500Response);
        } catch (Exception e) {
            e.printStackTrace();
            DialogTerminationOn50XTest.fail("Shootme: Failed on process INFO"e);
        }
    }

    
Process the invite request.
    public void processInvite(RequestEvent requestEventServerTransaction serverTransaction) {
        try {
            // System.out.println("ProcessInvite");
            Request request = requestEvent.getRequest();
            SipProvider sipProvider = (SipProviderrequestEvent.getSource();
            // Note you need to create the Server Transaction
            // before the listener returns but you can delay sending the
            // response
            ServerTransaction st = sipProvider.getNewServerTransaction(request);
            TTask ttask = new TTask(requestEventst);
            int ttime = 100;
            new Timer().schedule(ttaskttime);
        } catch (Exception ex) {
            ex.printStackTrace();
            DialogTerminationOn50XTest.fail("Shootme: Failed on process INVITE"ex);
        }
    }
    public void processIOException(IOExceptionEvent exceptionEvent) {
        ..println("IOException event");
        DialogTerminationOn50XTest.fail("Got IOException event");
    }
    public void processRequest(RequestEvent requestEvent) {
        Request request = requestEvent.getRequest();
        ServerTransaction serverTransactionId = requestEvent.getServerTransaction();
        ..println("GOT REQUEST: " + request.getMethod());
        if (request.getMethod().equals(.)) {
            processInvite(requestEventserverTransactionId);
        } else if (request.getMethod().equals(.)) {
            processAck(requestEventserverTransactionId);
        } else if (request.getMethod().equals(.)) {
            processInfo(requestEvent);
        }
    }
    public void processResponse(ResponseEvent responseReceivedEvent) {
        // System.out.println("Got a response");
        Response response = (ResponseresponseReceivedEvent.getResponse();
        Transaction tid = responseReceivedEvent.getClientTransaction();
        // System.out.println("Response received with client transaction id "
        // + tid + ":\n" + response);
        ..println("GOT RESPONSE: " + response.getStatusCode());
        try {
            if (response.getStatusCode() == . && ((CSeqHeaderresponse.getHeader(.)).getMethod().equals(.)) {
                Dialog dialog = tid.getDialog();
                Request request = tid.getRequest();
                dialog.sendAck(request);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            DialogTerminationOn50XTest.fail("Shootme: Failed on process response: " + response.getStatusCode(), ex);
        }
    }
    public void processTimeout(javax.sip.TimeoutEvent timeoutEvent) {
        Transaction transaction;
        if (timeoutEvent.isServerTransaction()) {
            transaction = timeoutEvent.getServerTransaction();
        } else {
            transaction = timeoutEvent.getClientTransaction();
        }
        /*
         * System.out.println("state = " + transaction.getState());
         * System.out.println("dialog = " + transaction.getDialog());
         * System.out.println("dialogState = " +
         * transaction.getDialog().getState());
         * System.out.println("Transaction Time out" +
         * transaction.getBranchId());
         */
    }
    public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) {
        // System.out.println("TransactionTerminatedEvent");
    }
    public void setResponseCodeToINFO(int responseCodeToINFO) {
        this. = responseCodeToINFO;
    }
New to GrepCode? Check out our FAQ X