예제 #1
0
  /**
   * Populates a specific <tt>Request</tt> instance with the headers common to dialog-creating
   * <tt>Request</tt>s and ones sent inside existing dialogs and specific to the general event
   * package subscription functionality that this instance and a specific <tt>Subscription</tt>
   * represent.
   *
   * @param req the <tt>Request</tt> instance to be populated with common headers and ones specific
   *     to the event package of a specific <tt>Subscription</tt>
   * @param subscription the <tt>Subscription</tt> which is to be described in the specified
   *     <tt>Request</tt> i.e. its properties are to be used to populate the specified
   *     <tt>Request</tt>
   * @param expires the subscription duration to be set into the Expires header of the specified
   *     SUBSCRIBE <tt>Request</tt>
   * @throws OperationFailedException if we fail parsing or populating the subscription request.
   */
  protected void populateSubscribeRequest(Request req, Subscription subscription, int expires)
      throws OperationFailedException {
    HeaderFactory headerFactory = protocolProvider.getHeaderFactory();

    // Event
    EventHeader evHeader;
    try {
      evHeader = headerFactory.createEventHeader(eventPackage);

      String eventId = subscription.getEventId();
      if (eventId != null) evHeader.setEventId(eventId);
    } catch (ParseException e) {
      // these two should never happen.
      logger.error("An unexpected error occurred while" + "constructing the EventHeader", e);
      throw new OperationFailedException(
          "An unexpected error occurred while" + "constructing the EventHeader",
          OperationFailedException.INTERNAL_ERROR,
          e);
    }
    req.setHeader(evHeader);

    // Accept
    AcceptHeader accept;
    try {
      accept = headerFactory.createAcceptHeader("application", contentSubType);
    } catch (ParseException e) {
      logger.error("wrong accept header", e);
      throw new OperationFailedException(
          "An unexpected error occurred while" + "constructing the AcceptHeader",
          OperationFailedException.INTERNAL_ERROR,
          e);
    }
    req.setHeader(accept);

    // Expires
    ExpiresHeader expHeader;
    try {
      expHeader = headerFactory.createExpiresHeader(expires);
    } catch (InvalidArgumentException e) {
      logger.error("Invalid expires value: " + expires, e);
      throw new OperationFailedException(
          "An unexpected error occurred while" + "constructing the ExpiresHeader",
          OperationFailedException.INTERNAL_ERROR,
          e);
    }
    req.setHeader(expHeader);
  }
예제 #2
0
 /**
  * Adds a specific <tt>Subscription</tt> to the list of subscriptions managed by this instance
  * only if another <tt>Subscription</tt> with the same subscription <tt>Address</tt>/Request URI
  * and id tag of its associated Event header does not exist in the list.
  *
  * @param subscription the new <tt>Subscription</tt> to be added to the list of subscriptions
  *     managed by this instance if there is no other <tt>Subscription</tt> in the list which has
  *     the same subscription <tt>Address</tt>/Request URI and id tag of its Event header
  * @throws OperationFailedException if we fail constructing or sending the subscription request
  */
 public void poll(Subscription subscription) throws OperationFailedException {
   if (getSubscription(subscription.getAddress(), subscription.getEventId()) == null)
     subscribe(subscription);
 }