Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package test.unit.gov.nist.javax.sip.stack;
  
  
 
 
 
 import  junit.framework.TestCase;
 
 public class CtxExpiredTest extends TestCase {
 
 
 
 
     private Shootist shootist;
 
     private Shootme shootme;
 
     private SipStackExt shootistStack;
 
     private SipStackExt shootmeStack;
 
     private static String PEER_ADDRESS = .;
 
     private static int PEER_PORT = .;
 
     private static String peerHostPort =  + ":" + ;
 
     private static Logger logger = Logger.getLogger(CtxExpiredTest.class);
     static {
         .addAppender(new ConsoleAppender());
     }
 
     class Shootist implements SipListener {
 
         protected static final String myAddress = "127.0.0.1";
 
         protected static final int myPort = 6050;
 
         private SipProviderExt provider;
 
         private boolean saw1xx;
 
         private ClientTransaction inviteTid;
 
         private Dialog dialog;
 
         private boolean timeoutSeen;
 
         public void checkState() {
             assertTrue("Should see timeout ");
             assertTrue("Should see 1xx ");
         }
 
         public Shootist(SipStackExt sipStackthrows Exception {
             ListeningPoint lp = sipStack.createListeningPoint("127.0.0.1",
                     "udp");
             this. = (SipProviderExtsipStack.createSipProvider(lp);
            .addSipListener(this);
        }
        public void sendInvite() {
            try {
                // Note that a provider has multiple listening points.
                // all the listening points must have the same IP address
                // and port but differ in their transport parameters.
                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);
                Address fromNameAddress = 
                        .createAddress(fromAddress);
                fromNameAddress.setDisplayName(fromDisplayName);
                FromHeader fromHeader = .createFromHeader(
                        fromNameAddressnew Integer(
                                (int) (Math.random() * .))
                                .toString());
                // create To Header
                SipURI toAddress = .createSipURI(toUser,
                        toSipAddress);
                Address toNameAddress = .createAddress(toAddress);
                toNameAddress.setDisplayName(toDisplayName);
                ToHeader toHeader = .createToHeader(toNameAddress,
                        null);
                // create Request URI
                SipURI requestURI = .createSipURI(toUser,
                        );
                // Create ViaHeaders
                ArrayList viaHeaders = new ArrayList();
                int port = .getListeningPoint("udp").getPort();
                ViaHeader viaHeader = .createViaHeader(,
                        port"udp"null);
                // add via headers
                viaHeaders.add(viaHeader);
                // Create ContentTypeHeader
                ContentTypeHeader contentTypeHeader = 
                        .createContentTypeHeader("application""sdp");
                // Create a new CallId header
                CallIdHeader callIdHeader = .getNewCallId();
                // JvB: Make sure that the implementation matches the
                // messagefactory
                callIdHeader = .createCallIdHeader(callIdHeader
                        .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
                // Create the contact name address.
                SipURI contactURI = .createSipURI(fromName,
                        );
                contactURI.setPort(.getListeningPoint("udp").getPort());
                Address contactAddress = 
                        .createAddress(contactURI);
                // Add the contact address.
                contactAddress.setDisplayName(fromName);
                ContactHeader contactHeader = 
                        .createContactHeader(contactAddress);
                request.addHeader(contactHeader);
                ExpiresHeader expires = .createExpiresHeader(20);
                request.setHeader(expires);
                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";
                request.setContent(sdpDatacontentTypeHeader);
                // The following is the preferred method to route requests
                // to the peer. Create a route header and set the "lr"
                // parameter for the router header.
                Address address = .createAddress("<sip:"
                        +  + ":" +  + ">");
                // SipUri sipUri = (SipUri) address.getURI();
                // sipUri.setPort(PEER_PORT);
                RouteHeader routeHeader = 
                        .createRouteHeader(address);
                ((SipURIaddress.getURI()).setLrParam();
                request.addHeader(routeHeader);
                // Create the client transaction.
                this. = .getNewClientTransaction(request);
                this. = this..getDialog();
                // Note that the response may have arrived right away so
                // we cannot check after the message is sent.
                TestCase
                        .assertTrue(this..getState() == null);
                // send the request out.
                this..sendRequest();
            } catch (Exception ex) {
                .error("Unexpected exception"ex);
                TestCase.fail("unexpected exception");
            }
        }
        
        public void processDialogTerminated(
                DialogTerminatedEvent dialogTerminatedEvent) {
        }
        
        public void processIOException(IOExceptionEvent exceptionEvent) {
            TestCase.fail("Unexpected event");
        }
        
        public void processRequest(RequestEvent requestEvent) {
            TestCase.fail("Unexpected event : processRequest");
        }
        
        public void processResponse(ResponseEvent responseEvent) {
            if (responseEvent.getResponse().getStatusCode() == 100) {
                this. = true;
            }
        }
        
        public void processTimeout(TimeoutEvent timeoutEvent) {
            this. = true;
            ClientTransaction ctx = timeoutEvent.getClientTransaction();
            TestCase.assertSame("Should see a timeout for INVITE"ctx,
                    this.);
            TestCase.assertEquals("Should be in proceeding state",
                    .ctx.getState());
            try {
                Request cancelRequest = timeoutEvent.getClientTransaction()
                        .createCancel();
                ClientTransaction cancelTx = this.
                        .getNewClientTransaction(cancelRequest);
                cancelTx.sendRequest();
            } catch (Exception ex) {
                .error("Unexpected exception"ex);
                TestCase.fail("Unexpected exception");
            }
        }
        
        public void processTransactionTerminated(
                TransactionTerminatedEvent transactionTerminatedEvent) {
            .debug("Transaction Terminated Event seen");
        }
    }
    public class Shootme implements SipListener {
        public static final int myPort = 6060;
        public static final String myAddress = "127.0.0.1";
        private SipProviderExt provider;
        public Shootme(SipStackExt sipStackthrows Exception {
            ListeningPoint lp = sipStack.createListeningPoint("127.0.0.1",
                    "udp");
            this. = (SipProviderExtsipStack.createSipProvider(lp);
            .addSipListener(this);
        }
        
        public void processDialogTerminated(
                DialogTerminatedEvent dialogTerminatedEvent) {
            // TODO Auto-generated method stub
        }
        
        public void processIOException(IOExceptionEvent exceptionEvent) {
            // TODO Auto-generated method stub
        }
        
        public void processRequest(RequestEvent requestEvent) {
            try {
                Request request = requestEvent.getRequest();
                if (request.getMethod().equals(.)) {
                    if (requestEvent.getServerTransaction() == null) {
                        ServerTransactionExt serverTransaction = (ServerTransactionExtthis.
                                .getNewServerTransaction(request);
                        Response tryingResponse = 
                                .createResponse(100, request);
                        serverTransaction.sendResponse(tryingResponse);
                    }
                } else if (request.getMethod().equals(.)) {
                    ServerTransaction stx = requestEvent.getServerTransaction();
                    Response okResponse = .createResponse(200,
                            request);
                    stx.sendResponse(okResponse);
                }
            } catch (Exception ex) {
                .error("Unexpected exception"ex);
                TestCase.fail("Unexpected exception");
            }
        }
        
        public void processResponse(ResponseEvent responseEvent) {
            // TODO Auto-generated method stub
        }
        
        public void processTimeout(TimeoutEvent timeoutEvent) {
            // TODO Auto-generated method stub
        }
        
        public void processTransactionTerminated(
                TransactionTerminatedEvent transactionTerminatedEvent) {
            // TODO Auto-generated method stub
        }
    }
    
    public void setUp() throws Exception {
        SipFactory sipFactory = null;
        sipFactory = SipFactory.getInstance();
        sipFactory.setPathName("gov.nist");
        Properties properties;
        try {
             = (HeaderFactoryExtsipFactory.createHeaderFactory();
             = sipFactory.createAddressFactory();
             = (MessageFactoryExtsipFactory
                    .createMessageFactory();
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Unexpected exception");
        }
        try {
            // Create SipStack object
            properties = new Properties();
            properties.setProperty("javax.sip.STACK_NAME""shootist");
            // You need 16 for logging traces. 32 for debug + traces.
            // Your code will limp at 32 but it is best for debugging.
            properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL""32");
            properties.setProperty("gov.nist.javax.sip.DEBUG_LOG",
                    "shootistdebug.txt");
          
            this. = (SipStackExtsipFactory
                    .createSipStack(properties);
            this. = new Shootist();
            // -----------------------------
            properties = new Properties();
            properties.setProperty("javax.sip.STACK_NAME""shootme");
            // You need 16 for logging traces. 32 for debug + traces.
            // Your code will limp at 32 but it is best for debugging.
            properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL""32");
            properties.setProperty("gov.nist.javax.sip.DEBUG_LOG",
                    "shootmedebug.txt");
            this. = (SipStackExtsipFactory
                    .createSipStack(properties);
            this. = new Shootme();
        } catch (PeerUnavailableException e) {
            // could not find
            // gov.nist.jain.protocol.ip.sip.SipStackImpl
            // in the classpath
            e.printStackTrace();
            ..println(e.getMessage());
            if (e.getCause() != null)
                e.getCause().printStackTrace();
            TestCase.fail("Unexpected exception");
        }
    }
    
    public void tearDown() throws Exception {
        Thread.sleep(30000);
        this..checkState();
        this..stop();
        this..stop();
    }
    public void testSendInviteExpectTimeout() {
        this..sendInvite();
    }
New to GrepCode? Check out our FAQ X