Пример #1
0
  /**
   * Initializes a new <tt>EventPackageSubscriber</tt> instance which is to provide subscriber
   * support according to RFC 3265 to a specific SIP <tt>ProtocolProviderService</tt> implementation
   * for a specific event package.
   *
   * @param protocolProvider the SIP <tt>ProtocolProviderService</tt> implementation for which the
   *     new instance is to provide subscriber support for a specific event package
   * @param eventPackage the name of the event package the new instance is to implement and carry in
   *     the Event and Allow-Events headers
   * @param subscriptionDuration the duration of each subscription to be managed by the new instance
   *     and to be carried in the Expires headers
   * @param contentSubType the sub-type of the content type of the NOTIFY bodies to be announced,
   *     expected and supported by the subscriptions to be managed by the new instance
   * @param timer the <tt>Timer</tt> support which is to refresh the subscriptions to be managed by
   *     the new instance
   * @param refreshMargin the number of seconds before a subscription to be managed by the new
   *     instance expires that the new instance should attempt to refresh it
   */
  public EventPackageSubscriber(
      ProtocolProviderServiceSipImpl protocolProvider,
      String eventPackage,
      int subscriptionDuration,
      String contentSubType,
      TimerScheduler timer,
      int refreshMargin) {
    super(protocolProvider, eventPackage, subscriptionDuration, contentSubType, timer);

    this.refreshMargin = refreshMargin;
    this.messageFactory = protocolProvider.getMessageFactory();
  }
Пример #2
0
  /**
   * Receives options requests and replies with an OK response containing methods that we support.
   *
   * @param requestEvent the incoming options request.
   * @return <tt>true</tt> if request has been successfully processed, <tt>false</tt> otherwise
   */
  @Override
  public boolean processRequest(RequestEvent requestEvent) {
    Response optionsOK = null;
    try {
      optionsOK =
          provider.getMessageFactory().createResponse(Response.OK, requestEvent.getRequest());

      // add to the allows header all methods that we support
      for (String method : provider.getSupportedMethods()) {
        // don't support REGISTERs
        if (!method.equals(Request.REGISTER))
          optionsOK.addHeader(provider.getHeaderFactory().createAllowHeader(method));
      }

      Iterable<String> knownEventsList = provider.getKnownEventsList();

      synchronized (knownEventsList) {
        for (String event : knownEventsList)
          optionsOK.addHeader(provider.getHeaderFactory().createAllowEventsHeader(event));
      }
    } catch (ParseException ex) {
      // What else could we do apart from logging?
      logger.warn("Failed to create an incoming OPTIONS request", ex);
      return false;
    }

    try {
      SipStackSharing.getOrCreateServerTransaction(requestEvent).sendResponse(optionsOK);
    } catch (TransactionUnavailableException ex) {
      // this means that we received an OPTIONS request outside the scope
      // of a transaction which could mean that someone is simply sending
      // us b****hit to keep a NAT connection alive, so let's not get too
      // excited.
      if (logger.isInfoEnabled())
        logger.info("Failed to respond to an incoming " + "transactionless OPTIONS request");
      if (logger.isTraceEnabled()) logger.trace("Exception was:", ex);
      return false;
    } catch (InvalidArgumentException ex) {
      // What else could we do apart from logging?
      logger.warn("Failed to send an incoming OPTIONS request", ex);
      return false;
    } catch (SipException ex) {
      // What else could we do apart from logging?
      logger.warn("Failed to send an incoming OPTIONS request", ex);
      return false;
    }

    return true;
  }