Package org.wso2.eventing

Examples of org.wso2.eventing.Subscription


        }
    }

    public static Subscription createSubscription(String endpoint, String filterDialect,
                                                  String topic) throws InvalidMessageException {
        Subscription subscription = new CarbonSubscription();
        subscription.setDeliveryMode(CommandBuilderConstants.WSE_DEFAULT_DELIVERY_MODE);
        if (endpoint == null) {
            throw new InvalidMessageException("Endpoint not found in the subscription request");
        }
        subscription.setEndpointUrl(endpoint.trim());
        subscription.setAddressUrl(endpoint);
        if (topic == null) {
            throw new InvalidMessageException("Error in creating subscription. Topic not defined");
        }
        subscription.setFilterDialect(filterDialect);
        subscription.setFilterValue(topic);
        return subscription;
    }
View Full Code Here


    /**
     * {@inheritDoc}
     */
    public boolean renew(Subscription subscription) throws EventException {
        Subscription subscriptionOrig = getSubscription(subscription.getId());
        if (subscriptionOrig.getId() != null) {
            try {
                resTopicIndex = registry.get(getTopicIndexPath());
                String topic = resTopicIndex.getProperty(subscription.getId());
                String subStorePath = getSubscriptionStoragePath();
                if (subStorePath != null) {
                    subStorePath = subStorePath + topic;
                } else {
                    subStorePath = topic;
                }
                String regPath = subStorePath + "/" + subscription.getId();
                Resource resource = registry.get(regPath);
                subscriptionOrig.setExpires(subscription.getExpires());
                // set the new content
                OMElement subElem = subscriptionToRegStorage(subscriptionOrig, resource, false);
                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                subElem.serialize(outStream);
                resource.setContent(outStream.toByteArray());
View Full Code Here

                                subStorePath = topic;
                            }
                            String regPath = subStorePath + "/" + id;
                            Resource resource = registry.get(regPath);
                            if (resource != null) {
                                Subscription sub;
                                if (EPR_TYPE.equals(resource.getMediaType())) {
                                    sub = regStorageToSubscription(resource);
                                    sub.setId(id);
                                    subscriptionList.add(sub);
                                }
                            }
                        }
                    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public Subscription getSubscription(String id) throws EventException {
        Subscription sub = null;
        try {
            resTopicIndex = registry.get(getTopicIndexPath());
            String topic = resTopicIndex.getProperty(id);
            String subStorePath = getSubscriptionStoragePath();
            if (subStorePath != null) {
                subStorePath = subStorePath + topic;
            } else {
                subStorePath = topic;
            }
            Resource resource = registry.get(subStorePath + "/" + id);
            if (resource != null) {
                if (EPR_TYPE.equals(resource.getMediaType())) {
                    sub = regStorageToSubscription(resource);
                    sub.setId(id);
                }
            }
        } catch (RegistryException e) {
            log.error("Error reading subscription" + e.toString());
        } catch (XMLStreamException e) {
View Full Code Here

     * @param resource
     * @return
     */
    private Subscription regStorageToSubscription(Resource resource)
            throws RegistryException, XMLStreamException {
        Subscription subscription = new Subscription();
        SubscriptionData subscriptionData = new SubscriptionData();
        String eprContent = new String((byte[]) resource.getContent());
        OMElement payload = AXIOMUtil.stringToOM(eprContent);
        if (payload.getFirstElement() != null) {
            OMElement element = payload.getFirstElement();
            try {
                if (element.getFirstElement() == null) {
                    handleException("EPR creation failure");
                }
                String url = element.getFirstElement().getAttributeValue(new QName(URI));
                subscription.setEndpointUrl(url);
                subscription.setAddressUrl(url);
            } catch (Exception e) {
                handleException("EPR creation failure", e);
            }
        }
        Properties property = resource.getProperties();
        if (property != null) {
            if (!property.isEmpty()) {
                for (Enumeration e = property.propertyNames() ; e.hasMoreElements() ;) {
                    String propName = (String)e.nextElement();
                    if (propName.equals(EXPIRES)) {
                        if (resource.getProperty(EXPIRES).equals("*")) {
                            subscription.setExpires(null); // never expire subscription
                        } else {
                            subscription.setExpires(ConverterUtil.convertToDateTime(
                                    resource.getProperty(EXPIRES)));
                        }
                    } else if (propName.equals(SUB_MANAGER_URI)) {
                        subscription
                                .setSubManUrl(resource.getProperty(SUB_MANAGER_URI));
                    } else if (propName.equals(FILTER_VALUE)) {
                        subscription.setFilterValue(resource.getProperty(FILTER_VALUE));
                    } else if (propName.equals(FILTER_DIALECT)) {
                        subscription.setFilterDialect(resource.getProperty(FILTER_DIALECT));
                    } else {
                        subscriptionData.setProperty(propName, resource.getProperty(propName));
                    }
                }
            }
        }
        subscription.setSubscriptionData(subscriptionData);
        return subscription;
    }
View Full Code Here

                    Collection subs = (Collection) registry.get(subscriptionsCollection);
                    String[] subsPaths = (String[]) subs.getContent();
                    for (String subsPath : subsPaths) {
                        Resource resource = registry.get(subsPath);
                        String id = resource.getId();
                        Subscription sub = new Subscription();
                        if (EPR_TYPE.equals(resource.getMediaType())) {
                            sub = regStorageToSubscription(resource);
                        }
                        // check for expiration
                        Calendar current =
                                Calendar.getInstance(); //Get current date and time
                        if (sub.getExpires() != null) {
                            if (current.before(sub.getExpires())) {
                                // add only valid subscriptions by checking the expiration
                                subscriptions.add(sub);
                            }
                        } 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();
        SubscribeCommandBuilder builder = new SubscribeCommandBuilder(mc);

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

        assertNotNull("The subscription object is null", subscription);
        assertNotNull("The subscription id is null", subscription.getId());
        assertEquals("Invalid expiration time", 2034968820000L,
                subscription.getExpires().getTimeInMillis() +
                        TimeZone.getTimeZone("GMT-08:00").getOffset(0));
        assertEquals("Invalid time zone offset", TimeZone.getDefault().getOffset(0),
                subscription.getExpires().getTimeZone().getOffset(0));
        assertEquals("Invalid endpoint url", "http://www.other.example.com/OnStormWarning",
                        subscription.getEndpointUrl());
        assertEquals("Invalid address url", "http://www.other.example.com/OnStormWarning",
                        subscription.getAddressUrl());
        assertEquals("Invalid filter dialect", "http://www.example.org/topicFilter",
                        subscription.getFilterDialect());
        assertEquals("Invalid filter value", "weather.storms",
                                subscription.getFilterValue());

        Exception expected = null;
        try {
            builder.toSubscription(
                    CommandBuilderTestUtils.payloadToSOAP12Envelope(REQUEST_PAYLOAD_SOAP12_EXPIRED));
View Full Code Here

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

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

        assertNotNull("The subscription object is null", subscription);
        assertNotNull("The subscription id is null", subscription.getId());
        assertEquals("Invalid expiration time", 2034968820000L,
                subscription.getExpires().getTimeInMillis() +
                        TimeZone.getTimeZone("GMT-08:00").getOffset(0));
        assertEquals("Invalid time zone offset", TimeZone.getDefault().getOffset(0),
                subscription.getExpires().getTimeZone().getOffset(0));
        assertEquals("Invalid endpoint url", "http://www.other.example.com/OnStormWarning",
                        subscription.getEndpointUrl());
        assertEquals("Invalid address url", "http://www.other.example.com/OnStormWarning",
                        subscription.getAddressUrl());
        assertEquals("Invalid filter dialect", "http://www.example.org/topicFilter",
                        subscription.getFilterDialect());
        assertEquals("Invalid filter value", "weather.storms",
                                subscription.getFilterValue());

        Exception expected = null;
        try {
            builder.toSubscription(
                    CommandBuilderTestUtils.payloadToSOAP11Envelope(REQUEST_PAYLOAD_SOAP11_EXPIRED));
View Full Code Here

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

    public void testSubscriptionToSOAP12Envelope() throws Exception {
        Subscription subscription = new Subscription();
        subscription.setSubManUrl("http://www.example.org/oceanwatch/SubscriptionManager");
        subscription.setId("uuid:22e8a584-0d18-4228-b2a8-3716fa2097fa");
        MessageContext mc = CommandBuilderTestUtils.getMCWithSOAP12Envelope();
        SubscribeCommandBuilder builder = new  SubscribeCommandBuilder(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();
        subscription.setSubManUrl("http://www.example.org/oceanwatch/SubscriptionManager");
        subscription.setId("uuid:22e8a584-0d18-4228-b2a8-3716fa2097fa");
        MessageContext mc = CommandBuilderTestUtils.getMCWithSOAP11Envelope();
        SubscribeCommandBuilder builder = new  SubscribeCommandBuilder(mc);

        OMElement payload = builder.fromSubscription(subscription);
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.