Search in sources :

Example 1 with OutputEventAdapterException

use of org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException in project carbon-business-process by wso2.

the class NotificationScheduler method publishEmailNotifications.

/**
 * Publish Email notifications by extracting the information from the incoming message rendering tags
 * <htd:renderings>
 *  <htd:rendering type="wso2:email" xmlns:wso2="http://wso2.org/ht/schema/renderings/">
 *     <wso2:to name="to" type="xsd:string">wso2bpsemail@wso2.com</wso2:to>
 *     <wso2:subject name="subject" type="xsd:string">email subject to user</wso2:subject>
 *     <wso2:body name="body" type="xsd:string">Hi email notifications</wso2:body>
 *  </htd:rendering>
 *  <htd:rendering type="wso2:sms" xmlns:wso2="http://wso2.org/ht/schema/renderings/">
 *      <wso2:receiver name="receiver" type="xsd:string">94777459299</wso2:receiver>
 *      <wso2:body name="body" type="xsd:string">Hi $firstname$</wso2:body>
 *  </htd:rendering>
 *</htd:renderings>
 *
 * @param  task TaskDAO object for this notification task instance
 * @param taskConfiguration task configuration instance for this notification task definition
 */
public void publishEmailNotifications(TaskDAO task, HumanTaskBaseConfiguration taskConfiguration) throws IOException, SAXException, ParserConfigurationException {
    String rendering = CommonTaskUtil.getRendering(task, taskConfiguration, new QName(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.RENDERING_TYPE_EMAIL));
    if (rendering != null) {
        Map<String, String> dynamicPropertiesForEmail = new HashMap<String, String>();
        Element root = DOMUtils.stringToDOM(rendering);
        if (root != null) {
            String emailBody = null;
            String mailSubject = null;
            String mailTo = null;
            String contentType = null;
            NodeList mailToList = root.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.EMAIL_TO_TAG);
            if (log.isDebugEnabled()) {
                log.debug("Parsing Email notification rendering element to for notification id " + task.getId());
            }
            if (mailToList != null && mailToList.getLength() > 0) {
                mailTo = mailToList.item(0).getTextContent();
            } else {
                log.warn("Email to address not specified for email notification with notification id " + task.getId());
            }
            NodeList mailSubjectList = root.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.EMAIL_SUBJECT_TAG);
            if (log.isDebugEnabled()) {
                log.debug("Paring Email notification rendering element subject " + task.getId());
            }
            if (mailSubjectList != null && mailSubjectList.getLength() > 0) {
                mailSubject = mailSubjectList.item(0).getTextContent();
            } else {
                log.warn("Email subject not specified for email notification with notification id " + task.getId());
            }
            NodeList mailContentType = root.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.EMAIL_CONTENT_TYPE_TAG);
            if (log.isDebugEnabled()) {
                log.debug("Paring Email notification rendering element contentType " + task.getId());
            }
            if (mailContentType != null && mailContentType.getLength() > 0) {
                contentType = mailContentType.item(0).getTextContent();
            } else {
                contentType = HumanTaskConstants.CONTENT_TYPE_TEXT_PLAIN;
                log.warn("Email contentType not specified for email notification with notification id " + task.getId() + ". Using text/plain.");
            }
            if (log.isDebugEnabled()) {
                log.debug("Parsing Email notification rendering element body tag for notification id " + task.getId());
            }
            NodeList emailBodyList = root.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.EMAIL_OR_SMS_BODY_TAG);
            if (emailBodyList != null && emailBodyList.getLength() > 0) {
                emailBody = emailBodyList.item(0).getTextContent();
            } else {
                log.warn("Email notification message body not specified for notification with id " + task.getId());
            }
            dynamicPropertiesForEmail.put(HumanTaskConstants.ARRAY_EMAIL_ADDRESS, mailTo);
            dynamicPropertiesForEmail.put(HumanTaskConstants.ARRAY_EMAIL_SUBJECT, mailSubject);
            dynamicPropertiesForEmail.put(HumanTaskConstants.ARRAY_EMAIL_TYPE, contentType);
            String adaptorName = getAdaptorName(task.getName(), HumanTaskConstants.RENDERING_TYPE_EMAIL);
            if (!emailAdapterNames.contains(adaptorName)) {
                OutputEventAdapterConfiguration outputEventAdapterConfiguration = createOutputEventAdapterConfiguration(adaptorName, HumanTaskConstants.RENDERING_TYPE_EMAIL, HumanTaskConstants.EMAIL_MESSAGE_FORMAT);
                try {
                    HumanTaskServiceComponent.getOutputEventAdapterService().create(outputEventAdapterConfiguration);
                    emailAdapterNames.add(adaptorName);
                } catch (OutputEventAdapterException e) {
                    log.error("Unable to create Output Event Adapter : " + adaptorName, e);
                }
            }
            HumanTaskServiceComponent.getOutputEventAdapterService().publish(adaptorName, dynamicPropertiesForEmail, emailBody);
        // emailAdapter.publish(emailBody, dynamicPropertiesForEmail);
        }
    } else {
        log.warn("Email Rendering type not found for task definition with task id " + task.getId());
    }
}
Also used : OutputEventAdapterException(org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) OutputEventAdapterConfiguration(org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration)

Example 2 with OutputEventAdapterException

use of org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException in project carbon-business-process by wso2.

the class NotificationScheduler method publishSMSNotifications.

/**
 * Publish SMS notifications by extracting the information from the incoming message rendering tags
 * <htd:renderings>
 *  <htd:rendering type="wso2:email" xmlns:wso2="http://wso2.org/ht/schema/renderings/">
 *     <wso2:to name="to" type="xsd:string">wso2bpsemail@wso2.com</wso2:to>
 *     <wso2:subject name="subject" type="xsd:string">email subject to user</wso2:subject>
 *     <wso2:body name="body" type="xsd:string">Hi email notifications</wso2:body>
 *  </htd:rendering>
 *  <htd:rendering type="wso2:sms" xmlns:wso2="http://wso2.org/ht/schema/renderings/">
 *      <wso2:receiver name="receiver" type="xsd:string">94777459299</wso2:receiver>
 *      <wso2:body name="body" type="xsd:string">Hi $firstname$</wso2:body>
 *  </htd:rendering>
 * </htd:renderings>
 * @param task Task Dao Object for this notification task
 * @param taskConfiguration task Configuration for this notification task instance
 */
public void publishSMSNotifications(TaskDAO task, HumanTaskBaseConfiguration taskConfiguration) throws IOException, SAXException, ParserConfigurationException {
    String renderingSMS = CommonTaskUtil.getRendering(task, taskConfiguration, new QName(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.RENDERING_TYPE_SMS));
    if (renderingSMS != null) {
        Map<String, String> dynamicPropertiesForSms = new HashMap<String, String>();
        Element rootSMS = DOMUtils.stringToDOM(renderingSMS);
        if (rootSMS != null) {
            String smsReceiver = null;
            String smsBody = null;
            if (log.isDebugEnabled()) {
                log.debug("Parsing SMS notification rendering element 'receiver' for notification id " + task.getId());
            }
            NodeList smsReceiverList = rootSMS.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.SMS_RECEIVER_TAG);
            if (smsReceiverList != null && smsReceiverList.getLength() > 0) {
                smsReceiver = smsReceiverList.item(0).getTextContent();
            } else {
                log.warn("SMS notification rendering element 'receiver' not specified for notification with id " + task.getId());
            }
            NodeList smsBodyList = rootSMS.getElementsByTagNameNS(HumanTaskConstants.RENDERING_NAMESPACE, HumanTaskConstants.EMAIL_OR_SMS_BODY_TAG);
            if (log.isDebugEnabled()) {
                log.debug("Parsing SMS notification rendering element 'body' for notification id " + task.getId());
            }
            if (smsBodyList != null && smsBodyList.getLength() > 0) {
                smsBody = smsBodyList.item(0).getTextContent();
            } else {
                log.warn("SMS notification rendering element 'body' not specified for notification with id " + task.getId());
            }
            dynamicPropertiesForSms.put(HumanTaskConstants.ARRAY_SMS_NO, smsReceiver);
            String adaptorName = getAdaptorName(task.getName(), HumanTaskConstants.RENDERING_TYPE_SMS);
            if (!smsAdapterNames.contains(adaptorName)) {
                OutputEventAdapterConfiguration outputEventAdapterConfiguration = createOutputEventAdapterConfiguration(adaptorName, HumanTaskConstants.RENDERING_TYPE_SMS, HumanTaskConstants.SMS_MESSAGE_FORMAT);
                try {
                    HumanTaskServiceComponent.getOutputEventAdapterService().create(outputEventAdapterConfiguration);
                    smsAdapterNames.add(adaptorName);
                } catch (OutputEventAdapterException e) {
                    log.error("Unable to create Output Event Adapter : " + adaptorName, e);
                }
            }
            HumanTaskServiceComponent.getOutputEventAdapterService().publish(adaptorName, dynamicPropertiesForSms, smsBody);
        // smsAdapter.publish(smsBody, dynamicPropertiesForSms);
        }
    } else {
        log.warn("SMS Rendering type not found for task definition with task id " + task.getId());
    }
}
Also used : OutputEventAdapterException(org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) OutputEventAdapterConfiguration(org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration)

Example 3 with OutputEventAdapterException

use of org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException in project carbon-apimgt by wso2.

the class APIManagerComponent method configureRecommendationEventPublisherProperties.

private void configureRecommendationEventPublisherProperties() {
    OutputEventAdapterConfiguration adapterConfiguration = new OutputEventAdapterConfiguration();
    adapterConfiguration.setName(APIConstants.RECOMMENDATIONS_WSO2_EVENT_PUBLISHER);
    adapterConfiguration.setType(APIConstants.BLOCKING_EVENT_TYPE);
    adapterConfiguration.setMessageFormat(APIConstants.BLOCKING_EVENT_FORMAT);
    Map<String, String> adapterParameters = new HashMap<>();
    if (ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService() != null) {
        APIManagerConfiguration configuration = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
        if (configuration.getApiRecommendationEnvironment() != null) {
            try {
                String receiverPort = System.getProperty(configuration.RECEIVER_URL_PORT);
                String authPort = System.getProperty(configuration.AUTH_URL_PORT);
                adapterParameters.put(APIConstants.RECEIVER_URL, "tcp://localhost:" + receiverPort);
                adapterParameters.put(APIConstants.AUTHENTICATOR_URL, "ssl://localhost:" + authPort);
                adapterParameters.put(APIConstants.USERNAME, APIUtil.getAdminUsername());
                adapterParameters.put(APIConstants.PASSWORD, APIUtil.getAdminPassword());
                adapterParameters.put(APIConstants.PROTOCOL, "Binary");
                adapterParameters.put(APIConstants.PUBLISHING_MODE, APIConstants.NON_BLOCKING);
                adapterParameters.put(APIConstants.PUBLISHING_TIME_OUT, "0");
                adapterConfiguration.setStaticProperties(adapterParameters);
                ServiceReferenceHolder.getInstance().getOutputEventAdapterService().create(adapterConfiguration);
                log.info("API Recommendation system for dev portal is activated");
            } catch (OutputEventAdapterException e) {
                log.error("Exception occurred while creating recommendationEventPublisher Adapter." + " Request Blocking may not work properly", e);
            } catch (APIMgtInternalException e) {
                log.error("Exception occurred while reading the admin username and password", e);
            }
        }
    }
}
Also used : APIMgtInternalException(org.wso2.carbon.apimgt.api.APIMgtInternalException) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) OutputEventAdapterException(org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException) HashMap(java.util.HashMap) OutputEventAdapterConfiguration(org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration)

Example 4 with OutputEventAdapterException

use of org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException in project carbon-apimgt by wso2.

the class APIManagerComponent method configureEventPublisherProperties.

private void configureEventPublisherProperties() {
    OutputEventAdapterConfiguration adapterConfiguration = new OutputEventAdapterConfiguration();
    adapterConfiguration.setName(APIConstants.BLOCKING_EVENT_PUBLISHER);
    adapterConfiguration.setType(APIConstants.BLOCKING_EVENT_TYPE);
    adapterConfiguration.setMessageFormat(APIConstants.BLOCKING_EVENT_FORMAT);
    Map<String, String> adapterParameters = new HashMap<>();
    if (ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService() != null) {
        APIManagerConfiguration configuration = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
        if (configuration.getThrottleProperties().getTrafficManager() != null && configuration.getThrottleProperties().getPolicyDeployer().isEnabled()) {
            ThrottleProperties.TrafficManager trafficManager = configuration.getThrottleProperties().getTrafficManager();
            adapterParameters.put(APIConstants.RECEIVER_URL, trafficManager.getReceiverUrlGroup());
            adapterParameters.put(APIConstants.AUTHENTICATOR_URL, trafficManager.getAuthUrlGroup());
            adapterParameters.put(APIConstants.USERNAME, trafficManager.getUsername());
            adapterParameters.put(APIConstants.PASSWORD, trafficManager.getPassword());
            adapterParameters.put(APIConstants.PROTOCOL, trafficManager.getType());
            adapterParameters.put(APIConstants.PUBLISHING_MODE, APIConstants.NON_BLOCKING);
            adapterParameters.put(APIConstants.PUBLISHING_TIME_OUT, "0");
            adapterConfiguration.setStaticProperties(adapterParameters);
            try {
                ServiceReferenceHolder.getInstance().getOutputEventAdapterService().create(adapterConfiguration);
            } catch (OutputEventAdapterException e) {
                log.warn("Exception occurred while creating WSO2 Event Adapter. Request Blocking may not work " + "properly", e);
            }
        } else {
            log.info("Wso2Event Publisher not enabled.");
        }
    } else {
        log.info("api-manager.xml not loaded. Wso2Event Publisher will not be enabled.");
    }
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) OutputEventAdapterException(org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException) HashMap(java.util.HashMap) OutputEventAdapterConfiguration(org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties)

Example 5 with OutputEventAdapterException

use of org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException in project carbon-apimgt by wso2.

the class EventHubEventPublisherFactory method configure.

@Override
public void configure(Map<String, String> properties) {
    OutputEventAdapterConfiguration adapterConfiguration = new OutputEventAdapterConfiguration();
    adapterConfiguration.setName(EventHubEventPublisherConstants.EVENT_HUB_NOTIFICATION_EVENT_PUBLISHER);
    adapterConfiguration.setType(EventHubEventPublisherConstants.BLOCKING_EVENT_TYPE);
    adapterConfiguration.setMessageFormat(EventHubEventPublisherConstants.BLOCKING_EVENT_FORMAT);
    adapterConfiguration.setStaticProperties(properties);
    try {
        ServiceReferenceHolder.getInstance().getOutputEventAdapterService().create(adapterConfiguration);
    } catch (OutputEventAdapterException e) {
        log.warn("Exception occurred while creating WSO2 Event Adapter. Event notification may not work " + "properly", e);
    }
}
Also used : OutputEventAdapterException(org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException) OutputEventAdapterConfiguration(org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration)

Aggregations

OutputEventAdapterConfiguration (org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration)7 OutputEventAdapterException (org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException)6 HashMap (java.util.HashMap)5 QName (javax.xml.namespace.QName)2 Element (org.w3c.dom.Element)2 NodeList (org.w3c.dom.NodeList)2 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 MultiThreadedHttpConnectionManager (org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)1 Test (org.junit.Test)1 APIMgtInternalException (org.wso2.carbon.apimgt.api.APIMgtInternalException)1 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)1 Subscriber (org.wso2.carbon.apimgt.api.model.Subscriber)1 ThrottleProperties (org.wso2.carbon.apimgt.impl.dto.ThrottleProperties)1 NotificationException (org.wso2.carbon.apimgt.impl.notification.exception.NotificationException)1 AccessTokenGenerator (org.wso2.carbon.apimgt.impl.recommendationmgt.AccessTokenGenerator)1 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)1