Package javax.servlet.sip

Examples of javax.servlet.sip.SipServletResponse


      return;
    }
   
       try
    {
         SipServletResponse error = request.createResponse(SipServletResponse.SC_SERVER_INTERNAL_ERROR);
      error.setContent(content, "text/plain");
      error.send();
    }
    catch (Exception e1)
    {
      __logger.warn("Failed to send error on " + request.getMethod(), e1);
    }
View Full Code Here


      if (e instanceof TooManyHopsException)
        throw (TooManyHopsException) e;
     
      if (!request.isCommitted() && !request.getMethod().equalsIgnoreCase("ACK"))
      {
        SipServletResponse error = request.createResponse(SipServletResponse.SC_SERVER_INTERNAL_ERROR);
       
              try
        {
          error.setContent(content, "text/plain");
          error.send();
          return;
        }
        catch (Exception e1)
        {
          __logger.warn("Failed to send error on " + request.getMethod(), e1);
View Full Code Here

   
  protected void doRequest(SipServletRequest req1) throws ServletException,
  IOException {
  if (!"ACK".equals(req1.getMethod())) {
   
    SipServletResponse resp = req1.createResponse(200);
    resp.send();
    if (!"INVITE".equals(req1.getMethod()))
      req1.getApplicationSession().invalidate();
  }
}
View Full Code Here

        URL url = getClass().getClassLoader().getResource(filename);
        File file;
        try {
            file = new File(url.toURI());
        } catch (URISyntaxException e) {
            SipServletResponse resp = invite.createResponse(
                    SipServletResponse.SC_SERVER_INTERNAL_ERROR);
            resp.send();
            return;
        }
        Player player = new Player(file.getAbsolutePath(),
                rtpConnection.getHost(), rtpConnection.getPort(),
                payloadType);
        player.addEventListener(this);
        try {
            player.init();
        } catch (Exception e) {
            SipServletResponse resp = invite.createResponse(
                    SipServletResponse.SC_SERVER_INTERNAL_ERROR);
            resp.send();
            return;
        }
        int localPort = player.getLocalPort();
        Recorder recorder = new Recorder(localPort);
        Map<Integer, Recorder> recorders = (Map<Integer, Recorder>)
            servletContext.getAttribute(Recorder.class.getName());
        recorders.put(localPort, recorder);
        invite.getApplicationSession(true).setAttribute(
                Player.class.getName(), player);
        SipServletResponse resp =
            invite.createResponse(SipServletResponse.SC_OK);
        String sdpAnswer = "v=0\r\n"
            + "o=user1 123 456 IN IP4 127.0.0.1\r\n"
            + "s=-\r\n"
            + "c=IN IP4 127.0.0.1\r\n"
            + "t=0 0\r\n"
            + "m=audio " + player.getLocalPort() + " RTP/AVP "
                + payloadType + "\r\n"
            + "a=rtpmap:0 PCMU/8000\r\n";
       
        resp.setContent(sdpAnswer.getBytes(charset), "application/sdp");
        resp.send();
    }
View Full Code Here

            dtmfSession.init();
        }
        catch (Exception e)
        {
            Log.warn("cannot initialize dtmf session on port " + port, e);
            SipServletResponse resp = invite.createResponse(
                    SipServletResponse.SC_SERVER_INTERNAL_ERROR);
            resp.send();
            return;
        }
        invite.getApplicationSession(true).setAttribute(
                DtmfSession.class.getName(), dtmfSession);

        SipServletResponse resp =
            invite.createResponse(SipServletResponse.SC_OK);
        String sdpAnswer = "v=0\r\n"
            + "o=user1 123 456 IN IP4 127.0.0.1\r\n"
            + "s=-\r\n"
            + "c=IN IP4 127.0.0.1\r\n"
            + "t=0 0\r\n"
            + "m=audio " + dtmfSession.getLocalPort() + " RTP/AVP "
                + audioPayloadType + " " + DTMF_PAYLOAD_TYPE + "\r\n"
            + "a=rtpmap:0 PCMU/8000\r\n"
            + "a=rtpmap:" + DTMF_PAYLOAD_TYPE + " telephone-event/8000\r\n"
            + "a=fmtp:" + DTMF_PAYLOAD_TYPE + " 0-15\r\n";
       
        resp.setContent(sdpAnswer.getBytes(charset), "application/sdp");
        resp.send();
    }
View Full Code Here

    else if (PresenceEventPackage.NAME.equals(event)
        || WatcherInfoEventPackage.NAME.equals(event))
      getServletContext().getNamedDispatcher("presence").forward(subscribe, null);
    else
    {
      SipServletResponse response = subscribe.createResponse(SipServletResponse.SC_BAD_EVENT);
      response.addHeader(Constants.ALLOW_EVENTS, RegEventPackage.NAME);
      response.addHeader(Constants.ALLOW_EVENTS, PresenceEventPackage.NAME);
      response.addHeader(Constants.ALLOW_EVENTS, WatcherInfoEventPackage.NAME);
      response.send();
      response.getApplicationSession().invalidate();
    }
  }
View Full Code Here

    String aor = URIUtil.toCanonical(register.getTo().getURI());
   
    ListIterator<String> it2 = register.getHeaders(Constants.REQUIRE);
    if (it2.hasNext())
    {
      SipServletResponse response = register.createResponse(SipServletResponse.SC_BAD_EXTENSION);
      while (it2.hasNext())
        response.addHeader(Constants.UNSUPPORTED, it2.next());
      response.send();
      return;
    }
   
    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);
    }
   
    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

  {
    String event = subscribe.getHeader(Constants.EVENT);
   
    if (event == null || !(event.equals(_regEventPackage.getName())))
    {
      SipServletResponse response = subscribe.createResponse(SipServletResponse.SC_BAD_EVENT);
      response.addHeader(Constants.ALLOW_EVENTS, _regEventPackage.getName());
      response.send();
      response.getApplicationSession().invalidate();
      return;
    }
   
    if(!checkAcceptHeader(subscribe))
      return;
       
    int expires = subscribe.getExpires();
    if (expires != -1)
    {
      if (expires != 0)
      {
        if (expires < _regEventPackage.getMinExpires())
        {
          SipServletResponse response = subscribe.createResponse(SipServletResponse.SC_INTERVAL_TOO_BRIEF);
          response.addHeader(Constants.MIN_EXPIRES, Integer.toString(_regEventPackage.getMinExpires()));
          response.send();
          response.getApplicationSession().invalidate();
          return;
        }
        else if (expires > _regEventPackage.getMaxExpires())
        {
          expires = _regEventPackage.getMaxExpires();
        }
      }
    }
    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());
        }
        else
        {
          subscription.setExpirationTime(now + expires * 1000);
         
          if (_log.isDebugEnabled())
            _log.debug("refreshed reg subscription {} to registration resource {}",
                subscription.getSession().getId(), regResource.getUri());
        }
      }
     
      int code = (subscription.getState() != Subscription.State.PENDING) ?
          SipServletResponse.SC_OK : SipServletResponse.SC_ACCEPTED;
     
      SipServletResponse response = subscribe.createResponse(code);
      response.setExpires(expires);
      response.send();
       
      _regEventPackage.notify(subscription);
    }
    finally
    {
View Full Code Here

      doPresenceSubscribe(subscribe);
    else if (_watcherInfo.getName().equals(event))
      doWatcherInfoSubscribe(subscribe);
    else
    {
      SipServletResponse response = subscribe.createResponse(SipServletResponse.SC_BAD_EVENT);
      response.addHeader(Constants.ALLOW_EVENTS, _presence.getName());
      response.send();
      response.getApplicationSession().invalidate();
      return;
    }   
  }
View Full Code Here

    {
      if (expires != 0)
      {
        if (expires < _presence.getMinExpires())
        {
          SipServletResponse response = subscribe.createResponse(SipServletResponse.SC_INTERVAL_TOO_BRIEF);
          response.addHeader(Constants.MIN_EXPIRES, Integer.toString(_presence.getMinExpires()));
          response.send();
          response.getApplicationSession().invalidate();
          return;
        }
        else if (expires > _presence.getMaxExpires())
        {
          expires = _presence.getMaxExpires();
        }
      }
    }
    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());
        }
        else
        {
          subscription.setExpirationTime(now + expires * 1000);
         
          if (_log.isDebugEnabled())
            _log.debug("refreshed presence subscription {} to presentity {}",
                subscription.getSession().getId(), presentity.getUri());
        }
      }
     
      int code = (subscription.getState() != Subscription.State.PENDING) ?
          SipServletResponse.SC_OK : SipServletResponse.SC_ACCEPTED;
     
      SipServletResponse response = subscribe.createResponse(code);
      response.setExpires(expires);
      response.send();
     
      // Ensure 200/SUBSCRIBE is received before NOTIFY
      try { Thread.sleep(50); } catch (Exception e) {}
      _presence.notify(subscription);
    }
View Full Code Here

TOP

Related Classes of javax.servlet.sip.SipServletResponse

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.