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.*;

Concurrent calls test. The client creates 20 concurrent dialogs on the server. The server replies to each one.

Author(s):
baranowb
 
 
 public class Shootist implements SipListener {
 
     private ListeningPoint listeningPoint;
     private ProtocolObjects protocolObjects;
     /* move variables as class variables from init() */
     private SipURI requestURI;
 
     private CSeqHeader cSeqHeader;
 
     private FromHeader fromHeader;
 
     private ToHeader toHeader;
 
     private MaxForwardsHeader maxForwards;
 
     private SipProvider sipProvider;
 
     private Address fromNameAddress;
 
 
     private ContactHeader contactHeader;
     // If you want to try TCP transport change the following to
     // String transport = "tcp";
     String transport = "udp";
 
     private HeaderFactory headerFactory;
 
     private AddressFactory addressFactory;
 
     private MessageFactory messageFactory;
 
     private static String PEER_ADDRESS = .;
 
     private static int PEER_PORT = .;
 
     private static String peerHostPort =  + ":" + ;
 
     // To run on two machines change these to suit.
     public static final String myAddress = "127.0.0.1";
 
     private static final int myPort = 5060;
 
     private int responseCodeToINFO = 500;
 
     private boolean stateIsOk = true;
 
     private static Logger logger = Logger.getLogger(Shootist.class);
 
     static {
         if (.getAllAppenders().equals(NullEnumeration.getInstance())) {
 
             .addAppender(new ConsoleAppender(new SimpleLayout()));
 
         }
     }
 
     public Shootist(ProtocolObjects protocolObjects) {
         super();
         this. = protocolObjects;
 
     }
 
     public boolean checkState() {
 
         return ;
     }
 
     public SipProvider createSipProvider() {
         try {
              = ..createListeningPoint(
                     .);
 
              = .
                     .createSipProvider();
             return ;
        } catch (Exception ex) {
            .error(ex);
            DialogTerminationOn50XTest
                    .fail("Shootist: unable to create provider");
            return null;
        }
    }
    public void init() {
        SipFactory sipFactory = null;
        sipFactory = SipFactory.getInstance();
        sipFactory.setPathName("gov.nist");
        Properties properties = new Properties();
        /* remote peer host */
        String peerHostPort = .;
        String localHost = ;
        try {
             = .;
             = .;
             = .;
            String fromName = "BigGuy";
            String fromSipAddress = "here.com";
            String fromDisplayName = "The Master Blaster";
            String toSipAddress = "there.com";
            String toUser = "LittleGuy";
            String toDisplayName = "The Little Blister";
            // create >From Header
            SipURI fromAddress = .createSipURI(fromName,
                    fromSipAddress);
             = .createAddress(fromAddress);
            .setDisplayName(fromDisplayName);
            // create To Header
            SipURI toAddress = 
                    .createSipURI(toUsertoSipAddress);
            Address toNameAddress = .createAddress(toAddress);
            toNameAddress.setDisplayName(toDisplayName);
             = .createToHeader(toNameAddressnull);
            // create Request URI
             = .createSipURI(toUserpeerHostPort);
            // Create ContentTypeHeader
                    "application""sdp");
            // Create a new MaxForwardsHeader
             = .createMaxForwardsHeader(70);
            // Create contact headers
            String host = localHost;
            SipURI contactUrl = .createSipURI(fromNamehost);
            contactUrl.setPort(.getPort());
            // Create the contact name address.
            SipURI contactURI = .createSipURI(fromNamehost);
            contactURI.setPort(.getPort());
            Address contactAddress = .createAddress(contactURI);
            // Add the contact address.
            contactAddress.setDisplayName(fromName);
             = .createContactHeader(contactAddress);
        } catch (Exception ex) {
            ..println(ex.getMessage());
            ex.printStackTrace();
            DialogTerminationOn50XTest.fail("Shootist: Error on init!"ex);
        }
    }
    public void processDialogTerminated(
            DialogTerminatedEvent dialogTerminatedEvent) {
        ..println("Shootist: Dialog Terminated Event "
                + dialogTerminatedEvent.getDialog().getDialogId());
        if ((this.) >= 300) {
            DialogTerminationOn50XTest
                    .fail("Shootist: Got DialogTerinatedEvent, this shouldnt happen");
             = false;
        }
    }
    public void processIOException(IOExceptionEvent exceptionEvent) {
        ..println("An IO Exception occured!");
        DialogTerminationOn50XTest.fail("An IO Exception occured!");
    }
    public void processRequest(RequestEvent requestReceivedEvent) {
        Request request = requestReceivedEvent.getRequest();
        ServerTransaction serverTransactionId = requestReceivedEvent
                .getServerTransaction();
        ..println("GOT REQUEST (we shouldnt get that): "
                + request.getMethod());
        DialogTerminationOn50XTest.fail("Shouldnt receive any request:\n"
                + request);
    }
    public void processResponse(ResponseEvent responseReceivedEvent) {
        Response response = (ResponseresponseReceivedEvent.getResponse();
        Transaction tid = responseReceivedEvent.getClientTransaction();
        ..println("GOT RESPONSE:" + response.getStatusCode());
        try {
            if (response.getStatusCode() == .
                    && ((CSeqHeaderresponse.getHeader(.))
                            .getMethod().equals(.)) {
                Dialog dialog = responseReceivedEvent.getDialog();
                CSeqHeader cseq = (CSeqHeaderresponse
                        .getHeader(.);
                Request ackRequest = dialog.createAck(cseq.getSeqNumber());
                ..println("Sending ACK");
                dialog.sendAck(ackRequest);
                ..println("Dialog Confirmed: dialogID = "
                        + dialog.getDialogId() + " dialogState = "
                        + dialog.getState());
                if (tid == null)
                    ..println("null txID");
                Thread.currentThread().sleep(100);
                ..println("Sending INFO");
                Request infoRequest = dialog.createRequest(.);
                ClientTransaction infoCTX = 
                        .getNewClientTransaction(infoRequest);
                dialog.sendRequest(infoCTX);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            DialogTerminationOn50XTest.fail(
                    "Shootist: Exception on process respons/send info"ex);
        }
    }
    public void processTimeout(javax.sip.TimeoutEvent timeoutEvent) {
        DialogTerminationOn50XTest.fail("Shootist:Received timeout even!!!");
    }
    public void processTransactionTerminated(
            TransactionTerminatedEvent transactionTerminatedEvent) {
        // System.out.println("TransactionTerminated event notification");
    }
    void sendInviteRequest() {
        ..println("====Send INVITE");
        try {
             = .createCSeqHeader(1L, .);
            // Create a new CallId header
            CallIdHeader callIdHeader = .getNewCallId();
            int fromTag = 1000 + hashCode();
                    new Integer(fromTag).toString());
            String sdpData = "v=0\r\n"
                    + "o=4855 13760799956958020 13760799956958020"
                    + " IN IP4  129.6.55.78\r\n" + "s=mysession session\r\n"
                    + "p=+46 8 52018010\r\n" + "c=IN IP4  129.6.55.78\r\n"
                    + "t=0 0\r\n" + "m=audio 6022 RTP/AVP 0 4 18\r\n"
                    + "a=rtpmap:0 PCMU/8000\r\n" + "a=rtpmap:4 G723/8000\r\n"
                    + "a=rtpmap:18 G729A/8000\r\n" + "a=ptime:20\r\n";
            // Create ViaHeaders
            ArrayList viaHeaders = new ArrayList();
            ViaHeader viaHeader = .createViaHeader(,
                    .getPort(), null);
            // add via headers
            viaHeaders.add(viaHeader);
            Request request = .createRequest(,
                    .callIdHeader,
                    viaHeaders);
            request.setHeader();
            request.setContent(sdpData);
            // Create the client transaction.
            ClientTransaction inviteTid = 
                    .getNewClientTransaction(request);
            ..println("inviteTid = " + inviteTid + " sipDialog = "
                    + inviteTid.getDialog());
            // send the request out.
            inviteTid.sendRequest();
        } catch (Exception ex) {
            ..println("Fail to sendInviteRequest with SipException:\n"
                    + ex.getMessage());
            DialogTerminationOn50XTest.fail(
                    "Shootist: Failed to send invite: "ex);
        }
        return;
    }
    public void setResponseCodeToINFO(int responseCodeToINFO) {
        this. = responseCodeToINFO;
    }
New to GrepCode? Check out our FAQ X