Package org.wso2.eventing

Examples of org.wso2.eventing.Subscription


        assertEquals("Invalid subscription id", "uuid:22e8a584-0d18-4228-b2a8-3716fa2097fa",
                subscription.getId());
    }

    public void testSubscriptionToSOAP12Envelope() throws Exception {
        Subscription subscription = new Subscription();
        MessageContext mc = CommandBuilderTestUtils.getMCWithSOAP12Envelope();
        UnSubscribeCommandBuilder builder = new  UnSubscribeCommandBuilder(mc);

        OMElement payload = builder.fromSubscription(subscription);
View Full Code Here


        assertEquals("Invalid response for the get status request", RESPONSE_PAYLOAD_SOAP12,
                payload.toString());
    }

    public void testSubscriptionToSOAP11Envelope() throws Exception {
        Subscription subscription = new Subscription();
        MessageContext mc = CommandBuilderTestUtils.getMCWithSOAP11Envelope();
        UnSubscribeCommandBuilder builder = new  UnSubscribeCommandBuilder(mc);

        OMElement payload = builder.fromSubscription(subscription);
View Full Code Here

    public Subscription toSubscription(SOAPEnvelope envelope) throws InvalidMessageException {
        if (envelope == null) {
            log.error("No SOAP envelope was provided.");
            throw new BuilderException("No SOAP envelope was provided.");
        }
        Subscription subscription = new CarbonSubscription();
        OMElement elem = null;
        if (envelope.getHeader() != null) {
            elem = envelope.getHeader().getFirstChildWithName(IDENTIFIER);
        }
        if (elem == null) {
            log.error(
                    "Subscription Identifier is required as a header of the subscription message.");
            throw new InvalidMessageException(
                    "Subscription Identifier is required as a header of the subscription message.");
        }
        String id = elem.getText().trim();
        subscription.setId(id);

        return subscription;
    }
View Full Code Here

    protected void handleSubscribe(MessageContext mc) throws AxisFault, EventException {
        if (!isEnabled(mc, ENABLE_SUBSCRIBE)) {
            log.warn("Subscribe operation is disabled");
            return;
        }
        Subscription subscription = null;
        SubscribeCommandBuilder builder = new SubscribeCommandBuilder(mc);
        try {
            subscription = builder.toSubscription(mc.getEnvelope());
            if (mc.getTo() != null) {
                subscription.setAddressUrl(mc.getTo().getAddress());
            }
        } catch (InvalidExpirationTimeException e) {
            if (log.isDebugEnabled()) {
                log.debug(e.getMessage());
            }
            SOAPEnvelope soapEnvelope = BuilderUtils.genFaultResponse(
                    CommandBuilderConstants.WSE_FAULT_CODE_RECEIVER, "InvalidExpirationTime",
                    e.getMessage(), "", mc.isSOAP11());
            dispatchResponse(soapEnvelope, CommandBuilderConstants.WSA_FAULT, mc, true);
        } catch (InvalidMessageException e) {
            if (log.isDebugEnabled()) {
                log.debug(e.getMessage());
            }
            SOAPEnvelope soapEnvelope = BuilderUtils.genFaultResponse(
                    CommandBuilderConstants.WSE_FAULT_CODE_RECEIVER, "InvalidMessage",
                    e.getMessage(), "", mc.isSOAP11());
            dispatchResponse(soapEnvelope, CommandBuilderConstants.WSA_FAULT, mc, true);
        }
        if (subscription != null && subscription.getId() != null) {
            if (log.isDebugEnabled()) {
                log.debug("Subscription request recieved  : " + subscription.getId());
            }
            String subID = getBrokerService().getSubscriptionManager().subscribe(subscription);
            if (subID != null) {
                if (log.isDebugEnabled()) {
                    log.debug("Sending subscription response for Subscription ID : " +
                            subscription.getId());
                }
                SOAPEnvelope soapEnvelope = builder.fromSubscription(subscription);
                dispatchResponse(soapEnvelope, CommandBuilderConstants.WSE_SUBSCRIBE_RESPONSE, mc, false);
            } else {
                log.debug("Subscription Failed, sending fault response");
View Full Code Here

        if (!isEnabled(mc, ENABLE_UNSUBSCRIBE)) {
            log.warn("Unsubscribe operation is disabled");
            return;
        }
        UnSubscribeCommandBuilder builder = new UnSubscribeCommandBuilder(mc);
        Subscription subscription = builder.toSubscription(mc.getEnvelope());
        if (mc.getTo() != null) {
            subscription.setAddressUrl(mc.getTo().getAddress());
        }
        if (log.isDebugEnabled()) {
            log.debug("UnSubscribe response recived for Subscription ID : " +
                    subscription.getId());
        }
        if (getBrokerService().getSubscriptionManager().unsubscribe(subscription.getId())) {
            if (log.isDebugEnabled()) {
                log.debug("Sending UnSubscribe responce for Subscription ID : " +
                        subscription.getId());
            }
            SOAPEnvelope soapEnvelope = builder.fromSubscription(subscription);
            dispatchResponse(soapEnvelope, CommandBuilderConstants.WSE_UNSUBSCRIBE_RESPONSE, mc, false);
        } else {
            log.debug("UnSubscription failed, sending fault repsponse");
View Full Code Here

        if (!isEnabled(mc, ENABLE_GET_STATUS)) {
            log.warn("Get Status operation is disabled");
            return;
        }
        GetStatusCommandBuilder builder = new GetStatusCommandBuilder(mc);
        Subscription subscription = builder.toSubscription(mc.getEnvelope());
        if (mc.getTo() != null) {
            subscription.setAddressUrl(mc.getTo().getAddress());
        }
        if (log.isDebugEnabled()) {
            log.debug("GetStatus request recived for Subscription ID : " +
                    subscription.getId());
        }
        subscription = getBrokerService().getSubscriptionManager().getSubscription(subscription.getId());
        if (subscription != null) {
            if (log.isDebugEnabled()) {
                log.debug("Sending GetStatus responce for Subscription ID : " +
                        subscription.getId());
            }
            SOAPEnvelope soapEnvelope = builder.fromSubscription(subscription);
            dispatchResponse(soapEnvelope, CommandBuilderConstants.WSE_GET_STATUS_RESPONSE, mc, false);
        } else {
            log.debug("GetStatus failed, sending fault response");
View Full Code Here

        if (!isEnabled(mc, ENABLE_RENEW)) {
            log.warn("Renew operation is disabled");
            return;
        }
        RenewCommandBuilder builder = new RenewCommandBuilder(mc);
        Subscription subscription = null;
        try {
            subscription = builder.toSubscription(mc.getEnvelope());
            if (mc.getTo() != null) {
                subscription.setAddressUrl(mc.getTo().getAddress());
            }
        } catch (InvalidExpirationTimeException e) {
            if (log.isDebugEnabled()) {
                log.debug(e.getMessage());
            }
            SOAPEnvelope soapEnvelope = BuilderUtils.genFaultResponse(
                    CommandBuilderConstants.WSE_FAULT_CODE_RECEIVER, "InvalidExpirationTime",
                    e.getMessage(), "", mc.isSOAP11());
            dispatchResponse(soapEnvelope, CommandBuilderConstants.WSA_FAULT, mc, true);
        }

        if (subscription != null && subscription.getId() != null) {
            if (log.isDebugEnabled()) {
                log.debug("Renew request recived for Subscription ID : " +
                        subscription.getId());
            }
            if (getBrokerService().getSubscriptionManager().renew(subscription)) {
                if (log.isDebugEnabled()) {
                    log.debug("Sending Renew response for Subscription ID : " +
                            subscription.getId());
                }
                SOAPEnvelope soapEnvelope =
                        builder.fromSubscription(subscription);
                dispatchResponse(soapEnvelope, CommandBuilderConstants.WSE_RENEW_RESPONSE, mc, false);
            } else {
View Full Code Here

    public Subscription toSubscription(SOAPEnvelope envelope) throws InvalidMessageException {
        if (envelope == null) {
            log.error("No SOAP envelope was provided.");
            throw new BuilderException("No SOAP envelope was provided.");
        }
        Subscription subscription = new CarbonSubscription();
        OMElement elem = null;
        if (envelope.getHeader() != null) {
            elem = envelope.getHeader().getFirstChildWithName(IDENTIFIER);
        }
        if (elem == null) {
            log.error(
                    "Subscription Identifier is required as a header of the subscription message.");
            throw new InvalidMessageException(
                    "Subscription Identifier is required as a header of the subscription message.");
        }
        String id = elem.getText().trim();
        subscription.setId(id);
       
        return subscription;
    }
View Full Code Here

     * @throws InvalidMessageException
     * @throws InvalidExpirationTimeException
     */
    public Subscription toSubscription(SOAPEnvelope envelope) throws InvalidMessageException,
        InvalidExpirationTimeException {
        Subscription subscription = null;
        OMElement notifyToElem;
        if (envelope == null) {
            log.error("No SOAP envelope was provided.");
            throw new BuilderException("No SOAP envelope was provided.");
        }
        OMElement elem = null;
        if (envelope.getBody() != null) {
            elem = envelope.getBody().getFirstChildWithName(SUBSCRIBE_QNAME);
        }
        if (elem != null) {
            OMElement deliveryElem = elem.getFirstChildWithName(DELIVERY_QNAME);
            if (deliveryElem != null) {
                notifyToElem = deliveryElem.getFirstChildWithName(NOTIFY_TO_QNAME);
                if (notifyToElem != null) {
                    String ep = BuilderUtils.getEndpointFromWSAAddress(
                            notifyToElem.getFirstElement());
                    if (ep != null) {
                        subscription = new CarbonSubscription();
                        subscription.setDeliveryMode(WSE_DEFAULT_DELIVERY_MODE);
                        subscription.setEndpointUrl(ep);
                        subscription.setAddressUrl(notifyToElem.getFirstElement().getText().trim());
                    }
                } else {
                    log.error("NotifyTo element not found in the subscription message.");
                    throw new InvalidMessageException(
                            "NotifyTo element not found in the subscription message.");
                }
            } else {
                log.error("Delivery element is not found in the subscription message.");
                throw new InvalidMessageException(
                        "Delivery element is not found in the subscription message.");
            }

            OMElement filterElem = elem.getFirstChildWithName(FILTER_QNAME);
            if (subscription != null && filterElem != null) {
                OMAttribute dialectAttr = filterElem.getAttribute(ATT_DIALECT);
                if (dialectAttr != null && dialectAttr.getAttributeValue() != null) {
                    subscription.setFilterDialect(dialectAttr.getAttributeValue());
                    subscription.setFilterValue(filterElem.getText().trim());
                } else {
                    log.error("Error in creating subscription. Filter dialect not defined.");
                    throw new BuilderException(
                            "Error in creating subscription. Filter dialect not defined.");
                }
            } else if (subscription == null) {
                log.error("Error in creating subscription.");
                throw new BuilderException("Error in creating subscription.");
            }
            OMElement expiryElem = elem.getFirstChildWithName(EXPIRES);
            if (expiryElem != null) {
                Calendar calendarExpires;
                try {
                    String expiryText = expiryElem.getText().trim();
                    if (expiryText.startsWith("P")) {
                        calendarExpires = ConverterUtil.convertToDuration(expiryText)
                                .getAsCalendar();
                    } else {
                        calendarExpires = ConverterUtil.convertToDateTime(expiryText);
                    }
                } catch (Exception e) {
                    log.error("Error converting the expiration date.", e);
                    throw new InvalidExpirationTimeException(
                            "Error converting the expiration date.", e);
                }
                Calendar calendarNow = Calendar.getInstance();
                if (calendarNow.before(calendarExpires)) {
                    subscription.setExpires(calendarExpires);
                } else {
                    log.error("The expiration time has passed.");
                    throw new InvalidExpirationTimeException("The expiration time has passed.");
                }
            }
View Full Code Here

        InvalidExpirationTimeException {
        if (envelope == null) {
            log.error("No SOAP envelope was provided.");
            throw new BuilderException("No SOAP envelope was provided.");
        }
        Subscription subscription = new CarbonSubscription();
        OMElement elem = null;
        if (envelope.getHeader() != null) {
            elem = envelope.getHeader().getFirstChildWithName(IDENTIFIER);
        }
        if (elem == null) {
            log.error(
                    "Subscription Identifier is required as a header of the subscription message.");
            throw new InvalidMessageException(
                    "Subscription Identifier is required as a header of the subscription message.");
        }
        String id = elem.getText().trim();
        subscription.setId(id);
       
        OMElement renewElem = envelope.getBody().getFirstChildWithName(RENEW);
        if (renewElem != null) {
            OMElement expiryElem = renewElem.getFirstChildWithName(EXPIRES);
            if (expiryElem != null) {
                Calendar calendarExpires;
                try {
                    String expiryText = expiryElem.getText().trim();
                    if (expiryText.startsWith("P")) {
                        calendarExpires = ConverterUtil.convertToDuration(expiryText)
                                .getAsCalendar();
                    } else {
                        calendarExpires = ConverterUtil.convertToDateTime(expiryText);
                    }
                } catch (Exception e) {
                    log.error("Error converting the expiration date", e);
                    throw new InvalidExpirationTimeException(
                            "Error converting the expiration date", e);
                }
                Calendar calendarNow = Calendar.getInstance();
                if (calendarNow.before(calendarExpires)) {
                    subscription.setExpires(calendarExpires);
                } else {
                    log.error("The expiration time has passed");
                    throw new InvalidExpirationTimeException("The expiration time has passed");
                }

                subscription.setExpires(calendarExpires);
            } else {
                log.error("The expiration time was not given");
                throw new InvalidExpirationTimeException("The expiration time was not given");
            }
        }
View Full Code Here

TOP

Related Classes of org.wso2.eventing.Subscription

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.