Services
The application is a class extending the Application
class, and it declares the root HTTP path that a client will use through the @ApplicationPath
annotation. Here's a sample of the application:
@ApplicationPath("/services") publicclass CalculatorApplication extends Application { @Override public Set<Class<?>> getClasses() { final Set<Class<?>> classes = new HashSet<>(); ... classes.add(Calculator.class); returnclasses; } ... }
The getClasses()
method contains all the components and services used in the application.
The REST services are beans annotated with the JAX-RS annotations. These services can be declared along with the other enterprise components, such as servlets or EJB. The REST services must be contained in an application. In this sample, we see a stateless REST service:
@Path("/calculator") @Stateless publicclass Calculator { @GET @Path("/sum") @Produces(MediaType.TEXT_PLAIN) publicdouble...