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  test.tck.TestHarness;
This class is a UAC template.

Author(s):
M. Ranganathan
 
 
 public class Shootist implements SipListener {
 
     private static SipProvider sipProvider;
 
     private static AddressFactory addressFactory;
 
     private static MessageFactory messageFactory;
 
     private static HeaderFactory headerFactory;
 
     private static SipStack sipStack;
 
     private ContactHeader contactHeader;
 
     private ClientTransaction inviteTid;
 
     private Dialog dialog;
 
     private String transport;
 
 
     public static final int myPort = 5070;
 
     private static Logger logger = Logger.getLogger(Shootist.class);
     static {
         try {
             .setLevel(.);
             .addAppender(new FileAppender(new SimpleLayout(),
                     "logs/telurlshootist.txt"));
         } catch (Exception ex) {
             throw new RuntimeException(ex);
        }
    }
    private String toUser = "LittleGuy";
    private boolean gotInviteOK;
    private boolean gotBye;
    public Shootist(ProtocolObjects protObjects) {
         = protObjects.addressFactory;
         = protObjects.messageFactory;
         = protObjects.headerFactory;
         = protObjects.sipStack;
         = protObjects.transport;
    }
    public SipProvider createProvider() throws Exception {
        ListeningPoint lp = .createListeningPoint("127.0.0.1",
                );
         = .createSipProvider(lp);
        .info( + " SIP provider " + );
        return ;
    }
    public void processRequest(RequestEvent requestReceivedEvent) {
        Request request = requestReceivedEvent.getRequest();
        ServerTransaction serverTransactionId = requestReceivedEvent
                .getServerTransaction();
        .info("\n\nRequest " + request.getMethod()
                + " received at " + .getStackName()
                + " with server transaction id " + serverTransactionId);
        // We are the UAC so the only request we get is the BYE.
        if (request.getMethod().equals(.))
            processBye(requestserverTransactionId);
    }
    public void processBye(Request request,
            ServerTransaction serverTransactionId) {
        try {
            .info("shootist:  got a bye .");
            if (serverTransactionId == null) {
                .info("shootist:  null TID.");
                return;
            }
            Dialog dialog = serverTransactionId.getDialog();
            .info("Dialog State = " + dialog.getState());
            Response response = .createResponse(200, request);
            this. = true;
            serverTransactionId.sendResponse(response);
            .info("shootist:  Sending OK.");
            .info("Dialog State = " + dialog.getState());
        } catch (Exception ex) {
            TestHarness.fail(ex.getMessage());
            System.exit(0);
        }
    }
    public void processResponse(ResponseEvent responseReceivedEvent) {
        .info("Got a response");
        Response response = (ResponseresponseReceivedEvent.getResponse();
        ClientTransaction tid = responseReceivedEvent.getClientTransaction();
        CSeqHeader cseq = (CSeqHeaderresponse.getHeader(.);
        .info("Response received : Status Code = "
                + response.getStatusCode() + " " + cseq);
        if (tid == null) {
            .info("Stray response -- dropping ");
            return;
        }
        .info("transaction state is " + tid.getState());
        .info("Dialog = " + tid.getDialog());
        .info("Dialog State is " + tid.getDialog().getState());
        SipProvider provider = (SipProviderresponseReceivedEvent.getSource();
        AbstractRouterTestCase.assertEquals("Provider is not equal to the original proivder",
                provider);
        try {
            if (response.getStatusCode() == .) {
                if (cseq.getMethod().equals(.)) {
                    Request ackRequest = .createAck(cseq.getSeqNumber());
                    .info("Sending ACK");
                    .sendAck(ackRequest);
                    this. = true;
                }
            }
        } catch (Exception ex) {
            AbstractRouterTestCase.fail(ex.getMessage());
        }
    }
    public void processTimeout(javax.sip.TimeoutEvent timeoutEvent) {
        AbstractRouterTestCase.fail("Unexpected event");
    }
    public void sendInvite() {
        try {
            String fromName = "BigGuy";
            String fromSipAddress = "here.com";
            String fromDisplayName = "The Master Blaster";
            String toSipAddress = "there.com";
            String toDisplayName = "The Little Blister";
            // create >From Header
            SipURI fromAddress = .createSipURI(fromName,
                    fromSipAddress);
            Address fromNameAddress = .createAddress(fromAddress);
            fromNameAddress.setDisplayName(fromDisplayName);
            FromHeader fromHeader = .createFromHeader(
                    fromNameAddress"12345");
            // create To Header
            SipURI toAddress = 
                    .createSipURI(toSipAddress);
            Address toNameAddress = .createAddress(toAddress);
            toNameAddress.setDisplayName(toDisplayName);
            ToHeader toHeader = .createToHeader(toNameAddress,
                    null);
            // create Request URI
            URI requestURI = .createURI("tel:46317014291;phone-context=+5");
            // Create ViaHeaders
            ArrayList viaHeaders = new ArrayList();
            ViaHeader viaHeader = .createViaHeader("127.0.0.1",
                    .getListeningPoint().getPort(),
                    null);
            // add via headers
            viaHeaders.add(viaHeader);
            // Create a new CallId header
            CallIdHeader callIdHeader = .getNewCallId();
            // JvB: Make sure that the implementation matches the messagefactory
            callIdHeader = .createCallIdHeadercallIdHeader.getCallId() );
            // Create a new Cseq header
            CSeqHeader cSeqHeader = .createCSeqHeader(1L,
                    .);
            // Create a new MaxForwardsHeader
            MaxForwardsHeader maxForwards = 
                    .createMaxForwardsHeader(70);
            // Create the request.
            Request request = .createRequest(requestURI,
                    .callIdHeadercSeqHeaderfromHeader,
                    toHeaderviaHeadersmaxForwards);
            // Create contact headers
            String host = "127.0.0.1";
            SipURI contactUrl = .createSipURI(fromNamehost);
            ListeningPoint lp = .getListeningPoint();
            contactUrl.setPort(lp.getPort());
            // Create the contact name address.
            SipURI contactURI = .createSipURI(fromNamehost);
            contactURI.setPort(.getListeningPoint()
                    .getPort());
            Address contactAddress = .createAddress(contactURI);
            // Add the contact address.
            contactAddress.setDisplayName(fromName);
             = .createContactHeader(contactAddress);
            request.addHeader();
            // Create the client transaction.
             = .getNewClientTransaction(request);
             = .getDialog();
            AbstractRouterTestCase.assertTrue("dialog state ",
                    != null && .getState() == null);
            // send the request out.
            .sendRequest();
        } catch (Exception ex) {
            TestHarness.fail("sendInvite failed because of " + ex.getMessage());
        }
    }
    public void processIOException(IOExceptionEvent exceptionEvent) {
        .info("IOException happened for "
                + exceptionEvent.getHost() + " port = "
                + exceptionEvent.getPort());
        AbstractRouterTestCase.fail("unexpected exception IOException");
    }
    public void processTransactionTerminated(
            TransactionTerminatedEvent transactionTerminatedEvent) {
        .info("Transaction terminated event recieved");
    }
    public void processDialogTerminated(
            DialogTerminatedEvent dialogTerminatedEvent) {
        .info("dialogTerminatedEvent");
    }
    public void checkState() {
        TestHarness.assertTrue(this. && this. );
    }
New to GrepCode? Check out our FAQ X