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

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


        try {
            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());
                subscription.setOwner(EventBrokerUtils.getLoggedInUserName());
            } 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) {
                if (log.isDebugEnabled()) {
                    log.debug(e.getMessage());
                }
                SOAPEnvelope soapEnvelope = BuilderUtils.genFaultResponse(
                        EventingConstants.WSE_FAULT_CODE_RECEIVER, "InvalidMessage",
                        e.getMessage(), "", mc.isSOAP11());
                dispatchResponse(soapEnvelope, EventingConstants.WSA_FAULT, mc, true);
            }

            if (subscription != null) {
                // set the topic name using the url
                String toAddress = mc.getOptions().getTo().getAddress();
                String topicName = subscription.getEventFilter().getValue();

                if ((topicName == null) || (topicName.equals(""))) {
                    // we take string after the service name as the topic name
                    if (toAddress.indexOf(EventingConstants.BROKER_SERVICE_NAME + "/") > 0) {
                        topicName = toAddress.substring(
                                toAddress.indexOf(EventingConstants.BROKER_SERVICE_NAME + "/")
                                        + EventingConstants.BROKER_SERVICE_NAME.length() + 1);
                    }
                }

                subscription.setTopicName(topicName);

                if (log.isDebugEnabled()) {
                    log.debug("Subscription request recieved  : " + subscription.getId());
                }
                if (subscription.getEventSinkURL().startsWith("sqs://")){
                    subscription.setEventDispatcherName(EventBrokerConstants.EVENT_SINK_DISPATCHER_NAME);
                } else {
                    subscription.setEventDispatcherName(EventBrokerConstants.WS_EVENT_DISPATCHER_NAME);
                }
               
                String subID = WSEventBrokerHolder.getInstance().getEventBroker().subscribe(subscription);
                subscription.setId(subID);
                if (subID != null) {
                    if (log.isDebugEnabled()) {
                        log.debug("Sending subscription response for Subscription ID : " +
                                subscription.getId());
                    }
                    SOAPEnvelope soapEnvelope = builder.fromSubscription(subscription);
                    dispatchResponse(soapEnvelope, EventingConstants.WSE_SUBSCRIBE_RESPONSE, mc, false);
                } else {
                    log.debug("Subscription Failed, sending fault response");
View Full Code Here


                        ServiceStatisticsPublisherConstants.BAM_SERVER_URL);

                if (serverURL != null) {
                    EventBroker broker = eventBroker;

                    Subscription subscription = new Subscription();

                    subscription.setEventSinkURL(serverURL +
                            ServiceStatisticsPublisherConstants.
                                    BAM_SERVICE_STAT_RECEIVER_SERVICE);
                    subscription.setTopicName(ServiceStatisticsPublisherConstants.BAM_REG_PATH);

                    subscription.setOwner(CarbonConstants.REGISTRY_SYSTEM_USERNAME);
                    subscription.setEventDispatcherName(EventBrokerConstants.WS_EVENT_DISPATCHER_NAME);

                    try {
                        SuperTenantCarbonContext.startTenantFlow();
                        int tenantId = SuperTenantCarbonContext.getCurrentContext(StatisticsServiceComponent.getConfigurationContext()).getTenantId();
                        SuperTenantCarbonContext.getCurrentContext().setTenantId(tenantId);
View Full Code Here

        }
    }

    public static Subscription createSubscription(String endpoint, String filterDialect,
                                                  String topic) throws InvalidMessageException {
        Subscription subscription = new Subscription();
        if (endpoint == null) {
            throw new InvalidMessageException("Endpoint not found in the subscription request");
        }
        subscription.setEventSinkURL(endpoint);
        if (topic == null) {
            throw new InvalidMessageException("Error in creating subscription. Topic not defined");
        }
       
        subscription.setTopicName(topic);
        return subscription;
    }
View Full Code Here

        if (Utils.getRegistryEventingService() == null) {
            log.warn("No event source found, can't unsubscribe");
            return false;
        }
        try {
            Subscription subscription = null;
            if (url == null || userName == null) {
                subscription = Utils.getRegistryEventingService().getSubscription(id);
            } else  {
                subscription = Utils.getRegistryEventingService().getSubscription(id, userName,
                        url);
            }

            if (subscription == null) {
                log.warn("Subscription not found, can't unsubscribe");
                return false;
            }
            if (subscription.getTenantId() != registry.getCallerTenantId()) {
                log.warn("TenantId for subscription doesn't match with the logged-in tenant");
                return false;
            }
            String username = subscription.getOwner();
            if (username.indexOf("@") > 0) {
                username = username.split("@")[0];
            }
            if (username == null || !username.equals(registry.getUserName())) {
                if (!SubscriptionBeanPopulator.isAuthorized(registry, path,
View Full Code Here

        }

        /*
         * Adding new subscriptions.
         */
        Subscription subscription;
        for (String epr : endpointUrls) {
            try {
                subscription = new Subscription();
                subscription.setEventSinkURL(epr);
                subscription.setId(UUID.randomUUID().toString());
                subscription.setTopicName(topic);
                subscription.setEventDispatcherName(EVENT_DISPATCHER_NAME);
                subscription.setOwner(this.getDataService().getName());
                eventBroker.subscribe(subscription);
            } catch (Exception e) {
                throw new DataServiceFault(e, "Error in event subscription for EPR: " + epr +
                        " Topic:" + topic);
            }
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

    public String subscribe(Subscription subscription)
            throws EventBrokerException {

        //if there is a subscription with the same topic and event sink url then
        //we think it is the same subscription.
        Subscription existingSubscription = getExistingNonExpiredSubscription(subscription);
        if (existingSubscription != null){
            return existingSubscription.getId();
        }
        if (EventBrokerHolder.getInstance().getTenantDomain() != null) {
            subscription.setTenantDomain(EventBrokerHolder.getInstance().getTenantDomain());
            subscription.setTenantId(EventBrokerHolder.getInstance().getTenantId());
        }
View Full Code Here

    private Subscription getExistingNonExpiredSubscription(Subscription newSubscription)
            throws EventBrokerException {
        Subscription[] subscriptions =
                this.topicManager.getSubscriptions(newSubscription.getTopicName(), false);
        Subscription existingSubscription = null;
        Calendar calendar = Calendar.getInstance();
        for (Subscription subscription : subscriptions) {
            if (subscription.getEventSinkURL() != null) {
                if (subscription.getEventSinkURL().equalsIgnoreCase(newSubscription.getEventSinkURL())) {
                    if ((subscription.getExpires() == null) || (calendar.before(subscription.getExpires()))) {
View Full Code Here

        String topic = RegistryEventingConstants.TOPIC_PREFIX + absolutePath +
                RegistryEvent.TOPIC_SEPARATOR + "#";

        SuperTenantCarbonContext.startTenantFlow();
        try {
            Subscription subscription =
                    BuilderUtils.createSubscription(endpoint,
                            "http://wso2.org/registry/eventing/dialect/topicFilter",
                            topic);
            subscription.setEventDispatcherName(RegistryEventingConstants.TOPIC_PREFIX);
            subscription.setTenantId(registry.getCallerTenantId());
            subscription.setOwner(registry.getUserName());

            SuperTenantCarbonContext currentContext = SuperTenantCarbonContext.getCurrentContext();
            currentContext.setTenantId(registry.getCallerTenantId(), true);
            currentContext.setUserRealm(registry.getUserRealm());
            currentContext.setUsername(registry.getUserName());
View Full Code Here

        // add the static subscriptions
       Iterator subscriptionsIter =
               config.getChildrenWithName(new QName(EventBrokerConstants.EB_CONF_NAMESPACE, EB_ELE_SUBSCRIPTION));
        OMElement subscriptionElement = null;
        Subscription subscription = null;
        String id = null;

        for (;subscriptionsIter.hasNext();) {
            subscriptionElement = (OMElement) subscriptionsIter.next();
            subscription = new Subscription();
            subscription.setId(subscriptionElement.getAttributeValue(new QName(null, EB_ATTR_ID)));
            // add this subscription only if it does not exists.
            try {
                if (registrySubscriptionManager.getSubscription(subscription.getId()) == null){
                    subscription.setTopicName(JavaUtil.getValue(subscriptionElement, EB_ELE_TOPIC));
                    subscription.setOwner(JavaUtil.getValue(subscriptionElement, EB_ELE_OWNER));
                    subscription.setEventSinkURL(
                            JavaUtil.getValue(subscriptionElement, EB_ELE_EVENT_SINK_URL));
                    subscription.setExpires(
                            ConverterUtil.convertToDateTime(
                                    JavaUtil.getValue(subscriptionElement, EB_ELE_EXPIRES)));
                    if (subscription.getEventSinkURL().startsWith("sqs://")) {
                        subscription.setEventDispatcherName(EventBrokerConstants.EVENT_SINK_DISPATCHER_NAME);
                    } else {
                        subscription.setEventDispatcherName(EventBrokerConstants.WS_EVENT_DISPATCHER_NAME);
                    }
                    registrySubscriptionManager.addSubscription(subscription);

                }
            } catch (EventBrokerException e) {
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.