Package org.wso2.carbon.event.core.subscription

Examples of org.wso2.carbon.event.core.subscription.Subscription


        }

        try {

            UnSubscribeCommandBuilder builder = new UnSubscribeCommandBuilder(mc);
            Subscription subscription = builder.toSubscription(mc.getEnvelope());
            if (log.isDebugEnabled()) {
                log.debug("UnSubscribe response recived for Subscription ID : " +
                        subscription.getId());
            }
            getBrokerService().unsubscribe(subscription.getId());
            if (log.isDebugEnabled()) {
                log.debug("Sending UnSubscribe responce for Subscription ID : " +
                        subscription.getId());
            }
            SOAPEnvelope soapEnvelope = builder.fromSubscription(subscription);
            dispatchResponse(soapEnvelope, EventingConstants.WSE_UNSUBSCRIBE_RESPONSE, mc, false);
        } catch (InvalidMessageException e) {
            throw new WSEventException("Invalid message ", e);
View Full Code Here


            log.warn("Get Status operation is disabled");
            return;
        }
        try {
            GetStatusCommandBuilder builder = new GetStatusCommandBuilder(mc);
            Subscription subscription = builder.toSubscription(mc.getEnvelope());

            if (log.isDebugEnabled()) {
                log.debug("GetStatus request recived for Subscription ID : " +
                        subscription.getId());
            }
            subscription = getBrokerService().getSubscription(subscription.getId());
            if (subscription != null) {
                String loggedInUser = EventBrokerUtils.getLoggedInUserName();
                if (!loggedInUser.equals("admin") && !loggedInUser.equals(subscription.getOwner())) {
                    throw new WSEventException("User " + loggedInUser + " does not own subscription " + subscription.getId());
                }
                if (log.isDebugEnabled()) {
                    log.debug("Sending GetStatus responce for Subscription ID : " +
                            subscription.getId());
                }
                SOAPEnvelope soapEnvelope = builder.fromSubscription(subscription);
                dispatchResponse(soapEnvelope, EventingConstants.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());
        } catch (InvalidExpirationTimeException e) {
            if (log.isDebugEnabled()) {
                log.debug(e.getMessage());
            }
            SOAPEnvelope soapEnvelope = BuilderUtils.genFaultResponse(
                    EventingConstants.WSE_FAULT_CODE_RECEIVER, "InvalidExpirationTime",
                    e.getMessage(), "", mc.isSOAP11());
            dispatchResponse(soapEnvelope, EventingConstants.WSA_FAULT, mc, true);
        } catch (InvalidMessageException e) {
            e.printStackTrace();
        }

        if (subscription != null && subscription.getId() != null) {
            if (log.isDebugEnabled()) {
                log.debug("Renew request recived for Subscription ID : " +
                        subscription.getId());
            }

            try {
                getBrokerService().renewSubscription(subscription);
                if (log.isDebugEnabled()) {
                    log.debug("Sending Renew response for Subscription ID : " +
                            subscription.getId());
                }
                SOAPEnvelope soapEnvelope =
                        builder.fromSubscription(subscription);
                dispatchResponse(soapEnvelope, EventingConstants.WSE_RENEW_RESPONSE, mc, false);
            } catch (EventBrokerException e) {
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 Subscription();
        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

    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 Subscription();
        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 Subscription();
                        subscription.setEventSinkURL(ep);
                    }
                } 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 dialectAttribute = filterElem.getAttribute(ATT_DIALECT);
                if (dialectAttribute != null && dialectAttribute.getAttributeValue() != null) {
                    subscription.setEventFilter(
                            new EventFilter(dialectAttribute.getAttributeValue(),
                                    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 = Calendar.getInstance();
                        Duration duration = ConverterUtil.convertToDuration(expiryText);
                        calendarExpires.add(Calendar.YEAR, duration.getYears());
                        calendarExpires.add(Calendar.MONTH, duration.getMonths());
                        calendarExpires.add(Calendar.DAY_OF_MONTH, duration.getDays());
                        calendarExpires.add(Calendar.HOUR_OF_DAY, duration.getHours());
                        calendarExpires.add(Calendar.MINUTE, duration.getMinutes());
                        calendarExpires.add(Calendar.SECOND, (int)duration.getSeconds());
                    } 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.");
                }
            }

            OMElement scriptElement = elem.getFirstChildWithName(new QName(EventingConstants.WSE_EXTENDED_EVENTING_NS, EventingConstants.EVENTING_EXECUTABLE_SCRIPT_ELEMENT));
            if (scriptElement != null) {
                subscription.getProperties().put(EventingConstants.EVENTING_EXECUTABLE_SCRIPT_ELEMENT, scriptElement.getText());
            }
        } else {
            log.error("Subscribe element is required as the payload of the subscription message.");
            throw new InvalidMessageException(
                    "Subscribe element is required as the payload of the subscription message.");
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 Subscription();
        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 = Calendar.getInstance();
                        Duration duration = ConverterUtil.convertToDuration(expiryText);
                        calendarExpires.add(Calendar.YEAR, duration.getYears());
                        calendarExpires.add(Calendar.MONTH, duration.getMonths());
                        calendarExpires.add(Calendar.DAY_OF_MONTH, duration.getDays());
                        calendarExpires.add(Calendar.HOUR_OF_DAY, duration.getHours());
                        calendarExpires.add(Calendar.MINUTE, duration.getMinutes());
                        calendarExpires.add(Calendar.SECOND, (int)duration.getSeconds());
                    } 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

        OMElement response = fac.createOMElement("getSubscriptionsResponse",wseexns);
       
        int addedCount = 0;
       
        for(int i = startIndex; i< Math.min(subscriptions.size(), startIndex+ maxResultCount); i++){
            Subscription subscription = subscriptions.get(i);
            OMElement subsciptionEle = fac.createOMElement("subscriptionDetail", wseexns, response);
            //fac.createOMElement("dialect", wseexns,subsciptionEle).setText("");
            fac.createOMElement("subscriptionId", wseexns,subsciptionEle).setText(subscription.getId());
            fac.createOMElement("eventSinkAddress", wseexns,subsciptionEle).setText(subscription.getEventSinkURL());
            if(subscription.getExpires() != null){
                //Time time = new Ti
                Calendar calendar = Calendar.getInstance();
                calendar.setTimeInMillis(subscription.getExpires().getTimeInMillis());
                fac.createOMElement("subscriptionEndingTime", wseexns,subsciptionEle).setText(ConverterUtil.convertToString(calendar));   
            }
            fac.createOMElement("topic", wseexns,subsciptionEle).setText(subscription.getTopicName());
            if(subscription.getCreatedTime() != null){
                Calendar calendar = Calendar.getInstance();
                calendar.setTimeInMillis(subscription.getCreatedTime().getTime());
                fac.createOMElement("createdTime", wseexns,subsciptionEle)
                    .setText(ConverterUtil.convertToString(calendar));
            }
            addedCount++;
        }
View Full Code Here

                            buffer.append(entry.getMessage()).append("/n/n");
                        }
                        RegistryEvent<String> re = new RegistryEvent<String>(buffer.toString());
                        re.setTopic("DigestEvent");
                        DispatchEvent de = new DispatchEvent(re, e.getKey(), true);
                        Subscription subscription = new Subscription();
                        subscription.setTopicName(re.getTopic());
                        publishEvent(de, subscription, e.getKey(), true);
                    }
                } catch (Exception ignored) {
                }
            }
View Full Code Here

        //Add static subscription only if bam url is set
        if (serverURL != null) {
            String serviceURL = serverURL + UsageAgentConstants.BAM_SERVER_STAT_SERVICE;

            EventBroker eventBrokerService = getEventBrokerService();
            Subscription subscription = new Subscription();
            // set the subscription end point to the service url
            subscription.setEventSinkURL(serviceURL);
            subscription.setTopicName(UsageAgentConstants.BAM_SERVER_STAT_FILTER);
            subscription.setOwner(CarbonConstants.REGISTRY_SYSTEM_USERNAME);
            subscription.setEventDispatcherName(EventBrokerConstants.WS_EVENT_DISPATCHER_NAME);

            try {
                eventBrokerService.subscribe(subscription);
            } catch (EventBrokerException e) {
                String msg = "Cannot subscribe to the event broker ";
View Full Code Here

TOP

Related Classes of org.wso2.carbon.event.core.subscription.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.