Search in sources :

Example 6 with OutputEventAdapterException

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

the class ExtendedHTTPEventAdapter method init.

@Override
public void init() throws OutputEventAdapterException {
    tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    // ExecutorService will be assigned  if it is null
    if (executorService == null) {
        int minThread;
        int maxThread;
        long defaultKeepAliveTime;
        int jobQueSize;
        // If global properties are available those will be assigned else constant values will be assigned
        if (globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME) != null) {
            minThread = Integer.parseInt(globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME));
        } else {
            minThread = ExtendedHTTPEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE;
        }
        if (globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME) != null) {
            maxThread = Integer.parseInt(globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME));
        } else {
            maxThread = ExtendedHTTPEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE;
        }
        if (globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME) != null) {
            defaultKeepAliveTime = Integer.parseInt(globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME));
        } else {
            defaultKeepAliveTime = ExtendedHTTPEventAdapterConstants.DEFAULT_KEEP_ALIVE_TIME_IN_MILLIS;
        }
        if (globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME) != null) {
            jobQueSize = Integer.parseInt(globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME));
        } else {
            jobQueSize = ExtendedHTTPEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE;
        }
        executorService = new ThreadPoolExecutor(minThread, maxThread, defaultKeepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(jobQueSize));
        // configurations for the httpConnectionManager which will be shared by every http adapter
        int defaultMaxConnectionsPerHost;
        int maxTotalConnections;
        if (globalProperties.get(ExtendedHTTPEventAdapterConstants.DEFAULT_MAX_CONNECTIONS_PER_HOST) != null) {
            defaultMaxConnectionsPerHost = Integer.parseInt(globalProperties.get(ExtendedHTTPEventAdapterConstants.DEFAULT_MAX_CONNECTIONS_PER_HOST));
        } else {
            defaultMaxConnectionsPerHost = ExtendedHTTPEventAdapterConstants.DEFAULT_DEFAULT_MAX_CONNECTIONS_PER_HOST;
        }
        if (globalProperties.get(ExtendedHTTPEventAdapterConstants.MAX_TOTAL_CONNECTIONS) != null) {
            maxTotalConnections = Integer.parseInt(globalProperties.get(ExtendedHTTPEventAdapterConstants.MAX_TOTAL_CONNECTIONS));
        } else {
            maxTotalConnections = ExtendedHTTPEventAdapterConstants.DEFAULT_MAX_TOTAL_CONNECTIONS;
        }
        connectionManager = new MultiThreadedHttpConnectionManager();
        connectionManager.getParams().setDefaultMaxConnectionsPerHost(defaultMaxConnectionsPerHost);
        connectionManager.getParams().setMaxTotalConnections(maxTotalConnections);
        Map<String, String> staticProperties = eventAdapterConfiguration.getStaticProperties();
        if (staticProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_OAUTH_CONSUMER_KEY) != null) {
            accessTokenGenerator = new AccessTokenGenerator(staticProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_OAUTH_URL), staticProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_OAUTH_CONSUMER_KEY), staticProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_OAUTH_CONSUMER_SECRET));
            this.oauthURL = staticProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_OAUTH_URL);
        }
    }
}
Also used : AccessTokenGenerator(org.wso2.carbon.apimgt.impl.recommendationmgt.AccessTokenGenerator) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 7 with OutputEventAdapterException

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

the class ExtendedHTTPEventAdaptorTestCase method testHttpPublisherConnect2.

@Test
public void testHttpPublisherConnect2() throws OutputEventAdapterException {
    logger.info("Test case for connection of Extended HTTP output adaptor.");
    setupCarbonConfig();
    PrivilegedCarbonContext privilegedCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    privilegedCarbonContext.setTenantId(-1234);
    OutputEventAdapterConfiguration eventAdapterConfiguration = new OutputEventAdapterConfiguration();
    eventAdapterConfiguration.setName("TestHttpAdaptor");
    eventAdapterConfiguration.setType("http-extended");
    eventAdapterConfiguration.setMessageFormat("text");
    Map<String, String> staticPropertes = new HashMap<>();
    staticPropertes.put("http.client.method", "HttpPost");
    staticPropertes.put("http.proxy.port", null);
    staticPropertes.put("http.proxy.host", null);
    staticPropertes.put("oauth.url", null);
    staticPropertes.put("oauth.consumer.key", null);
    staticPropertes.put("oauth.consumer.secret", null);
    eventAdapterConfiguration.setStaticProperties(staticPropertes);
    Map<String, String> globalProperties = new HashMap<>();
    globalProperties.put("jobQueueSize", "10000");
    globalProperties.put("keepAliveTimeInMillis", "20000");
    globalProperties.put("maxThread", "100");
    globalProperties.put("minThread", "8");
    globalProperties.put("defaultMaxConnectionsPerHost", "50");
    globalProperties.put("maxTotalConnections", "1000");
    ExtendedHTTPEventAdapter httpEventAdapter = new ExtendedHTTPEventAdapter(eventAdapterConfiguration, globalProperties);
    httpEventAdapter.init();
    httpEventAdapter.connect();
    httpEventAdapter.disconnect();
    httpEventAdapter.destroy();
}
Also used : HashMap(java.util.HashMap) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) OutputEventAdapterConfiguration(org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration) Test(org.junit.Test)

Example 8 with OutputEventAdapterException

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

the class NewAPIVersionEmailNotifier method sendNotifications.

@Override
public void sendNotifications(NotificationDTO notificationDTO) throws NotificationException {
    APIIdentifier api = (APIIdentifier) notificationDTO.getProperties().get(NotifierConstants.API_KEY);
    Set<Subscriber> subscriberList = (Set<Subscriber>) notificationDTO.getProperty(NotifierConstants.SUBSCRIBERS_PER_API);
    Map<String, String> emailProperties = null;
    // Notifications are sent only if there are subscribers
    if (subscriberList.size() > 0) {
        Set<String> notifierSet = getNotifierSet(notificationDTO);
        notificationDTO.setNotifierSet(notifierSet);
        notificationDTO = loadMessageTemplate(notificationDTO);
        emailProperties = getEmailProperties(notificationDTO);
        if (emailProperties != null) {
            String tenantDomain = getTenantDomain();
            String adapterName = NotifierConstants.ADAPTER_NAME + tenantDomain;
            String message = notificationDTO.getMessage();
            try {
                synchronized (Notifier.class) {
                    if (!adapterList.contains(adapterName)) {
                        OutputEventAdapterConfiguration outputEventAdapterConfiguration = createOutputEventAdapterConfiguration(adapterName, NotifierConstants.EMAIL_ADAPTER_TYPE);
                        createOutputEventAdapterService(outputEventAdapterConfiguration);
                        getOutputEventAdapterTypes();
                        adapterList.add(adapterName);
                    }
                }
                publishNotification(emailProperties, adapterName, message);
                log.info("notification sent to Email Adapter ");
            } catch (OutputEventAdapterException e) {
                throw new NotificationException("Adapter Creation Failed ", e);
            }
        } else {
            log.info("Empty email list. Please set subscriber's email addresses");
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("No exiting Subscribers to send notifications for " + api.getApiName() + api.getVersion());
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) OutputEventAdapterException(org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) NotificationException(org.wso2.carbon.apimgt.impl.notification.exception.NotificationException) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) 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