@Context is what I used in the code example. It still didn't work. I only get
null in the interceptor.

package test.tomee.interceptor;

import java.util.Arrays;

import javax.enterprise.context.RequestScoped;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Context;

@InterceptMe @Interceptor
@RequestScoped
public class TestInterceptor {
        
        
        @Context        HttpServletRequest request;

        @AroundInvoke
        public Object logStuff(InvocationContext ctx) throws Exception {
                System.out.println("In interceptor");
                System.out.println("calling method: " + ctx.getMethod());
                System.out.println("arguments are: " +
Arrays.toString(ctx.getParameters()));
                System.out.println("request headers are: " + ( request !=null ?
request.getHeaderNames().toString(): "null"));
                Object returnValue = ctx.proceed();
                System.out.println("called method: " + ctx.getMethod());
                return returnValue;
        }
}

---

package test.tomee.interceptor;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
import javax.interceptor.InterceptorBinding;

@InterceptorBinding
@Target({ TYPE, METHOD })
@Retention(RUNTIME)
public @interface InterceptMe {
}

---

package test.tomee.webservice;

import javax.enterprise.context.RequestScoped;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import test.tomee.interceptor.InterceptMe;

@InterceptMe
@RequestScoped
@Path("/test")
public class TestService {

        
        @GET
        @Path("/sayHello")
        @Produces("text/plain")
        public String sayHello()
        {
                return "hello";
        }
}

--

<beans>
 <interceptors>
    <class>test.tomee.interceptor.TestInterceptor</class>
  </interceptors>
</beans>

--






--
View this message in context: 
http://openejb.979440.n4.nabble.com/Custom-Security-for-REST-tp4660361p4660383.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Reply via email to