Package javax.sip.message

Examples of javax.sip.message.Request


    // Ensure Alice is not registered
    RegisterSession registerSession = new RegisterSession(getAlicePhone());
    registerSession.register(null, 0);
   
    SubscribeSession session = new SubscribeSession(getAlicePhone(), "reg");
    Request subscribe = session.newInitialSubscribe(100, getAliceUri()); // 1
    session.sendRequest(subscribe, Response.OK); // 2
   
    ServerTransaction tx = session.waitForNotify();
    Request notify = tx.getRequest(); // 3
    //System.out.println(notify);
    session.sendResponse(Response.OK, tx); // 4
    SubscriptionStateHeader subState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
    assertEquals(SubscriptionStateHeader.ACTIVE.toLowerCase(), subState.getState().toLowerCase());
    assertBetween(95, 100, subState.getExpires());
    assertEquals("reg", ((EventHeader) notify.getHeader(EventHeader.NAME)).getEventType());
    Reginfo regInfo = getRegInfo(notify);
    int version = regInfo.getVersion().intValue();
    Registration registration = regInfo.getRegistrationArray(0);
    assertEquals(State.INIT, registration.getState());
    assertEquals(getAliceUri(), registration.getAor());
    assertEquals(0, registration.getContactArray().length);
   
    registerSession.register(null, 1800); // 5 and 6
   
    tx = session.waitForNotify();
    notify = tx.getRequest(); // 7
    //System.out.println(notify);
    session.sendResponse(Response.OK, tx); // 8
    regInfo = getRegInfo(notify);
    registration = regInfo.getRegistrationArray(0);
    assertEquals(1, registration.getContactArray().length);
    assertEquals(version + 1, regInfo.getVersion().intValue());
    assertEquals(State.ACTIVE, registration.getState());
    Contact contact = registration.getContactArray(0);
    assertBetween(1795, 1800, contact.getExpires().intValue());
    assertEquals(Event.REGISTERED, contact.getEvent());
   
    registerSession.register(null, 0); // 9 and  10
    tx = session.waitForNotify();
    notify = tx.getRequest(); // 11
    //System.out.println(notify);
    session.sendResponse(Response.OK, tx); // 12
    regInfo = getRegInfo(notify);
    registration = regInfo.getRegistrationArray(0);
    assertEquals(1, registration.getContactArray().length);
    assertEquals(version + 2, regInfo.getVersion().intValue());
    assertEquals(State.TERMINATED, registration.getState());
    contact = registration.getContactArray(0);
    assertEquals(0, contact.getExpires().intValue());
    assertEquals(Event.UNREGISTERED, contact.getEvent());
   
    subscribe = session.newSubsequentSubscribe(0); // 13
    session.sendRequest(subscribe, Response.OK); // 14
   
    tx = session.waitForNotify();
    notify = tx.getRequest(); // 15
    //System.out.println(notify);
    session.sendResponse(Response.OK, tx); // 16
    subState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
    assertEquals(SubscriptionStateHeader.TERMINATED.toLowerCase(),
        subState.getState());
    regInfo = getRegInfo(notify);
    registration = regInfo.getRegistrationArray(0);
    assertEquals(State.TERMINATED, registration.getState());
View Full Code Here


  {
    getAlicePhone().register(null, 1500);
    assertLastOperationSuccess(getAlicePhone());
   
    SubscribeSession session = new SubscribeSession(getAlicePhone(), "reg");
    Request subscribe = session.newInitialSubscribe(100, getAliceUri());
    session.sendRequest(subscribe, Response.OK);
   
    ServerTransaction tx = session.waitForNotify();
    Request notify = tx.getRequest();
    //System.out.println(notify);
    session.sendResponse(Response.OK, tx);
    SubscriptionStateHeader subState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
    assertEquals(SubscriptionStateHeader.ACTIVE.toLowerCase(), subState.getState().toLowerCase());
    assertBetween(95, 100, subState.getExpires());
    assertEquals("reg", ((EventHeader) notify.getHeader(EventHeader.NAME)).getEventType());
    Reginfo regInfo = getRegInfo(notify);
    Registration registration = regInfo.getRegistrationArray(0);
    assertEquals(0, regInfo.getVersion().intValue());
    assertEquals(State.ACTIVE, registration.getState());
    assertEquals(getAliceUri(), registration.getAor());
    assertEquals(1, registration.getContactArray().length);
   
   
    getAlicePhone().unregister(null, 2000);
    assertLastOperationSuccess(getAlicePhone());
    tx = session.waitForNotify();
    notify = tx.getRequest();
    session.sendResponse(Response.OK, tx);
    regInfo = getRegInfo(notify);
    registration = regInfo.getRegistrationArray(0);
    assertEquals(1, registration.getContactArray().length);
    assertEquals(1, regInfo.getVersion().intValue());
    assertEquals(State.TERMINATED, registration.getState());
    Contact contact = registration.getContactArray(0);
    assertEquals(0, contact.getExpires().intValue());
    assertEquals(Event.UNREGISTERED, contact.getEvent());
       
    subscribe = session.newSubsequentSubscribe(0);
    session.sendRequest(subscribe, Response.OK);
   
    tx = session.waitForNotify();
    notify = tx.getRequest();
    //System.out.println(notify);
    session.sendResponse(Response.OK, tx);
    subState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
    assertEquals(SubscriptionStateHeader.TERMINATED.toLowerCase(),
        subState.getState());
    regInfo = getRegInfo(notify);
    registration = regInfo.getRegistrationArray(0);
    assertEquals(State.TERMINATED, registration.getState());
View Full Code Here

  }
 
    public void testMinExpires() throws Exception
    {      
        SubscribeSession session = new SubscribeSession(getAlicePhone(), "reg");
        Request request = session.newInitialSubscribe(1, getAliceUri());
        Response response = session.sendRequest(request,SipResponse.INTERVAL_TOO_BRIEF);
        MinExpiresHeader minExpiresHeader = (MinExpiresHeader) response.getHeader(MinExpiresHeader.NAME);
        assertNotNull(minExpiresHeader);
    }
View Full Code Here

        RequestEvent reqevent = s.waitNotify(10000);
        assertNotNull(reqevent);
        assertNoSubscriptionErrors(s);

        // examine the request object
        Request request = reqevent.getRequest();
        assertEquals(Request.NOTIFY, request.getMethod());           
        assertBetween(55, 60, ((SubscriptionStateHeader) request
                .getHeader(SubscriptionStateHeader.NAME)).getExpires());

        // process the NOTIFY
        response = s.processNotify(reqevent);
        // reply to the NOTIFY
        assertTrue(s.format(), s.replyToNotify(reqevent, response));

        // check PRESENCE info - devices/tuples
        // -----------------------------------------------
        HashMap<String, PresenceDeviceInfo> devices = s.getPresenceDevices();
        assertEquals(1, devices.size());
        PresenceDeviceInfo dev = devices.values().iterator().next();
        assertNotNull(dev);
        assertEquals("closed", dev.getBasicStatus());
       
        Thread.sleep(200);
       
        PublishSession publishSession = new PublishSession(getBobPhone());
        Request publish = publishSession.newPublish(getClass().getResourceAsStream("publish1.xml"), 20);
        publishSession.sendRequest(publish, SipResponse.OK);

        // get the NOTIFY
        reqevent = s.waitNotify(10000);
        assertNotNull(s.format(), reqevent);
View Full Code Here

    }

    public void testMinExpires() throws Exception
    {      
        SubscribeSession session = new SubscribeSession(getAlicePhone(), "presence");
        Request request = session.newInitialSubscribe(1, getAliceUri());
        Response response = session.sendRequest(request, SipResponse.INTERVAL_TOO_BRIEF);
        MinExpiresHeader minExpiresHeader = (MinExpiresHeader) response.getHeader(MinExpiresHeader.NAME);
        assertNotNull(minExpiresHeader);
    }
View Full Code Here

   
    @SuppressWarnings("unchecked")
  public void testBadEvent() throws Exception
    {      
        SubscribeSession session = new SubscribeSession(getAlicePhone(), "unknown");
        Request request = session.newInitialSubscribe(100, getAliceUri());
        Response response = session.sendRequest(request, SipResponse.BAD_EVENT);
        Iterator it = response.getHeaders(AllowEventsHeader.NAME);
        List<String> l = new ArrayList<String>();
        while (it.hasNext())
    {
View Full Code Here

   
    public void testBadAcceptHeader() throws Exception
    {      
        AbstractSession session = new AbstractSession(getAlicePhone());
        HeaderFactory hf = session.getHeaderFactory();
        Request request = session.newRequest(Request.SUBSCRIBE, 1, getBobUri());
        request.setHeader(hf.createExpiresHeader(60));
        request.setHeader(hf.createEventHeader("presence"));
        request.setHeader(getAlicePhone().getContactInfo().getContactHeader());
        request.setHeader(hf.createAcceptHeader("application", "unknown"));
        session.sendRequest(request, SipResponse.UNSUPPORTED_MEDIA_TYPE);
    }
View Full Code Here

   
   
    public void testEtags() throws Exception
    {      
       PublishSession publishSession = new PublishSession(getBobPhone());
         Request publish = publishSession.newPublish(getClass().getResourceAsStream("publish1.xml"), 20);
         Response response = publishSession.sendRequest(publish, SipResponse.OK);
        
         SIPETagHeader etagHeader = (SIPETagHeader) response.getHeader(SIPETagHeader.NAME);
         assertNotNull(etagHeader);
         String etag = etagHeader.getETag();
        
         publish = publishSession.newPublish(getClass().getResourceAsStream("publish2.xml"), 20);
         HeaderFactory hf = publishSession.getHeaderFactory();
         publish.setHeader(hf.createSIPIfMatchHeader(etag));
         response = publishSession.sendRequest(publish, SipResponse.OK);
         etagHeader = (SIPETagHeader) response.getHeader(SIPETagHeader.NAME);
         assertNotNull(etagHeader);
        
         publish = publishSession.newPublish(getClass().getResourceAsStream("publish1.xml"), 20);
         publish.setHeader(hf.createSIPIfMatchHeader(etag)); //Use old etag
         response = publishSession.sendRequest(publish, SipServletResponse.SC_CONDITIONAL_REQUEST_FAILED);
        
         publish = publishSession.newUnpublish(); // 25
      publishSession.sendRequest(publish, Response.OK); // 26
    }
View Full Code Here

 
  @SuppressWarnings("unchecked")
  public void testSimpleRegister() throws Exception
  {
    RegisterSession session = new RegisterSession(getAlicePhone());
    Request request = session.createRegister(null, 1800);
    Response response =
      session.sendRegistrationMessage(request, Response.OK);
    ListIterator<ContactHeader> contacts = response.getHeaders(ContactHeader.NAME);
    ContactHeader contact = contacts.next();
    assertBetween(1795, 1800, contact.getExpires());
View Full Code Here

 
  @SuppressWarnings("unchecked")
  public void testMultipleContacts() throws Exception
  {
    RegisterSession session =  new RegisterSession(getAlicePhone());
    Request request = session.createRegister(null, 1800);
    ContactHeader contact2 = newContact("<sip:localhost>");
    contact2.setExpires(1500);
    request.addHeader(contact2);
    Response response =
      session.sendRegistrationMessage(request, Response.OK);
    ListIterator<ContactHeader> contacts = response.getHeaders(ContactHeader.NAME);
    while (contacts.hasNext()) {
      ContactHeader contact = (ContactHeader) contacts.next();
View Full Code Here

TOP

Related Classes of javax.sip.message.Request

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.