package com.dbs.consentServer.handler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.dbs.consentServer.util.CommonUtils;

/***
 * http start, end point
 * @author songjunekeun
 */
@Component
public class HttpInterceptor extends HandlerInterceptorAdapter {

  private final Logger logger = LoggerFactory.getLogger(this.getClass());
  
  /***
   * http start method
   * @author songjunekeun
   */
  @Override
  public boolean preHandle(HttpServletRequest request,
               HttpServletResponse response,
               Object handler) {
    logger.info("Before Method Time : " + CommonUtils.logTime());
    return true;
  }

  /***
   * http Executed method
   * @author songjunekeun
   */
  @Override
  public void postHandle( HttpServletRequest request,
              HttpServletResponse response,
              Object handler,
              ModelAndView modelAndView) {
    logger.info("Method Executed Time : " + CommonUtils.logTime());
  }
  
  /***
   * http Completed method
   * @author songjunekeun
   */
  @Override
  public void afterCompletion(HttpServletRequest request,
                HttpServletResponse response, 
                Object handler, 
                Exception ex) {
    logger.info("Method Completed Time : " + CommonUtils.logTime());
  }
}