Olá pessoal. O que achei que ia ser uma aplicação simples está sendo a mais complicada hehe. É o seguinte: eu programava antes na ide NetBeans e tudo ia muito bem. Eu criei um sistema no netbeans com os frameworks: Hibernate e VRaptor. Hoje em dia estou programando na ide MyEclipse e criei um projeto com os mesmos frameworks e ainda criei outro que está dando o mesmo erro com: Hibernate + Spring e VRaptor. O erro é que para a manipulação de logins eu uso filtros normais e no netbeans funcionava muito bem quando eu tentava acessar um jsp ou um método do vraptor que eu uso a extensão .brz de costume. Só que nessas aplicações que usei o myeclipse, ele funciona perfeitamente com jsps mais quando é um método do vraptor com extensão .brz ele não funciona o código response.sendRedirect("…");.
Por exemplo:
Deixo um filtro bloqueando a pasta admin para usuários que não estão na session.
se eu acesso assim: http://localhost:8080/exemplo/admin/pagina.jsp ele barra e faz o sendRedirect.
mas se eu fasso assim: http://localhost:8080/exemplo/admin/metodo.brz ele é filtrado, mas não da o sendRedirect.
Filtro:
package com.redirect.filtros;
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;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class ManipulaLogin implements Filter {
public void init(FilterConfig filterConfig) throws ServletException {
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpSession session = ((HttpServletRequest) request).getSession();
String NomeUsuario = (String) session.getAttribute("NomeUsuario");
if (NomeUsuario == null) {
((HttpServletResponse) response).sendRedirect("/redirect");
} else {
chain.doFilter(request, response);
}
}
public void destroy() {
}
}
web.xml:
<filter>
<filter-name>vraptor</filter-name>
<filter-class>br.com.caelum.vraptor.VRaptor</filter-class>
</filter>
<filter>
<filter-name>ManipulaLogin</filter-name>
<filter-class>com.redirect.filtros.ManipulaLogin</filter-class>
</filter>
<filter-mapping>
<filter-name>vraptor</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>ManipulaLogin</filter-name>
<url-pattern>/admin/*</url-pattern>
</filter-mapping>
O que aparece no console quando digito algo.brz em uma pasta bloqueada sem estar logado:
16:41:54,232 DEBUG [VRaptor ] VRaptor received a new request
16:41:54,451 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ResourceLookupInterceptor
16:41:54,451 DEBUG [DefaultResourceTranslator] trying to access /admin/estabelecimentos.brz
16:41:54,462 DEBUG [DefaultResourceTranslator] found resource [DefaultResourceMethod: EstabelecimentoController.estabelecimentosEstabelecimentoController.estabelecimentos()]
16:41:54,496 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ExceptionHandlerInterceptor
16:41:54,507 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor FlashInterceptor
16:41:54,584 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor InstantiateInterceptor
16:41:54,591 INFO [ClassPathXmlApplicationContext] Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@431693: startup date [Mon Nov 28 16:41:54 BRST 2011]; root of context hierarchy
16:41:54,595 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from class path resource [applicationContext.xml]
16:41:54,632 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2a730e: defining beans [dataSource,sessionFactory,SitesDAO,MensagemDAO,VisitasDAO,EstabelecimentoDAO,CidadesDAO,LoginDAO]; root of factory hierarchy
16:41:54,690 INFO [AnnotationSessionFactoryBean] Building new Hibernate SessionFactory
16:41:54,773 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ExecuteMethodInterceptor
16:41:54,773 DEBUG [ExecuteMethodInterceptor] Invoking EstabelecimentoController.estabelecimentos()
16:41:55,069 DEBUG [DefaultPageResult ] forwarding to /admin/estabelecimentos.jsp
16:41:55,074 DEBUG [DefaultStaticContentHandler] Deferring request to container: /redirect/admin/estabelecimentos.jsp
28/11/2011 16:41:55 org.apache.jasper.compiler.TldLocationsCache tldScanJar
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
16:41:57,503 INFO [ClassPathXmlApplicationContext] Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1eeeaed: startup date [Mon Nov 28 16:41:57 BRST 2011]; root of context hierarchy
16:41:57,504 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from class path resource [applicationContext.xml]
16:41:57,538 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@f82fe7: defining beans [dataSource,sessionFactory,SitesDAO,MensagemDAO,VisitasDAO,EstabelecimentoDAO,CidadesDAO,LoginDAO]; root of factory hierarchy
16:41:57,580 INFO [AnnotationSessionFactoryBean] Building new Hibernate SessionFactory
16:41:58,055 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ForwardToDefaultViewInterceptor
16:41:58,055 DEBUG [ForwardToDefaultViewInterceptor] Request already dispatched and commited somewhere else, not forwarding.
16:41:58,080 DEBUG [VRaptor ] VRaptor ended the request
16:41:58,084 DEBUG [VRaptor ] VRaptor received a new request
16:41:58,092 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ResourceLookupInterceptor
16:41:58,092 DEBUG [DefaultResourceTranslator] trying to access /admin/Scripts/swfobject_modified.js
16:41:58,093 DEBUG [VRaptor ] VRaptor ended the request
16:41:58,102 DEBUG [VRaptor ] VRaptor received a new request
16:41:58,111 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ResourceLookupInterceptor
16:41:58,111 DEBUG [DefaultResourceTranslator] trying to access /
16:41:58,111 DEBUG [VRaptor ] VRaptor received a new request
16:41:58,116 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ResourceLookupInterceptor
16:41:58,117 DEBUG [DefaultResourceTranslator] trying to access /index
16:41:58,117 DEBUG [DefaultResourceTranslator] found resource [DefaultResourceMethod: RedirectController.indexRedirectController.index()]
16:41:58,122 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ExceptionHandlerInterceptor
16:41:58,125 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor FlashInterceptor
16:41:58,144 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor InstantiateInterceptor
16:41:58,157 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ExecuteMethodInterceptor
16:41:58,157 DEBUG [ExecuteMethodInterceptor] Invoking RedirectController.index()
16:41:58,157 INFO [ClassPathXmlApplicationContext] Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1944ae: startup date [Mon Nov 28 16:41:58 BRST 2011]; root of context hierarchy
16:41:58,157 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from class path resource [applicationContext.xml]
16:41:58,185 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1ebf1eb: defining beans [dataSource,sessionFactory,SitesDAO,MensagemDAO,VisitasDAO,EstabelecimentoDAO,CidadesDAO,LoginDAO]; root of factory hierarchy
16:41:58,223 INFO [AnnotationSessionFactoryBean] Building new Hibernate SessionFactory
16:41:58,363 DEBUG [DefaultPageResult ] forwarding to /index.brz
16:41:58,363 DEBUG [VRaptor ] VRaptor received a new request
16:41:58,367 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ResourceLookupInterceptor
16:41:58,367 DEBUG [DefaultResourceTranslator] trying to access /index.brz
16:41:58,368 DEBUG [DefaultResourceTranslator] found resource [DefaultResourceMethod: RedirectController.indexbrzRedirectController.indexbrz()]
16:41:58,368 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ExceptionHandlerInterceptor
16:41:58,369 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor FlashInterceptor
16:41:58,370 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor InstantiateInterceptor
16:41:58,374 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ExecuteMethodInterceptor
16:41:58,374 DEBUG [ExecuteMethodInterceptor] Invoking RedirectController.indexbrz()
16:41:58,374 INFO [ClassPathXmlApplicationContext] Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@777255: startup date [Mon Nov 28 16:41:58 BRST 2011]; root of context hierarchy
16:41:58,374 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from class path resource [applicationContext.xml]
16:41:58,406 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@b1656f: defining beans [dataSource,sessionFactory,SitesDAO,MensagemDAO,VisitasDAO,EstabelecimentoDAO,CidadesDAO,LoginDAO]; root of factory hierarchy
16:41:58,442 INFO [AnnotationSessionFactoryBean] Building new Hibernate SessionFactory
16:41:58,499 DEBUG [DefaultPageResult ] forwarding to /index.jsp
16:41:58,499 DEBUG [DefaultStaticContentHandler] Deferring request to container: /redirect/index.jsp
16:41:58,698 INFO [ClassPathXmlApplicationContext] Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1509443: startup date [Mon Nov 28 16:41:58 BRST 2011]; root of context hierarchy
16:41:58,699 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from class path resource [applicationContext.xml]
16:41:58,723 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1be9d36: defining beans [dataSource,sessionFactory,SitesDAO,MensagemDAO,VisitasDAO,EstabelecimentoDAO,CidadesDAO,LoginDAO]; root of factory hierarchy
16:41:58,936 INFO [AnnotationSessionFactoryBean] Building new Hibernate SessionFactory
16:41:58,982 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ForwardToDefaultViewInterceptor
16:41:58,982 DEBUG [ForwardToDefaultViewInterceptor] Request already dispatched and commited somewhere else, not forwarding.
16:41:58,982 DEBUG [VRaptor ] VRaptor ended the request
16:41:58,983 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ForwardToDefaultViewInterceptor
16:41:58,983 DEBUG [ForwardToDefaultViewInterceptor] Request already dispatched and commited somewhere else, not forwarding.
16:41:58,983 DEBUG [VRaptor ] VRaptor ended the request
16:41:58,983 DEBUG [VRaptor ] VRaptor ended the request
O que aparece quando tento com um jsp:
16:42:46,656 DEBUG [DefaultStaticContentHandler] Deferring request to container: /redirect/admin/estabelecimentos.jsp
16:42:46,656 DEBUG [VRaptor ] VRaptor received a new request
16:42:46,674 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ResourceLookupInterceptor
16:42:46,674 DEBUG [DefaultResourceTranslator] trying to access /
16:42:46,675 DEBUG [VRaptor ] VRaptor received a new request
16:42:46,680 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ResourceLookupInterceptor
16:42:46,680 DEBUG [DefaultResourceTranslator] trying to access /index
16:42:46,680 DEBUG [DefaultResourceTranslator] found resource [DefaultResourceMethod: RedirectController.indexRedirectController.index()]
16:42:46,686 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ExceptionHandlerInterceptor
16:42:46,688 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor FlashInterceptor
16:42:46,702 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor InstantiateInterceptor
16:42:46,705 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ExecuteMethodInterceptor
16:42:46,705 DEBUG [ExecuteMethodInterceptor] Invoking RedirectController.index()
16:42:46,705 INFO [ClassPathXmlApplicationContext] Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@de5f5: startup date [Mon Nov 28 16:42:46 BRST 2011]; root of context hierarchy
16:42:46,705 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from class path resource [applicationContext.xml]
16:42:46,733 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1ed4d06: defining beans [dataSource,sessionFactory,SitesDAO,MensagemDAO,VisitasDAO,EstabelecimentoDAO,CidadesDAO,LoginDAO]; root of factory hierarchy
16:42:46,766 INFO [AnnotationSessionFactoryBean] Building new Hibernate SessionFactory
16:42:46,820 DEBUG [DefaultPageResult ] forwarding to /index.brz
16:42:46,821 DEBUG [VRaptor ] VRaptor received a new request
16:42:46,829 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ResourceLookupInterceptor
16:42:46,829 DEBUG [DefaultResourceTranslator] trying to access /index.brz
16:42:46,829 DEBUG [DefaultResourceTranslator] found resource [DefaultResourceMethod: RedirectController.indexbrzRedirectController.indexbrz()]
16:42:46,830 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ExceptionHandlerInterceptor
16:42:46,831 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor FlashInterceptor
16:42:46,832 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor InstantiateInterceptor
16:42:46,833 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ExecuteMethodInterceptor
16:42:46,833 DEBUG [ExecuteMethodInterceptor] Invoking RedirectController.indexbrz()
16:42:46,834 INFO [ClassPathXmlApplicationContext] Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1871a69: startup date [Mon Nov 28 16:42:46 BRST 2011]; root of context hierarchy
16:42:46,834 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from class path resource [applicationContext.xml]
16:42:46,857 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@351f6d: defining beans [dataSource,sessionFactory,SitesDAO,MensagemDAO,VisitasDAO,EstabelecimentoDAO,CidadesDAO,LoginDAO]; root of factory hierarchy
16:42:46,890 INFO [AnnotationSessionFactoryBean] Building new Hibernate SessionFactory
16:42:46,940 DEBUG [DefaultPageResult ] forwarding to /index.jsp
16:42:46,941 DEBUG [DefaultStaticContentHandler] Deferring request to container: /redirect/index.jsp
16:42:46,957 INFO [ClassPathXmlApplicationContext] Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@c4b664: startup date [Mon Nov 28 16:42:46 BRST 2011]; root of context hierarchy
16:42:46,958 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from class path resource [applicationContext.xml]
16:42:46,981 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1ae9565: defining beans [dataSource,sessionFactory,SitesDAO,MensagemDAO,VisitasDAO,EstabelecimentoDAO,CidadesDAO,LoginDAO]; root of factory hierarchy
16:42:47,015 INFO [AnnotationSessionFactoryBean] Building new Hibernate SessionFactory
16:42:47,064 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ForwardToDefaultViewInterceptor
16:42:47,064 DEBUG [ForwardToDefaultViewInterceptor] Request already dispatched and commited somewhere else, not forwarding.
16:42:47,065 DEBUG [VRaptor ] VRaptor ended the request
16:42:47,065 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ForwardToDefaultViewInterceptor
16:42:47,065 DEBUG [ForwardToDefaultViewInterceptor] Request already dispatched and commited somewhere else, not forwarding.
16:42:47,065 DEBUG [VRaptor ] VRaptor ended the request
16:42:47,066 DEBUG [VRaptor ] VRaptor ended the request
Obrigado pessoal!