From 6f999bcedcf9fa1a7802a8303169358440f2964e Mon Sep 17 00:00:00 2001 From: lucio Date: Wed, 15 Jun 2022 17:44:52 +0200 Subject: [PATCH] added caller information --- .../request/RequestAccounting.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/gcube/smartgears/handlers/application/request/RequestAccounting.java b/src/main/java/org/gcube/smartgears/handlers/application/request/RequestAccounting.java index 3fad47f..c556472 100644 --- a/src/main/java/org/gcube/smartgears/handlers/application/request/RequestAccounting.java +++ b/src/main/java/org/gcube/smartgears/handlers/application/request/RequestAccounting.java @@ -28,7 +28,7 @@ public class RequestAccounting extends RequestHandler { private static ThreadLocal startCallThreadLocal = new ThreadLocal(); - + private static final String UNKNOWN = "Unknown"; @Override public String getName() { @@ -42,15 +42,14 @@ public class RequestAccounting extends RequestHandler { String context = getContext(appContext); - String calledMethod = e.request().getHeader(Constants.called_method_header); - if (calledMethod==null){ - calledMethod = e.request().getRequestURI().substring(e.request().getContextPath().length()); - if (calledMethod.isEmpty()) - calledMethod = "/"; - calledMethod= e.request().getMethod()+" "+calledMethod; - } + String calledMethod = e.request().getRequestURI().substring(e.request().getContextPath().length()); + if (calledMethod.isEmpty()) + calledMethod = "/"; + calledMethod= e.request().getMethod()+" "+calledMethod; + InnerMethodName.instance.set(calledMethod); - String caller = "Unknown"; + String caller = SecretManagerProvider.instance.get()!=null ? SecretManagerProvider.instance.get().getOwner().getId(): + UNKNOWN; startCallThreadLocal.set(System.currentTimeMillis()); log.info("REQUEST START ON {}:{}({}) CALLED FROM {}@{} IN SCOPE {} ", @@ -67,8 +66,9 @@ public class RequestAccounting extends RequestHandler { String context = getContext(appContext); - String caller = "Unknown"; - String callerQualifier = "UNKNOWN"; + String caller = SecretManagerProvider.instance.get()!=null ? SecretManagerProvider.instance.get().getOwner().getId(): + UNKNOWN; + String callerQualifier = UNKNOWN; //retieves caller Ip when there is a proxy String callerIp = e.request().getHeader("x-forwarded-for"); if(callerIp==null) @@ -77,7 +77,7 @@ public class RequestAccounting extends RequestHandler { boolean success = e.response().getStatus()<400; if (appContext.container().configuration().mode()!=Mode.offline) - generateAccounting(caller,callerQualifier,callerIp==null?"UNKNOWN":callerIp , success, context, appContext); + generateAccounting(caller,callerQualifier,callerIp==null?UNKNOWN:callerIp , success, context, appContext); long durationInMillis = System.currentTimeMillis()-startCallThreadLocal.get();