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);
}
}
}
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();
}
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());
}
}
}
Aggregations