2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
38 package org.onap.portalapp.portal.logging.aop;
40 import java.net.InetAddress;
41 import java.text.SimpleDateFormat;
42 import java.util.Date;
43 import java.util.UUID;
45 import javax.servlet.http.HttpServletRequest;
47 import org.onap.portalapp.portal.domain.EPApp;
48 import org.onap.portalapp.portal.domain.EPUser;
49 import org.onap.portalapp.portal.service.AppsCacheService;
50 import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
51 import org.onap.portalapp.portal.utils.EcompPortalUtils;
52 import org.onap.portalapp.util.EPUserUtils;
53 import org.onap.portalsdk.core.exception.SessionExpiredException;
54 import org.onap.portalsdk.core.logging.format.AlarmSeverityEnum;
55 import org.onap.portalsdk.core.logging.format.AuditLogFormatter;
56 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
57 import org.onap.portalsdk.core.logging.logic.LoggerProperties;
58 import org.onap.portalsdk.core.util.SystemProperties;
59 import org.onap.portalsdk.core.util.SystemProperties.SecurityEventTypeEnum;
60 import org.onap.portalsdk.core.web.support.UserUtils;
62 import org.springframework.beans.factory.annotation.Autowired;
64 import com.att.eelf.configuration.Configuration;
66 @org.springframework.context.annotation.Configuration
67 public class EPEELFLoggerAdvice {
69 private EELFLoggerDelegate adviceLogger = EELFLoggerDelegate.getLogger(EPEELFLoggerAdvice.class);
72 AppsCacheService appCacheService;
75 * DateTime Format according to the ONAP Application Logging Guidelines.
79 * @return Current date and time in the format specified by the ONAP
80 * Application Logging Guidelines.
82 public static String getCurrentDateTimeUTC() {
83 SimpleDateFormat ecompLogDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
84 String currentDateTime = ecompLogDateFormat.format(new Date());
85 return currentDateTime;
89 * Sets logging context with values from HttpServletRequest object.
93 * @param securityEventType
94 * SecurityEventTypeEnum
96 public void loadServletRequestBasedDefaults(HttpServletRequest req, SecurityEventTypeEnum securityEventType) {
98 setHttpRequestBasedDefaultsIntoGlobalLoggingContext(req, securityEventType, req.getServletPath());
99 } catch (Exception e) {
100 adviceLogger.error(EELFLoggerDelegate.errorLogger, "loadServletRequestBasedDefaults failed", e);
106 * @param securityEventType
109 * @return Object array
111 public Object[] before(SecurityEventTypeEnum securityEventType, Object[] args, Object[] passOnArgs) {
113 String className = "";
114 if (passOnArgs.length > 0 && passOnArgs[0] != null)
115 className = passOnArgs[0].toString();
116 String methodName = EPCommonSystemProperties.ECOMP_PORTAL_BE;
117 if (passOnArgs.length > 1 && passOnArgs[1] != null)
118 methodName = passOnArgs[1].toString();
120 // Initialize Request defaults only for controller methods.
121 MDC.put(className + methodName + EPCommonSystemProperties.METRICSLOG_BEGIN_TIMESTAMP, getCurrentDateTimeUTC());
122 MDC.put(EPCommonSystemProperties.METRICSLOG_BEGIN_TIMESTAMP, getCurrentDateTimeUTC());
123 MDC.put(EPCommonSystemProperties.TARGET_ENTITY, EPCommonSystemProperties.ECOMP_PORTAL_BE);
124 MDC.put(EPCommonSystemProperties.TARGET_SERVICE_NAME, methodName);
125 if (MDC.get(Configuration.MDC_KEY_REQUEST_ID) == null||MDC.get(Configuration.MDC_KEY_REQUEST_ID).isEmpty()){
126 String requestId = UUID.randomUUID().toString();
127 MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId);
129 MDC.put(EPCommonSystemProperties.PARTNER_NAME, "Unknown");
131 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(className);
132 MDC.put(EPCommonSystemProperties.STATUS_CODE, "INPROGRESS");
134 // Log security message, if necessary
135 if (securityEventType != null) {
136 MDC.put(className + methodName + EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP,
137 getCurrentDateTimeUTC());
138 MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP,getCurrentDateTimeUTC());
139 MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP, getCurrentDateTimeUTC());
140 this.calculateDateTimeDifference(MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP),MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP));
141 HttpServletRequest req = null;
142 if (args.length > 0 && args[0] != null && args[0] instanceof HttpServletRequest) {
143 req = (HttpServletRequest) args[0];
144 this.setHttpRequestBasedDefaultsIntoGlobalLoggingContext(req, securityEventType, methodName);
147 MDC.put(Configuration.MDC_SERVER_FQDN, InetAddress.getLocalHost().getCanonicalHostName());
148 } catch (Exception e) {
149 adviceLogger.error(EELFLoggerDelegate.errorLogger,
150 " while setting the IP address ", e);
152 MDC.put(SystemProperties.CUSTOM_FIELD1, "ENTRY");
153 MDC.put(SystemProperties.CUSTOM_FIELD2, "InvocationID="+MDC.get(Configuration.MDC_KEY_REQUEST_ID));
154 this.logSecurityMessage(logger, securityEventType, methodName);
156 // Outgoing & LDAP messages are part of Incoming requests so,
157 // keep "RequestId", "PartnerName", "ServiceName", "LoginId" &
158 // "ResponseCode" etc. in memory and remove it only when
159 // finished processing the parent incoming message.
160 if (securityEventType != SecurityEventTypeEnum.OUTGOING_REST_MESSAGE
161 && securityEventType != SecurityEventTypeEnum.LDAP_PHONEBOOK_USER_SEARCH) {
162 MDC.remove(Configuration.MDC_KEY_REQUEST_ID);
163 MDC.remove(EPCommonSystemProperties.PARTNER_NAME);
164 MDC.remove(Configuration.MDC_SERVICE_NAME);
165 MDC.remove(EPCommonSystemProperties.MDC_LOGIN_ID);
166 MDC.remove(EPCommonSystemProperties.EXTERNAL_API_RESPONSE_CODE);
168 MDC.remove(Configuration.MDC_KEY_REQUEST_ID);
169 MDC.remove(EPCommonSystemProperties.PARTNER_NAME);
170 MDC.remove(Configuration.MDC_SERVICE_NAME);
172 logger.debug(EELFLoggerDelegate.debugLogger, "{} was invoked.", methodName);
174 MDC.remove(Configuration.MDC_SERVER_FQDN);
176 MDC.put(SystemProperties.METRICSLOG_END_TIMESTAMP, getCurrentDateTimeUTC());
177 this.calculateDateTimeDifference(MDC.get(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP),MDC.get(SystemProperties.METRICSLOG_END_TIMESTAMP));
178 MDC.put(SystemProperties.CUSTOM_FIELD1, "INVOKE");
179 MDC.put(SystemProperties.CUSTOM_FIELD2, " InvocationID="+MDC.get(Configuration.MDC_KEY_REQUEST_ID));
180 logger.info(EELFLoggerDelegate.metricsLogger, methodName + " operation is started.");
182 logger.debug(EELFLoggerDelegate.debugLogger, "EPEELFLoggerAdvice#before: entering {}", methodName);
183 } catch (Exception e) {
184 adviceLogger.error(EELFLoggerDelegate.errorLogger, "before failed", e);
186 return new Object[] { "" };
191 * @param securityEventType
193 * @param responseCode
198 public void after(SecurityEventTypeEnum securityEventType, String statusCode, String responseCode, Object[] args,
199 Object[] returnArgs, Object[] passOnArgs) {
201 String className = "";
202 if (passOnArgs.length > 0 && passOnArgs[0] != null)
203 className = passOnArgs[0].toString();
205 String methodName = EPCommonSystemProperties.ECOMP_PORTAL_BE;
206 if (passOnArgs.length > 1 && passOnArgs[1] != null)
207 methodName = passOnArgs[1].toString();
209 if (MDC.get(EPCommonSystemProperties.TARGET_SERVICE_NAME) == null
210 || MDC.get(EPCommonSystemProperties.TARGET_SERVICE_NAME) == "")
211 MDC.put(EPCommonSystemProperties.TARGET_SERVICE_NAME, methodName);
213 if (MDC.get(EPCommonSystemProperties.TARGET_ENTITY) == null
214 || MDC.get(EPCommonSystemProperties.TARGET_ENTITY) == "")
215 MDC.put(EPCommonSystemProperties.TARGET_ENTITY, EPCommonSystemProperties.ECOMP_PORTAL_BE);
217 if (MDC.get(Configuration.MDC_KEY_REQUEST_ID) == null||MDC.get(Configuration.MDC_KEY_REQUEST_ID).isEmpty()){
218 String requestId = UUID.randomUUID().toString();
219 MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId);
222 if (MDC.get(EPCommonSystemProperties.PARTNER_NAME) == null|| MDC.get(EPCommonSystemProperties.PARTNER_NAME).isEmpty()){
223 MDC.put(EPCommonSystemProperties.PARTNER_NAME, "Unknown");
227 MDC.put(EPCommonSystemProperties.METRICSLOG_BEGIN_TIMESTAMP,
228 MDC.get(className + methodName + EPCommonSystemProperties.METRICSLOG_BEGIN_TIMESTAMP));
229 MDC.put(EPCommonSystemProperties.METRICSLOG_END_TIMESTAMP, getCurrentDateTimeUTC());
230 this.calculateDateTimeDifference(MDC.get(EPCommonSystemProperties.METRICSLOG_BEGIN_TIMESTAMP),
231 MDC.get(EPCommonSystemProperties.METRICSLOG_END_TIMESTAMP));
233 // Making sure to reload the INCOMING request MDC defaults if they have
234 // been wiped out by either Outgoing or LDAP Phone book search
236 if (securityEventType != null && args.length > 0 && args[0] != null && args[0] instanceof HttpServletRequest
237 && securityEventType == SecurityEventTypeEnum.INCOMING_REST_MESSAGE
238 && (MDC.get(EPCommonSystemProperties.FULL_URL) == null
239 || MDC.get(EPCommonSystemProperties.FULL_URL).isEmpty())) {
240 HttpServletRequest req = (HttpServletRequest) args[0];
241 this.setHttpRequestBasedDefaultsIntoGlobalLoggingContext(req, securityEventType, methodName);
244 // Use external API response code in case if it resulted in an error.
245 String externalAPIResponseCode = MDC.get(EPCommonSystemProperties.EXTERNAL_API_RESPONSE_CODE);
246 if (externalAPIResponseCode == null || externalAPIResponseCode == ""
247 || externalAPIResponseCode.trim().equalsIgnoreCase("200")) {
248 MDC.put(EPCommonSystemProperties.RESPONSE_CODE, responseCode);
249 MDC.put(EPCommonSystemProperties.STATUS_CODE, statusCode);
251 MDC.put(EPCommonSystemProperties.RESPONSE_CODE, externalAPIResponseCode);
252 MDC.put(EPCommonSystemProperties.STATUS_CODE, "ERROR");
254 MDC.put(EPCommonSystemProperties.STATUS_CODE, "COMPLETE");
255 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(className);
257 // Log security message, if necessary
258 if (securityEventType != null) {
259 MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP,
260 MDC.get(className + methodName + EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP));
261 MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP, getCurrentDateTimeUTC());
262 this.calculateDateTimeDifference(MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP),
263 MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP));
264 MDC.put(SystemProperties.CUSTOM_FIELD1, "EXIT");
265 MDC.put(SystemProperties.CUSTOM_FIELD2, "InvocationID="+MDC.get(Configuration.MDC_KEY_REQUEST_ID));
267 MDC.put(Configuration.MDC_SERVER_FQDN, InetAddress.getLocalHost().getCanonicalHostName());
268 } catch (Exception e) {
269 adviceLogger.error(EELFLoggerDelegate.errorLogger,
270 " while setting the IP address ", e);
272 this.logSecurityMessage(logger, securityEventType, methodName);
274 // Outgoing & LDAP messages are part of Incoming requests so,
275 // keep "RequestId", "PartnerName", "ServiceName", "LoginId" &
276 // "ResponseCode" etc. in memory and remove it only when
277 // finished processing the parent incoming message.
278 if (securityEventType != SecurityEventTypeEnum.OUTGOING_REST_MESSAGE
279 && securityEventType != SecurityEventTypeEnum.LDAP_PHONEBOOK_USER_SEARCH) {
280 MDC.remove(Configuration.MDC_KEY_REQUEST_ID);
281 MDC.remove(EPCommonSystemProperties.PARTNER_NAME);
282 MDC.remove(Configuration.MDC_SERVICE_NAME);
283 MDC.remove(EPCommonSystemProperties.MDC_LOGIN_ID);
284 MDC.remove(EPCommonSystemProperties.EXTERNAL_API_RESPONSE_CODE);
286 MDC.remove(Configuration.MDC_KEY_REQUEST_ID);
287 MDC.remove(EPCommonSystemProperties.PARTNER_NAME);
288 MDC.remove(Configuration.MDC_SERVICE_NAME);
291 // clear when finishes audit logging
292 MDC.remove(Configuration.MDC_SERVER_FQDN);
293 MDC.remove(EPCommonSystemProperties.FULL_URL);
294 MDC.remove(EPCommonSystemProperties.PROTOCOL);
295 MDC.remove(EPCommonSystemProperties.STATUS_CODE);
296 MDC.remove(className + methodName + EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
297 MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
298 MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
299 MDC.remove(EPCommonSystemProperties.RESPONSE_CODE);
302 MDC.put(SystemProperties.CUSTOM_FIELD1, "INVOKE-RETURN");
303 MDC.put(SystemProperties.CUSTOM_FIELD2, " InvocationID="+MDC.get(Configuration.MDC_KEY_REQUEST_ID));
304 // add the metrics log
305 logger.info(EELFLoggerDelegate.metricsLogger, methodName + " operation is completed.");
307 logger.debug(EELFLoggerDelegate.debugLogger, "EPEELFLoggerAdvice#after: finished {}", methodName);
308 MDC.remove(SystemProperties.CUSTOM_FIELD1);
309 MDC.remove(SystemProperties.CUSTOM_FIELD2);
310 MDC.remove(className + methodName + EPCommonSystemProperties.METRICSLOG_BEGIN_TIMESTAMP);
311 MDC.remove(EPCommonSystemProperties.METRICSLOG_BEGIN_TIMESTAMP);
312 MDC.remove(EPCommonSystemProperties.METRICSLOG_END_TIMESTAMP);
313 MDC.remove(EPCommonSystemProperties.MDC_TIMER);
314 MDC.remove(EPCommonSystemProperties.TARGET_ENTITY);
315 MDC.remove(EPCommonSystemProperties.TARGET_SERVICE_NAME);
316 } catch (Exception e) {
317 adviceLogger.error(EELFLoggerDelegate.errorLogger, "after failed", e);
325 * @param securityEventType
328 private void logSecurityMessage(EELFLoggerDelegate logger, SecurityEventTypeEnum securityEventType,
330 StringBuilder additionalInfoAppender = new StringBuilder();
331 String auditMessage = "";
333 if (securityEventType == SecurityEventTypeEnum.OUTGOING_REST_MESSAGE) {
334 additionalInfoAppender.append(String.format("%s '%s' request was initiated.", restMethod,
335 MDC.get(EPCommonSystemProperties.TARGET_SERVICE_NAME)));
336 } else if (securityEventType == SecurityEventTypeEnum.LDAP_PHONEBOOK_USER_SEARCH) {
337 additionalInfoAppender.append("LDAP Phonebook search operation is performed.");
339 additionalInfoAppender.append(String.format("%s request was received.", restMethod));
341 if (securityEventType == SecurityEventTypeEnum.FE_LOGIN_ATTEMPT) {
343 String additionalMessage = " Successfully authenticated.";
344 loginId = MDC.get(EPCommonSystemProperties.MDC_LOGIN_ID);
345 if (loginId == null || loginId == "" || loginId == EPCommonSystemProperties.UNKNOWN) {
346 additionalMessage = " No cookies are found.";
348 additionalInfoAppender.append(additionalMessage);
349 } else if (securityEventType == SecurityEventTypeEnum.FE_LOGOUT) {
350 additionalInfoAppender.append(" User has been successfully logged out.");
354 String fullURL = MDC.get(EPCommonSystemProperties.FULL_URL);
355 if (fullURL != null && fullURL != "") {
356 additionalInfoAppender.append(" Request-URL:" + MDC.get(EPCommonSystemProperties.FULL_URL));
359 auditMessage = AuditLogFormatter.getInstance().createMessage(MDC.get(EPCommonSystemProperties.PROTOCOL),
360 securityEventType.name(), MDC.get(EPCommonSystemProperties.MDC_LOGIN_ID),
361 additionalInfoAppender.toString());
363 logger.info(EELFLoggerDelegate.auditLogger, auditMessage);
369 * @param securityEventType
372 private void setHttpRequestBasedDefaultsIntoGlobalLoggingContext(HttpServletRequest req,
373 SecurityEventTypeEnum securityEventType, String restMethod) {
375 * No need to load the request based defaults for the following security
376 * messages since either they are initiated by the Portal BE or not Http
380 if (securityEventType != SecurityEventTypeEnum.OUTGOING_REST_MESSAGE
381 && securityEventType != SecurityEventTypeEnum.LDAP_PHONEBOOK_USER_SEARCH
382 && securityEventType != SecurityEventTypeEnum.INCOMING_UEB_MESSAGE) {
383 // Load the RequestID (aka TrasactionId) into MDC context.
386 loadPartnerName(req);
390 loadUrlProtocol(req);
392 loadServicePath(req, restMethod);
394 loadClientAddress(req);
396 } else if (securityEventType == SecurityEventTypeEnum.LDAP_PHONEBOOK_USER_SEARCH) {
397 MDC.put(EPCommonSystemProperties.TARGET_ENTITY, "Phonebook");
398 MDC.put(EPCommonSystemProperties.TARGET_SERVICE_NAME, "search");
401 MDC.put(Configuration.MDC_SERVICE_NAME, restMethod);
402 MDC.put(EPCommonSystemProperties.PARTNER_NAME, EPCommonSystemProperties.ECOMP_PORTAL_FE);
405 MDC.put(Configuration.MDC_SERVICE_INSTANCE_ID, "");
406 MDC.put(Configuration.MDC_ALERT_SEVERITY, AlarmSeverityEnum.INFORMATIONAL.severity());
408 MDC.put(Configuration.MDC_SERVER_FQDN, InetAddress.getLocalHost().getCanonicalHostName());
409 MDC.put(Configuration.MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
410 MDC.put(Configuration.MDC_INSTANCE_UUID, SystemProperties.getProperty(SystemProperties.INSTANCE_UUID));
411 } catch (Exception e) {
412 adviceLogger.error(EELFLoggerDelegate.errorLogger,
413 "setHttpRequestBasedDefaultsIntoGlobalLoggingContext failed", e);
417 private void loadClientAddress(HttpServletRequest req) {
418 // Client IPAddress i.e. IPAddress of the remote host who is
419 // making this request.
420 String clientIPAddress = "";
421 clientIPAddress = req.getHeader("X-FORWARDED-FOR");
422 if (clientIPAddress == null) {
423 clientIPAddress = req.getRemoteAddr();
425 MDC.put(EPCommonSystemProperties.CLIENT_IP_ADDRESS, clientIPAddress);
428 private void loadServicePath(HttpServletRequest req, String restMethod) {
430 MDC.put(Configuration.MDC_SERVICE_NAME, restMethod);
431 String restPath = req.getServletPath();
432 //if (restPath != null && restPath != "") {
433 if (restPath != null && restPath.trim().length()>0) {
435 MDC.put(Configuration.MDC_SERVICE_NAME, restPath);
439 private void loadUrlProtocol(HttpServletRequest req) {
440 // Rest URL & Protocol
442 MDC.put(EPCommonSystemProperties.FULL_URL, EPCommonSystemProperties.UNKNOWN);
443 MDC.put(EPCommonSystemProperties.PROTOCOL, EPCommonSystemProperties.HTTP);
444 restURL = UserUtils.getFullURL(req);
445 //if (restURL != null && restURL != "") {
446 if (restURL != null && restURL.trim().length()>0) {
447 MDC.put(EPCommonSystemProperties.FULL_URL, restURL);
448 if (restURL.toLowerCase().contains("https")) {
449 MDC.put(EPCommonSystemProperties.PROTOCOL, EPCommonSystemProperties.HTTPS);
454 private void loadRequestId(HttpServletRequest req) {
455 String requestId = UserUtils.getRequestId(req);
456 if (requestId == null||requestId.trim().length()==0) {
457 requestId = UUID.randomUUID().toString();
459 MDC.put(Configuration.MDC_KEY_REQUEST_ID, requestId);
462 private void loadLoginId(HttpServletRequest req) {
463 // Load loginId into MDC context.
464 String loginId = "NoUser";
467 EPUser user = EPUserUtils.getUserSession(req);
468 loginId = (user != null ? user.getOrgUserId(): loginId);
469 } catch (SessionExpiredException se) {
470 adviceLogger.debug(EELFLoggerDelegate.debugLogger,
471 "setHttpRequestBasedDefaultsIntoGlobalLoggingContext: No user found in session");
474 // try fetching from username in header
475 final String nameHeader = req.getHeader(EPCommonSystemProperties.USERNAME);
476 if (nameHeader != null) {
477 loginId = nameHeader;
480 // try fetching from BasicAuth info
481 final String authHeader = req.getHeader(EPCommonSystemProperties.AUTHORIZATION);
482 if (authHeader != null) {
483 String[] accountNamePassword = EcompPortalUtils.getUserNamePassword(authHeader);
484 if (accountNamePassword != null && accountNamePassword.length == 2) {
485 loginId = accountNamePassword[0];
490 MDC.put(EPCommonSystemProperties.MDC_LOGIN_ID, loginId );
494 private void loadPartnerName(HttpServletRequest req) {
497 // Load user agent into MDC context, if available.
498 String accessingClient = req.getHeader(SystemProperties.USERAGENT_NAME);
499 accessingClient = (accessingClient == null || accessingClient.trim().length()==0)?"Unknown":accessingClient;
500 if (accessingClient != null && accessingClient.trim().length()==0 && (accessingClient.contains("Mozilla")
501 || accessingClient.contains("Chrome") || accessingClient.contains("Safari"))) {
502 accessingClient = EPCommonSystemProperties.ECOMP_PORTAL_FE;
504 MDC.put(EPCommonSystemProperties.PARTNER_NAME, accessingClient);
506 // try get the Partner name from uebkey
507 String uebVal = req.getHeader(EPCommonSystemProperties.UEB_KEY);
509 EPApp appRecord = appCacheService.getAppFromUeb(uebVal);
510 MDC.put(EPCommonSystemProperties.PARTNER_NAME, appRecord.getName());
518 * @param beginDateTime
521 private void calculateDateTimeDifference(String beginDateTime, String endDateTime) {
522 if (beginDateTime != null && endDateTime != null && !beginDateTime.isEmpty()&&!endDateTime.isEmpty()) {
524 SimpleDateFormat ecompLogDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
525 Date beginDate = ecompLogDateFormat.parse(beginDateTime);
526 Date endDate = ecompLogDateFormat.parse(endDateTime);
527 String timeDifference = String.format("%d", endDate.getTime() - beginDate.getTime());
528 MDC.put(SystemProperties.MDC_TIMER, timeDifference);
529 } catch (Exception e) {
530 adviceLogger.error(EELFLoggerDelegate.errorLogger, "calculateDateTimeDifference failed", e);
535 public String getInternalResponseCode() {
536 return MDC.get(EPCommonSystemProperties.RESPONSE_CODE);