Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * Conditions Of Use
  *
  * This software was developed by employees of the National Institute of
  * Standards and Technology (NIST), and others.
  * This software is has been contributed to the public domain.
  * As a result, a formal license is not needed to use the software.
  *
  * This software is 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.
 *
 *
 */
 package test.tck.msgflow.callflows.router;
 
 import javax.sip.*;
 
 
 
 import java.util.*;

This class is a UAC template.

Author(s):
M. Ranganathan
 
 
 public class Shootme implements SipListener {
 
     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 Dialog dialog;
 
     private String toTag;
 
     private String transport;
 
     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);
         }
 
     }
 
 
 
     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());
            Dialog dialog = serverTransaction.getDialog();
            AbstractRouterTestCase.assertTrue("Dialog mismatch"dialog == this.);
            SipProvider provider = (SipProviderrequestEvent.getSource();
            AbstractRouterTestCase.assertTrue("Provider mismatch" == provider);
            Request byeRequest = dialog.createRequest(.);
            ClientTransaction ct = provider.getNewClientTransaction(byeRequest);
            dialog.sendRequest(ct);
        } catch (Exception ex) {
            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;
            Address address = .createAddress("Shootme <sip:"
                    +  + ":" +  + ">");
            ContactHeader contactHeader = 
                    .createContactHeader(address);
            okResponse.addHeader(contactHeader);
            .info("sending response.");
            st.sendResponse(okResponse);
            // new Timer().schedule(new MyTimerTask(this), 100);
        } catch (Exception ex) {
            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