pedruhenrik 11 de jul. de 2011
qual versão do vraptor vc usa?
eu estou utilizando 3.3.1 e minha classe fica da seguinte maneira:
import br.com.caelum.vraptor.Result ;
import br.com.caelum.vraptor.core.RequestInfo ;
import br.com.caelum.vraptor.http.route.ResourceNotFoundException ;
import br.com.caelum.vraptor.http.route.Router ;
import br.com.caelum.vraptor.ioc.Component ;
import br.com.caelum.vraptor.ioc.RequestScoped ;
import br.com.caelum.vraptor.resource.DefaultResourceNotFoundHandler ;
import br.com.caelum.vraptor.resource.HttpMethod ;
@Component
@RequestScoped
public class Url extends DefaultResourceNotFoundHandler {
private final Router router ;
private final Result result ;
public Url ( Router router , Result result ) {
this . router = router ;
this . result = result ;
}
@Override
public void couldntFind ( RequestInfo requestInfo ) {
try {
String uri = requestInfo . getRequestedUri ();
if ( uri . endsWith ( "/" )) {
tryMovePermanentlyTo ( requestInfo ,
uri . substring ( 0 , uri . length () - 1 ));
} else {
tryMovePermanentlyTo ( requestInfo , uri + "/" );
}
} catch ( ResourceNotFoundException ex ) {
super . couldntFind ( requestInfo );
}
}
private void tryMovePermanentlyTo ( RequestInfo requestInfo , String newUri ) {
router . parse ( newUri , HttpMethod . of ( requestInfo . getRequest ()),
requestInfo . getRequest ());
result . permanentlyRedirectTo ( newUri );
}
}
att,
atilaraphael 11 de jul. de 2011
Olá pedruhenrik, eu também utilizo a versão 3.3.1
veja as minhas libs.
Lucas_Cavalcanti 11 de jul. de 2011
qual erro está acontecendo?
atilaraphael 11 de jul. de 2011
Olá Lucas,
na primeira mensagem eu coloquei uma imagem em anexo, lá na linha 39 ta dando um erro, parece que são tipos incompatíveis. O pedruhenrik passou o código acima, mas deu o mesmo erro.
Olha o erro na imagem abaixo
Obs.: Estou usando Tomcat 7
Lucas_Cavalcanti 11 de jul. de 2011
posta o código aqui, entre e , não a imagem
atilaraphael 11 de jul. de 2011
O código está assim
import br.com.caelum.vraptor.Result ;
import br.com.caelum.vraptor.core.RequestInfo ;
import br.com.caelum.vraptor.http.route.ResourceNotFoundException ;
import br.com.caelum.vraptor.http.route.Router ;
import br.com.caelum.vraptor.ioc.Component ;
import br.com.caelum.vraptor.ioc.RequestScoped ;
import br.com.caelum.vraptor.resource.DefaultResourceNotFoundHandler ;
import br.com.caelum.vraptor.resource.HttpMethod ;
@Component
@RequestScoped
public class Error404 extends DefaultResourceNotFoundHandler {
private final Router router ;
private final Result result ;
public Error404 ( Router router , Result result ) {
this . router = router ;
this . result = result ;
}
@Override
public void couldntFind ( RequestInfo requestInfo ) {
try {
String uri = requestInfo . getRequestedUri ();
if ( uri . endsWith ( "/" )) {
tryMovePermanentlyTo ( requestInfo , uri . substring ( 0 , uri . length () - 1 ));
} else {
tryMovePermanentlyTo ( requestInfo , uri + "/" );
}
} catch ( ResourceNotFoundException ex ) {
super . couldntFind ( requestInfo );
}
}
private void tryMovePermanentlyTo ( RequestInfo requestInfo , String newUri ) {
router . parse ( newUri , HttpMethod . of ( requestInfo . getRequest ()), requestInfo . getRequest ());
result . permanentlyRedirectTo ( newUri );
}
}
Se eu tentar rodar da o seguinte erro no browser
org . springframework . beans . factory . UnsatisfiedDependencyException : Error creating bean with name 'resourceLookupInterceptor' : Unsatisfied dependency expressed through constructor argument with index 2 of type [ br . com . caelum . vraptor . resource . ResourceNotFoundHandler ]: : Error creating bean with name 'error404' : Instantiation of bean failed ; nested exception is org . springframework . beans . BeanInstantiationException : Could not instantiate bean class [ net . newtecnologia . newbusca . erro . Error404 ]: Constructor threw exception ; nested exception is java . lang . Error : Unresolved compilation problems :
The type javax . servlet . http . HttpServletRequest cannot be resolved . It is indirectly referenced from required . class files
The method of ( HttpServletRequest ) from the type HttpMethod refers to the missing type HttpServletRequest
; nested exception is org . springframework . beans . factory . BeanCreationException : Error creating bean with name 'error404' : Instantiation of bean failed ; nested exception is org . springframework . beans . BeanInstantiationException : Could not instantiate bean class [ net . newtecnologia . newbusca . erro . Error404 ]: Constructor threw exception ; nested exception is java . lang . Error : Unresolved compilation problems :
The type javax . servlet . http . HttpServletRequest cannot be resolved . It is indirectly referenced from required . class files
The method of ( HttpServletRequest ) from the type HttpMethod refers to the missing type HttpServletRequest
org . springframework . beans . factory . support . ConstructorResolver . createArgumentArray ( ConstructorResolver . java : 730 )
org . springframework . beans . factory . support . ConstructorResolver . autowireConstructor ( ConstructorResolver . java : 196 )
org . springframework . beans . factory . support . AbstractAutowireCapableBeanFactory . autowireConstructor ( AbstractAutowireCapableBeanFactory . java : 1003 )
org . springframework . beans . factory . support . AbstractAutowireCapableBeanFactory . createBeanInstance ( AbstractAutowireCapableBeanFactory . java : 907 )
org . springframework . beans . factory . support . AbstractAutowireCapableBeanFactory . doCreateBean ( AbstractAutowireCapableBeanFactory . java : 485 )
org . springframework . beans . factory . support . AbstractAutowireCapableBeanFactory . createBean ( AbstractAutowireCapableBeanFactory . java : 456 )
org . springframework . beans . factory . support . AbstractBeanFactory $ 2. getObject ( AbstractBeanFactory . java : 329 )
org . springframework . web . context . request . AbstractRequestAttributesScope . get ( AbstractRequestAttributesScope . java : 43 )
org . springframework . beans . factory . support . AbstractBeanFactory . doGetBean ( AbstractBeanFactory . java : 325 )
org . springframework . beans . factory . support . AbstractBeanFactory . getBean ( AbstractBeanFactory . java : 194 )
org . springframework . beans . factory . support . DefaultListableBeanFactory . getBean ( DefaultListableBeanFactory . java : 263 )
org . springframework . context . support . AbstractApplicationContext . getBean ( AbstractApplicationContext . java : 1083 )
br . com . caelum . vraptor . ioc . spring . SpringBasedContainer . instanceFor ( SpringBasedContainer . java : 86 )
br . com . caelum . vraptor . core . ToInstantiateInterceptorHandler . execute ( ToInstantiateInterceptorHandler . java : 47 )
br . com . caelum . vraptor . core . DefaultInterceptorStack . next ( DefaultInterceptorStack . java : 54 )
br . com . caelum . vraptor . core . EnhancedRequestExecution . execute ( EnhancedRequestExecution . java : 23 )
br . com . caelum . vraptor . VRaptor $ 1. insideRequest ( VRaptor . java : 92 )
br . com . caelum . vraptor . ioc . spring . SpringProvider . provideForRequest ( SpringProvider . java : 58 )
br . com . caelum . vraptor . VRaptor . doFilter ( VRaptor . java : 89 )
Lucas_Cavalcanti 11 de jul. de 2011
bizarro ele não ter o httpservletRequest… tenta colocar a servlet-api.jar no seu WEB-INF/lib (não deveria precisar, mas enfim)
atilaraphael 11 de jul. de 2011
Muito obrigado Lucas, funcionou perfeitamente.