Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * This source code has been contributed to the public domain by Mobicents
   *
   * This software is provided by NIST as a service and is expressly
   * provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
   * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
   * AND DATA ACCURACY.  NIST does not warrant or make any representations
   * regarding the use of the software or the results thereof, including but
  * not limited to the correctness, accuracy, reliability or usefulness of
  * the software.
  *
  * Permission to use this software is contingent upon your acceptance
  * of the terms of this agreement.
  */
 package test.unit.gov.nist.javax.sip.stack.dialog.timeout;
 
 
 
 
 
 import  test.tck.msgflow.callflows.ProtocolObjects;

This class sends an INVITE and upon receiving a 200 OK it doesn't send the ACK to test is the Dialog Timeout Event is correctly passed to the application The timeout Reason should be ACK not sent

Author(s):
jean deruelle
 
 
 public class Shootist implements SipListenerExt {
 
     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 boolean stateIsOk = false;
    
    private boolean sendByeOnDialogTimeout = false;
    
    private Dialog dialog = null;
    private static Logger logger = Logger.getLogger(Shootist.class);
    static {
        if (.getAllAppenders().equals(NullEnumeration.getInstance())) {
            .addAppender(new ConsoleAppender(new SimpleLayout()));
        }
    }
    class ByeTask  extends TimerTask {
        Dialog dialog;
        public ByeTask(Dialog dialog)  {
            this. = dialog;
        }
        public void run () {
            try {
               Request byeRequest = this..createRequest(.);
               ClientTransaction ct = .getNewClientTransaction(byeRequest);
               .sendRequest(ct);
            } catch (Exception ex) {
                ex.printStackTrace();
                System.exit(0);
            }
        }
    }
    
    public Shootist(ProtocolObjects protocolObjects) {
        super();
        this. = protocolObjects;
         = protocolObjects.autoDialog;
    }
    public boolean checkState() {
        return ;
    }
    public SipProvider createSipProvider() {
        try {
             = ..createListeningPoint(
                    .);
             = .
                    .createSipProvider();
            return ;
        } catch (Exception ex) {
            .error(ex);
            DialogTimeoutTest
                    .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();
            DialogTimeoutTest.fail("Shootist: Error on init!"ex);
        }
    }
    public void processDialogTerminated(
            DialogTerminatedEvent dialogTerminatedEvent) {
    		 = true;
    		return;
    	}
    		 = true;
    		return;
    	}
    		 = false;
    		DialogTimeoutTest.fail("This shouldn't be called since a dialogtimeout event should be passed to the application instead!");
    	} else {
    		 = true;
    	}
    	
    }
    public void processIOException(IOExceptionEvent exceptionEvent) {
        ..println("An IO Exception occured!");
        DialogTimeoutTest.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());
        DialogTimeoutTest.fail("Shouldnt receive any request:\n"
                + request);
    }
    public void processResponse(ResponseEvent responseReceivedEvent) {
        Response response = (ResponseresponseReceivedEvent.getResponse();
        ..println("GOT RESPONSE:" + response.getStatusCode());
        if(responseReceivedEvent.getClientTransaction() == null) {
        	return;
        }
        try {
            if (response.getStatusCode() == .
                    && ((CSeqHeaderresponse.getHeader(.))
                            .getMethod().equals(.)) {            	
            	..println("Not Sending ACK to test dialog timeout");            	
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            DialogTimeoutTest.fail(
                    "Shootist: Exception on process respons/send info"ex);
        }
    }
    public void processTimeout(javax.sip.TimeoutEvent timeoutEvent) {
    		DialogTimeoutTest.fail(
            	"Shootist: Exception on timeout, event shouldn't be thrown on automatic dailog creation by the stack");
    	}    	
    }
    
    public void processDialogTimeout(DialogTimeoutEvent timeoutEvent) {    	
		DialogTimeoutEvent dialogTimeoutEvent = (DialogTimeoutEvent)timeoutEvent;
		Dialog timeoutDialog = dialogTimeoutEvent.getDialog();
		if(timeoutDialog == null){
			DialogTimeoutTest.fail(
                    "Shootist: Exception on timeout, dialog shouldn't be null");
		}
		if(dialogTimeoutEvent.getReason() == .) {
				new Timer().schedule(new ByeTask(), 4000) ;
else {
				 = true;
			}
		}
	}
    
    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);
            if(!.) {
            	 = .getNewDialog(inviteTid);
            }
            ..println("inviteTid = " + inviteTid + " sipDialog = "
                    + inviteTid.getDialog());
            // send the request out.
            inviteTid.sendRequest();
        } catch (Exception ex) {
            ..println("Fail to sendInviteRequest with SipException:\n"
                    + ex.getMessage());
            DialogTimeoutTest.fail(
                    "Shootist: Failed to send invite: "ex);
        }
        return;
    }

Parameters:
sendByeOnDialogTimeout the sendByeOnDialogTimeout to set
	public void setSendByeOnDialogTimeout(boolean sendByeOnDialogTimeout) {
		this. = sendByeOnDialogTimeout;
	}

Returns:
the sendByeOnDialogTimeout
	public boolean isSendByeOnDialogTimeout() {
	}
New to GrepCode? Check out our FAQ X