Package javax.servlet.sip

Examples of javax.servlet.sip.Address


public class B2bHelperTest
{
  @Test
  public void testMergeContact() throws Exception
  {
    Address destination = new NameAddr("<sip:127.0.0.1:5060>");
    B2bHelper.mergeContact("Bob <sip:bob@127.0.0.22:5070;transport=UDP;ttl=1>;p=2", destination);
    assertEquals("Bob <sip:bob@127.0.0.1:5060;transport=UDP>;p=2", destination.toString());
  }
View Full Code Here


public class TestReadOnly
{
  @Test
  public void testAddress() throws Exception
  {
    Address orig = new NameAddr("\"Hello World\" <sip:foo@bar.com;transport=tcp>;tag=12345");
    Address readOnly = new ReadOnlyAddress((Address) orig.clone());
   
    assertEquals(orig, readOnly);
    try { readOnly.setParameter("foo", "bar"); fail();} catch (IllegalStateException e) {}
    try { readOnly.removeParameter("tag"); fail();} catch (IllegalStateException e) {}
    try { readOnly.setDisplayName(""); fail();} catch (IllegalStateException e) {}
    try { ((SipURI) readOnly.getURI()).removeParameter("transport"); fail();} catch (IllegalStateException e) {}
    try { ((SipURI) readOnly.getURI()).setUser("foo2"); fail();} catch (IllegalStateException e) {}
   
    assertEquals(orig, readOnly);
    assertEquals(readOnly, orig);
   
    try { readOnly.setURI(new TelURLImpl("tel:+3398648;user=phone")); fail();} catch (IllegalStateException e) {}
   
    assertEquals(orig, readOnly);
    assertEquals(readOnly, orig);
    assertEquals(orig.toString(), readOnly.toString());
    Address clone = (Address) readOnly.clone();
    clone.setParameter("a", "b");
    testSerializable(readOnly);
  }
View Full Code Here

  @Test
  public void testContact() throws Exception
  {
    SipRequest request = (SipRequest) getMessage(INVITE);
    Address contact = request.getAddressHeader("Contact");
    assertEquals("<sip:127.0.0.1:5060;transport=TCP>", contact.toString());
    contact.setDisplayName("Bob");
    contact.setParameter("isfocus", "");
    assertEquals("Bob", contact.getDisplayName());
    SipURI uri = (SipURI) contact.getURI();
    uri.setUser("bob");
    assertEquals("bob", uri.getUser());
    try { uri.setHost("bad"); fail(); } catch (IllegalStateException e) {}
    try { uri.setLrParam(true); fail(); } catch (IllegalStateException e) {}
    try { uri.setMAddrParam("bad"); fail(); } catch (IllegalStateException e) {}
    try { uri.setMethodParam("Bad"); fail(); } catch (IllegalStateException e) {}
    try { uri.setTTLParam(2); fail(); } catch (IllegalStateException e) {}
    try { uri.setParameter("lr", ""); fail(); } catch (IllegalStateException e) {}
    try { uri.removeParameter("Maddr"); fail(); } catch (IllegalStateException e) {}
    uri.setParameter("transport", "UDP");
    assertEquals("UDP", uri.getParameter("transport"));
    assertEquals("Bob <sip:bob@127.0.0.1:5060;transport=UDP>;isfocus", contact.toString());
   
    // Full read-only on committed
    request.setCommitted(true);
    contact = request.getAddressHeader("Contact");
    uri = (SipURI) contact.getURI();
    try { contact.setDisplayName("bad"); fail(); } catch (IllegalStateException e) {}
    try { uri.setUser("bad"); fail(); } catch (IllegalStateException e) {}
   
    // Full writable on REGISTER
    request = (SipRequest) getMessage(REGISTER);
    contact = request.getAddressHeader("Contact");
    uri = (SipURI) contact.getURI();
    contact.setDisplayName("Bob");
    uri.setHost("nexcom.fr");
    uri.setPort(5062);
    uri.removeParameter("transport");
    uri.setUser("bob");
    assertEquals("Bob <sip:bob@nexcom.fr:5062>", contact.toString());   
  }
View Full Code Here

  protected void assertAddress(List<String> expected, ListIterator<Address> it)
  {
    while (it.hasNext())
    {
      int index = it.nextIndex();
      Address address = (Address) it.next();
      assertEquals(expected.get(index), address.toString());
    }
    assertEquals("Not same number of address", expected.size(), it.nextIndex());
  }
View Full Code Here

  @Test
  public void testProxyAddress() throws Exception
  {
    SipRequest request = new SipRequest();
    NameAddr address = new NameAddr("sip:alice@atlanta.com");
    Address readOnlyAddress = new ReadOnlyAddress(address);
   
    request.addAddressHeader("p-asserted-identity", readOnlyAddress, true);
   
    Address addr = request.getAddressHeader("p-asserted-identity");
    assertEquals("alice", ((SipURI) addr.getURI()).getUser());
  }
View Full Code Here

        List<Address> contacts = new ArrayList<Address>();
        boolean wildcard = false;
       
        while (it.hasNext())
        {
          Address contact = it.next();
          if (contact.isWildcard())
          {
            wildcard = true;
            if (it.hasNext() || contacts.size() > 0 || register.getExpires() > 0)
            {
              register.createResponse(SipServletResponse.SC_BAD_REQUEST, "Invalid wildcard").send();
              return;
            }
          }
          contacts.add(contact);
        }
       
        String callId = register.getCallId();
        int cseq;
        try
        {
          String s = register.getHeader(Constants.CSEQ);
          cseq = Integer.parseInt(s.substring(0, s.indexOf(' ')));
        }
        catch (Exception e)
        {
          register.createResponse(SipServletResponse.SC_BAD_REQUEST).send();
          return;
        }
       
        if (wildcard)
        {
          for (Binding binding : bindings)
          {
            if (callId.equals(binding.getCallId()) && cseq < binding.getCSeq())
            {
              _log.debug("Got lower CSeq for aor {} and call-ID {}", aor, binding.getCallId());
              register.createResponse(SipServletResponse.SC_SERVER_INTERNAL_ERROR, "Lower CSeq").send();
              return;
            }
          }
          if (_log.isDebugEnabled())
            _log.debug("removing all bindings for aor " + aor);
          record.removeAllBindings();
        }
        else
        {       
          for (Address contact : contacts)
          {
            int expires = -1;
            expires = contact.getExpires();
            if (expires < 0)
              expires = register.getExpires();
           
            if (expires != 0)
            {
              if (expires < 0)
                expires = _defaultExpires;
              if (expires > _maxExpires)
                expires = _maxExpires;
              if (expires < _minExpires)
              {
                SipServletResponse response = register.createResponse(SipServletResponse.SC_INTERVAL_TOO_BRIEF);
                response.addHeader(Constants.MIN_EXPIRES, Integer.toString(_minExpires));
                response.send();
                return;
              }
            }
            Binding binding = null;
           
            for (int i = 0; i < bindings.size() && binding == null; i++)
            {
              binding = bindings.get(i);
              if (!contact.getURI().equals(binding.getContact()))
                binding = null;
            }
            if (binding != null)
            {
              if (callId.equals(binding.getCallId()) && cseq < binding.getCSeq())
              {
                _log.debug("Got lower CSeq for aor {} and call-ID {}", aor, binding.getCallId());
                register.createResponse(SipServletResponse.SC_SERVER_INTERNAL_ERROR, "Lower CSeq").send();
                return;
              }
              if (expires == 0)
              {
                if (_log.isDebugEnabled())
                  _log.debug("removing binding {} for aor {}", binding, aor);
                record.removeBinding(binding);
              }
              else
              {
                if (_log.isDebugEnabled())
                  _log.debug("updating binding {} for aor {}", binding, aor);
                record.updateBinding(binding, contact.getURI(), callId, cseq, now + expires*1000);
              }
            }
           
            if (binding == null && expires != 0)
            {
              binding = new Binding(contact.getURI(), callId, cseq, now + expires*1000);
             
              if (_log.isDebugEnabled())
                _log.debug("adding binding {} to aor {}", binding, aor);
              record.addBinding(binding);
            }
          }
        }
        bindings = record.getBindings();
      }
    }
    finally
    {
      _locationService.put(record);
    }
   
    SipServletResponse ok = register.createResponse(SipServletResponse.SC_OK);
    ok.addHeader(Constants.DATE, _dateFormat.format(new Date(now)));
    if (bindings != null)
    {
      for (Binding binding : bindings)
      {
        Address address = _sipFactory.createAddress(binding.getContact());
        address.setExpires((int) ((binding.getExpirationTime() - now) / 1000));
        ok.addAddressHeader(Constants.CONTACT, address,false);
      }
    }
    ok.send();
  }
View Full Code Here

   
    _fields.addAddress("Contact", new NameAddr("<sip:foo.org>;tag=1234"), false);
    p = _fields.getParameterable(SipHeaders.CACHE.lookup("contact"));
    assertEquals("1234", p.getParameter("tag"));
   
    Address address = _fields.getAddress(SipHeaders.CONTACT_BUFFER);
    assertEquals("foo.org", ((SipURI) address.getURI()).getHost());
    p = _fields.getParameterableValues("contact").next();
    assertEquals("1234", p.getParameter("tag"));
  }
View Full Code Here

          try
                  {
            Iterator<Address> it = response.getAddressHeaders(SipHeaders.CONTACT);
            while (it.hasNext())
                      {
              Address contact = (Address) it.next();
              if (contact.getURI().isSipURI())
              {
                Branch branch = addTarget(contact.getURI());
                if (branch != null)
                {
                  _recursedBranches = LazyList.add(_recursedBranches, branch);
                  branch.setRecurse(_branchRecurse);
                }
View Full Code Here

          {
            int expires = response.getExpires();
         
            if (expires == -1)
            {
              Address contact = response.getAddressHeader(SipHeaders.CONTACT);
              expires = contact.getExpires();
            }
            long expiryTime = System.currentTimeMillis() + expires * 1000l;
            _registerSession.setAttribute("expiryTime", expiryTime);
           
            System.out.println("expires " + expires);
View Full Code Here

  public boolean equals(Object o)
  {
    if (o == null || !(o instanceof Address))
      return false;
   
    Address other = (Address) o;
   
    if (!_uri.equals(other.getURI()))
      return false;
       
    for (String key : _params.keySet())
    {
      String otherValue = other.getParameter(key);
      if (otherValue != null && !getParameter(key).equals(otherValue))
        return false;
    }
    return true;
  }
View Full Code Here

TOP

Related Classes of javax.servlet.sip.Address

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.