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

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


                    this.registryService.getGovernanceSystemRegistry(EventBrokerHolder.getInstance().getTenantId());
            Resource topicIndexResource = userRegistry.get(this.indexStoragePath);
            String subscriptionPath = getResourcePath(id, topicIndexResource.getProperty(id));
            if (subscriptionPath != null) {
                Resource subscriptionResource = userRegistry.get(subscriptionPath);
                Subscription subscription = JavaUtil.getSubscription(subscriptionResource);
                subscription.setTenantId(EventBrokerHolder.getInstance().getTenantId());
                return subscription;
            } else {
                return null;
            }
        } catch (RegistryException e) {
View Full Code Here


                if (subscription.getExpires() != null) {
                    subscriptionResource.setProperty(EventBrokerConstants.EB_RES_EXPIRS,
                            ConverterUtil.convertToString(subscription.getExpires()));
                }
                // There might be updated subscription properties. Set them too.
                Subscription currentSubscription = JavaUtil.getSubscription(subscriptionResource);
                Map<String, String> properties = currentSubscription.getProperties();
                for (String key : properties.keySet()) {
                    subscriptionResource.removeProperty(key);
                }
                properties = subscription.getProperties();
                for (String key : properties.keySet()) {
View Full Code Here

     * @param subscriptionResource
     * @return
     */
    public static Subscription getSubscription(Resource subscriptionResource) {

        Subscription subscription = new Subscription();
        Properties properties = subscriptionResource.getProperties();
        if ((properties != null) && (!properties.isEmpty())) {
            for (Enumeration enumeration = properties.propertyNames(); enumeration.hasMoreElements();) {
                String propertyName = (String) enumeration.nextElement();
                if (EventBrokerConstants.EB_RES_SUBSCRIPTION_URL.equals(propertyName)) {
                    subscription.setEventSinkURL(
                            subscriptionResource.getProperty(EventBrokerConstants.EB_RES_SUBSCRIPTION_URL));
                } else if (EventBrokerConstants.EB_RES_EVENT_DISPATCHER_NAME.equals(propertyName)) {
                    subscription.setEventDispatcherName(
                            subscriptionResource.getProperty(EventBrokerConstants.EB_RES_EVENT_DISPATCHER_NAME));
                } else if (EventBrokerConstants.EB_RES_EXPIRS.equals(propertyName)) {
                    subscription.setExpires(
                            ConverterUtil.convertToDateTime(
                                    subscriptionResource.getProperty(EventBrokerConstants.EB_RES_EXPIRS)));
                } else if (EventBrokerConstants.EB_RES_OWNER.equals(propertyName)) {
                    subscription.setOwner(subscriptionResource.getProperty(EventBrokerConstants.EB_RES_OWNER));
                } else if (EventBrokerConstants.EB_RES_TOPIC_NAME.equals(propertyName)) {
                    subscription.setTopicName(subscriptionResource.getProperty(EventBrokerConstants.EB_RES_TOPIC_NAME));
                } else if (EventBrokerConstants.EB_RES_CREATED_TIME.equals(propertyName)) {
                    subscription.setCreatedTime(new Date(Long.parseLong(subscriptionResource.getProperty(EventBrokerConstants.EB_RES_CREATED_TIME))));
                } else if (EventBrokerConstants.EB_RES_MODE.equals(propertyName)) {
                    subscription.setMode(subscriptionResource.getProperty(EventBrokerConstants.EB_RES_MODE));
                } else {
                    subscription.addProperty(propertyName, subscriptionResource.getProperty(propertyName));
                }
            }
        }
        return subscription;
    }
View Full Code Here

            if (userRegistry.resourceExists(topicResourcePath)) {
                Collection subscriptions = (Collection) userRegistry.get(topicResourcePath);
                String[] subscriptionPaths = (String[]) subscriptions.getContent();
                for (String subscriptionPath : subscriptionPaths) {
                    Resource resource = userRegistry.get(subscriptionPath);
                    Subscription subscription = JavaUtil.getSubscription(resource);
                    subscriptionID = subscriptionPath.substring(subscriptionPath.lastIndexOf("/") + 1);
                    subscription.setId(subscriptionID);
                    subscription.setTopicName(topicName);

                    // check for expiration
                    Calendar current = Calendar.getInstance(); //Get current date and time
                    if (subscription.getExpires() != null) {
                        if (current.before(subscription.getExpires())) {
                            // add only valid subscriptions by checking the expiration
                            matchingSubscriptions.add(subscription);
                        }
                    } else {
                        // If a expiration dosen't exisits treat it as a never expire subscription, valid till unsubscribe
View Full Code Here

    public void testSOAP12EnvelopeToSubscription() throws Exception {
        MessageContext mc = CommandBuilderTestUtils.getMCWithSOAP12Envelope();
        RenewCommandBuilder builder = new RenewCommandBuilder(mc);

        Subscription subscription = builder.toSubscription(
                CommandBuilderTestUtils.payloadToSOAP12Envelope(REQUEST_PAYLOAD_SOAP12));

        assertNotNull("The subscription object is null", subscription);
        assertEquals("Invalid subscription id", "uuid:22e8a584-0d18-4228-b2a8-3716fa2097fa",
                subscription.getId());
        assertEquals("Invalid expiration time", 2034968820000L,
                subscription.getExpires().getTimeInMillis() +
                TimeZone.getTimeZone("GMT-08:00").getOffset(0));

        Exception expected = null;
        try {
            builder.toSubscription(
View Full Code Here

    public void testSOAP11EnvelopeToSubscription() throws Exception {
        MessageContext mc = CommandBuilderTestUtils.getMCWithSOAP11Envelope();
        RenewCommandBuilder builder = new RenewCommandBuilder(mc);

        Subscription subscription = builder.toSubscription(
                CommandBuilderTestUtils.payloadToSOAP11Envelope(REQUEST_PAYLOAD_SOAP11));

        assertNotNull("The subscription object is null", subscription);
        assertEquals("Invalid subscription id", "uuid:22e8a584-0d18-4228-b2a8-3716fa2097fa",
                subscription.getId());
        assertEquals("Invalid expiration time", 2034968820000L,
                subscription.getExpires().getTimeInMillis() +
                TimeZone.getTimeZone("GMT-08:00").getOffset(0));

        Exception expected = null;
        try {
            builder.toSubscription(
View Full Code Here

        assertTrue("Invalid exception generated for expired renew request",
                expected instanceof InvalidExpirationTimeException);
    }

    public void testSubscriptionToSOAP12Envelope() throws Exception {
        Subscription subscription = new Subscription();
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(12345678);
        subscription.setExpires(calendar);
        MessageContext mc = CommandBuilderTestUtils.getMCWithSOAP12Envelope();
        RenewCommandBuilder builder = new RenewCommandBuilder(mc);

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

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

    public void testSubscriptionToSOAP11Envelope() throws Exception {
        Subscription subscription = new Subscription();
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(12345678);
        subscription.setExpires(calendar);
        MessageContext mc = CommandBuilderTestUtils.getMCWithSOAP11Envelope();
        RenewCommandBuilder builder = new RenewCommandBuilder(mc);

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

    public void testSOAP12EnvelopeToSubscription() throws Exception {
        MessageContext mc = CommandBuilderTestUtils.getMCWithSOAP12Envelope();
        GetStatusCommandBuilder builder = new GetStatusCommandBuilder(mc);
       
        Subscription subscription = builder.toSubscription(
                CommandBuilderTestUtils.payloadToSOAP12Envelope(REQUEST_PAYLOAD_SOAP12));

        assertNotNull("The subscription object is null", subscription);
        assertEquals("Invalid subscription id", "uuid:22e8a584-0d18-4228-b2a8-3716fa2097fa",
                subscription.getId());
    }
View Full Code Here

            } else if (!hasPermissionToSubscribeViaEmail(userRegistry, path, endpoint)) {
                throw new SecurityException("User does not have enough priviledges to subscribe another user");
            } else if (Utils.getRegistryEventingService() == null) {
                throw new IllegalStateException("Registry Eventing Service Not Found");
            } else {
                Subscription subscription =
                        BuilderUtils.createSubscription(endpoint,
                                "http://wso2.org/registry/eventing/dialect/topicFilter",
                                RegistryEventingConstants.TOPIC_PREFIX + path +
                                        RegistryEvent.TOPIC_SEPARATOR + eventName);
                subscription.setEventDispatcherName(RegistryEventingConstants.TOPIC_PREFIX);
                int callerTenantId = userRegistry.getCallerTenantId();
                subscription.setTenantId(callerTenantId);
                String name = userRegistry.getUserName();
                if (callerTenantId != MultitenantConstants.SUPER_TENANT_ID &&
                        callerTenantId > -1) {
                    try {
                        SuperTenantCarbonContext.startTenantFlow();
                        SuperTenantCarbonContext currentContext =
                                SuperTenantCarbonContext.getCurrentContext();
                        currentContext.setTenantId(callerTenantId, true);
                        String tenantDomain = currentContext.getTenantDomain();
                        if (tenantDomain != null) {
                            name = name + "@" + tenantDomain;
                        }
                    } finally {
                        SuperTenantCarbonContext.endTenantFlow();
                    }
                }
                subscription.setOwner(name);
                Map<String, String> data = new HashMap<String, String>();
                if (doRest) {
                    data.put(RegistryEventingConstants.DO_REST, Boolean.toString(Boolean.TRUE));
                }
                subscription.setProperties(data);
                String subscriptionId;
                if (url == null || userName == null) {
                    subscriptionId =
                            Utils.getRegistryEventingService().subscribe(subscription);
                } else {
                    throw new UnsupportedOperationException("You cannot directly subscribe to a " +
                            "Remote Resource. Use the Registry Browser User Interface to add a " +
                            "Remote Subscription.");
                }
                if (subscriptionId == null) {
                    throw new IllegalStateException("Subscription Id invalid");
                }
                subscription.setId(subscriptionId);
                SubscriptionInstance subscriptionInstance = populate(path, subscription);
                if (subscriptionInstance != null) {
                    subscriptionInstance.setOwner(userRegistry.getUserName());
                    subscriptionInstances.add(subscriptionInstance);
                }
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.