Boa tarde, pessoal.
Estou com um problema para definir um filtro aqui (exercício 10.2 da apostila fj-21 da Caelum): ele está no pacote br.com.caelum.filtro, e mapeei tudo no web.xml conforme indicado na apostila, porém, quando faço alguma alteração em qualquer contato, não é gerada a saída no console gerada pela classe de filtro.
Seguem códigos abaixo.
package br.com.caelum.filtro;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
public class FiltroTempoDeExecucao implements Filter {
@Override
public void destroy() {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
long tempoInicial = System.currentTimeMillis();
chain.doFilter(request, response);
long tempoFinal = System.currentTimeMillis();
String uri = ((HttpServletRequest)request).getRequestURI();
System.out.println("Tempo de execução de " + uri + " demorou (ms): " +
(tempoFinal - tempoInicial));
}
@Override
public void init(FilterConfig arg0) throws ServletException {
}
}
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" metadata-complete="true" version="3.0">
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<filter>
<filter-name>cronometro</filter-name>
<filter-class>br.com.caelum.filtro.FiltroTempoDeExecucao</filter-class>
</filter>
<filter-mapping>
<filter-name>cronometro</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>controlador</servlet-name>
<servlet-class>br.com.caelum.mvc.ControllerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>controlador</servlet-name>
<url-pattern>/mvc</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>AdicionaContato</servlet-name>
<servlet-class>br.com.caelum.servlet.AdicionaContatoServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdicionaContato</servlet-name>
<url-pattern>/adicionaContato</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>servletOiMundo</servlet-name>
<servlet-class>br.com.caelum.servlet.OiMundo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>servletOiMundo</servlet-name>
<url-pattern>/oi</url-pattern>
</servlet-mapping>
</web-app>
Como pode ser visto no código da classe FiltroTempoDeExecucao, o co´digo geraria uma saída no console, e pelo web.xml, da pra ver que qualquer requisição passa pelo filtro antes.
O que acontece é que não é gerada saída alguma no console quando executo a página de alteração de contatos. O problema é que não gera erro algum, apenas parece que o filtro não existe mesmo. Estou há 2 horas tentando encontrar o problema aqui, e até agora nada. Se alguem conseguir identificar qual o problema, fico muito agradecido.
Um grande abraço a todos.