serverFQDN = addr.getCanonicalHostName();
MDC.put(ONAPLogConstants.MDCs.SERVER_IP_ADDRESS, addr.getHostAddress());
} catch (UnknownHostException e) {
- logger.warn("Cannot Resolve Host Name");
+ logger.trace("Cannot Resolve Host Name");
serverFQDN = "";
}
MDC.put(ONAPLogConstants.MDCs.SERVER_FQDN, serverFQDN);
String invocationId = headers.get(ONAPLogConstants.Headers.INVOCATION_ID);
if (invocationId == null || invocationId.isEmpty())
invocationId = UUID.randomUUID().toString();
- MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId);
- }
-
- public void setInvocationIdFromMDC() {
- String invocationId = MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID);
- if (invocationId == null || invocationId.isEmpty())
- invocationId = UUID.randomUUID().toString();
+ MDC.put(ONAPLogConstants.MDCs.SERVER_INVOCATION_ID, invocationId);
MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId);
}
return partnerName;
}
- logger.trace(checkHeaderLogPattern, Constants.HttpHeaders.CLIENT_ID, ONAPLogConstants.MDCs.PARTNER_NAME);
- partnerName = headers.get(Constants.HttpHeaders.CLIENT_ID);
- if (partnerName != null && !partnerName.isEmpty()) {
- return partnerName;
- }
-
logger.trace("{} value could not be determined, defaulting partnerName to {}.",
ONAPLogConstants.MDCs.PARTNER_NAME, Constants.DefaultValues.UNKNOWN);
return Constants.DefaultValues.UNKNOWN;
}
public void setElapsedTime() {
- DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME;
- ZonedDateTime entryTimestamp =
- ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP), timeFormatter);
- ZonedDateTime endTimestamp = ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP), timeFormatter);
-
- MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME,
- Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp)));
+ try {
+ DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME;
+ ZonedDateTime entryTimestamp =
+ ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP), timeFormatter);
+ ZonedDateTime endTimestamp =
+ ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP), timeFormatter);
+
+ MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME,
+ Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp)));
+ } catch (Exception e) {
+ logger.trace("Unable to calculate elapsed time due to error: {}", e.getMessage());
+ }
}
public void setElapsedTimeInvokeTimestamp() {
- DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME;
- ZonedDateTime entryTimestamp =
- ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP), timeFormatter);
- ZonedDateTime endTimestamp = ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP), timeFormatter);
-
- MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME,
- Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp)));
+ try {
+ DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME;
+ ZonedDateTime entryTimestamp =
+ ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP), timeFormatter);
+ ZonedDateTime endTimestamp =
+ ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP), timeFormatter);
+
+ MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME,
+ Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp)));
+ } catch (Exception e) {
+ logger.trace("Unable to calculate elapsed time due to error: {}", e.getMessage());
+ }
}
public void setResponseStatusCode(int code) {
}
public void clearClientMDCs() {
- MDC.remove(ONAPLogConstants.MDCs.INVOCATION_ID);
+ MDC.remove(ONAPLogConstants.MDCs.CLIENT_INVOCATION_ID);
MDC.remove(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION);
MDC.remove(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE);
MDC.remove(ONAPLogConstants.MDCs.RESPONSE_CODE);
}
public String getProperty(String property) {
- logger.info("Checking for system property [{}]", property);
String propertyValue = System.getProperty(property);
if (propertyValue == null || propertyValue.isEmpty()) {
- logger.info("System property was null or empty. Checking environment variable for: {}", property);
propertyValue = System.getenv(property);
if (propertyValue == null || propertyValue.isEmpty()) {
- logger.info("Environment variable: {} was null or empty. Returning value: {}", property,
- Constants.DefaultValues.UNKNOWN);
propertyValue = Constants.DefaultValues.UNKNOWN;
}
}
protected String getBasicAuthUserName(SimpleMap headers) {
String encodedAuthorizationValue = headers.get(HttpHeaders.AUTHORIZATION);
- if (encodedAuthorizationValue != null) {
+ if (encodedAuthorizationValue != null && encodedAuthorizationValue.startsWith("Basic")) {
try {
// This will strip the word Basic and single space
encodedAuthorizationValue = encodedAuthorizationValue.substring(6);