A simple
throw new WebApplicationException(400);
or any other
throw new ...
Gets thrown by javax.ejb.EJBException with the Caused by: being the exception you just threw. When monitoring the log, this is a pain because not every exception prints a stack trace. But EJBException does that. >:(
Please understand – EJBException does not affect the application at all, only that it prints an unwanted stack trace with every thrown exception.
The EJBException javadoc says:
The EJBException is thrown to report that the invoked business method
or callback method could not be completed because of an unexpected
error (e.g. the instance failed to open a database connection).
There must be a way to keep EJBException quiet…
(Update) Example:
@Stateless
@Path("roads")
public class RoadsREST {
@PersistenceContext(unitName = "rd")
@GET
@Produces("application/json")
public List<NationalRoads> retrieve() {
CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
Root subs = cq.from(NationalRoads.class);
List<NationalRoads> roads = em.createQuery(cq).getResultList();
if (roads.isEmpty()) {
throw new WebApplicationException(404);
}
return roads;
}
}
Simplest solution would be to create a subclass of
WebApplicationExceptionand annotate it with@ApplicationException, like so:this should stop the Exceptions from appearing in your logfiles as well