package com.instinctools.padlaboris.application.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;

/**
 * Interceptor used for logging controller method calls and completion status.
 */
@Slf4j
public class LoggerInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(final HttpServletRequest request,
                             final HttpServletResponse response,
                             final Object handler) throws Exception {
        final Method method = ((HandlerMethod) handler).getMethod();
        final String message = "Called method '"
                + method.getName()
                + "' in controller '"
                + method.getDeclaringClass().getSimpleName()
                + "'";

        log.info(message);
        return super.preHandle(request, response, handler);
    }

    @Override
    public void afterCompletion(final HttpServletRequest request,
                                final HttpServletResponse response,
                                final Object handler,
                                final Exception ex) throws Exception {
        final Method method = ((HandlerMethod) handler).getMethod();
        final String message = "Method '"
                + method.getName()
                + "' in controller '"
                + method.getDeclaringClass().getSimpleName()
                + "' finished with code "
                + Integer.toString(response.getStatus());

        log.info(message);
        super.afterCompletion(request, response, handler, ex);
    }
}

@@ -710,32 +710,85 @@
 ows Exception %7B%0A
+%0A        if (handler instanceof HandlerMethod) %7B%0A    
         final Me
@@ -840,32 +840,36 @@
 thod();%0A        
+   
+ 
 final String mes
@@ -901,32 +901,36 @@
                 
+    
 + method.getName
@@ -940,32 +940,36 @@
                 
+ 
+   
 + %22' in controll
@@ -982,32 +982,36 @@
                 
+  
+  
 + method.getDecl
@@ -1059,16 +1059,20 @@
     
+    
 + %22'%22;%0A%0A
     
@@ -1067,16 +1067,20 @@
 + %22'%22;%0A%0A
+    
         
@@ -1090,32 +1090,43 @@
 .info(message);%0A
+        %7D%0A%0A
         return s
@@ -1449,16 +1449,69 @@
 ption %7B%0A
+%0A        if (handler instanceof HandlerMethod) %7B%0A    
         
@@ -1571,32 +1571,36 @@
 thod();%0A        
+    
 final String mes
@@ -1625,32 +1625,36 @@
                 
+  
+  
 + method.getName
@@ -1648,32 +1648,36 @@
 ethod.getName()%0A
+    
                 
@@ -1706,32 +1706,36 @@
                 
+    
 + method.getDecl
@@ -1775,24 +1775,28 @@
             
+ 
+   
 + %22' finishe
@@ -1809,16 +1809,20 @@
  code %22%0A
+    
         
@@ -1872,32 +1872,36 @@
 us());%0A%0A        
+    
 log.info(message
@@ -1895,32 +1895,43 @@
 .info(message);%0A
+        %7D%0A%0A
         super.af

fix class cast exception in interceptor