View Javadoc
1   package info.ejava.examples.jaxrs.todos.rs;
2   
3   import javax.ejb.Stateless;
4   import javax.ejb.TransactionAttribute;
5   import javax.ejb.TransactionAttributeType;
6   
7   import info.ejava.examples.jaxrs.todos.ejb.InternalErrorException;
8   import info.ejava.examples.jaxrs.todos.ejb.InvalidRequestException;
9   
10  @Stateless
11  public class GreetingEJB {
12      @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
13      public String greet(String name) throws InvalidRequestException {
14          try {
15              if (name==null || name.isEmpty()) {
16                  throw new InvalidRequestException("Unable to greet, name not supplied");
17              }
18              
19              return String.format("hello %s", name);  //core business code
20              
21          } catch (RuntimeException ex) {
22              throw new InternalErrorException("Internal error greeting name[%s]: %s", name, ex);
23          }
24      }
25  }