Package org.cipango.kaleo.location

Examples of org.cipango.kaleo.location.Registration


   
    JSON.getDefault().addConvertor(Registration.class, new Convertor()
    {
      public void toJSON(Object obj, Output out)
      {
        Registration record = (Registration) obj;
        out.add("aor", record.getUri());
        out.add("bindings", record.getBindings());
      }
      public Object fromJSON(Map object)  { return null; }
    });
    JSON.getDefault().addConvertor(Binding.class, new Convertor()
    {
View Full Code Here


    Reginfo reginfo = ((ReginfoDocument) regResource.getState().getContent()).getReginfo();
    assertEquals(aor, reginfo.getRegistrationArray(0).getAor());
    assertEquals(State.INIT, reginfo.getRegistrationArray(0).getState());
    assertEquals(0, reginfo.getRegistrationArray(0).getContactArray().length);
   
    Registration registration = new Registration(aor);
    registration.addListener(regResource)
    Binding binding1 = new Binding(new UriImpl("sip:alice@localhost"), "123@localhost", 1, now + 100000);
    registration.addBinding(binding1);
   
    //System.out.println(regResource.getState().getContent());
    assertEquals(1, reginfo.getRegistrationArray(0).getContactArray().length);
    assertEquals(State.ACTIVE, reginfo.getRegistrationArray(0).getState());
    Contact contact = reginfo.getRegistrationArray(0).getContactArray(0);
    assertEquals(Event.REGISTERED, contact.getEvent());
    assertEquals("sip:alice@localhost", contact.getUri());
    //assertTrue(contact.getExpires().intValue() > 98 && contact.getExpires().intValue() <= 100);
   
    registration.addBinding(new Binding(new UriImpl("sip:alice@localhost:5070"), "567@localhost", 1, now + 200000));
    assertEquals(2, reginfo.getRegistrationArray(0).getContactArray().length);
    assertEquals(State.ACTIVE, reginfo.getRegistrationArray(0).getState());
    assertEquals(Event.REGISTERED, reginfo.getRegistrationArray(0).getContactArray(1).getEvent());
    assertEquals("sip:alice@localhost", reginfo.getRegistrationArray(0).getContactArray(0).getUri());
    assertEquals("sip:alice@localhost:5070", reginfo.getRegistrationArray(0).getContactArray(1).getUri());
   
    registration.updateBinding(binding1, new UriImpl("sip:alice@newContact"), "123@localhost", 1, now + 200000);
    assertEquals(2, reginfo.getRegistrationArray(0).getContactArray().length);
    assertEquals(State.ACTIVE, reginfo.getRegistrationArray(0).getState());
    assertEquals(Event.REFRESHED, reginfo.getRegistrationArray(0).getContactArray(0).getEvent());
    assertEquals(contact.getId(), reginfo.getRegistrationArray(0).getContactArray(0).getId());
    assertEquals("sip:alice@newContact", reginfo.getRegistrationArray(0).getContactArray(0).getUri());
   
    registration.removeBinding(binding1);
    assertEquals(1, reginfo.getRegistrationArray(0).getContactArray().length);
    assertEquals(State.ACTIVE, reginfo.getRegistrationArray(0).getState());
   
   
    registration.addBinding(binding1);
    registration.removeAllBindings();
    assertEquals(0, reginfo.getRegistrationArray(0).getContactArray().length);
    assertEquals(State.TERMINATED, reginfo.getRegistrationArray(0).getState());
  }
View Full Code Here

    }
   
    long now = System.currentTimeMillis();
    List<Binding> bindings;

    Registration record = _locationService.get(aor);
   
    record.addListener(_regEventPackage.getRegistrationListener());
   
    try
    {
      bindings = record.getBindings();
      if (bindings == null)
        bindings = Collections.emptyList();
       
      Iterator<Address> it = register.getAddressHeaders(Constants.CONTACT);
      if (it.hasNext())
      {
        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);
View Full Code Here

    return NAME;
  }
 
  protected RegResource newResource(String uri)
  {
    Registration registration = _locationService.get(uri);
    try
    {
      RegResource regResource = new RegResource(uri, registration);
      regResource.addListener(getEventNotifier());
      return regResource;
View Full Code Here

TOP

Related Classes of org.cipango.kaleo.location.Registration

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.