Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package test.unit.gov.nist.javax.sip.stack;
  
  import java.util.Timer;
  
 
 import  junit.framework.TestCase;
 
 public class DeliverUnsolicitedNotifyTest extends TestCase implements
         SipListener {
 
 
 
     private boolean notifySeen = false;
 
     private boolean notifyResponseSeen = false;
 
     private MessageFactory messageFactory;
 
     private SipProvider sipProvider;
 
     private AddressFactory addressFactory;
 
     private HeaderFactory headerFactory;
 
     private ListeningPoint listeningPoint;
 
     private int port;
 
     private String transport;
 
     private SipStack sipStack;
 
     private static Timer timer = new Timer();
 
     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 {
             if (requestEvent.getRequest().getMethod().equals(.)) {
                 this. = true;
             }
             Response response = this..createResponse(.,
                     requestEvent.getRequest());
             ServerTransaction st = requestEvent.getServerTransaction();
             if (st == null) {
                 st = .getNewServerTransaction(requestEvent
                         .getRequest());
             }
             st.sendResponse(response);
 
         } catch (Exception ex) {
             ex.printStackTrace();
             fail("Unexpected exception ");
         }
     }
 
     public void processResponse(ResponseEvent responseEvent) {
        this. = true;
    }
    public void processTimeout(TimeoutEvent timeoutEvent) {
        // TODO Auto-generated method stub
    }
    public void processTransactionTerminated(
            TransactionTerminatedEvent transactionTerminatedEvent) {
        // TODO Auto-generated method stub
    }
    public void setUp() {
        SipFactory sipFactory = SipFactory.getInstance();
        sipFactory.resetFactory();
        sipFactory.setPathName("gov.nist");
        Properties properties = new Properties();
        properties.setProperty("javax.sip.STACK_NAME""mystack");
        // The following properties are specific to nist-sip
        // and are not necessarily part of any other jain-sip
        // implementation.
        properties.setProperty("gov.nist.javax.sip.THREAD_POOL_SIZE""1");
        properties.setProperty("gov.nist.javax.sip.DELIVER_UNSOLICITED_NOTIFY",
                "true");
        try {
            this. = 6050;
            this. = "udp";
            this. = sipFactory.createSipStack(properties);
            this. = .createListeningPoint("127.0.0.1",
                    );
            this. = sipFactory.createAddressFactory();
            this. = sipFactory.createHeaderFactory();
            // Create the request.
            this. = sipFactory.createMessageFactory();
            .addSipListener(this);
            .schedule(new TimerTask() {
                public void run() {
                    if (! || !) {
                        fail("Did not see expected event");
                    }
                    .stop();
                }
            }, 4000);
        } catch (Exception e) {
            e.printStackTrace();
            fail("Could not create sip stack");
        }
    }
    public void testSendRequest() {
        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);
            Address fromNameAddress = .createAddress(fromAddress);
            fromNameAddress.setDisplayName(fromDisplayName);
            FromHeader fromHeader = .createFromHeader(
                    fromNameAddress"12345");
            // create To Header
            SipURI toAddress = 
                    .createSipURI(toUsertoSipAddress);
            Address toNameAddress = .createAddress(toAddress);
            toNameAddress.setDisplayName(toDisplayName);
            ToHeader toHeader = .createToHeader(toNameAddress,
                    null);
            // create Request URI
            SipURI requestURI = .createSipURI(toUser,
                    toSipAddress);
            // Create ViaHeaders
            ArrayList viaHeaders = new ArrayList();
            ViaHeader viaHeader = .createViaHeader("127.0.0.1",
                    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 = .createCallIdHeader(callIdHeader
                    .getCallId());
            // Create a new Cseq header
            CSeqHeader cSeqHeader = .createCSeqHeader(1L,
                    .);
            // Create a new MaxForwardsHeader
            MaxForwardsHeader maxForwards = 
                    .createMaxForwardsHeader(70);
            Request request = .createRequest(requestURI,
                    .callIdHeadercSeqHeaderfromHeader,
                    toHeaderviaHeadersmaxForwards);
            // Create contact headers
            String host = .getIPAddress();
            SipURI contactUrl = .createSipURI(fromNamehost);
            contactUrl.setPort(.getPort());
            // Create the contact name address.
            SipURI contactURI = .createSipURI(fromNamehost);
            contactURI.setTransportParam();
            contactURI.setPort(.getListeningPoint()
                    .getPort());
            Address contactAddress = .createAddress(contactURI);
            // Add the contact address.
            contactAddress.setDisplayName(fromName);
            ContactHeader contactHeader = 
                    .createContactHeader(contactAddress);
            request.addHeader(contactHeader);
            // JvB: To test forked SUBSCRIBEs, send it via the Forker
            // Note: BIG Gotcha: Need to do this before creating the
            // ClientTransaction!
                    .createAddress("<sip:127.0.0.1:" +  + ";transport="
                            +  + ";lr>"));
            request.addHeader(route);
            // JvB end added
            // Create an event header for the subscription.
            EventHeader eventHeader = .createEventHeader("foo");
            eventHeader.setEventId("foo");
            request.addHeader(eventHeader);
            SubscriptionStateHeader ssh = 
                    .createSubscriptionStateHeader(.);
            // Create the client transaction.
            request.addHeader(ssh);
            ClientTransaction ct = .getNewClientTransaction(request);
            ct.sendRequest();
            Thread.sleep(10000);
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Unexpected exception sending request");
        }
    }
New to GrepCode? Check out our FAQ X