diff --git a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/pom.xml b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/pom.xml index af3e4754..344acd07 100644 --- a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/pom.xml +++ b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/pom.xml @@ -28,7 +28,7 @@ ../../pom.xml - org.wso2.financial.services.accelerator.event.notification.endpoint + org.wso2.financial.services.accelerator.event.notifications.endpoint war WSO2 Financial Services - Event Notification Endpoint diff --git a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventCreationEndpoint.java b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventCreationEndpoint.java index 48580315..b1116214 100644 --- a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventCreationEndpoint.java +++ b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventCreationEndpoint.java @@ -52,9 +52,19 @@ public class EventCreationEndpoint { private static final Log log = LogFactory.getLog(EventCreationEndpoint.class); - private static final EventCreationServiceHandler eventCreationServiceHandler = EventNotificationUtils. - getEventNotificationCreationServiceHandler(); + private final EventCreationServiceHandler eventCreationServiceHandler; private static final String specialChars = "!@#$%&*()'+,./:;<=>?[]^_`{|}"; + private static final String illegalChars = "\\\\r|\\\\n|\\r|\\n|\\[|]| "; + + public EventCreationEndpoint() { + + eventCreationServiceHandler = EventNotificationUtils.getEventNotificationCreationServiceHandler(); + } + + public EventCreationEndpoint(EventCreationServiceHandler handler) { + + eventCreationServiceHandler = handler; + } /** * This API will be used to create events. @@ -82,7 +92,7 @@ public Response createEvents(@Context HttpServletRequest request, @Context HttpS if (!parameterMap.isEmpty() && parameterMap.containsKey(EventNotificationEndPointConstants.REQUEST)) { requestData = parameterMap.get(EventNotificationEndPointConstants.REQUEST). - toString().replaceAll("\\\\r|\\\\n|\\r|\\n|\\[|]| ", StringUtils.EMPTY); + toString().replaceAll(illegalChars, StringUtils.EMPTY); byte[] decodedBytes = Base64.getDecoder().decode(requestData); String decodedString = new String(decodedBytes, StandardCharsets.UTF_8); @@ -124,9 +134,8 @@ public Response createEvents(@Context HttpServletRequest request, @Context HttpS } //set events to notificationCreationDTO - JSONObject finalNotificationEvents = notificationEvents; notificationEvents.keySet().forEach(eventName -> { - JSONObject eventInformation = (JSONObject) finalNotificationEvents.get(eventName); + JSONObject eventInformation = notificationEvents.getJSONObject(eventName); notificationCreationDTO.setEventPayload(eventName, eventInformation); }); @@ -142,6 +151,7 @@ public Response createEvents(@Context HttpServletRequest request, @Context HttpS .getErrorDTO(EventNotificationEndPointConstants.INVALID_REQUEST_PAYLOAD, EventNotificationEndPointConstants.REQUEST_PAYLOAD_ERROR)).build(); } catch (FSEventNotificationException e) { + log.error(EventNotificationEndPointConstants.EVENT_CREATION_ERROR_RESPONSE, e); return Response.status(e.getStatus()).entity(EventNotificationServiceUtil .getErrorDTO(EventNotificationEndPointConstants.INVALID_REQUEST, e.getMessage())).build(); diff --git a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventPollingEndpoint.java b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventPollingEndpoint.java index 5aec5a6a..c6c3c171 100644 --- a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventPollingEndpoint.java +++ b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventPollingEndpoint.java @@ -58,9 +58,18 @@ @Path("/events") public class EventPollingEndpoint { - private static final Log log = LogFactory.getLog(EventCreationEndpoint.class); - private static final EventPollingServiceHandler eventPollingServiceHandler = EventNotificationUtils. - getEventPollingServiceHandler(); + private static final Log log = LogFactory.getLog(EventPollingEndpoint.class); + private EventPollingServiceHandler eventPollingServiceHandler; + + public EventPollingEndpoint() { + + eventPollingServiceHandler = EventNotificationUtils.getEventPollingServiceHandler(); + } + + public EventPollingEndpoint(EventPollingServiceHandler handler) { + + eventPollingServiceHandler = handler; + } /** * Retrieve Event Notifications Using Aggregated Polling. diff --git a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventSubscriptionEndpoint.java b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventSubscriptionEndpoint.java index 404e0e34..324e2a81 100644 --- a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventSubscriptionEndpoint.java +++ b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventSubscriptionEndpoint.java @@ -58,8 +58,17 @@ public class EventSubscriptionEndpoint { private static final Log log = LogFactory.getLog(EventSubscriptionEndpoint.class); - private static final EventSubscriptionServiceHandler eventSubscriptionServiceHandler = EventSubscriptionUtils. - getEventSubscriptionServiceHandler(); + private final EventSubscriptionServiceHandler eventSubscriptionServiceHandler; + + public EventSubscriptionEndpoint() { + + eventSubscriptionServiceHandler = EventSubscriptionUtils.getEventSubscriptionServiceHandler(); + } + + public EventSubscriptionEndpoint(EventSubscriptionServiceHandler handler) { + + eventSubscriptionServiceHandler = handler; + } /** * Register an Event Notification Subscription. diff --git a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/util/EventNotificationUtils.java b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/util/EventNotificationUtils.java index 23a34898..c706bcc4 100644 --- a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/util/EventNotificationUtils.java +++ b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/util/EventNotificationUtils.java @@ -40,6 +40,10 @@ public class EventNotificationUtils { private static final Log log = LogFactory.getLog(EventNotificationUtils.class); + private EventNotificationUtils() { + + } + /** * This method is to get the event creation service handler as per the config. * @return EventCreationServiceHandler diff --git a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/util/EventSubscriptionUtils.java b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/util/EventSubscriptionUtils.java index a690ce6a..67655ba3 100644 --- a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/util/EventSubscriptionUtils.java +++ b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/util/EventSubscriptionUtils.java @@ -36,6 +36,10 @@ */ public class EventSubscriptionUtils { + private EventSubscriptionUtils() { + + } + /** * Extract string payload from request object. */