package org.zalando.nakadi.filters;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.Principal;
import java.util.Optional;

@Component
public class LoggingFilter extends OncePerRequestFilter {

    private static final Logger LOG = LoggerFactory.getLogger(LoggingFilter.class);

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
            throws ServletException, IOException
    {
        long start = System.currentTimeMillis();

        //execute request
        try {
            filterChain.doFilter(request, response);
        } finally {
            long time = System.currentTimeMillis();
            Long timing = time - start;
            Optional<String> userAgent = Optional.ofNullable(request.getHeader("User-Agent"));
            Optional<String> user = Optional.ofNullable(request.getUserPrincipal()).map(Principal::getName);
            LOG.info("{} \"{}\" \"{}\" \"{}\" {} {} ms",
                    request.getMethod(),
                    request.getRequestURI(),
                    userAgent.orElse("-"),
                    user.orElse("-"),
                    response.getStatus(),
                    timing);
        }
    }
}

@@ -656,16 +656,22 @@
 nternal(
+final 
 HttpServ
@@ -689,16 +689,58 @@
 request,
+%0A                                    final
  HttpSer
@@ -761,16 +761,22 @@
 esponse,
+ final
  FilterC
@@ -852,24 +852,30 @@
   %7B%0A        
+final 
 long start =
@@ -1029,16 +1029,22 @@
         
+final 
 long tim
@@ -1087,16 +1087,22 @@
         
+final 
 Long tim
@@ -1125,32 +1125,38 @@
 rt;%0A            
+final 
 Optional%3CString%3E
@@ -1234,16 +1234,22 @@
         
+final 
 Optional

fix checkstyle