package org.onap.aai.dmaap;
+import java.util.Map;
+import java.util.Objects;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+
import org.json.JSONException;
import org.json.JSONObject;
import org.onap.aai.aailog.logs.AaiDmaapMetricLog;
import org.springframework.http.HttpMethod;
import org.springframework.web.client.RestTemplate;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.jms.TextMessage;
-import java.util.Map;
-import java.util.Objects;
-
public class AAIDmaapEventJMSConsumer implements MessageListener {
private static final String EVENT_TOPIC = "event-topic";
private Environment environment;
private Map<String, String> mdcCopy;
-
public AAIDmaapEventJMSConsumer(Environment environment, RestTemplate restTemplate, HttpHeaders httpHeaders) {
super();
mdcCopy = MDC.getCopyOfContextMap();
String aaiElsErrorCode = AaiElsErrorCode.SUCCESS;
String errorDescription = "";
- if ( mdcCopy != null ) {
+ if (mdcCopy != null) {
MDC.setContextMap(mdcCopy);
}
} else {
return;
}
- if (jo.getString("event-topic") != null) {
- eventName = jo.getString("event-topic");
+ if (jo.getString(EVENT_TOPIC) != null) {
+ eventName = jo.getString(EVENT_TOPIC);
}
if (joPayload.has("event-header")) {
try {
if (aaiEventHeader.has("entity-link")) {
serviceName = aaiEventHeader.get("entity-link").toString();
}
- }
- catch (JSONException jexc) {
+ } catch (JSONException jexc) {
// ignore, this is just used for logging
}
}
if ("AAI-EVENT".equals(eventName)) {
restTemplate.exchange(baseUrl + endpoint, HttpMethod.POST, httpEntity, String.class);
} else {
- LOGGER.error(eventName + "|Event Topic invalid.");
+ LOGGER.error(String.format("%s|Event Topic invalid.", eventName));
}
} catch (JMSException | JSONException e) {
aaiElsErrorCode = AaiElsErrorCode.DATA_ERROR;
aaiElsErrorCode = AaiElsErrorCode.AVAILABILITY_TIMEOUT_ERROR;
errorDescription = e.getMessage();
ErrorLogHelper.logException(new AAIException("AAI_7304", jsmMessageTxt));
- }
- finally {
+ } finally {
metricLog.post(aaiElsErrorCode, errorDescription);
}
}