summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event/plugins-event-carrier
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2018-09-14 13:19:52 +0000
committerGerrit Code Review <gerrit@onap.org>2018-09-14 13:19:52 +0000
commitec351d2ee36a37af78476feaff401fac47afe524 (patch)
treeba9de9c01422f471c18120e5e5be618597f3d706 /plugins/plugins-event/plugins-event-carrier
parent330836ad1aa9c88dd3c308fcd750ccd1aaf3e4b9 (diff)
parentcd68fc9bae7d6258f77ff59c1431e4f925f61a4c (diff)
Merge "Address sonar/Checkstyle Issues"
Diffstat (limited to 'plugins/plugins-event/plugins-event-carrier')
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerEndpoint.java52
1 files changed, 37 insertions, 15 deletions
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerEndpoint.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerEndpoint.java
index f8524fcfd..ca2d797b9 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerEndpoint.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerEndpoint.java
@@ -43,8 +43,10 @@ import org.slf4j.LoggerFactory;
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
@Path("/{eventInput}")
-@Produces({ MediaType.APPLICATION_JSON })
-@Consumes({ MediaType.APPLICATION_JSON })
+@Produces(
+ { MediaType.APPLICATION_JSON })
+@Consumes(
+ { MediaType.APPLICATION_JSON })
public class RestServerEndpoint {
// Get a reference to the logger
private static final Logger LOGGER = LoggerFactory.getLogger(RestServerEndpoint.class);
@@ -56,8 +58,7 @@ public class RestServerEndpoint {
// This map is used to hold all the REST server event inputs. This is used to determine which consumer to send input
// events to
- private static Map<String, ApexRestServerConsumer> consumerMap =
- new LinkedHashMap<>();
+ private static Map<String, ApexRestServerConsumer> consumerMap = new LinkedHashMap<>();
// The ID of this event input. This gets injected from the URL.
@PathParam("eventInput")
@@ -70,7 +71,7 @@ public class RestServerEndpoint {
* @param consumer The consumer to register
*/
public static void registerApexRestServerConsumer(final String consumerEventInputId,
- final ApexRestServerConsumer consumer) {
+ final ApexRestServerConsumer consumer) {
consumerMap.put(consumerEventInputId, consumer);
}
@@ -82,12 +83,12 @@ public class RestServerEndpoint {
@Path("/Status")
@GET
public Response serviceGetStats() {
- getMessagesReceived++;
+ incrementGetMessages();
return Response.status(Response.Status.OK.getStatusCode())
- .entity("{\n" + "\"INPUTS\": \"" + consumerMap.keySet() + "\",\n" + "\"STAT\": " + getMessagesReceived
- + ",\n" + "\"POST\": " + postEventMessagesReceived + ",\n" + "\"PUT\": "
- + putEventMessagesReceived + "\n}")
- .build();
+ .entity("{\n" + "\"INPUTS\": \"" + consumerMap.keySet() + "\",\n" + "\"STAT\": "
+ + getMessagesReceived + ",\n" + "\"POST\": " + postEventMessagesReceived + ",\n"
+ + "\"PUT\": " + putEventMessagesReceived + "\n}")
+ .build();
}
/**
@@ -99,7 +100,7 @@ public class RestServerEndpoint {
@Path("/EventIn")
@POST
public Response servicePostRequest(final String jsonString) {
- postEventMessagesReceived++;
+ incrementPostEventMessages();
if (LOGGER.isDebugEnabled()) {
String message = "event input " + eventInputId + ", received POST of event \"" + jsonString + "\"";
@@ -119,7 +120,7 @@ public class RestServerEndpoint {
@Path("/EventIn")
@PUT
public Response servicePutRequest(final String jsonString) {
- putEventMessagesReceived++;
+ incrementPutEventMessages();
if (LOGGER.isDebugEnabled()) {
String message = "event input \"" + eventInputId + "\", received PUT of event \"" + jsonString + "\"";
@@ -140,13 +141,34 @@ public class RestServerEndpoint {
// Find the correct consumer for this REST message
final ApexRestServerConsumer eventConsumer = consumerMap.get(eventInputId);
if (eventConsumer == null) {
- final String errorMessage =
- "event input " + eventInputId + " is not defined in the Apex configuration file";
+ final String errorMessage = "event input " + eventInputId
+ + " is not defined in the Apex configuration file";
LOGGER.warn(errorMessage);
return Response.status(Response.Status.BAD_REQUEST.getStatusCode())
- .entity("{'errorMessage', '" + errorMessage + "'}").build();
+ .entity("{'errorMessage', '" + errorMessage + "'}").build();
}
return eventConsumer.receiveEvent(jsonString);
}
+
+ /**
+ * Increment number of get messages received.
+ */
+ private static void incrementGetMessages() {
+ getMessagesReceived++;
+ }
+
+ /**
+ * Increment number of get messages received.
+ */
+ private static void incrementPutEventMessages() {
+ putEventMessagesReceived++;
+ }
+
+ /**
+ * Increment number of get messages received.
+ */
+ private static void incrementPostEventMessages() {
+ postEventMessagesReceived++;
+ }
}