The document provides an overview of Jersey, an open source framework for developing RESTful web services in Java. It describes how Jersey implements JAX-RS and supports developing resources using Java annotations like @Path, @GET and @Produces. Resources are POJOs that handle HTTP requests at specific URI paths. Jersey also supports object injection, sub-resources, response building and common deployment options like using Grizzly HTTP server.
8. "A JAX-RS resource is an annotated
POJO that provides so-called resource
methods that are able to handle HTTP
requests for URI paths that the resource
is bound to."
28. What's a "matrix param"?
http://www.w3.org/DesignIssues/MatrixURIs.html
Also, see Tim-Berners Lee on matrix param
design issues circa 1996...
acme.com/rest/samples/color;red=25;green=78;blue=192
Parameters separate by semi-colons, e.g.
Not widely used, supported (or known)
39. Scopes
Per-Request (default)
new instance created on each request
Per-lookup
new instance created on each lookup
(perhaps within same request)
Singleton
only one instance for entire app
41. Defines components of a JAX-RS
application, i.e. resources
Application class
Independent of deployment environment
JAX-RS apps provide concrete
implementation class
42. Simple Application
public class SampleApplication extends Application {
!
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<>();
!
classes.add(SampleResource.class);
classes.add(SimpleResource.class);
classes.add(UserResource.class);
!
return classes;
}
}
43. Jersey's implementation of Application
Jersey ResourceConfig
Extend or create programmatically
Provides additional features like
resource classpath scanning
44. Jersey ResourceConfig
public class SampleJerseyApp extends ResourceConfig {
!
public SampleJerseyApp() {
// scan classpath for resources
packages("com.acme.rest", "com.foo.services");
!
// register filters
register(CsrfProtectionFilter.class);
register(UriConnegFilter.class);
register(HttpMethodOverrideFilter.class);
!
// other configuration, etc.
}
}
48. public class Server {
public static final String BASE_URI = "http://localhost:8080/rest/";
!
public static HttpServer startServer() {
ResourceConfig config = new ResourceConfig()
.packages("com.acme.rest")
.register(CsrfProtectionFilter.class)
.register(UriConnegFilter.class)
.register(HttpMethodOverrideFilter.class);
!
// create a new Grizzly HTTP server rooted at BASE_URI
return GrizzlyHttpServerFactory
.createHttpServer(URI.create(BASE_URI), config);
}
!
public static void main(String[] args) throws Exception {
final HttpServer server = startServer();
System.out.printf("Jersey app started with WADL available at "
+ "%sapplication.wadlnHit enter to stop it...n", BASE_URI);
System.in.read();
server.shutdownNow();
}
}
Grizzly Server