X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fcrud%2Flogging%2FLoggingUtil.java;h=31c0c1f39ad22c3d78e132e3a0e1122f3ec9dd26;hb=36a7dbfd2672ee6629c4b375df2d6982d942fa43;hp=453dc9d92ae993b556bfd2b892d2e23cd1301d0e;hpb=908b4693e5a0a4c2f323dbf518b35e4620f183a1;p=aai%2Fgizmo.git diff --git a/src/main/java/org/onap/crud/logging/LoggingUtil.java b/src/main/java/org/onap/crud/logging/LoggingUtil.java index 453dc9d..31c0c1f 100644 --- a/src/main/java/org/onap/crud/logging/LoggingUtil.java +++ b/src/main/java/org/onap/crud/logging/LoggingUtil.java @@ -1,16 +1,15 @@ /** * ============LICENSE_START======================================================= - * Gizmo + * org.onap.aai * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. - * Copyright © 2017 Amdocs - * All rights reserved. + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,8 +17,6 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.crud.logging; @@ -40,21 +37,29 @@ public class LoggingUtil { */ public static void initMdcContext(HttpServletRequest httpReq, HttpHeaders headers) { String fromIp = httpReq.getRemoteAddr(); - String fromAppId = ""; - String transId = null; - if (headers.getRequestHeaders().getFirst("X-FromAppId") != null) { + MdcContext.initialize(getTransactionId(headers), CrudServiceConstants.CRD_SERVICE_NAME, "", getAppId(headers), fromIp); + } + + public static String getAppId(HttpHeaders headers) { + String fromAppId = ""; + if (headers.getRequestHeaders().getFirst("X-FromMsId") != null) { + fromAppId = headers.getRequestHeaders().getFirst("X-FromMsId"); + } else if (headers.getRequestHeaders().getFirst("X-FromAppId") != null) { fromAppId = headers.getRequestHeaders().getFirst("X-FromAppId"); } - + return fromAppId; + } + + public static String getTransactionId(HttpHeaders headers) { + String transId = null; if ((headers.getRequestHeaders().getFirst("X-TransactionId") == null) - || headers.getRequestHeaders().getFirst("X-TransactionId").isEmpty()) { + || headers.getRequestHeaders().getFirst("X-TransactionId").isEmpty()) { transId = java.util.UUID.randomUUID().toString(); } else { transId = headers.getRequestHeaders().getFirst("X-TransactionId"); } - - MdcContext.initialize(transId, CrudServiceConstants.CRD_SERVICE_NAME, "", fromAppId, fromIp); + return transId; } /**