public Request setNotifyContent(
      Subscription subscription,
      Request notify,
      Object content,
      ContentTypeHeader contentTypeHeader,
      ImplementedSubscriptionControlSbbLocalObject childSbb)
      throws JAXBException, ParseException, IOException {

    if (!subscription.getResourceList()) {
      // filter content per subscriber (notifier rules)
      Object filteredContent =
          childSbb.filterContentPerSubscriber(
              subscription.getSubscriber(),
              subscription.getNotifier(),
              subscription.getKey().getEventPackage(),
              content);
      // filter content per notifier (subscriber rules)
      // TODO
      // marshall content to string
      StringWriter stringWriter = new StringWriter();
      childSbb.getMarshaller().marshal(filteredContent, stringWriter);
      notify.setContent(stringWriter.toString(), contentTypeHeader);
      stringWriter.close();
    } else {
      // resource list subscription, no filtering
      if (content instanceof JAXBElement) {
        // marshall content to string
        StringWriter stringWriter = new StringWriter();
        childSbb.getMarshaller().marshal(content, stringWriter);
        notify.setContent(stringWriter.toString(), contentTypeHeader);
        stringWriter.close();
      } else {
        notify.setContent(content, contentTypeHeader);
      }
    }
    return notify;
  }
  // creates a notify request and fills headers
  public Request createNotify(Dialog dialog, Subscription subscription) {

    Request notify = null;
    try {
      notify = dialog.createRequest(Request.NOTIFY);
      // add event header
      EventHeader eventHeader =
          sipSubscriptionHandler
              .sbb
              .getHeaderFactory()
              .createEventHeader(subscription.getKey().getEventPackage());
      if (subscription.getKey().getRealEventId() != null)
        eventHeader.setEventId(subscription.getKey().getRealEventId());
      notify.setHeader(eventHeader);
      // add max forwards header
      notify.setHeader(
          sipSubscriptionHandler
              .sbb
              .getHeaderFactory()
              .createMaxForwardsHeader(
                  sipSubscriptionHandler.sbb.getConfiguration().getMaxForwards()));
      /*
       * NOTIFY requests MUST contain a "Subscription-State" header with a
       * value of "active", "pending", or "terminated". The "active" value
       * indicates that the subscription has been accepted and has been
       * authorized (in most cases; see section 5.2.). The "pending" value
       * indicates that the subscription has been received, but that
       * policy information is insufficient to accept or deny the
       * subscription at this time. The "terminated" value indicates that
       * the subscription is not active.
       */
      SubscriptionStateHeader ssh = null;
      if (subscription.getStatus().equals(Subscription.Status.active)
          || subscription.getStatus().equals(Subscription.Status.pending)) {
        ssh =
            sipSubscriptionHandler
                .sbb
                .getHeaderFactory()
                .createSubscriptionStateHeader(subscription.getStatus().toString());
        /*
         * If the value of the "Subscription-State" header is "active"
         * or "pending", the notifier SHOULD also include in the
         * "Subscription- State" header an "expires" parameter which
         * indicates the time remaining on the subscription.
         */
        ssh.setExpires(subscription.getRemainingExpires());
      } else if (subscription.getStatus().equals(Subscription.Status.waiting)
          || subscription.getStatus().equals(Subscription.Status.terminated)) {
        ssh =
            sipSubscriptionHandler
                .sbb
                .getHeaderFactory()
                .createSubscriptionStateHeader("terminated");
        /*
         * If the value of the "Subscription-State" header is
         * "terminated", the notifier SHOULD also include a "reason"
         * parameter.
         */
        if (subscription.getLastEvent() != null) {
          ssh.setReasonCode(subscription.getLastEvent().toString());
        }
      }
      notify.addHeader(ssh);

      // if it's a RLS notify a required header must be present
      if (subscription.getResourceList()) {
        notify.addHeader(
            sipSubscriptionHandler.sbb.getHeaderFactory().createRequireHeader("eventlist"));
      }

    } catch (Exception e) {
      logger.error("unable to fill notify headers", e);
    }
    return notify;
  }