Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jboss.resteasy.cdi.ejb;
  
  import java.util.HashMap;
  
  import javax.ejb.EJB;
  import  javax.enterprise.context.Dependent;
 

Author(s):
Ron Sigal
Version:
$Revision: 1.1 $ Copyright Jun 29, 2012
 
 @Dependent
 @Path("/")
 public class EJBBookResource implements EJBLocalResourceEJBRemoteResource
 {
    private static HashMap<Integer,Bookbooks = new HashMap<Integer,Book>();
    
    @Inject private Logger log;
    @Inject private Utilities utilities;
    @Inject @CounterBinding private Counter counter;
    
    @Inject private EJBBookReader readerCDI;     // EJBBookReaderImpl implements @Local interface EJBBookReader
    @EJB    private EJBBookReader readerEJB;
    @Inject private EJBBookWriterImpl writerCDI// EJBBookWriterImpl has a no-interface view
    @EJB    private EJBBookWriterImpl writerEJB;
    
    @GET
    @Override
    @Path("verifyScopes")
    public int verifyScopes()
    {
       .info("entering verifyScopes()");
       .info("EJBBookReader scope:      " + .getScope(EJBBookReader.class));
       .info("EJBBookReaderImpl scope:  " + .getScope(EJBBookReaderImpl.class));
       .info("EJBBookWriterImpl scope:  " + .getScope(EJBBookWriterImpl.class));
       .info("EJBLocalResource scope:   " + .getScope(EJBLocalResource.class));
       .info("EJBRemoteResource scope:  " + .getScope(EJBRemoteResource.class));
       .info("EJBBookResource scope:    " + .getScope(EJBBookResource.class));
       
       boolean result = true;
       result &= .isApplicationScoped(EJBBookReader.class);
       result &= .isApplicationScoped(EJBBookWriterImpl.class);
       result &= .isDependentScoped(EJBLocalResource.class);
       return result ? 200 : 500;
    }
    
    @GET
    @Override
    @Path("verifyInjection")
    public int verifyInjection()
    {
       .info("entering verifyInjection()");
       .info("readerCDI: " + );
       .info("readerEJB: " + );
       .info("writerCDI: " + );
       .info("writerEJB: " + );
       
       boolean result = true;
       result &=  != null;
       result &=  != null;
       result &=  != null;
       result &=  != null;
       return result ? 200 : 500;
    }
 
    @POST
    @Path("create")
    public int createBook(Book book)
    {
       .info("entering createBook()");
       int id = .getNext();
       book.setId(id);
       .put(idbook);  
       .info("stored: " + id + "->" + book); 
       return id;
    }
    
    @GET
    @Path("book/{id:[0-9][0-9]*}")
   public Book lookupBookById(@PathParam("id"int id)
   {
      .info("entering lookupBookById(" + id + ")");
      .info("books: " + );
      Book book = .get(id);
      if (book == null)
      {
         throw new WebApplicationException(..);
      }
      return book;
   }
   
   @GET
   @Path("uses/{count}")
   public int testUse(@PathParam("count"int count)
   {
      .info("entering testUse()");
      .info("readerEJB uses: " + .getUses());
      .info("writerEJB uses: " + .getUses());
      .info("readerCDI uses: " + .getUses());
      .info("writerCDI uses: " + .getUses());
      int readerUses = .getUses();
      int writerUses = .getUses();
      .reset();
      .reset();
      return (readerUses == count && writerUses == count) ? 200 : 500;
   }
   
   @GET
   @Path("reset")
   public void reset()
   {
      .info("entering reset()");
      .reset();
   }
New to GrepCode? Check out our FAQ X