Package javax.servlet.sip

Examples of javax.servlet.sip.SipSession


    else
    {
      expires = _regEventPackage.getDefaultExpires();
    }
   
    SipSession session = subscribe.getSession();
    String uri = null;
   
    if (subscribe.isInitial())
    {
      uri = URIUtil.toCanonical(subscribe.getRequestURI());
    }
    else
    {
      uri = (String) session.getAttribute(Constants.SUBSCRIPTION_ATTRIBUTE);
      if (uri == null)
      {
        subscribe.createResponse(SipServletResponse.SC_CALL_LEG_DONE).send();
        subscribe.getApplicationSession().invalidate();
        return;
      }
    }
   
    RegResource regResource = _regEventPackage.get(uri);
   
    try
    {
      Subscription subscription = null;
     
      if (expires == 0)
      {
        subscription = regResource.removeSubscription(session.getId());
       
        if (subscription == null)
        {
          subscription = new Subscription(regResource, session, -1);
        }
        else
        {
          subscription.setExpirationTime(System.currentTimeMillis());
          if (_log.isDebugEnabled())
            _log.debug("removed reg subscription {} to registration resource {}",
              subscription.getSession().getId(), regResource.getUri());
       
        subscription.setState(Subscription.State.TERMINATED, Reason.TIMEOUT);
      }
      else
      {
        long now = System.currentTimeMillis();
       
        subscription = regResource.getSubscription(session.getId());
   
        if (subscription == null)
        {
          subscription = new Subscription(regResource, session, now + expires*1000);
          subscription.setState(State.ACTIVE, Reason.SUBSCRIBE);
          regResource.addSubscription(subscription);
         
          session.setAttribute(Constants.SUBSCRIPTION_ATTRIBUTE, uri);
         
          if (_log.isDebugEnabled())
            _log.debug("added reg subscription {} to registration resource {}",
                subscription.getSession().getId(), regResource.getUri());
        }
View Full Code Here


    else
    {
      expires = _presence.getDefaultExpires();
    }
   
    SipSession session = subscribe.getSession();
    String uri = null;
   
    if (subscribe.isInitial())
    {
      uri = URIUtil.toCanonical(subscribe.getRequestURI());
    }
    else
    {
      uri = (String) session.getAttribute(Constants.SUBSCRIPTION_ATTRIBUTE);
      if (uri == null)
      {
        subscribe.createResponse(SipServletResponse.SC_CALL_LEG_DONE).send();
        subscribe.getApplicationSession().invalidate();
        return;
      }
    }
       
    Presentity presentity = _presence.get(uri);
   
    String subscriberUri = null;
    if (subscribe.getAddressHeader(Constants.P_ASSERTED_IDENTITY) != null)
      subscriberUri = URIUtil.toCanonical(subscribe.getAddressHeader(Constants.P_ASSERTED_IDENTITY).getURI());
    else
      subscriberUri = URIUtil.toCanonical(subscribe.getFrom().getURI());
   
    try
    {     
      SubHandling subHandling = _policyManager.getPolicy(subscriberUri, presentity);
      if (subHandling == SubHandling.BLOCK)
      {
        _log.debug("Reject presence subscription from {} to {} due to policy", subscriberUri, presentity.getUri());
        SipServletResponse response = subscribe.createResponse(SipServletResponse.SC_FORBIDDEN);
        response.send();
        return;
      }
     
      Subscription subscription = null;
     
      if (expires == 0)
      {
        subscription = presentity.removeSubscription(session.getId());
       
        if (subscription == null)
        {
          subscription = new Subscription(presentity, session, -1, subscriberUri);
          subscription.addListener(_watcherInfo.getSubscriptionListener());
        }
        else
        {
          subscription.setExpirationTime(System.currentTimeMillis());
          if (_log.isDebugEnabled())
            _log.debug("removed presence subscription {} to presentity {}",
              subscription.getSession().getId(), presentity.getUri());
       
        if (subHandling == SubHandling.CONFIRM)
          subscription.setState(Subscription.State.WAITING, Reason.TIMEOUT, subHandling == SubHandling.ALLOW);
        else
          subscription.setState(Subscription.State.TERMINATED, Reason.TIMEOUT, subHandling == SubHandling.ALLOW);
      }
      else
      {
        long now = System.currentTimeMillis();
       
        subscription = presentity.getSubscription(session.getId());
   
        if (subscription == null)
        {
          subscription = new Subscription(presentity, session, now + expires*1000, subscriberUri);
          subscription.addListener(_watcherInfo.getSubscriptionListener());
          presentity.addSubscription(subscription);
         
          switch (subHandling)
          {
          case ALLOW:
            subscription.setState(State.ACTIVE, Reason.SUBSCRIBE, true);
            break;
          case CONFIRM:
            subscription.setState(State.PENDING, Reason.SUBSCRIBE, false);
            break;
          case POLITE_BLOCK:
            subscription.setState(State.ACTIVE, Reason.SUBSCRIBE, false);
            break;
          default:
            break;
          }
         
          session.setAttribute(Constants.SUBSCRIPTION_ATTRIBUTE, uri);
         
          if (_log.isDebugEnabled())
            _log.debug("added presence subscription {} to presentity {}",
                subscription.getId(), presentity.getUri());
        }
View Full Code Here

    else
    {
      expires = _watcherInfo.getDefaultExpires();
    }
   
    SipSession session = subscribe.getSession();
    String uri = null;
   
    if (subscribe.isInitial())
    {
      uri = URIUtil.toCanonical(subscribe.getRequestURI());
    }
    else
    {
      uri = (String) session.getAttribute(Constants.SUBSCRIPTION_ATTRIBUTE);
      if (uri == null)
      {
        subscribe.createResponse(SipServletResponse.SC_CALL_LEG_DONE).send();
        subscribe.getApplicationSession().invalidate();
        return;
      }
    }
       
    WatcherResource resource = _watcherInfo.get(uri);
   
    String subscriberUri = null;
    if (subscribe.getAddressHeader(Constants.P_ASSERTED_IDENTITY) != null)
      subscriberUri = URIUtil.toCanonical(subscribe.getAddressHeader(Constants.P_ASSERTED_IDENTITY).getURI());
    else
      subscriberUri = URIUtil.toCanonical(subscribe.getFrom().getURI());
   
    try
    {
      Subscription subscription = null;
     
      if (expires == 0)
      {
        subscription = resource.removeSubscription(session.getId());
       
        if (subscription == null)
          subscription = new Subscription(resource, session, -1, subscriberUri);
        else
        {
          subscription.setExpirationTime(System.currentTimeMillis());
          if (_log.isDebugEnabled())
            _log.debug("removed presence.winfo subscription {} to resource {}",
              subscription.getSession().getId(), resource.getUri());
       
        subscription.setState(Subscription.State.TERMINATED, Reason.TIMEOUT);
      }
      else
      {
        long now = System.currentTimeMillis();
       
        subscription = resource.getSubscription(session.getId());
   
        if (subscription == null)
        {
          subscription = new Subscription(resource, session, now + expires*1000, subscriberUri);
          subscription.setState(State.ACTIVE, Reason.SUBSCRIBE);
          resource.addSubscription(subscription);
         
          session.setAttribute(Constants.SUBSCRIPTION_ATTRIBUTE, uri);
         
          if (_log.isDebugEnabled())
            _log.debug("added presence.winfo subscription {} to resource {}",
                subscription.getSession().getId(), resource.getUri());
        }
View Full Code Here

  @SuppressWarnings("unchecked")
  public void notify(Subscription subscription)
  {
    try
    {
      SipSession session = subscription.getSession();
      if (session.isValid())
      {
        SipServletRequest notify = session.createRequest(Constants.NOTIFY);
        notify.addHeader(Constants.EVENT, getName());
       
        String s = subscription.getState().getName();
        if (subscription.getState() == Subscription.State.ACTIVE
            || subscription.getState() == Subscription.State.PENDING)
View Full Code Here

    }
  }
 
  protected MessageHandler getHandler(SipServletMessage message)
  {
    SipSession session = message.getSession();
    MessageHandler handler = (MessageHandler) session.getAttribute(MessageHandler.class.getName());
   
    if (handler == null)
      handler = _defaultHandler;
   
    return handler;
View Full Code Here

  @Override
  protected void doRequest(SipServletRequest request) throws ServletException, IOException
  {
   
    B2buaHelper b2bHelper = request.getB2buaHelper();
    SipSession leg2 = b2bHelper.getLinkedSession(request.getSession());
   
    // If the call is not established, refuse reINVITE and send CANCEL on BYE.
    if (leg2.getState() == State.EARLY || leg2.getState() == State.INITIAL)
    {
      String method = request.getMethod();
      if ("BYE".equals(method))
      {
        List<SipServletMessage> list = b2bHelper.getPendingMessages(leg2, UAMode.UAC);
        if (list.size() == 1)
        {
          SipServletRequest invite = (SipServletRequest) list.get(0);
          invite.createCancel().send();
          request.createResponse(SipServletResponse.SC_OK).send();
          leg2.getApplicationSession().invalidate();
        }
        else
          log("Could not found initial INVITE");
      }
      else
View Full Code Here

 
  protected void doInitialInviteResponse(SipServletResponse response) throws ServletException, IOException
  {

    B2buaHelper b2bHelper = response.getRequest().getB2buaHelper();
    SipSession leg1 = response.getSession();
    SipSession leg2 = b2bHelper.getLinkedSession(leg1);
    int status = response.getStatus();
    if (leg2 == null)
    {
      if (status >= SipServletResponse.SC_OK
          && status < SipServletResponse.SC_MULTIPLE_CHOICES)
      {
        // Create second leg               
        SipServletRequest request = _sipFactory.createRequest(response.getApplicationSession(),
            response.getMethod(),
            response.getTo(),
            response.getFrom());
        copy(response, request);

        b2bHelper.linkSipSessions(leg1, request.getSession());

        request.setAttribute(RESP_INV, response);
        request.getSession().setHandler(getServletName());

        // if leg2 took more than 10s to pick up call, cancel it.
        ServletTimer cancelCallTask = _timerService.createTimer(leg1.getApplicationSession(), 15000,
            false, new CancelCallTask(leg1, request));
       
        leg1.setAttribute(CancelCallTask.class.getName(), cancelCallTask);
       
        request.send();
      }
      else if (response.getStatus() >= SipServletResponse.SC_MULTIPLE_CHOICES)
      {
        response.getApplicationSession().invalidate();
      }
    }
    else
    {
      if (status >= SipServletResponse.SC_OK
          && status < SipServletResponse.SC_MULTIPLE_CHOICES)
      { 
        ((ServletTimer) leg2.getAttribute(CancelCallTask.class.getName())).cancel();
       
        // ACK to leg2
        SipServletResponse leg2Resp = (SipServletResponse) response.getRequest().getAttribute(RESP_INV);
        SipServletRequest request = leg2Resp.createAck();
        copy(response, request);
        request.send();
       
        // ACK to leg1
        response.createAck().send();
      }
      else if (status >= SipServletResponse.SC_MULTIPLE_CHOICES)
      {
        leg2.createRequest("BYE").send();
        leg1.getApplicationSession().invalidate();
     
    }
  }
View Full Code Here

   
    if (!sipSession.getApplicationSession().equals(origRequest.getApplicationSession()))
      throw new IllegalArgumentException("SipSession " + sipSession
          + " does not belong to same application session as original request");
   
    SipSession linkedSession = getLinkedSession(origRequest.getSession());
    if (linkedSession != null && !linkedSession.equals(sipSession))
      throw new IllegalArgumentException("Original request is already linked to another sipSession");
 
    if (getLinkedSipServletRequest(origRequest) != null)
      throw new IllegalArgumentException("Original request is already linked to another request");
   
View Full Code Here

  {
    _b2bHelper = b2bHelper;
    Iterator<?> it = session.getSessions("sip");
    while (it.hasNext())
    {
      SipSession sipSession = (SipSession) it.next();
      if (_leg1 == null)
        _leg1 = sipSession;
      else if (_leg1.getCreationTime() > sipSession.getCreationTime())
      {
        _leg1 = sipSession;
        _leg2 = _leg1;
      }
      else
View Full Code Here

            return;
        }

        Address storedPathValue = feAddrMapForRegisterReq.get(contact);
        if (storedPathValue == null) {
            SipSession session = request.getSession(false);
            if (session == null || !session.isValid()) {
                if (logger.isLoggable(Level.FINER)) {
                    logger.finer("Session is null or invalid");
                }
                return;
            }
            storedPathValue = (Address) session.getAttribute(
                    CLBConstants.CLB_FE_ADDRESS);
        }
        if (storedPathValue != null) {
            request.pushRoute(storedPathValue);
            TargetTuple tt = null;
View Full Code Here

TOP

Related Classes of javax.servlet.sip.SipSession

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.