View Javadoc
1   package info.ejava.examples.ejb.basic.webejb;
2   
3   import info.ejava.examples.ejb.basic.dto.Greeting;
4   
5   import info.ejava.examples.ejb.basic.dto.Name;
6   import info.ejava.examples.ejb.basic.ejb.BadRequestException;
7   import info.ejava.examples.ejb.basic.ejb.GreeterRemote;
8   
9   import java.util.Date;
10  
11  import javax.annotation.PostConstruct;
12  import javax.ejb.Stateless;
13  
14  import org.slf4j.Logger;
15  import org.slf4j.LoggerFactory;
16  
17  @Stateless
18  public class WebGreeterEJB implements GreeterRemote {
19      private static final Logger logger = LoggerFactory.getLogger(WebGreeterEJB.class);
20  
21      @PostConstruct
22      public void init() {
23          logger.info("*** WebGreeterEJB ***");
24      }
25      
26      /**
27       * This method is an example of a business method that can be invoked by
28       * users of this object (if a POJO) or bean (if deployed as an EJB).
29       */
30      @Override
31      public String sayHello(String name) throws BadRequestException {
32          logger.debug("sayHello({})", name);
33  
34          if (name == null || name.isEmpty()) {
35              throw new BadRequestException(
36                      "you must have a name for me to say hello");
37          }
38          return "hello " + name;
39      }
40  
41      /**
42       * This method is an example of a business method that
43       */
44      @Override
45      public Greeting sayHello(Name name) throws BadRequestException {
46          logger.debug("sayHello({})", name);
47  
48          if (name == null) {
49              throw new BadRequestException(
50                      "you must have a name for me to say hello");
51          }
52          return new Greeting(new Date(), 
53                  "hello " + name.getFirstName() + " " + name.getLastName());
54      }
55  
56  }