private SOAPEnvelope createSubscriptionEnvelope()

in modules/core/src/main/java/org/apache/savan/eventing/client/EventingClient.java [238:318]


    private SOAPEnvelope createSubscriptionEnvelope(EventingClientBean bean, String SOAPVersion)
            throws Exception {
        SOAPFactory factory = null;

        if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(SOAPVersion))
            factory = OMAbstractFactory.getSOAP11Factory();
        else if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(SOAPVersion))
            factory = OMAbstractFactory.getSOAP12Factory();
        else throw new Exception("Unknown SOAP version");

        SOAPEnvelope envelope = factory.getDefaultEnvelope();
        SOAPBody body = envelope.getBody();

        OMNamespace ens = factory.createOMNamespace(EventingConstants.EVENTING_NAMESPACE,
                                                    EventingConstants.EVENTING_PREFIX);

        OMElement subscriptionElement =
                factory.createOMElement(EventingConstants.ElementNames.Subscribe, ens);

        EndpointReference endToEPR = bean.getEndToEPR();
        if (bean.getEndToEPR() != null) {
            OMElement endToElement = EndpointReferenceHelper.toOM(
                    subscriptionElement.getOMFactory(), endToEPR, new QName(
                    EventingConstants.EVENTING_NAMESPACE, EventingConstants.ElementNames.EndTo,
                    EventingConstants.EVENTING_PREFIX),
                                                                  AddressingConstants.Submission.WSA_NAMESPACE);
            subscriptionElement.addChild(endToElement);
        }

        EndpointReference deliveryEPR = bean.getDeliveryEPR();
        if (deliveryEPR == null)
            throw new Exception("Delivery EPR is not set");

        OMElement deliveryElement =
                factory.createOMElement(EventingConstants.ElementNames.Delivery, ens);
        OMElement notifyToElement = EndpointReferenceHelper.toOM(subscriptionElement.getOMFactory(),
                                                                 deliveryEPR, new QName(
                EventingConstants.EVENTING_NAMESPACE, EventingConstants.ElementNames.NotifyTo,
                EventingConstants.EVENTING_PREFIX), AddressingConstants.Submission.WSA_NAMESPACE);

        deliveryElement.addChild(notifyToElement);
        subscriptionElement.addChild(deliveryElement);

        if (bean.getExpirationTime() != null || bean.getExpirationDuration() != null) {
            String timeString = null;

            //if time is set it will be taken. Otherwise duration will be taken.
            if (bean.getExpirationTime() != null) {
                Date date = bean.getExpirationTime();
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                timeString = ConverterUtil.convertToString(calendar);
            } else if (bean.getExpirationDuration() != null) {
                Duration duration = bean.getExpirationDuration();
                timeString = ConverterUtil.convertToString(duration);
            }

            OMElement expiresElement =
                    factory.createOMElement(EventingConstants.ElementNames.Expires, ens);
            expiresElement.setText(timeString);
            subscriptionElement.addChild(expiresElement);
        }

        if (bean.getFilter() != null) {
            String filter = bean.getFilter();
            String dialect = bean.getFilterDialect();

            OMElement filterElement =
                    factory.createOMElement(EventingConstants.ElementNames.Filter, ens);
            OMAttribute dialectAttr = factory.createOMAttribute(
                    EventingConstants.ElementNames.Dialect, null, dialect);
            filterElement.addAttribute(dialectAttr);
            filterElement.setText(filter);

            subscriptionElement.addChild(filterElement);
        }

        body.addChild(subscriptionElement);

        return envelope;
    }