package demojsoncrud.servlets;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebFilter("/*")
public class RequestFilter implements Filter, ServletContextListener {

  @Override
  public void init(FilterConfig filterConfig) throws ServletException {

  }

  @Override
  public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
    System.out.println("Filter");
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;
    System.out.println("req URI ==> " + request.getRequestURI());

    System.out.println("req Path ==> " + request.getContextPath());

    String login = request.getContextPath() + "/vistas/index.jsp";
    String assets = request.getContextPath() + "/plantilla/assets";
    String css = request.getContextPath() + "/plantilla/css";
    String js = request.getContextPath() + "/plantilla/js";

    chain.doFilter(request, response);

  }

  @Override
  public void destroy() {

  }

  @Override
  public void contextInitialized(ServletContextEvent sce) {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  }

  @Override
  public void contextDestroyed(ServletContextEvent sce) {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  }

}
