I have a restful web service (using spring-jersey, spring 4.1.4, jersey 2.14) ,
@POST
@Path("myPath")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.TEXT_HTML })
@CustomAnnotation
public Response myMethod(@Context HttpServletRequest request){
}
and I have a spring AOP Advice
@Aspect
@Component
public class MyAdvice {
@Before(" @annotation(CustomAnnotation)")
public void checkSomething(JoinPoint jp) throws AppException {
for (Object o : jp.getArgs()) {
if(o instanceof HttpServletRequest){
// do something
}
}
}
my question is instead of passing HttpServletRequest as method parameter, can I get access to HttpServletRequest from inside of my AOP somehow?
i've tried
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest();
inside checkSomething method, and it throws an exception
"org.glassfish.jersey.server.spring.scope.JaxrsRequestAttributes cannot be cast to org.springframework.web.context.request.ServletRequestAttributes"
Thank you guys in advance.
Aucun commentaire:
Enregistrer un commentaire