Package org.wso2.event

Examples of org.wso2.event.Subscription


    public void testSOAP11EnvelopeToSubscription() throws Exception {
        MessageContext mc = CommandBuilderTestUtils.getMCWithSOAP11Envelope();
        UnSubscribeCommandBuilder builder = new UnSubscribeCommandBuilder(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());
    }
View Full Code Here


        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);
        System.out.println("[TODO] The UnSubscribe Response is not compatible with the WS-Eventing " +
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);
        System.out.println("[TODO] The UnSubscribe Response is not compatible with the WS-Eventing " +
View Full Code Here

  }


    public boolean unsubscribe(String id) throws EventException {
        if (store.containsKey(id)) {
            Subscription subscription = store.remove(id);
           
            List<Subscription> tempList = topic2SubscriptionsMap.get(subscription.getFilterDesc().getFilterValue());
            tempList.remove(subscription);
            return true;
        } else {
            return false;
        }
View Full Code Here

        }
    }


    public boolean renew(Subscription subscription) throws EventException {
        Subscription subscriptionOld = getSubscription(subscription.getId());
        if (subscriptionOld != null) {
            subscriptionOld.setExpires(subscription.getExpires());
            return true;
        } else {
            return false;
        }
    }
View Full Code Here

  /**
     * {@inheritDoc}
     */
    public String subscribe(Subscription subscription) throws EventException {
        //Check whether there is already a subscription available for this topic + serverURL
        Subscription existingSubscription = getExistingSubscription(subscription);
        if(existingSubscription != null){
            //A subscription already exists. return that subscription id
            return existingSubscription.getId();
        }
       
        //No subscription available. so create a new subscription
        try {
            Resource resource = registry.newResource();
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public boolean renew(Subscription subscription) throws EventException {
        Subscription subscriptionOrig = getSubscription(subscription.getId());
        if (subscriptionOrig.getId() != null) {
            try {
                if (!registry.resourceExists(getTopicIndexPath())) {
                    log.warn("No subscription found by the given id: " + subscriptionOrig.getId());
                    return false;
                }
                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

                    }               
                   
                    Collection results = registry.executeQuery(null, map);
                    for(String path:results.getChildren()){
                       if(path.startsWith(subStorePath)){
                            Subscription sub = regStorageToSubscription(registry.get(path));
                            String id = path.substring(path.indexOf('/'));
                            sub.setId(id);
                            subscriptionList.add(sub);
                       }
                    }
                }else{
                    Properties property = resTopicIndex.getProperties();
                    if (property != null) {
                        if (!property.isEmpty()) {
                            for (Enumeration e = property.propertyNames() ; e.hasMoreElements() ;) {
                                String id = (String)e.nextElement();
                                if (RegistryUtils.isHiddenProperty(id)) {
                                    continue;
                                }
                                String topic = resTopicIndex.getProperty(id);
                                String subStorePath = getSubscriptionStoragePath();
                                if (subStorePath != null) {
                                    subStorePath = subStorePath + topic;
                                } else {
                                    subStorePath = topic;
                                }
                                String regPath = subStorePath + "/" + id;
                                if (registry.resourceExists(regPath)) {
                                    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 {
            if (!registry.resourceExists(getTopicIndexPath())) {
                log.warn("No subscription found by the given id: " + id);
                return sub;
            }
            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 (RegistryUtils.isHiddenProperty(propName)) {
                        continue;
                    }
                    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.getFilterDesc().setFilterValue(resource.getProperty(FILTER_VALUE));
                    } else if (propName.equals(FILTER_DIALECT)) {
                        subscription.getFilterDesc().setFilterDialect(resource.getProperty(FILTER_DIALECT));
                    } else if (propName.equals(PERSISTANT)) {
                        subscription.setPersistant(Boolean.valueOf(resource.getProperty(PERSISTANT)));      
                    } else if (propName.equals(OWNER)) {
                        subscription.setOwner(resource.getProperty(OWNER));       
                    } else if (propName.equals(FORMATTER)) {
                        subscription.setFormatter(resource.getProperty(FORMATTER));
                    } else if (propName.equals(CREATED_TIME)) {
                        subscription.setCreatedTime(new Date(Long.valueOf(resource.getProperty(CREATED_TIME))));
                    } else {
                        subscriptionData.setProperty(propName, resource.getProperty(propName));
                    }
                }
            }
        }
        subscription.setSubscriptionData(subscriptionData);
        return subscription;
    }
View Full Code Here

TOP

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