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 receives an INVITE and sends a 180 and a 200 OK, the Shootist will not send the ACK to test is the Dialog Timeout Event is correctly passed to the application. The timeout Reason should be ACK not received

Author(s):
jean deruelle
 
 
 public class Shootme implements SipListenerExt {
 
     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);
                 
                 if(!.) {
                 	((SipProvider).getSource()).getNewDialog();
                 }
                 
                 // System.out.println("got a server tranasaction " + st);
                 .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();
                 DialogTimeoutTest.fail("Shootme: Failed in timer task!!!"ex);
            }
        }
    }
    private static AddressFactory addressFactory;
    private static MessageFactory messageFactory;
    private static HeaderFactory headerFactory;
    private boolean stateIsOk = false;
    
    private boolean receiveBye = false;
    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;
         = protocolObjects.autoDialog;
    }
    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();
            DialogTimeoutTest.fail("Shootme: Failed on process ACK"ex);
        }
    }
    public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) {
    		 = false;
    		DialogTimeoutTest.fail("This shouldn't be called since a dialogtimeout event should be passed to the application instead!");
    	} else {
    		 = true;
    	}
    }
    public void processInfo(RequestEvent requestEvent) {
        try {
            Response info500Response = .createResponse(this.requestEvent.getRequest());
            requestEvent.getServerTransaction().sendResponse(info500Response);
        } catch (Exception e) {
            e.printStackTrace();
            DialogTimeoutTest.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();
            DialogTimeoutTest.fail("Shootme: Failed on process INVITE"ex);
        }
    }
    public void processIOException(IOExceptionEvent exceptionEvent) {
        ..println("IOException event");
        DialogTimeoutTest.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);
        } else if (request.getMethod().equals(.)) {
            processBye(requestEventserverTransactionId);
        } 
    }
    
    
Process the bye request.
    public void processBye(RequestEvent requestEvent,
            ServerTransaction serverTransactionId) {
        SipProvider sipProvider = (SipProviderrequestEvent.getSource();
        Request request = requestEvent.getRequest();
        Dialog dialog = requestEvent.getDialog();
        ..println("local party = " + dialog.getLocalParty());
        try {
            ..println("shootme:  got a bye sending OK.");
            Response response = .createResponse(200, request);
            serverTransactionId.sendResponse(response);
            ..println("Dialog State is "
                    + serverTransactionId.getDialog().getState());
        } catch (Exception ex) {
            ex.printStackTrace();
            System.exit(0);
        }
    }
    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();
            DialogTimeoutTest.fail("Shootme: Failed on process response: " + response.getStatusCode(), 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");
    		 = false;
    	}    	    	
        /*
         * 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 processDialogTimeout(DialogTimeoutEvent timeoutEvent) {
    	DialogTimeoutEvent dialogAckTimeoutEvent = (DialogTimeoutEvent)timeoutEvent;
		Dialog timeoutDialog = dialogAckTimeoutEvent.getDialog();
		if(timeoutDialog == null){
			DialogTimeoutTest.fail(
                    "Shootist: Exception on timeout, dialog shouldn't be null");
		}
		if(dialogAckTimeoutEvent.getReason() == .) {
			 = true;
		}
	}
    public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) {
        // System.out.println("TransactionTerminatedEvent");
    }
    public void setResponseCodeToINFO(int responseCodeToINFO) {
        this. = responseCodeToINFO;
    }

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

Returns:
the receiveBye
	public boolean isReceiveBye() {
		return ;
	}
New to GrepCode? Check out our FAQ X