/**
   * Creates a new SUBSCRIBE request in the form of a <tt>ClientTransaction</tt> with the parameters
   * of a specific <tt>Subscription</tt>.
   *
   * @param subscription the <tt>Subscription</tt> to be described in a SUBSCRIBE request
   * @param dialog the <tt>Dialog</tt> with which this request should be associated
   * @param expires the subscription duration of the SUBSCRIBE request to be created
   * @return a new <tt>ClientTransaction</tt> initialized with a new SUBSCRIBE request which matches
   *     the parameters of the specified <tt>Subscription</tt> and is associated with the specified
   *     <tt>Dialog</tt>
   * @throws OperationFailedException if the message could not be generated
   */
  private ClientTransaction createSubscription(
      Subscription subscription, Dialog dialog, int expires) throws OperationFailedException {
    Request req = messageFactory.createRequest(dialog, Request.SUBSCRIBE);

    // Address
    Address toAddress = dialog.getRemoteTarget();
    // no Contact field
    if (toAddress == null) toAddress = dialog.getRemoteParty();

    // MaxForwards
    MaxForwardsHeader maxForwards = protocolProvider.getMaxForwardsHeader();
    req.setHeader(maxForwards);

    /*
     * Create the transaction and then add the via header as recommended by
     * the jain-sip documentation at
     * http://snad.ncsl.nist.gov/proj/iptel/jain-sip-1.2/javadoc
     * /javax/sip/Dialog.html#createRequest(String).
     */
    ClientTransaction transac = null;
    try {
      transac = protocolProvider.getDefaultJainSipProvider().getNewClientTransaction(req);
    } catch (TransactionUnavailableException ex) {
      logger.error(
          "Failed to create subscriptionTransaction.\n"
              + "This is most probably a network connection error.",
          ex);
      throw new OperationFailedException(
          "Failed to create the subscription transaction",
          OperationFailedException.NETWORK_FAILURE);
    }

    populateSubscribeRequest(req, subscription, expires);

    return transac;
  }