Package javax.servlet.sip

Examples of javax.servlet.sip.SipServletResponse


    {
      String contentType = it.next();
      if (contentType.equals("") ||  supported.contains(contentType))
        return true;
    }
    SipServletResponse response = subscribe.createResponse(SipServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
    for (String s : supported)
      response.addHeader(Constants.ACCEPT, s);

    response.send();
    response.getApplicationSession().invalidate();
    return false;
  }
View Full Code Here


    {
      if (expires != 0)
      {
        if (expires < _watcherInfo.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 > _watcherInfo.getMaxExpires())
        {
          expires = _watcherInfo.getMaxExpires();
        }
      }
    }
    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());
        }
        else
        {
          subscription.setExpirationTime(now + expires * 1000);
         
          if (_log.isDebugEnabled())
            _log.debug("refreshed presence.winfo subscription {} to resource {}",
                subscription.getSession().getId(), resource.getUri());
        }
      }
     
      int code = (subscription.getState() != Subscription.State.PENDING) ?
          SipServletResponse.SC_OK : SipServletResponse.SC_ACCEPTED;
     
      SipServletResponse response = subscribe.createResponse(code);
      response.setExpires(expires);
      response.send();
       
      _watcherInfo.notify(subscription);
    }
    finally
    {
View Full Code Here

    {
      String contentType = it.next();
      if (contentType.equals("") ||  supported.contains(contentType))
        return true;
    }
    SipServletResponse response = subscribe.createResponse(SipServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
    for (String s : supported)
      response.addHeader(Constants.ACCEPT, s);

    response.send();
    response.getApplicationSession().invalidate();
    return false;
  }
View Full Code Here

          && 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();
View Full Code Here

  @Test
  public void testNoReason() throws Exception
  {
    File msgFile = new File(TORTURE_VALID_DIR, "noreason.dat");
    SipServletResponse message = (SipServletResponse) getMessage(msgFile);
    assertEquals("", message.getReasonPhrase());
    //System.out.println(message);
  }
View Full Code Here

          {
            int code = SipServletResponse.SC_SERVER_INTERNAL_ERROR;
            if (e instanceof SipException)
              code = ((SipException) e).getCode();
           
            SipServletResponse response;
            if (code == SipServletResponse.SC_SERVER_INTERNAL_ERROR)
            {
              response = request.createResponse(
                    SipServletResponse.SC_SERVER_INTERNAL_ERROR,
                    "Error in handler: " + e.getMessage());
              ExceptionUtil.fillStackTrace(response, e);
            }
            else
            {
              response = request.createResponse(code);
            }
            response.send();
          }
          else
          {
            Log.debug(e);
          }
View Full Code Here

    SipTester bob = SipTest.create("bob");
   
    SipServletRequest request = alice.createRequest("OPTIONS", bob);
    request.send();
   
    SipServletResponse response = alice.getResponse(request);
   
    assertNotNull(response);
    assertEquals(200, response.getStatus());
  }
View Full Code Here

                {
                  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();
     
    }
    catch (Throwable e) {
      log("Caught unexpected exception on REGISTER processing", e);
      SipServletResponse response = register.createResponse(SipServletResponse.SC_SERVER_INTERNAL_ERROR);
      response.setContent(e, "text/stackTrace");
      response.send();
    }
    finally
    {
      register.getApplicationSession().invalidate();
    }
View Full Code Here

                    ((SipServletRequestImpl) request).setUser(authPrincipal.getName());
                    ((SipServletRequestImpl) request).setAuthInfoHeader(auth.getAuthInfoHeader());
                    removeProcessedAuthHeader(request, proxy);
                } else {
                    if (!(request.getMethod().equals("ACK") || request.getMethod().equals("CANCEL"))) {
                        SipServletResponse response = createErrorResponse(request, servletToInvoke);
                        response.send();
                        return;
                    }

                }
            }
View Full Code Here

    }

    public SipServletResponse createErrorResponse(
            SipServletRequest request, String servletName) {

        SipServletResponse resp = null;
        int statusCode = 401;

        boolean proxyAuthenticate = false;
        Key key = new Key(servletName, request.getMethod());
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.