diff --git a/components/event-publisher/event-output-adapters/org.wso2.carbon.event.output.adapter.http/src/main/java/org/wso2/carbon/event/output/adapter/http/HTTPEventAdapter.java b/components/event-publisher/event-output-adapters/org.wso2.carbon.event.output.adapter.http/src/main/java/org/wso2/carbon/event/output/adapter/http/HTTPEventAdapter.java index d900d4fb6b..fed756c596 100644 --- a/components/event-publisher/event-output-adapters/org.wso2.carbon.event.output.adapter.http/src/main/java/org/wso2/carbon/event/output/adapter/http/HTTPEventAdapter.java +++ b/components/event-publisher/event-output-adapters/org.wso2.carbon.event.output.adapter.http/src/main/java/org/wso2/carbon/event/output/adapter/http/HTTPEventAdapter.java @@ -299,12 +299,14 @@ public HttpClient getHttpClient() { public void run() { UUID uuid = UUID.randomUUID(); - EntityEnclosingMethod method = null; + HttpMethodBase method = null; try { if (clientMethod.equalsIgnoreCase(HTTPEventAdapterConstants.CONSTANT_HTTP_PUT)) { method = new PutMethod(this.getUrl()); + } else if (clientMethod.equalsIgnoreCase(HTTPEventAdapterConstants.CONSTANT_HTTP_GET)) { + method = new GetMethod(this.getUrl()); } else { method = new PostMethod(this.getUrl()); } @@ -318,8 +320,9 @@ public void run() { } } - method.setRequestEntity(new StringRequestEntity(this.getPayload(), contentType, "UTF-8")); - + if (method instanceof EntityEnclosingMethod) { + ((EntityEnclosingMethod) method).setRequestEntity(new StringRequestEntity(this.getPayload(), contentType, "UTF-8")); + } if (this.getUsername() != null && this.getUsername().trim().length() > 0) { method.setRequestHeader("Authorization", "Basic " + Base64 .encode((this.getUsername() + HTTPEventAdapterConstants.ENTRY_SEPARATOR + this @@ -359,4 +362,4 @@ public void run() { } } -} \ No newline at end of file +} diff --git a/components/event-publisher/event-output-adapters/org.wso2.carbon.event.output.adapter.http/src/main/java/org/wso2/carbon/event/output/adapter/http/internal/util/HTTPEventAdapterConstants.java b/components/event-publisher/event-output-adapters/org.wso2.carbon.event.output.adapter.http/src/main/java/org/wso2/carbon/event/output/adapter/http/internal/util/HTTPEventAdapterConstants.java index bd679775dd..2498b32cc9 100644 --- a/components/event-publisher/event-output-adapters/org.wso2.carbon.event.output.adapter.http/src/main/java/org/wso2/carbon/event/output/adapter/http/internal/util/HTTPEventAdapterConstants.java +++ b/components/event-publisher/event-output-adapters/org.wso2.carbon.event.output.adapter.http/src/main/java/org/wso2/carbon/event/output/adapter/http/internal/util/HTTPEventAdapterConstants.java @@ -45,6 +45,7 @@ public class HTTPEventAdapterConstants { public static final String ADAPTER_HTTP_CLIENT_METHOD = "http.client.method"; public static final String CONSTANT_HTTP_POST = "HttpPost"; public static final String CONSTANT_HTTP_PUT = "HttpPut"; + public static final String CONSTANT_HTTP_GET = "HttpGet"; public static final String ENABLE_FORM_URL_ENCODED = "enableFormUrlEncoded"; //configurations for the httpConnectionManager diff --git a/components/event-publisher/org.wso2.carbon.event.publisher.core/src/main/java/org/wso2/carbon/event/publisher/core/config/EventPublisherConstants.java b/components/event-publisher/org.wso2.carbon.event.publisher.core/src/main/java/org/wso2/carbon/event/publisher/core/config/EventPublisherConstants.java index dd2e9a0abb..6cb541239d 100644 --- a/components/event-publisher/org.wso2.carbon.event.publisher.core/src/main/java/org/wso2/carbon/event/publisher/core/config/EventPublisherConstants.java +++ b/components/event-publisher/org.wso2.carbon.event.publisher.core/src/main/java/org/wso2/carbon/event/publisher/core/config/EventPublisherConstants.java @@ -117,4 +117,10 @@ private EventPublisherConstants() { public static final String METRIC_DELIMITER = "."; public static final String METRIC_AGGREGATE_ANNOTATION = "[+]"; public static final String TEMP_CARBON_APPS_DIRECTORY = "carbonapps"; -} \ No newline at end of file + + public static final String DYNAMIC_PROPERTY_HTTP_URL = "http.url"; + public static final String DYNAMIC_PROPERTY_NOTIFICATION_EVENT = "notification-event"; + public static final String SMS_OTP = "smsotp"; + public static final String SEND_TO = "send-to"; + public static final String OTP_TOKEN = "otpToken"; +} diff --git a/components/event-publisher/org.wso2.carbon.event.publisher.core/src/main/java/org/wso2/carbon/event/publisher/core/internal/EventPublisher.java b/components/event-publisher/org.wso2.carbon.event.publisher.core/src/main/java/org/wso2/carbon/event/publisher/core/internal/EventPublisher.java index 382a8e3116..1d9798d154 100644 --- a/components/event-publisher/org.wso2.carbon.event.publisher.core/src/main/java/org/wso2/carbon/event/publisher/core/internal/EventPublisher.java +++ b/components/event-publisher/org.wso2.carbon.event.publisher.core/src/main/java/org/wso2/carbon/event/publisher/core/internal/EventPublisher.java @@ -385,6 +385,7 @@ public void process(Event event) { } + EventPublisherUtil.populateUrlPlaceholders(dynamicProperties, event.getArbitraryDataMap()); org.wso2.siddhi.core.event.Event siddhiEvent = EventPublisherUtil.convertToSiddhiEvent(event, inputStreamSize); try { diff --git a/components/event-publisher/org.wso2.carbon.event.publisher.core/src/main/java/org/wso2/carbon/event/publisher/core/internal/util/EventPublisherUtil.java b/components/event-publisher/org.wso2.carbon.event.publisher.core/src/main/java/org/wso2/carbon/event/publisher/core/internal/util/EventPublisherUtil.java index d7558e7062..e3895d1225 100644 --- a/components/event-publisher/org.wso2.carbon.event.publisher.core/src/main/java/org/wso2/carbon/event/publisher/core/internal/util/EventPublisherUtil.java +++ b/components/event-publisher/org.wso2.carbon.event.publisher.core/src/main/java/org/wso2/carbon/event/publisher/core/internal/util/EventPublisherUtil.java @@ -15,6 +15,7 @@ package org.wso2.carbon.event.publisher.core.internal.util; import org.apache.axis2.engine.AxisConfiguration; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.xerces.impl.Constants; @@ -38,6 +39,12 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import static org.wso2.carbon.event.publisher.core.config.EventPublisherConstants.DYNAMIC_PROPERTY_HTTP_URL; +import static org.wso2.carbon.event.publisher.core.config.EventPublisherConstants.DYNAMIC_PROPERTY_NOTIFICATION_EVENT; +import static org.wso2.carbon.event.publisher.core.config.EventPublisherConstants.OTP_TOKEN; +import static org.wso2.carbon.event.publisher.core.config.EventPublisherConstants.SEND_TO; +import static org.wso2.carbon.event.publisher.core.config.EventPublisherConstants.SMS_OTP; + public class EventPublisherUtil { private static final String JVM_BIT_ARCH_SYSTEM_PROPERTY = "sun.arch.data.model"; @@ -155,6 +162,40 @@ public static int getSize(org.wso2.carbon.databridge.commons.Event event) { return size; } + /** + * Replaces placeholders in the given URL with the corresponding values provided in the map. + * + * @param dynamicProperties The map containing the properties of the publisher. + * @param arbitraryDataMap The map containing the arbitrary data coming from the event. + */ + public static void populateUrlPlaceholders(Map dynamicProperties, Map arbitraryDataMap) { + + if (dynamicProperties == null || dynamicProperties.isEmpty() || + StringUtils.isBlank(dynamicProperties.get(DYNAMIC_PROPERTY_HTTP_URL))) { + // Return if the URL is not set. + return; + } + if (arbitraryDataMap == null || arbitraryDataMap.isEmpty()) { + // Return if the arbitrary data map is not set. + return; + } + + // Handle SMS OTP Flow. + if (arbitraryDataMap.get(DYNAMIC_PROPERTY_NOTIFICATION_EVENT) != null + && SMS_OTP.equalsIgnoreCase(arbitraryDataMap.get(DYNAMIC_PROPERTY_NOTIFICATION_EVENT))) { + String url = dynamicProperties.get(DYNAMIC_PROPERTY_HTTP_URL); + String encodedSmsMessage = "Verification Code: ".replaceAll("\\s", "+"); + if (StringUtils.isNotBlank(url) && StringUtils.isNotBlank(arbitraryDataMap.get(OTP_TOKEN)) && + StringUtils.isNotBlank(arbitraryDataMap.get(SEND_TO))) { + url = url.replaceAll("\\$ctx.num", arbitraryDataMap.get(SEND_TO)) + .replaceAll("\\$ctx.msg", encodedSmsMessage + arbitraryDataMap.get(OTP_TOKEN)) + .replaceAll("\\$ctx.otp", arbitraryDataMap.get(OTP_TOKEN)); + dynamicProperties.put(DYNAMIC_PROPERTY_HTTP_URL, url); + } + } + } + private static int getSize(Map arbitraryDataMap) { int size = 0; if (arbitraryDataMap != null) { diff --git a/features/analytics-gadget-templates/org.wso2.carbon.analytics.gadget.template.feature/pom.xml b/features/analytics-gadget-templates/org.wso2.carbon.analytics.gadget.template.feature/pom.xml index b56ec70daa..6767077dba 100644 --- a/features/analytics-gadget-templates/org.wso2.carbon.analytics.gadget.template.feature/pom.xml +++ b/features/analytics-gadget-templates/org.wso2.carbon.analytics.gadget.template.feature/pom.xml @@ -42,7 +42,6 @@ org.wso2.carbon.analytics-common org.wso2.carbon.analytics.gadget.rest.provider.template.feature - 5.2.62-SNAPSHOT zip @@ -95,4 +94,4 @@ - \ No newline at end of file +