Package javax.servlet.sip

Examples of javax.servlet.sip.Address


public class AddressTest
{
  @Test
  public void testEquals() throws Exception
  {
    Address a1 = new NameAddr("<sip:%61lice@bea.com;transport=TCP;lr>;q=0.5");
    Address a2 = new NameAddr("<sip:alice@BeA.CoM;Transport=tcp;lr>;q=0.6;expires=3601");
    Address a3 = new NameAddr("<sip:alice@BeA.CoM;Transport=tcp;lr>;q=0.5;expires=3601");
    Address a4 = new NameAddr("<sip:alice@BeA.CoM;Transport=tcp;lr>;q=0.5;expires=3601;param");
    Address a5 = new NameAddr("\"display name\" <sip:alice@BeA.CoM;Transport=tcp;lr>;q=0.5;expires=3601;param");
   
    assertFalse(a1.equals(a2));
    assertTrue(a1.equals(a3));

    assertTrue(a3.equals(a1));
    assertTrue(a1.equals(a4));
    assertTrue(a4.equals(a1));
    assertTrue(a1.equals(a5));
    assertTrue(a5.equals(a1));
  }
View Full Code Here


  }

  @Test
  public void testSetValue() throws Exception
  {
    Address a1 = new NameAddr("<sip:alice@nexcom.fr;transport=UDP>;q=0.5");
    a1.setValue("Bob <sip:bob@nexcom.fr;transport=TCP>");
    assertEquals("Bob <sip:bob@nexcom.fr;transport=TCP>", a1.getValue());
    assertEquals("bob", ((SipURI) a1.getURI()).getUser());
    assertEquals("Bob", a1.getDisplayName());
    assertEquals("Bob <sip:bob@nexcom.fr;transport=TCP>;q=0.5", a1.toString());
    assertEquals("0.5", a1.getParameter("q"));
    try { a1.setValue("aa"); fail(); } catch (Exception e) {};
   
    a1.setValue("Bob <sip:bob@nexcom.fr;transport=TCP>");
    a1.setValue("<sip:carol@nexcom.fr>");
    assertNull(a1.getDisplayName());
  }
View Full Code Here

  }

  @Test
  public void testTourtuous() throws ServletParseException
  {
    Address a1 = new NameAddr("sip:vivekg@chair-dnrc.example.com ; tag = 19923n");
    assertEquals("19923n", a1.getParameter("tag"));
    assertEquals("chair-dnrc.example.com", ((SipURI) a1.getURI()).getHost());
  }
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("cseq");
            cseq = Integer.parseInt(s.substring(0, s.indexOf(' ')));
          }
          catch (Exception e)
          {
            register.createResponse(SipServletResponse.SC_BAD_REQUEST, e.getMessage()).send();
            return;
          }
         
          if (wildcard)
          {
            for (Binding binding : bindings)
            {
              if (callId.equals(binding.getCallId()) && cseq < binding.getCseq())
              {
                register.createResponse(SipServletResponse.SC_SERVER_INTERNAL_ERROR,
                    "Lower cseq").send();
                return;
              }
              bindings.remove(binding);
            }
          }
          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;
                }
                else if (expires < _minExpires)
                {
                  SipServletResponse response = register.createResponse(423);
                  response.addHeader("Min-Expires", Integer.toString(_minExpires));
                  response.send();
                  return;
                }
              }
              boolean exist = false;
             
              Iterator<Binding> it2 = bindings.iterator();
              while (it2.hasNext())
              {
                Binding binding = it2.next();
               
                if (contact.getURI().equals(binding.getContact()))
                {
                  exist = true;
                  if (callId.equals(binding.getCallId()) && cseq < binding.getCseq())
                  {
                    register.createResponse(SipServletResponse.SC_SERVER_INTERNAL_ERROR,
                        "Lower CSeq").send();
                    return;
                  }
                  if (expires == 0)
                  {
                    it2.remove();
                  }
                  else
                  {
                    binding.setCallId(callId);
                    binding.setCseq(cseq);
                    binding.setExpires(expires);
                    binding.setQ(contact.getQ());
                  }
                }
              }
              if (!exist && expires != 0)
              {
                Binding binding = new Binding(aor, contact.getURI());
                binding.setCallId(callId);
                binding.setCseq(cseq);
                binding.setExpires(expires);
                binding.setQ(contact.getQ());
                bindings.add(binding);
              }
            }
          }
        }
       
        // Empty bindings set are removed in the scavenger to prevent deadlocks.
       
        SipServletResponse ok = register.createResponse(SipServletResponse.SC_OK);
        if (bindings.size() > 0)
        {
          for (Binding binding : bindings)
          {
            Address address = _sipFactory.createAddress(binding.getContact());
            address.setExpires(binding.getExpires());
            address.setQ(binding.getQ());
            ok.addAddressHeader("contact", address, false);
          }
        }
        ok.addHeader("Date", _dateFormat.format(new Date()));
        ok.send();
View Full Code Here

    return ((request.getTo().getParameter(SipParams.TAG) == null) && !request.isCancel());
  }
 
  public Address popLocalRoute(SipRequest request)
  {
    Address route = request.getTopRoute();
    if (route != null && getConnectorManager().isLocalUri(route.getURI()))
    {
      request.removeTopRoute();
      return route;
    }
    return null;
View Full Code Here

    {
    if (((SipMessage) message).isRequest())
    {
      SipRequest request = (SipRequest) message;
   
      Address route = popLocalRoute(request);
     
      if (isInitial(request))
          {
        request.setInitial(true);
       
        SipApplicationRouterInfo routerInfo = null;
        SipAppContext appContext = null;
       
        try
        {
          if (route != null)
          {
            SipURI uri = (SipURI) route.getURI();
            if (RouterInfoUtil.ROUTER_INFO.equals(uri.getUser()))
            {
              routerInfo = RouterInfoUtil.decode(uri);
              route = popLocalRoute(request);
            }
View Full Code Here

    String[] routes = routerInfo.getRoutes();
    try
    {
      if (SipRouteModifier.ROUTE == routerInfo.getRouteModifier() && routes != null)
      {
        Address topRoute = new NameAddr(routes[0]);
        if (getConnectorManager().isLocalUri(topRoute.getURI()))
          request.setPoppedRoute(topRoute);
        else
        {
          for (int i = routes.length; i >= 0; --i)
            request.pushRoute(new NameAddr(routes[i]));
View Full Code Here

    HeaderInfo hi = SipHeaders.getType(buffer);
   
    if (hi.getType() != HeaderInfo.ADDRESS && hi.getOrdinal() != -1)
      throw new ServletParseException("Header: " + name + " is not of address type");
   
    Address address;
    try
    {
      address = _fields.getAddress(buffer);
    }
    catch (LazyParsingException e)
View Full Code Here

        _tx = tx;
    }
 
  public void setToTag(String tag)
  {
    Address to = _fields.getAddress(SipHeaders.TO_BUFFER);
    to.setParameter(SipParams.TAG, tag);
  }
View Full Code Here

    return true; // TODO
  }
 
  public Address getContact()
  {
    Address address = getServer().getConnectorManager().getContact(SipConnectors.TCP_ORDINAL);
    address.getURI().setParameter(ID.APP_SESSION_ID_PARAMETER, _appSession.getAppId());
    return address;
  }
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.