Package org.wso2.event

Examples of org.wso2.event.Subscription


    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.getFilterDesc().getFilterDialect());
        assertEquals("Invalid filter value", "weather.storms",
                                subscription.getFilterDesc().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

        assertEquals("Invalid response for the get status request", RESPONSE_PAYLOAD_SOAP11,
                payload.toString());
    }

    public void testSubscriptionToSOAP12EnvelopeWithExpiry() 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);
        Calendar calendar = Calendar.getInstance();
        TimeZone tz = TimeZone.getTimeZone("GMT-08:00");
        calendar.setTimeZone(tz);
        calendar.setTimeInMillis(2034968820000L - TimeZone.getTimeZone("GMT-08:00").getOffset(0));
        subscription.setExpires(calendar);
        OMElement payload = builder.fromSubscription(subscription);

        assertEquals("Invalid response for the get status request", RESPONSE_PAYLOAD_SOAP12_WITH_EXPIRY,
                payload.toString());
    }
View Full Code Here

        assertEquals("Invalid response for the get status request", RESPONSE_PAYLOAD_SOAP12_WITH_EXPIRY,
                payload.toString());
    }

    public void testSubscriptionToSOAP11EnvelopeWithExpiry() 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);
        Calendar calendar = Calendar.getInstance();
        TimeZone tz = TimeZone.getTimeZone("GMT-08:00");
        calendar.setTimeZone(tz);
        calendar.setTimeInMillis(2034968820000L - TimeZone.getTimeZone("GMT-08:00").getOffset(0));
        subscription.setExpires(calendar);
        OMElement payload = builder.fromSubscription(subscription);

        assertEquals("Invalid response for the get status request", RESPONSE_PAYLOAD_SOAP11_WITH_EXPIRY,
                payload.toString());
    }
View Full Code Here

        assertEquals("Invalid response for the get status request", RESPONSE_PAYLOAD_SOAP11_WITH_EXPIRY,
                payload.toString());
    }

    public void testCarbonSubscriptionToSOAP12Envelope() throws Exception {
        Subscription subscription = new Subscription();
        subscription.setSubManUrl("http://www.example.org/oceanwatch/SubscriptionManager");
        String id = subscription.getId();
        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", expectPayload,
                payload.toString());
    }

    public void testCarbonSubscriptionToSOAP11Envelope() throws Exception {
        Subscription subscription = new Subscription();
        subscription.setSubManUrl("http://www.example.org/oceanwatch/SubscriptionManager");
        String id = subscription.getId();
        MessageContext mc = CommandBuilderTestUtils.getMCWithSOAP11Envelope();
        SubscribeCommandBuilder builder = new  SubscribeCommandBuilder(mc);

        OMElement payload = builder.fromSubscription(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.setDeliveryMode(WSE_DEFAULT_DELIVERY_MODE);
                        subscription.setEndpointUrl(ep);
                        subscription.setAddressUrl(notifyToElem.getFirstElement().getText().trim());
                    }
                } 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 dialectAttr = filterElem.getAttribute(ATT_DIALECT);
                if (dialectAttr != null && dialectAttr.getAttributeValue() != null) {
                  subscription.setFilterDesc(new EventFilterDesc(dialectAttr.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 = ConverterUtil.convertToDuration(expiryText)
                                .getAsCalendar();
                    } 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){
                if(subscription.getSubscriptionData() != null){
                    subscription.setSubscriptionData(new SubscriptionData());
                }
                subscription.getSubscriptionData().setProperty(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

        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());
            if (mc.getTo() != null) {
                subscription.setAddressUrl(mc.getTo().getAddress());
            }
        } catch (InvalidExpirationTimeException e) {
            if (log.isDebugEnabled()) {
                log.debug(e.getMessage());
            }
            SOAPEnvelope soapEnvelope = BuilderUtils.genFaultResponse(
                    CommandBuilderConstants.WSE_FAULT_CODE_RECEIVER, "InvalidExpirationTime",
                    e.getMessage(), "", mc.isSOAP11());
            dispatchResponse(soapEnvelope, CommandBuilderConstants.WSA_FAULT, mc, true);
        } catch (InvalidMessageException e) {
            if (log.isDebugEnabled()) {
                log.debug(e.getMessage());
            }
            SOAPEnvelope soapEnvelope = BuilderUtils.genFaultResponse(
                    CommandBuilderConstants.WSE_FAULT_CODE_RECEIVER, "InvalidMessage",
                    e.getMessage(), "", mc.isSOAP11());
            dispatchResponse(soapEnvelope, CommandBuilderConstants.WSA_FAULT, mc, true);
        }
       
        String topicName = subscription.getFilterDesc().getFilterValue();
        if(EventBrokerUtils.isSecureTopic(topicName)){
            UserRealm userRealm = AdminServicesUtil.getUserRealm();
            if(!userRealm.getAuthorizationManager().isUserAuthorized(EventBrokerUtils.getLoggedInUserName(),
                    Utils.getSecureTopicPermissionPath(topicName), "write")){
                throw new EventException("User is not authorized to subscribe to Secure topic "+ topicName);
            }
        }
       
       
        if (subscription != null && subscription.getId() != null) {
            if (log.isDebugEnabled()) {
                log.debug("Subscription request recieved  : " + subscription.getId());
            }
            String subID = getBrokerService().subscribe(subscription);
            if (subID != null) {
                if (log.isDebugEnabled()) {
                    log.debug("Sending subscription response for Subscription ID : " +
                            subscription.getId());
                }
                SOAPEnvelope soapEnvelope = builder.fromSubscription(subscription);
                dispatchResponse(soapEnvelope, CommandBuilderConstants.WSE_SUBSCRIBE_RESPONSE, mc, false);
            } else {
                log.debug("Subscription Failed, sending fault response");
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.