package im.dadoo.gale.http.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.MDC;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import im.dadoo.gale.http.server.GaleRequest;

@Aspect
@Order(1)
@Component
public class MdcAspect {

  private static final String REQUEST_URI = "RequestUri";
  
  @Around("execution(* im.dadoo.gale.http.server.GaleProcessor.process(..))")
  public Object mdc(ProceedingJoinPoint pjp) throws Throwable {
    GaleRequest request = (GaleRequest)pjp.getArgs()[0];
    MDC.put(REQUEST_URI, request.getUri());
    Object result = pjp.proceed();
    MDC.remove(REQUEST_URI);
    return result;
  }
  
}

@@ -381,16 +381,74 @@
 pect %7B%0A%0A
+  private static final String HTTP_METHOD = %22HttpMethod%22;%0A
   privat
@@ -699,16 +699,70 @@
 s()%5B0%5D;%0A
+    MDC.put(HTTP_METHOD, request.getMethod().name());%0A
     MDC.
@@ -832,16 +832,45 @@
 ceed();%0A
+    MDC.remove(HTTP_METHOD);%0A
     MDC.

improve mdc