Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jboss.resteasy.cdi.interceptors;
  
  import java.util.HashMap;
  import java.util.Map;
  
 import  javax.enterprise.context.RequestScoped;
 

Author(s):
Ron Sigal
Version:
$Revision: 1.1 $ Copyright May 7, 2012
 
 @Path("/")
 @RequestScoped
 public class InterceptorResource
 {  
    static private Map<IntegerBookcollection = new HashMap<IntegerBook>();
    static private AtomicInteger counter = new AtomicInteger();
    @Inject private Logger log;
    @Inject private Stereotyped stereotyped;
 
    public void postConstruct()
    {
       .info("executing InterceptorResource.postConstruct()");
    }
    
    public void PreDestroy()
    {
       .info("executing InterceptorResource.PreDestroy()");
    }
    
    @POST
    @Path("create")
    @Interceptors ({Interceptor1.class})
    public Response createBook(Book book)
    {
       .info("entering InterceptorResource.createBook()");
       int id = .getAndIncrement();
       book.setId(id);
       .put(idbook);
       .info("stored: " + id + "->" + book);
       .info("leaving InterceptorResource.createBook()");
       return Response.ok(id).build();
    }
    
    @GET
    @Path("book/{id:[0-9][0-9]*}")
    @Interceptors ({Interceptor1.class})
    public Book lookupBookById(@PathParam("id"int id)
    {
       .info("entering InterceptorResource.lookupBookById(" + id + ")");
       .info("books: " + );
       Book book = .get(id);
       if (book == null)
       {
          throw new WebApplicationException(..);
       }
       .info("leaving InterceptorResource.lookupBookById(" + id + ")");
       return book;
    }
    
    
    @POST
    @Path("test")
    @Interceptors ({Interceptor1.class})
   public Response test()
   {
      .info("entering InterceptorResource.test()");
      .test();
      ArrayList<Class<?>> expectedList = new ArrayList<Class<?>>();
      expectedList.add(RequestFilterInterceptor.class);          // TestRequestFilter.filter()
      expectedList.add(Interceptor0.class);                      // BookReader.isReadable()
      expectedList.add(Interceptor2.class);                      // BookReader.isReadable()
      expectedList.add(BookReaderInterceptorInterceptor.class);  // BookReaderInterceptor.aroundReadFrom()
      expectedList.add(BookReaderInterceptor.class);             // BookReader.readFrom()
      expectedList.add(Interceptor0.class);                      // BookReader.readFrom()
      expectedList.add(Interceptor1.class);                      // BookReader.readFrom()
      expectedList.add(Interceptor2.class);                      // BookReader.readFrom()
      expectedList.add(Interceptor3.class);                      // BookReader.readFrom()
      expectedList.add(PostConstructInterceptor.class);          // InterceptorResource.postConstruct()
      expectedList.add(Interceptor0.class);                      // InterceptorResource.createBook()
      expectedList.add(Interceptor1.class);                      // InterceptorResource.createBook()
      expectedList.add(Interceptor2.class);                      // InterceptorResource.createBook()
      expectedList.add(Interceptor3.class);                      // InterceptorResource.createBook()
      expectedList.add(ResponseFilterInterceptor.class);         // TestResponseFilter.filter()
      expectedList.add(BookWriterInterceptorInterceptor.class);  // BookWriterInterceptor.aroundWriteTo()
      expectedList.add(BookWriterInterceptor.class);             // BookWriter.writeTo()
      expectedList.add(PreDestroyInterceptor.class);             // InterceptorResource.preDestroy()
      expectedList.add(RequestFilterInterceptor.class);          // TestRequestFilter.filter()
      expectedList.add(PostConstructInterceptor.class);          // InterceptorResource.postConstruct()
      expectedList.add(Interceptor0.class);                      // InterceptorResource.lookBookById()
      expectedList.add(Interceptor1.class);                      // InterceptorResource.lookBookById()
      expectedList.add(Interceptor2.class);                      // InterceptorResource.lookBookById()
      expectedList.add(Interceptor3.class);                      // InterceptorResource.lookBookById()
      expectedList.add(ResponseFilterInterceptor.class);         // TestResponseFilter.filter()
      expectedList.add(Interceptor0.class);                      // BookWriter.isWriteable()
      expectedList.add(Interceptor2.class);                      // BookWriter.isWriteable()
      expectedList.add(Interceptor0.class);                      // BookWriter.getSize()
      expectedList.add(Interceptor2.class);                      // BookWriter.getSize()
      expectedList.add(BookWriterInterceptorInterceptor.class);  // BookWriterInterceptor.aroundWriteTo()
      expectedList.add(BookWriterInterceptor.class);             // BookWriter.writeTo()
      expectedList.add(Interceptor0.class);                      // BookWriter.writeTo()
      expectedList.add(Interceptor1.class);                      // BookWriter.writeTo()
      expectedList.add(Interceptor2.class);                      // BookWriter.writeTo()
      expectedList.add(Interceptor3.class);                      // BookWriter.writeTo()
      expectedList.add(PreDestroyInterceptor.class);             // InterceptorResource.preDestroy()
      expectedList.add(Interceptor0.class);                      // BookReader.isReadable()
      expectedList.add(Interceptor2.class);                      // BookReader.isReadable()
      expectedList.add(BookReaderInterceptorInterceptor.class);  // BookReaderInterceptor.aroundReadFrom()
      expectedList.add(BookReaderInterceptor.class);             // BookReader.readFrom()
      expectedList.add(Interceptor0.class);                      // BookReader.readFrom()
      expectedList.add(Interceptor1.class);                      // BookReader.readFrom()
      expectedList.add(Interceptor2.class);                      // BookReader.readFrom()
      expectedList.add(Interceptor3.class);                      // BookReader.readFrom()
      expectedList.add(PostConstructInterceptor.class);          // InterceptorResource.postConstruct()
      expectedList.add(Interceptor0.class);                      // InterceptorResource.test()
      expectedList.add(Interceptor1.class);                      // InterceptorResource.test()
      expectedList.add(Interceptor2.class);                      // InterceptorResource.test()
      expectedList.add(Interceptor3.class);                      // InterceptorResource.test()
      expectedList.add(Interceptor2.class);                      // Stereotyped.test()
      expectedList.add(Interceptor3.class);                      // Stereotyped.test()
      
      ArrayList<ObjectvisitList = VisitList.getList();
      boolean status = expectedList.size() == visitList.size();
      if (!status)
      {
         .info("expectedList.size() [" + expectedList.size() + "] != visitList.size() [" + visitList.size() + "]");
      }
      for (int i = 0; i < expectedList.size(); i++)
      {
         if (!expectedList.get(i).isAssignableFrom(visitList.get(i).getClass()))
         {
            status = false;
            .info("visitList.get(" + i + ") incorrect: should be an instance of: " + expectedList.get(i) + ", is: " + visitList.get(i));
            break;
         }
      }
      if (!status)
      {
         .info("\rexpected list:");
         for (int i = 0; i < expectedList.size(); i++)
         {
            .info(i + ": " + expectedList.get(i).toString());
         }
         .info("\rvisited list:");
         for (int i = 0; i < visitList.size(); i++)
         {
            .info(i + ": " + visitList.get(i).toString());
         }
      }
      .info("leaving InterceptorResource.test()");
      return status ? Response.ok().build() : Response.serverError().build();
   }
New to GrepCode? Check out our FAQ X