aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBogumil Zebek <bogumil.zebek@nokia.com>2018-07-30 12:53:48 +0200
committerbogumil_zebek <bogumil.zebek@nokia.com>2018-07-30 12:53:48 +0200
commita9fb66adad7c18fc2f3c80d36293268da280fe95 (patch)
treeb274ad918a466aa801c49f36187d5cee6bee08c6
parent549b8c5b7e90621fc4d77fa35e6a7be8d58e3182 (diff)
Fix potential null pointers
Change-Id: I309010480012cc66ac8d44d6be65f5897174ec3f Issue-ID: AAI-1430 Signed-off-by: bogumil_zebek <bogumil.zebek@nokia.com>
-rw-r--r--champ-service/src/main/java/org/onap/champ/ChampRESTAPI.java4
-rw-r--r--champ-service/src/main/java/org/onap/champ/async/ChampAsyncRequestProcessor.java73
2 files changed, 38 insertions, 39 deletions
diff --git a/champ-service/src/main/java/org/onap/champ/ChampRESTAPI.java b/champ-service/src/main/java/org/onap/champ/ChampRESTAPI.java
index b312af3..8db8c46 100644
--- a/champ-service/src/main/java/org/onap/champ/ChampRESTAPI.java
+++ b/champ-service/src/main/java/org/onap/champ/ChampRESTAPI.java
@@ -155,7 +155,9 @@ public class ChampRESTAPI {
response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
LoggingUtil.logInternalError(logger, e);
} finally {
- logger.debug(response.getEntity().toString());
+ if (response != null) {
+ logger.debug(response.getEntity().toString());
+ }
LoggingUtil.logRestRequest(logger, auditLogger, req, response);
metricsLogger.info(ChampMsgs.PROCESSED_REQUEST, "GET", Long.toString(System.currentTimeMillis() - startTimeInMs));
}
diff --git a/champ-service/src/main/java/org/onap/champ/async/ChampAsyncRequestProcessor.java b/champ-service/src/main/java/org/onap/champ/async/ChampAsyncRequestProcessor.java
index 346bd02..e091ee9 100644
--- a/champ-service/src/main/java/org/onap/champ/async/ChampAsyncRequestProcessor.java
+++ b/champ-service/src/main/java/org/onap/champ/async/ChampAsyncRequestProcessor.java
@@ -269,55 +269,52 @@ public class ChampAsyncRequestProcessor extends TimerTask {
if (asyncRequestConsumer == null) {
logger.error(ChampMsgs.CHAMP_ASYNC_REQUEST_PROCESSOR_ERROR,
"Unable to initialize ChampAsyncRequestProcessor");
- }
+ } else {
+ try {
+ Iterable<String> events = asyncRequestConsumer.consume();
+
+ if (events == null || !events.iterator().hasNext()) {
+ logger.info(ChampMsgs.CHAMP_ASYNC_REQUEST_PROCESSOR_INFO, "No events recieved");
+ } else {
+ processEvents(events);
+ }
- Iterable<String> events = null;
- try {
- events = asyncRequestConsumer.consume();
- } catch (Exception e) {
- logger.error(ChampMsgs.CHAMP_ASYNC_REQUEST_PROCESSOR_ERROR, e.getMessage());
- return;
+ asyncRequestConsumer.commitOffsets();
+ } catch (OperationNotSupportedException e) {
+ // Dmaap doesnt support commit with offset
+ logger.debug(ChampMsgs.CHAMP_ASYNC_REQUEST_PROCESSOR_WARN, e.getMessage());
+ } catch (Exception e) {
+ logger.error(ChampMsgs.CHAMP_ASYNC_REQUEST_PROCESSOR_WARN, e.getMessage());
+ }
}
- if (events == null || !events.iterator().hasNext()) {
- logger.info(ChampMsgs.CHAMP_ASYNC_REQUEST_PROCESSOR_INFO, "No events recieved");
+ }
- } else {
- for (String event : events) {
- try {
- GraphEventEnvelope requestEnvelope = GraphEventEnvelope.fromJson(event);
- GraphEvent requestEvent = requestEnvelope.getBody();
- auditLogger.info(ChampMsgs.CHAMP_ASYNC_REQUEST_PROCESSOR_INFO,
+ private void processEvents(Iterable<String> events) {
+ for (String event : events) {
+ try {
+ GraphEventEnvelope requestEnvelope = GraphEventEnvelope.fromJson(event);
+ GraphEvent requestEvent = requestEnvelope.getBody();
+ auditLogger.info(ChampMsgs.CHAMP_ASYNC_REQUEST_PROCESSOR_INFO,
"Event received of type: " + requestEvent.getObjectType() + " with key: "
- + requestEvent.getObjectKey() + " , transaction-id: " + requestEvent.getTransactionId()
- + " , operation: " + requestEvent.getOperation().toString());
- logger.info(ChampMsgs.CHAMP_ASYNC_REQUEST_PROCESSOR_INFO,
+ + requestEvent.getObjectKey() + " , transaction-id: " + requestEvent.getTransactionId()
+ + " , operation: " + requestEvent.getOperation().toString());
+ logger.info(ChampMsgs.CHAMP_ASYNC_REQUEST_PROCESSOR_INFO,
"Event received of type: " + requestEvent.getObjectType() + " with key: "
- + requestEvent.getObjectKey() + " , transaction-id: " + requestEvent.getTransactionId()
- + " , operation: " + requestEvent.getOperation().toString());
- logger.debug(ChampMsgs.CHAMP_ASYNC_REQUEST_PROCESSOR_INFO, "Event received with payload:" + event);
+ + requestEvent.getObjectKey() + " , transaction-id: " + requestEvent.getTransactionId()
+ + " , operation: " + requestEvent.getOperation().toString());
+ logger.debug(ChampMsgs.CHAMP_ASYNC_REQUEST_PROCESSOR_INFO, "Event received with payload:" + event);
- // Try to submit the event to be published to the event bus.
- if (!requestProcesserEventQueue.offer(requestEnvelope)) {
- logger.error(ChampMsgs.CHAMP_ASYNC_REQUEST_PROCESSOR_ERROR,
+ // Try to submit the event to be published to the event bus.
+ if (!requestProcesserEventQueue.offer(requestEnvelope)) {
+ logger.error(ChampMsgs.CHAMP_ASYNC_REQUEST_PROCESSOR_ERROR,
"Event could not be published to the event bus due to: Internal buffer capacity exceeded.");
- }
-
- } catch (Exception e) {
- logger.error(ChampMsgs.CHAMP_ASYNC_REQUEST_PROCESSOR_ERROR, e.getMessage());
}
- }
- }
- try {
- asyncRequestConsumer.commitOffsets();
- } catch (OperationNotSupportedException e) {
- // Dmaap doesnt support commit with offset
- logger.debug(ChampMsgs.CHAMP_ASYNC_REQUEST_PROCESSOR_WARN, e.getMessage());
- } catch (Exception e) {
- logger.error(ChampMsgs.CHAMP_ASYNC_REQUEST_PROCESSOR_WARN, e.getMessage());
+ } catch (Exception e) {
+ logger.error(ChampMsgs.CHAMP_ASYNC_REQUEST_PROCESSOR_ERROR, e.getMessage());
+ }
}
-
}
public Integer getRequestPollingTimeSeconds() {