SlideShare a Scribd company logo
1 of 62
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
1
JAX-RS 2.0: New and
Noteworthy in RESTful
Web Services API
Arun Gupta
Java EE & GlassFish Guy
blogs.oracle.com/arungupta, @arungupta
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
2
JAX-RS - Java API for RESTful Services
Ā§ļ‚§ā€Æ POJO-Based Resource Classes
Ā§ļ‚§ā€Æ HTTP Centric Programming Model
Ā§ļ‚§ā€Æ Entity Format Independence
Ā§ļ‚§ā€Æ Container Independence
Ā§ļ‚§ā€Æ Included in Java EE
Standard annotation-driven API
that aims to help developers
build RESTful Web services and clients
in Java
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
3
Example: JAX-RS API
@Path("/atm/{cardId}")	
public class AtmService {	
	
@GET @Path("/balance")	
@Produces("text/plain")	
public String balance(@PathParam("cardId") String card,	
@QueryParam("pin") String pin) {	
return Double.toString(getBalance(card, pin));	
}	
	
ā€¦	
	
Built-in
Serialization
Resources
URI Parameter
Injection
HTTP Method
Binding
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
4
Example: JAX-RS API (contd.)
ā€¦	
	
@POST @Path("/withdrawal")	
@Consumes("text/plain") 	
@Produces("application/json")	
public Money withdraw(@PathParam("card") String card,	
@QueryParam("pin") String pin, 	
String amount){	
return getMoney(card, pin, amount);	
}	
}	
Custom Serialization
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
5
Example: JAX-RS API (contd.)
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
6
Example: JAX-RS API (contd.)
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
7
JSR-339 a.k.a. JAX-RS 2.0
Ā§ļ‚§ā€Æ Expert Group formed in February, 2011
ā€“ā€Æ Lead by Oracle
Ā§ļ‚§ā€Æ Marek Potociar, Santiago Pericas-Geertsen
ā€“ā€Æ 13 Group members
Ā§ļ‚§ā€Æ Jan Algermissen, Florent Benoit (OW2), Sergey Beryozkin (Talend/CXF), Adam Bien,
Bill Burke (RedHat), Clinton L Combs, Bill De Hora, Markus Karg, Sastry Mallady
(eBay), Wendy Raschke (IBM), Julian Reschke, Guilherme Silveira, Dionysios
Synodinos
Ā§ļ‚§ā€Æ Public Review Draft published on Sep 28, 2012
ā€“ā€Æ See JSR-339 JCP site jcp.org/en/jsr/detail?id=339
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
8
JAX-RS 2.0
Ā§ļ‚§ā€ÆClient API
Ā§ļ‚§ā€ÆCommon configuration
Ā§ļ‚§ā€ÆAsynchronous processing
Ā§ļ‚§ā€ÆFilters
Ā§ļ‚§ā€ÆInterceptors
Ā§ļ‚§ā€ÆHypermedia support
Ā§ļ‚§ā€ÆServer-side content negotiation
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
9
JAX-RS 2.0
Ā§ļ‚§ā€ÆClient API
Ā§ļ‚§ā€ÆCommon configuration
Ā§ļ‚§ā€ÆAsynchronous processing
Ā§ļ‚§ā€ÆFilters
Ā§ļ‚§ā€ÆInterceptors
Ā§ļ‚§ā€ÆHypermedia support
Ā§ļ‚§ā€ÆServer-side content negotiation
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
10
Client API
Ā§ļ‚§ā€Æ HTTP client libraries too low level
Ā§ļ‚§ā€Æ Leveraging providers and concepts from the JAX-RS 1.x API
ā€“ā€Æ E.g., MBRs and MBWs
Ā§ļ‚§ā€Æ Proprietary APIs introduced by major JAX-RS 1.x implementations
ā€“ā€Æ Need for a standard
Motivation
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
11
Client API
// Get instance of Client
Client client = ClientFactory.newClient();
// Get account balance
String bal = client.target("http://.../atm/{cardId}/balance")
.resolveTemplate("cardId", "111122223333")
.queryParam("pin", "9876")
.request("text/plain").get(String.class);
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
12
Client API
// Withdraw some money
Money mon = client.target("http://.../atm/{cardId}/withdrawal")
.resolveTemplate("cardId", "111122223333")
.queryParam("pin", "9876")
.request("application/json")
.post(text("50.0"), Money.class);
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
13
Client API
Invocation inv1 =
client.target("http://.../atm/{cardId}/balance")ā€¦
.request(ā€œtext/plainā€).buildGet();
Invocation inv2 =
client.target("http://.../atm/{cardId}/withdraw")ā€¦
.request("application/json")
.buildPost(text("50.0"));
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
14
Client API
Collection<Invocation> invocations = Arrays.asList(inv1, inv2);
Collection<Response> responses = Collections.transform(
invocations,
new F<Invocation, Response>() {
public Response apply(Invocation inv) {
return inv.invoke();
}
});
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
15
Client API
// Create client and register MyProvider1
Client client = ClientFactory.newClient();
client.configuration().register(MyProvider1.class);
// Create atm target; inherits MyProvider1
WebTarget atm = client.target("http://.../atm");
// Register MyProvider2
atm.configuration().register(MyProvider2.class);
// Create balance target; inherits MyProvider1, MyProvider2
WebTarget balance = atm.path(ā€{cardId}/balance");
// Register MyProvider3
balance.configuration().register(MyProvider3.class);
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
16
JAX-RS 2.0
Ā§ļ‚§ā€ÆClient API
Ā§ļ‚§ā€ÆCommon configuration
Ā§ļ‚§ā€ÆAsynchronous processing
Ā§ļ‚§ā€ÆFilters
Ā§ļ‚§ā€ÆInterceptors
Ā§ļ‚§ā€ÆHypermedia support
Ā§ļ‚§ā€ÆServer-side content negotiation
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
17
Common configuration - motivation
client.configuration()
.register(JsonMessageBodyReader.class)
.register(JsonMessageBodyWriter.class)
.register(JsonpInterceptor.class)
.setProperty(ā€œjsonp.callback.nameā€, ā€œcallbackā€)
.setProperty(ā€œjsonp.callback.queryParamā€, ā€œtrueā€)
...
Client-side
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
18
Common configuration - motivation
public class MyApp extends javax.ws.rs.core.Application {
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<ā€¦>();
ā€¦
classes.add(JsonMessageBodyReader.class);
classes.add(JsonMessageBodyWriter.class);
classes.add(JsonpInterceptor.class);
ā€¦
return classes;
}
}
Server-side
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
19
Common configuration - solution
client.configuration()
.register(JsonMessageBodyReader.class)
.register(JsonMessageBodyWriter.class)
.register(JsonpInterceptor.class)
.setProperty(ā€œjsonp.callback.nameā€, ā€œcallbackā€)
.setProperty(ā€œjsonp.callback.queryParamā€, ā€œtrueā€)
...
JsonFeature jf = new JsonFeature().enableCallbackQueryParam();
Client.configuration().register(jf);
Client-side
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
20
Common configuration - solution
public Set<Class<?>> getClasses() {
ā€¦
classes.add(JsonMessageBodyReader.class);
classes.add(JsonMessageBodyWriter.class);
classes.add(JsonpInterceptor.class);
ā€¦
}
public Set<Class<?>> getClasses() {
ā€¦
classes.add(JsonFeature.class);
ā€¦
}
Server-side
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
21
Common configuration
public interface Configurable {
Map<String, Object> getProperties();
Object getProperty(String name);
Configurable setProperties(Map<String, ?> properties);
Configurable setProperty(String name, Object value);
Collection<Feature> getFeatures();
Set<Class<?>> getProviderClasses();
Set<Object> getProviderInstances();
Configurable register(...);
...
}
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
22
Common configuration
public interface Feature {
boolean configure(Configurable configurable);
}
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
23
A Feature example
public void JsonFeature implements Feature {
public boolean configure(Configurable config) {
config.register(JsonMessageBodyReader.class)
.register(JsonMessageBodyWriter.class)
.register(JsonpInterceptor.class)
.setProperty(CALLBACK_NAME, calbackName)
.setProperty(USE_QUERY_PARAM, useQueryParam);
return true;
}
}
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
24
Dynamic Feature
public interface DynamicFeature {
void configure(ResourceInfo ri, Configurable configurable);
}
public interface ResourceInfo {
Method getResourceMethod();
Class<?> getResourceClass();
}
Server-side only
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
25
JAX-RS 2.0
Ā§ļ‚§ā€ÆClient API
Ā§ļ‚§ā€ÆCommon configuration
Ā§ļ‚§ā€ÆAsynchronous processing
Ā§ļ‚§ā€ÆFilters
Ā§ļ‚§ā€ÆInterceptors
Ā§ļ‚§ā€ÆHypermedia support
Ā§ļ‚§ā€ÆServer-side content negotiation
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
26
Async Processing
Ā§ļ‚§ā€Æ Server API support
ā€“ā€Æ Off-load I/O container threads
Ā§ļ‚§ā€Æ Long-running operations
ā€“ā€Æ Efficient asynchronous event processing
Ā§ļ‚§ā€Æ Suspend while waiting for an event
Ā§ļ‚§ā€Æ Resume when event arrives
ā€“ā€Æ Leverage Servlet 3.x async support (if available)
Ā§ļ‚§ā€Æ Client API support
ā€“ā€Æ Asynchronous request invocation API
Ā§ļ‚§ā€Æ Future<RESPONSE>, InvocationCallback<RESPONSE>	
 Ā 
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
27
Async Processing: Server-side
@Path("/async/longRunning")
public class MyResource {
@GET
public void longRunningOp(@Suspended AsyncResponse ar) {
ar.setTimeoutHandler(new MyTimoutHandler());
ar.setTimeout(15, SECONDS);
Executors.newSingleThreadExecutor().submit(new Runnable() {
public void run() {
ā€¦
ar.resume(result);
}
});
}
}
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
28
Async Processing: Server-side
public interface AsyncResponse {
public void resume(Object/Throwable response);
public void cancel();
public void cancel(int/Date retryAfter);
public boolean isSuspended();
public boolean isCancelled();
public boolean isDone();
public void setTimeout(long time, TimeUnit unit);
public void setTimeoutHandler(TimeoutHandler handler);
public boolean register(Class<?> callback);
public boolean[] register(Class<?> callback, Class<?>... callbacks);
public boolean register(Object callback);
public boolean[] register(Object callback, Object... callbacks);
}
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
29
Async Processing: Server-side
@Target({ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Suspended {
}
public interface TimeoutHandler {
void handleTimeout(AsyncResponse asyncResponse);
}
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
30
Async Processing: Server-side
public interface ResumeCallback {
public void onResume(AsyncResponse resuming, Response response);
public void onResume(AsyncResponse resuming, Throwable error);
}
public interface CompletionCallback {
public void onComplete();
public void onError(Throwable throwable);
}
public interface ConnectionCallback {
public void onDisconnect(AsyncResponse disconnected);
}
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
31
Async Processing: Client-side
WebTarget target = client.target("http://.../balanceā€)ā€¦
// Start async call and register callback
Future<?> handle = target.request().async().get(
new InvocationCallback<String>() {
void complete(String balance) { ā€¦ }
void failed(InvocationException e) { ā€¦ }
});
// After waiting for too longā€¦
if (!handle.isDone()) handle.cancel(true);
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
32
JAX-RS 2.0
Ā§ļ‚§ā€ÆClient API
Ā§ļ‚§ā€ÆCommon configuration
Ā§ļ‚§ā€ÆAsynchronous processing
Ā§ļ‚§ā€ÆFilters
Ā§ļ‚§ā€ÆInterceptors
Ā§ļ‚§ā€ÆHypermedia support
Ā§ļ‚§ā€ÆServer-side content negotiation
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
33
Filters & Interceptors
Ā§ļ‚§ā€Æ Customize JAX-RS request/response processing
ā€“ā€Æ Use Cases: Logging, Compression, Security, Etc.
Ā§ļ‚§ā€Æ Introduced for client and server APIs
Ā§ļ‚§ā€Æ Replace existing proprietary support
ā€“ā€Æ Provided by most JAX-RS 1.x implementations
Ā§ļ‚§ā€Æ All using slightly different types or semantics
Motivation
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
34
Filters & Interceptors
Ā§ļ‚§ā€Æ Non-wrapping filter chain
ā€“ā€Æ Filters do not invoke next filter in
the chain directly
ā€“ā€Æ managed by the JAX-RS runtime
Ā§ļ‚§ā€Æ Each filter decides to proceed or
break the chain
Filter each incoming/outgoing message
Ā§ļ‚§ā€Æ Request ĆØļƒØ Request
ā€“ā€Æ ContainerRequestFilter,	
 Ā 
ClientRequestFilter	
 Ā 
Ā§ļ‚§ā€Æ Response ĆØļƒØ Response
ā€“ā€Æ ContainerResponseFilter,	
 Ā 
ClientResponseFilter
Ā§ļ‚§ā€Æ Server-side specialties
ā€“ā€Æ @PreMatching,	
 Ā DynamicFeature
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
35
Filters & Interceptors
public class RequestLoggingFilter implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext requestContext) {
log(requestContext);
// non-wrapping => returns without invoking the next filter
}
...
}
A Logging Filter Example
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
36
Filters & Interceptors
Ā§ļ‚§ā€Æ Invoked ONLY when/if entity
processing occurs
ā€“ā€Æ Performance boost
Ā§ļ‚§ā€Æ Wrapping interceptor chain
ā€“ā€Æ Each interceptor invokes the next
one in the chain via
context.proceed()	
 Ā 
Intercept entity providers
Ā§ļ‚§ā€Æ MessageBodyReader interceptor
ā€“ā€Æ ReaderInterceptor interface
Ā§ļ‚§ā€Æ MessageBodyWriter interceptor
ā€“ā€Æ WriterInterceptor interface
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
37
Filters & Interceptors
public class GzipInterceptor implements ReaderInterceptor {
@Override
Object aroundReadFrom(ReaderInterceptorContext ctx) {
InputStream old = ctx.getInputStream();
ctx.setInputStream(new GZIPInputStream(old));
// wrapping => invokes the next interceptor
Object entity = ctx.proceed();
ctx.setInputStream(old);
return entity;
}
}
A GZip Reader Interceptor Example
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
38
Application
Filters & Interceptors
Request Filter Filter
Network
Transport
ā€¦
ā€¦
Response Filter
Filter
write(ā€¦)
Writer
Interceptor
ā€¦ MBW
read(ā€¦) - optional
ā€¦
MBR
Writer
Interceptor
Reader
Interceptor
Reader
Interceptor
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
39
Response
Application
Filters & Interceptors
Filter Filter
Network
ā€¦ Response
Filter
Filter
write(ā€¦)
ā€¦
MBW
Writer
Interceptor
Writer
Interceptor
Filter Filter
ā€¦ Request
Request
read(ā€¦) - optional
Reader
Interceptor
ā€¦ MBR
Reader
Interceptor
Filter Filter
Resource
Matching
@PreMatching
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
40
Bindings & Priorities
Ā§ļ‚§ā€Æ Binding
ā€“ā€Æ Associating filters and interceptors with resource methods
ā€“ā€Æ Server-side concept
Ā§ļ‚§ā€Æ Priority
ā€“ā€Æ Declaring relative position in the execution chain
ā€“ā€Æ @BindingPriority(int	
 Ā priority)	
 Ā 
Ā§ļ‚§ā€Æ Shared concept by filters and interceptors
Scoped Binding Global Binding
Static @NameBinding (@Qualifier?)
Default
@PreMatching
Dynamic DynamicFeature N/A
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
41
Bindings
@NameBinding // or @Qualifier ?
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(value = RetentionPolicy.RUNTIME)
public @interface Logged {}
@Provider
@Logged
@BindingPriority(USER)
public class LoggingFilter
implements ContainerRequestFilter, ContainerResponseFilter { ā€¦ }
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
42
Bindings
@Path("/greet/{name}")
@Produces("text/plain")
public class MyResourceClass {
@Logged
@GET
public String hello(@PathParam("name") String name) {
return "Hello " + name;
}
}
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
43
A DynamicFeature example
public void SecurityFeature implements DynamicFeature {
public boolean configure(ResourceInfo ri, Configurable config) {
String[] roles = getRolesAllowed(ri);
if (roles != null) {
config.register(new RolesAllowedFilter(roles));
}
}
ā€¦
}
Server-side only
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
44
JAX-RS 2.0
Ā§ļ‚§ā€ÆClient API
Ā§ļ‚§ā€ÆCommon configuration
Ā§ļ‚§ā€ÆAsynchronous processing
Ā§ļ‚§ā€ÆFilters
Ā§ļ‚§ā€ÆInterceptors
Ā§ļ‚§ā€ÆHypermedia support
Ā§ļ‚§ā€ÆServer-side content negotiation
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
45
Hypermedia
Ā§ļ‚§ā€Æ REST principles
ā€“ā€Æ Identifiers and Links
ā€“ā€Æ HATEOAS (Hypermedia As The Engine Of App State)
Ā§ļ‚§ā€Æ Link types:
ā€“ā€Æ Structural Links
ā€“ā€Æ Transitional Links
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
46
Hypermedia
Link: <http://.../orders/1/ship>; rel=ship,
<http://.../orders/1/cancel>; rel=cancel
...
<order id="1">
<customer>http://.../customers/11</customer>
<address>http://.../customers/11/address/1</address>
<items>
<item>
<product>http://.../products/111</product>
<quantity>2</quantity>
</item>
<items>
...
</order>
Transitional Links
Structural Links
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
47
Hypermedia
Ā§ļ‚§ā€Æ Link and LinkBuilder classes
ā€“ā€Æ RFC 5988: Web Linking
Ā§ļ‚§ā€Æ Support for Link in ResponseBuilder and filters	
 Ā 
ā€“ā€Æ Transitional links (headers)
Ā§ļ‚§ā€Æ Support for manual structural links
ā€“ā€Æ Via Link.JaxbAdapter & Link.JaxbLink
Ā§ļ‚§ā€Æ Create a resource target from a Link in Client API
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
48
Hypermedia
// Producer API (server-side)
Link self = Link.fromResourceMethod(MyResource.class, ā€handleGetā€)
.build();
Link update = Link.fromResourceMethod(MyResource.class, ā€œhandlePostā€)
.rel(ā€updateā€)
.build();
...
Response res = Response.ok(order)
.link("http://.../orders/1/ship", "ship")
.links(self, update)
.build();
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
49
Hypermedia
Response order = client.target(ā€¦).request("application/xml").get();
// Consumer API (client-side)
Link shipmentLink = order.getLink(ā€œshipā€);
if (shipmentLink != null) {
Response shipment = client.target(shipmentLink).post(null);
ā€¦
}
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
50
JAX-RS 2.0
Ā§ļ‚§ā€ÆClient API
Ā§ļ‚§ā€ÆCommon configuration
Ā§ļ‚§ā€ÆAsynchronous processing
Ā§ļ‚§ā€ÆFilters
Ā§ļ‚§ā€ÆInterceptors
Ā§ļ‚§ā€ÆHypermedia support
Ā§ļ‚§ā€ÆServer-side content negotiation
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
51
Server Side Conneg
GET http://.../widgets2
Accept: text/*; q=1
ā€¦
Path("widgets2")
public class WidgetsResource2 {
@GET
@Produces("text/plain", "text/html")
public Widgets getWidget() {...}
}
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
52
Server Side Conneg
GET http://.../widgets2
Accept: text/*; q=1
ā€¦
Path("widgets2")
public class WidgetsResource2 {
@GET
@Produces("text/plain; qs=0.5", "text/html; qs=0.75")
public Widgets getWidget() {...}
}
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
53
JAX-RS 2.0 Summary
Ā§ļ‚§ā€Æ Major new features
ā€“ā€Æ Client API, Filters & Interceptors, Asynchronous Resources, Hypermedia
Ā§ļ‚§ā€Æ Many minor API improvements and extensions
ā€“ā€Æ Request / Response, URI builder, String Converters, @BeanParam,
MultivaluedHashMap, GenericType, ā€¦
Ā§ļ‚§ā€Æ Improved TCK coverage = improved portability
ā€“ā€Æ ~350 tests in JAX-RS 1.x, ~1700 tests in JAX-RS 2.0
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
54
<a href=ā€œā€¦ā€ >JAX-RS 2.0</a>
Ā§ļ‚§ā€Æ Project web site jax-rs-spec.java.net
Ā§ļ‚§ā€Æ Users mailing list users@jax-rs-spec.java.net
Ā§ļ‚§ā€Æ JSR-339 site jcp.org/en/jsr/detail?id=339
ā€“ā€Æ Latest specification text draft
Ā§ļ‚§ā€Æ java.net/projects/jax-rs-spec/sources/git/content/spec/spec.pdf
ā€“ā€Æ Latest API snapshot
Ā§ļ‚§ā€Æ jax-rs-spec.java.net/nonav/2.0-SNAPSHOT/apidocs/index.html
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
55
<a href=ā€œā€¦ā€ >Jersey 2.0</a>
Ā§ļ‚§ā€Æ Project web site jersey.java.net
Ā§ļ‚§ā€Æ Users mailing list users@jersey.java.net
ā€“ā€Æ Latest users guide
Ā§ļ‚§ā€Æ http://jersey.java.net/nonav/documentation/snapshot/index.html
ā€“ā€Æ Latest API documentation
Ā§ļ‚§ā€Æ http://jersey.java.net/nonav/apidocs/snapshot/jersey/index.html
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
56
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
57
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
58
JAX-RS 2.0
Ā§ļ‚§ā€ÆDI (JSR-330) Integration
Ā§ļ‚§ā€ÆBean Validation
Ā§ļ‚§ā€ÆImproved Java EE Security Support
Ā§ļ‚§ā€ÆPresentation Layer
Ā§ļ‚§ā€ÆHigh-level Client API
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
59
Dependency Injection Integration
Ā§ļ‚§ā€Æ Support Java Dependency Injection API (JSR-330)
ā€“ā€Æ Support	
 Ā @Inject	
 Ā and	
 Ā @Qualifier ?
ā€“ā€Æ @Qualifier	
 Ā as a replacement for	
 Ā @NamedBinding	
 Ā ?
ā€“ā€Æ Provider vs.	
 Ā ContextResolver ?
ā€“ā€Æ Support DI (JSR-330) or CDI (JSR-299)?
Ā§ļ‚§ā€Æ Issues
ā€“ā€Æ Interference with CDI providers
ā€“ā€Æ EG does not see enough added value for DI
Ā§ļ‚§ā€Æ DI-style injection support deferred
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
60
Dependency Injection Integration
Ā§ļ‚§ā€Æ Java EE Deployments
ā€“ā€Æ Tight CDI integration makes sense (unification of Java EE component
model)
Ā§ļ‚§ā€Æ Java SE Deployments
ā€“ā€Æ DI provides all the required features
ā€“ā€Æ CDI is too heavy-weight
Ā§ļ‚§ā€Æ Many redundant features
ā€“ā€Æ method interceptors, decorators, stereotypes ā€¦
Ā§ļ‚§ā€Æ Additional limitations put on managed components
Support DI (JSR-330) or CDI (JSR-299)?
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
61
Bean Validation
Ā§ļ‚§ā€Æ Dropped from JAX-RS 2.0 Public Review
ā€“ā€Æ Difficulty aligning schedules
Ā§ļ‚§ā€Æ Still supported via CDI 1.1
ā€“ā€Æ JAX-RS resource class must be CDI bean
ā€“ā€Æ BV 1.1 now supports method validation
Ā§ļ‚§ā€Æ May revisit current plan post Java EE 7
Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved.
62
More Topicsā€¦
Ā§ļ‚§ā€Æ Improved Java EE security
support
ā€“ā€Æ @RolesAllowed, ā€¦
ā€“ā€Æ SecurityContext.authenticate(ā€¦)
Ā§ļ‚§ā€Æ Pluggable Views
ā€“ā€Æ Completes the MVC pattern
Ā§ļ‚§ā€Æ High-level client API
ā€“ā€Æ Hard to design it to be RESTful
ā€“ā€Æ Jersey 2 provides an
experimental support
ā€“ā€Æ Donā€™t want to end-up with an
RPC-style API

More Related Content

What's hot

Websocket 1.0
Websocket 1.0Websocket 1.0
Websocket 1.0Arun Gupta
Ā 
Java Web Programming [5/9] : EL, JSTL and Custom Tags
Java Web Programming [5/9] : EL, JSTL and Custom TagsJava Web Programming [5/9] : EL, JSTL and Custom Tags
Java Web Programming [5/9] : EL, JSTL and Custom TagsIMC Institute
Ā 
Java Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicJava Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicIMC Institute
Ā 
What's new in Java Message Service 2?
What's new in Java Message Service 2?What's new in Java Message Service 2?
What's new in Java Message Service 2?Sivakumar Thyagarajan
Ā 
Java Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAXJava Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAXIMC Institute
Ā 
Javaone 2010
Javaone 2010Javaone 2010
Javaone 2010Hien Luu
Ā 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2Haroon Idrees
Ā 
Javatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparisonJavatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparisonJini Lee
Ā 
Introduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examplesIntroduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examplesecosio GmbH
Ā 
hibernate with JPA
hibernate with JPAhibernate with JPA
hibernate with JPAMohammad Faizan
Ā 
Java Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicJava Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicIMC Institute
Ā 
Java Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVCJava Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVCIMC Institute
Ā 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate TutorialRam132
Ā 
Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3IMC Institute
Ā 

What's hot (20)

Websocket 1.0
Websocket 1.0Websocket 1.0
Websocket 1.0
Ā 
Java Web Programming [5/9] : EL, JSTL and Custom Tags
Java Web Programming [5/9] : EL, JSTL and Custom TagsJava Web Programming [5/9] : EL, JSTL and Custom Tags
Java Web Programming [5/9] : EL, JSTL and Custom Tags
Ā 
Java ee7 1hour
Java ee7 1hourJava ee7 1hour
Java ee7 1hour
Ā 
Java Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicJava Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet Basic
Ā 
What's new in Java Message Service 2?
What's new in Java Message Service 2?What's new in Java Message Service 2?
What's new in Java Message Service 2?
Ā 
iBATIS
iBATISiBATIS
iBATIS
Ā 
Java Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAXJava Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAX
Ā 
Javaone 2010
Javaone 2010Javaone 2010
Javaone 2010
Ā 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2
Ā 
CDI @javaonehyderabad
CDI @javaonehyderabadCDI @javaonehyderabad
CDI @javaonehyderabad
Ā 
JPA 2.0
JPA 2.0JPA 2.0
JPA 2.0
Ā 
Javatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparisonJavatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparison
Ā 
Jpa 2.1 Application Development
Jpa 2.1 Application DevelopmentJpa 2.1 Application Development
Jpa 2.1 Application Development
Ā 
Java persistence api 2.1
Java persistence api 2.1Java persistence api 2.1
Java persistence api 2.1
Ā 
Introduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examplesIntroduction to JPA and Hibernate including examples
Introduction to JPA and Hibernate including examples
Ā 
hibernate with JPA
hibernate with JPAhibernate with JPA
hibernate with JPA
Ā 
Java Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicJava Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP Basic
Ā 
Java Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVCJava Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVC
Ā 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
Ā 
Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3Java Web Programming Using Cloud Platform: Module 3
Java Web Programming Using Cloud Platform: Module 3
Ā 

Similar to JAX-RS 2.0: Key Features of the Updated RESTful Web Services API

JAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesJAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesArun Gupta
Ā 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012Arun Gupta
Ā 
Java EE7
Java EE7Java EE7
Java EE7Jay Lee
Ā 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and ODataAnil Allewar
Ā 
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...jaxLondonConference
Ā 
Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Arun Gupta
Ā 
Ppt on web development and this has all details
Ppt on web development and this has all detailsPpt on web development and this has all details
Ppt on web development and this has all detailsgogijoshiajmer
Ā 
GlassFish REST Administration Backend
GlassFish REST Administration BackendGlassFish REST Administration Backend
GlassFish REST Administration BackendArun Gupta
Ā 
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Max Andersen
Ā 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasyJBug Italy
Ā 
112815 java ee8_davidd
112815 java ee8_davidd112815 java ee8_davidd
112815 java ee8_daviddTakashi Ito
Ā 
Networking and Data Access with Eqela
Networking and Data Access with EqelaNetworking and Data Access with Eqela
Networking and Data Access with Eqelajobandesther
Ā 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web servicesnbuddharaju
Ā 
REST made simple with Java
REST made simple with JavaREST made simple with Java
REST made simple with JavaNiklas Gustavsson
Ā 
Java EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c DevelopersJava EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c DevelopersBruno Borges
Ā 
OTN Tour 2013: What's new in java EE 7
OTN Tour 2013: What's new in java EE 7OTN Tour 2013: What's new in java EE 7
OTN Tour 2013: What's new in java EE 7Bruno Borges
Ā 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenchesLukas Smith
Ā 

Similar to JAX-RS 2.0: Key Features of the Updated RESTful Web Services API (20)

JAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesJAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web Services
Ā 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012
Ā 
Java EE7
Java EE7Java EE7
Java EE7
Ā 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and OData
Ā 
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Ā 
Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5
Ā 
Ppt on web development and this has all details
Ppt on web development and this has all detailsPpt on web development and this has all details
Ppt on web development and this has all details
Ā 
Intro to Laravel 4
Intro to Laravel 4Intro to Laravel 4
Intro to Laravel 4
Ā 
GlassFish REST Administration Backend
GlassFish REST Administration BackendGlassFish REST Administration Backend
GlassFish REST Administration Backend
Ā 
RESTEasy
RESTEasyRESTEasy
RESTEasy
Ā 
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Ā 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasy
Ā 
112815 java ee8_davidd
112815 java ee8_davidd112815 java ee8_davidd
112815 java ee8_davidd
Ā 
Rest
RestRest
Rest
Ā 
Networking and Data Access with Eqela
Networking and Data Access with EqelaNetworking and Data Access with Eqela
Networking and Data Access with Eqela
Ā 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web services
Ā 
REST made simple with Java
REST made simple with JavaREST made simple with Java
REST made simple with Java
Ā 
Java EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c DevelopersJava EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c Developers
Ā 
OTN Tour 2013: What's new in java EE 7
OTN Tour 2013: What's new in java EE 7OTN Tour 2013: What's new in java EE 7
OTN Tour 2013: What's new in java EE 7
Ā 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
Ā 

More from JAX London

Everything I know about software in spaghetti bolognese: managing complexity
Everything I know about software in spaghetti bolognese: managing complexityEverything I know about software in spaghetti bolognese: managing complexity
Everything I know about software in spaghetti bolognese: managing complexityJAX London
Ā 
Devops with the S for Sharing - Patrick Debois
Devops with the S for Sharing - Patrick DeboisDevops with the S for Sharing - Patrick Debois
Devops with the S for Sharing - Patrick DeboisJAX London
Ā 
Busy Developer's Guide to Windows 8 HTML/JavaScript Apps
Busy Developer's Guide to Windows 8 HTML/JavaScript AppsBusy Developer's Guide to Windows 8 HTML/JavaScript Apps
Busy Developer's Guide to Windows 8 HTML/JavaScript AppsJAX London
Ā 
It's code but not as we know: Infrastructure as Code - Patrick Debois
It's code but not as we know: Infrastructure as Code - Patrick DeboisIt's code but not as we know: Infrastructure as Code - Patrick Debois
It's code but not as we know: Infrastructure as Code - Patrick DeboisJAX London
Ā 
Locks? We Don't Need No Stinkin' Locks - Michael Barker
Locks? We Don't Need No Stinkin' Locks - Michael BarkerLocks? We Don't Need No Stinkin' Locks - Michael Barker
Locks? We Don't Need No Stinkin' Locks - Michael BarkerJAX London
Ā 
Worse is better, for better or for worse - Kevlin Henney
Worse is better, for better or for worse - Kevlin HenneyWorse is better, for better or for worse - Kevlin Henney
Worse is better, for better or for worse - Kevlin HenneyJAX London
Ā 
Java performance: What's the big deal? - Trisha Gee
Java performance: What's the big deal? - Trisha GeeJava performance: What's the big deal? - Trisha Gee
Java performance: What's the big deal? - Trisha GeeJAX London
Ā 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John StevensonJAX London
Ā 
HTML alchemy: the secrets of mixing JavaScript and Java EE - Matthias Wessendorf
HTML alchemy: the secrets of mixing JavaScript and Java EE - Matthias WessendorfHTML alchemy: the secrets of mixing JavaScript and Java EE - Matthias Wessendorf
HTML alchemy: the secrets of mixing JavaScript and Java EE - Matthias WessendorfJAX London
Ā 
Play framework 2 : Peter Hilton
Play framework 2 : Peter HiltonPlay framework 2 : Peter Hilton
Play framework 2 : Peter HiltonJAX London
Ā 
Complexity theory and software development : Tim Berglund
Complexity theory and software development : Tim BerglundComplexity theory and software development : Tim Berglund
Complexity theory and software development : Tim BerglundJAX London
Ā 
Why FLOSS is a Java developer's best friend: Dave Gruber
Why FLOSS is a Java developer's best friend: Dave GruberWhy FLOSS is a Java developer's best friend: Dave Gruber
Why FLOSS is a Java developer's best friend: Dave GruberJAX London
Ā 
Akka in Action: Heiko Seeburger
Akka in Action: Heiko SeeburgerAkka in Action: Heiko Seeburger
Akka in Action: Heiko SeeburgerJAX London
Ā 
NoSQL Smackdown 2012 : Tim Berglund
NoSQL Smackdown 2012 : Tim BerglundNoSQL Smackdown 2012 : Tim Berglund
NoSQL Smackdown 2012 : Tim BerglundJAX London
Ā 
Closures, the next "Big Thing" in Java: Russel Winder
Closures, the next "Big Thing" in Java: Russel WinderClosures, the next "Big Thing" in Java: Russel Winder
Closures, the next "Big Thing" in Java: Russel WinderJAX London
Ā 
Java and the machine - Martijn Verburg and Kirk Pepperdine
Java and the machine - Martijn Verburg and Kirk PepperdineJava and the machine - Martijn Verburg and Kirk Pepperdine
Java and the machine - Martijn Verburg and Kirk PepperdineJAX London
Ā 
Mongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdamsMongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdamsJAX London
Ā 
New opportunities for connected data - Ian Robinson
New opportunities for connected data - Ian RobinsonNew opportunities for connected data - Ian Robinson
New opportunities for connected data - Ian RobinsonJAX London
Ā 
HTML5 Websockets and Java - Arun Gupta
HTML5 Websockets and Java - Arun GuptaHTML5 Websockets and Java - Arun Gupta
HTML5 Websockets and Java - Arun GuptaJAX London
Ā 
The Big Data Con: Why Big Data is a Problem, not a Solution - Ian Plosker
The Big Data Con: Why Big Data is a Problem, not a Solution - Ian PloskerThe Big Data Con: Why Big Data is a Problem, not a Solution - Ian Plosker
The Big Data Con: Why Big Data is a Problem, not a Solution - Ian PloskerJAX London
Ā 

More from JAX London (20)

Everything I know about software in spaghetti bolognese: managing complexity
Everything I know about software in spaghetti bolognese: managing complexityEverything I know about software in spaghetti bolognese: managing complexity
Everything I know about software in spaghetti bolognese: managing complexity
Ā 
Devops with the S for Sharing - Patrick Debois
Devops with the S for Sharing - Patrick DeboisDevops with the S for Sharing - Patrick Debois
Devops with the S for Sharing - Patrick Debois
Ā 
Busy Developer's Guide to Windows 8 HTML/JavaScript Apps
Busy Developer's Guide to Windows 8 HTML/JavaScript AppsBusy Developer's Guide to Windows 8 HTML/JavaScript Apps
Busy Developer's Guide to Windows 8 HTML/JavaScript Apps
Ā 
It's code but not as we know: Infrastructure as Code - Patrick Debois
It's code but not as we know: Infrastructure as Code - Patrick DeboisIt's code but not as we know: Infrastructure as Code - Patrick Debois
It's code but not as we know: Infrastructure as Code - Patrick Debois
Ā 
Locks? We Don't Need No Stinkin' Locks - Michael Barker
Locks? We Don't Need No Stinkin' Locks - Michael BarkerLocks? We Don't Need No Stinkin' Locks - Michael Barker
Locks? We Don't Need No Stinkin' Locks - Michael Barker
Ā 
Worse is better, for better or for worse - Kevlin Henney
Worse is better, for better or for worse - Kevlin HenneyWorse is better, for better or for worse - Kevlin Henney
Worse is better, for better or for worse - Kevlin Henney
Ā 
Java performance: What's the big deal? - Trisha Gee
Java performance: What's the big deal? - Trisha GeeJava performance: What's the big deal? - Trisha Gee
Java performance: What's the big deal? - Trisha Gee
Ā 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
Ā 
HTML alchemy: the secrets of mixing JavaScript and Java EE - Matthias Wessendorf
HTML alchemy: the secrets of mixing JavaScript and Java EE - Matthias WessendorfHTML alchemy: the secrets of mixing JavaScript and Java EE - Matthias Wessendorf
HTML alchemy: the secrets of mixing JavaScript and Java EE - Matthias Wessendorf
Ā 
Play framework 2 : Peter Hilton
Play framework 2 : Peter HiltonPlay framework 2 : Peter Hilton
Play framework 2 : Peter Hilton
Ā 
Complexity theory and software development : Tim Berglund
Complexity theory and software development : Tim BerglundComplexity theory and software development : Tim Berglund
Complexity theory and software development : Tim Berglund
Ā 
Why FLOSS is a Java developer's best friend: Dave Gruber
Why FLOSS is a Java developer's best friend: Dave GruberWhy FLOSS is a Java developer's best friend: Dave Gruber
Why FLOSS is a Java developer's best friend: Dave Gruber
Ā 
Akka in Action: Heiko Seeburger
Akka in Action: Heiko SeeburgerAkka in Action: Heiko Seeburger
Akka in Action: Heiko Seeburger
Ā 
NoSQL Smackdown 2012 : Tim Berglund
NoSQL Smackdown 2012 : Tim BerglundNoSQL Smackdown 2012 : Tim Berglund
NoSQL Smackdown 2012 : Tim Berglund
Ā 
Closures, the next "Big Thing" in Java: Russel Winder
Closures, the next "Big Thing" in Java: Russel WinderClosures, the next "Big Thing" in Java: Russel Winder
Closures, the next "Big Thing" in Java: Russel Winder
Ā 
Java and the machine - Martijn Verburg and Kirk Pepperdine
Java and the machine - Martijn Verburg and Kirk PepperdineJava and the machine - Martijn Verburg and Kirk Pepperdine
Java and the machine - Martijn Verburg and Kirk Pepperdine
Ā 
Mongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdamsMongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdams
Ā 
New opportunities for connected data - Ian Robinson
New opportunities for connected data - Ian RobinsonNew opportunities for connected data - Ian Robinson
New opportunities for connected data - Ian Robinson
Ā 
HTML5 Websockets and Java - Arun Gupta
HTML5 Websockets and Java - Arun GuptaHTML5 Websockets and Java - Arun Gupta
HTML5 Websockets and Java - Arun Gupta
Ā 
The Big Data Con: Why Big Data is a Problem, not a Solution - Ian Plosker
The Big Data Con: Why Big Data is a Problem, not a Solution - Ian PloskerThe Big Data Con: Why Big Data is a Problem, not a Solution - Ian Plosker
The Big Data Con: Why Big Data is a Problem, not a Solution - Ian Plosker
Ā 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
Ā 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
Ā 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
Ā 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
Ā 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
Ā 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
Ā 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service šŸø 8923113531 šŸŽ° Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service šŸø 8923113531 šŸŽ° Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service šŸø 8923113531 šŸŽ° Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service šŸø 8923113531 šŸŽ° Avail...gurkirankumar98700
Ā 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
Ā 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
Ā 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
Ā 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
Ā 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
Ā 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
Ā 
FULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | DelhiFULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | Delhisoniya singh
Ā 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
Ā 
šŸ¬ The future of MySQL is Postgres šŸ˜
šŸ¬  The future of MySQL is Postgres   šŸ˜šŸ¬  The future of MySQL is Postgres   šŸ˜
šŸ¬ The future of MySQL is Postgres šŸ˜RTylerCroy
Ā 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
Ā 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
Ā 
Swan(sea) Song ā€“ personal research during my six years at Swansea ... and bey...
Swan(sea) Song ā€“ personal research during my six years at Swansea ... and bey...Swan(sea) Song ā€“ personal research during my six years at Swansea ... and bey...
Swan(sea) Song ā€“ personal research during my six years at Swansea ... and bey...Alan Dix
Ā 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
Ā 

Recently uploaded (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Ā 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Ā 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Ā 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
Ā 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
Ā 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
Ā 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service šŸø 8923113531 šŸŽ° Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service šŸø 8923113531 šŸŽ° Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service šŸø 8923113531 šŸŽ° Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service šŸø 8923113531 šŸŽ° Avail...
Ā 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Ā 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
Ā 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Ā 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
Ā 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
Ā 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Ā 
FULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | DelhiFULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | Delhi
Ā 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Ā 
šŸ¬ The future of MySQL is Postgres šŸ˜
šŸ¬  The future of MySQL is Postgres   šŸ˜šŸ¬  The future of MySQL is Postgres   šŸ˜
šŸ¬ The future of MySQL is Postgres šŸ˜
Ā 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Ā 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
Ā 
Swan(sea) Song ā€“ personal research during my six years at Swansea ... and bey...
Swan(sea) Song ā€“ personal research during my six years at Swansea ... and bey...Swan(sea) Song ā€“ personal research during my six years at Swansea ... and bey...
Swan(sea) Song ā€“ personal research during my six years at Swansea ... and bey...
Ā 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
Ā 

JAX-RS 2.0: Key Features of the Updated RESTful Web Services API

  • 1. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 1 JAX-RS 2.0: New and Noteworthy in RESTful Web Services API Arun Gupta Java EE & GlassFish Guy blogs.oracle.com/arungupta, @arungupta
  • 2. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 2 JAX-RS - Java API for RESTful Services Ā§ļ‚§ā€Æ POJO-Based Resource Classes Ā§ļ‚§ā€Æ HTTP Centric Programming Model Ā§ļ‚§ā€Æ Entity Format Independence Ā§ļ‚§ā€Æ Container Independence Ā§ļ‚§ā€Æ Included in Java EE Standard annotation-driven API that aims to help developers build RESTful Web services and clients in Java
  • 3. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 3 Example: JAX-RS API @Path("/atm/{cardId}") public class AtmService { @GET @Path("/balance") @Produces("text/plain") public String balance(@PathParam("cardId") String card, @QueryParam("pin") String pin) { return Double.toString(getBalance(card, pin)); } ā€¦ Built-in Serialization Resources URI Parameter Injection HTTP Method Binding
  • 4. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 4 Example: JAX-RS API (contd.) ā€¦ @POST @Path("/withdrawal") @Consumes("text/plain") @Produces("application/json") public Money withdraw(@PathParam("card") String card, @QueryParam("pin") String pin, String amount){ return getMoney(card, pin, amount); } } Custom Serialization
  • 5. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 5 Example: JAX-RS API (contd.)
  • 6. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 6 Example: JAX-RS API (contd.)
  • 7. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 7 JSR-339 a.k.a. JAX-RS 2.0 Ā§ļ‚§ā€Æ Expert Group formed in February, 2011 ā€“ā€Æ Lead by Oracle Ā§ļ‚§ā€Æ Marek Potociar, Santiago Pericas-Geertsen ā€“ā€Æ 13 Group members Ā§ļ‚§ā€Æ Jan Algermissen, Florent Benoit (OW2), Sergey Beryozkin (Talend/CXF), Adam Bien, Bill Burke (RedHat), Clinton L Combs, Bill De Hora, Markus Karg, Sastry Mallady (eBay), Wendy Raschke (IBM), Julian Reschke, Guilherme Silveira, Dionysios Synodinos Ā§ļ‚§ā€Æ Public Review Draft published on Sep 28, 2012 ā€“ā€Æ See JSR-339 JCP site jcp.org/en/jsr/detail?id=339
  • 8. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 8 JAX-RS 2.0 Ā§ļ‚§ā€ÆClient API Ā§ļ‚§ā€ÆCommon configuration Ā§ļ‚§ā€ÆAsynchronous processing Ā§ļ‚§ā€ÆFilters Ā§ļ‚§ā€ÆInterceptors Ā§ļ‚§ā€ÆHypermedia support Ā§ļ‚§ā€ÆServer-side content negotiation
  • 9. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 9 JAX-RS 2.0 Ā§ļ‚§ā€ÆClient API Ā§ļ‚§ā€ÆCommon configuration Ā§ļ‚§ā€ÆAsynchronous processing Ā§ļ‚§ā€ÆFilters Ā§ļ‚§ā€ÆInterceptors Ā§ļ‚§ā€ÆHypermedia support Ā§ļ‚§ā€ÆServer-side content negotiation
  • 10. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 10 Client API Ā§ļ‚§ā€Æ HTTP client libraries too low level Ā§ļ‚§ā€Æ Leveraging providers and concepts from the JAX-RS 1.x API ā€“ā€Æ E.g., MBRs and MBWs Ā§ļ‚§ā€Æ Proprietary APIs introduced by major JAX-RS 1.x implementations ā€“ā€Æ Need for a standard Motivation
  • 11. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 11 Client API // Get instance of Client Client client = ClientFactory.newClient(); // Get account balance String bal = client.target("http://.../atm/{cardId}/balance") .resolveTemplate("cardId", "111122223333") .queryParam("pin", "9876") .request("text/plain").get(String.class);
  • 12. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 12 Client API // Withdraw some money Money mon = client.target("http://.../atm/{cardId}/withdrawal") .resolveTemplate("cardId", "111122223333") .queryParam("pin", "9876") .request("application/json") .post(text("50.0"), Money.class);
  • 13. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 13 Client API Invocation inv1 = client.target("http://.../atm/{cardId}/balance")ā€¦ .request(ā€œtext/plainā€).buildGet(); Invocation inv2 = client.target("http://.../atm/{cardId}/withdraw")ā€¦ .request("application/json") .buildPost(text("50.0"));
  • 14. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 14 Client API Collection<Invocation> invocations = Arrays.asList(inv1, inv2); Collection<Response> responses = Collections.transform( invocations, new F<Invocation, Response>() { public Response apply(Invocation inv) { return inv.invoke(); } });
  • 15. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 15 Client API // Create client and register MyProvider1 Client client = ClientFactory.newClient(); client.configuration().register(MyProvider1.class); // Create atm target; inherits MyProvider1 WebTarget atm = client.target("http://.../atm"); // Register MyProvider2 atm.configuration().register(MyProvider2.class); // Create balance target; inherits MyProvider1, MyProvider2 WebTarget balance = atm.path(ā€{cardId}/balance"); // Register MyProvider3 balance.configuration().register(MyProvider3.class);
  • 16. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 16 JAX-RS 2.0 Ā§ļ‚§ā€ÆClient API Ā§ļ‚§ā€ÆCommon configuration Ā§ļ‚§ā€ÆAsynchronous processing Ā§ļ‚§ā€ÆFilters Ā§ļ‚§ā€ÆInterceptors Ā§ļ‚§ā€ÆHypermedia support Ā§ļ‚§ā€ÆServer-side content negotiation
  • 17. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 17 Common configuration - motivation client.configuration() .register(JsonMessageBodyReader.class) .register(JsonMessageBodyWriter.class) .register(JsonpInterceptor.class) .setProperty(ā€œjsonp.callback.nameā€, ā€œcallbackā€) .setProperty(ā€œjsonp.callback.queryParamā€, ā€œtrueā€) ... Client-side
  • 18. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 18 Common configuration - motivation public class MyApp extends javax.ws.rs.core.Application { public Set<Class<?>> getClasses() { Set<Class<?>> classes = new HashSet<ā€¦>(); ā€¦ classes.add(JsonMessageBodyReader.class); classes.add(JsonMessageBodyWriter.class); classes.add(JsonpInterceptor.class); ā€¦ return classes; } } Server-side
  • 19. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 19 Common configuration - solution client.configuration() .register(JsonMessageBodyReader.class) .register(JsonMessageBodyWriter.class) .register(JsonpInterceptor.class) .setProperty(ā€œjsonp.callback.nameā€, ā€œcallbackā€) .setProperty(ā€œjsonp.callback.queryParamā€, ā€œtrueā€) ... JsonFeature jf = new JsonFeature().enableCallbackQueryParam(); Client.configuration().register(jf); Client-side
  • 20. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 20 Common configuration - solution public Set<Class<?>> getClasses() { ā€¦ classes.add(JsonMessageBodyReader.class); classes.add(JsonMessageBodyWriter.class); classes.add(JsonpInterceptor.class); ā€¦ } public Set<Class<?>> getClasses() { ā€¦ classes.add(JsonFeature.class); ā€¦ } Server-side
  • 21. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 21 Common configuration public interface Configurable { Map<String, Object> getProperties(); Object getProperty(String name); Configurable setProperties(Map<String, ?> properties); Configurable setProperty(String name, Object value); Collection<Feature> getFeatures(); Set<Class<?>> getProviderClasses(); Set<Object> getProviderInstances(); Configurable register(...); ... }
  • 22. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 22 Common configuration public interface Feature { boolean configure(Configurable configurable); }
  • 23. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 23 A Feature example public void JsonFeature implements Feature { public boolean configure(Configurable config) { config.register(JsonMessageBodyReader.class) .register(JsonMessageBodyWriter.class) .register(JsonpInterceptor.class) .setProperty(CALLBACK_NAME, calbackName) .setProperty(USE_QUERY_PARAM, useQueryParam); return true; } }
  • 24. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 24 Dynamic Feature public interface DynamicFeature { void configure(ResourceInfo ri, Configurable configurable); } public interface ResourceInfo { Method getResourceMethod(); Class<?> getResourceClass(); } Server-side only
  • 25. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 25 JAX-RS 2.0 Ā§ļ‚§ā€ÆClient API Ā§ļ‚§ā€ÆCommon configuration Ā§ļ‚§ā€ÆAsynchronous processing Ā§ļ‚§ā€ÆFilters Ā§ļ‚§ā€ÆInterceptors Ā§ļ‚§ā€ÆHypermedia support Ā§ļ‚§ā€ÆServer-side content negotiation
  • 26. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 26 Async Processing Ā§ļ‚§ā€Æ Server API support ā€“ā€Æ Off-load I/O container threads Ā§ļ‚§ā€Æ Long-running operations ā€“ā€Æ Efficient asynchronous event processing Ā§ļ‚§ā€Æ Suspend while waiting for an event Ā§ļ‚§ā€Æ Resume when event arrives ā€“ā€Æ Leverage Servlet 3.x async support (if available) Ā§ļ‚§ā€Æ Client API support ā€“ā€Æ Asynchronous request invocation API Ā§ļ‚§ā€Æ Future<RESPONSE>, InvocationCallback<RESPONSE> Ā 
  • 27. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 27 Async Processing: Server-side @Path("/async/longRunning") public class MyResource { @GET public void longRunningOp(@Suspended AsyncResponse ar) { ar.setTimeoutHandler(new MyTimoutHandler()); ar.setTimeout(15, SECONDS); Executors.newSingleThreadExecutor().submit(new Runnable() { public void run() { ā€¦ ar.resume(result); } }); } }
  • 28. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 28 Async Processing: Server-side public interface AsyncResponse { public void resume(Object/Throwable response); public void cancel(); public void cancel(int/Date retryAfter); public boolean isSuspended(); public boolean isCancelled(); public boolean isDone(); public void setTimeout(long time, TimeUnit unit); public void setTimeoutHandler(TimeoutHandler handler); public boolean register(Class<?> callback); public boolean[] register(Class<?> callback, Class<?>... callbacks); public boolean register(Object callback); public boolean[] register(Object callback, Object... callbacks); }
  • 29. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 29 Async Processing: Server-side @Target({ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface Suspended { } public interface TimeoutHandler { void handleTimeout(AsyncResponse asyncResponse); }
  • 30. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 30 Async Processing: Server-side public interface ResumeCallback { public void onResume(AsyncResponse resuming, Response response); public void onResume(AsyncResponse resuming, Throwable error); } public interface CompletionCallback { public void onComplete(); public void onError(Throwable throwable); } public interface ConnectionCallback { public void onDisconnect(AsyncResponse disconnected); }
  • 31. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 31 Async Processing: Client-side WebTarget target = client.target("http://.../balanceā€)ā€¦ // Start async call and register callback Future<?> handle = target.request().async().get( new InvocationCallback<String>() { void complete(String balance) { ā€¦ } void failed(InvocationException e) { ā€¦ } }); // After waiting for too longā€¦ if (!handle.isDone()) handle.cancel(true);
  • 32. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 32 JAX-RS 2.0 Ā§ļ‚§ā€ÆClient API Ā§ļ‚§ā€ÆCommon configuration Ā§ļ‚§ā€ÆAsynchronous processing Ā§ļ‚§ā€ÆFilters Ā§ļ‚§ā€ÆInterceptors Ā§ļ‚§ā€ÆHypermedia support Ā§ļ‚§ā€ÆServer-side content negotiation
  • 33. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 33 Filters & Interceptors Ā§ļ‚§ā€Æ Customize JAX-RS request/response processing ā€“ā€Æ Use Cases: Logging, Compression, Security, Etc. Ā§ļ‚§ā€Æ Introduced for client and server APIs Ā§ļ‚§ā€Æ Replace existing proprietary support ā€“ā€Æ Provided by most JAX-RS 1.x implementations Ā§ļ‚§ā€Æ All using slightly different types or semantics Motivation
  • 34. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 34 Filters & Interceptors Ā§ļ‚§ā€Æ Non-wrapping filter chain ā€“ā€Æ Filters do not invoke next filter in the chain directly ā€“ā€Æ managed by the JAX-RS runtime Ā§ļ‚§ā€Æ Each filter decides to proceed or break the chain Filter each incoming/outgoing message Ā§ļ‚§ā€Æ Request ĆØļƒØ Request ā€“ā€Æ ContainerRequestFilter, Ā  ClientRequestFilter Ā  Ā§ļ‚§ā€Æ Response ĆØļƒØ Response ā€“ā€Æ ContainerResponseFilter, Ā  ClientResponseFilter Ā§ļ‚§ā€Æ Server-side specialties ā€“ā€Æ @PreMatching, Ā DynamicFeature
  • 35. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 35 Filters & Interceptors public class RequestLoggingFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) { log(requestContext); // non-wrapping => returns without invoking the next filter } ... } A Logging Filter Example
  • 36. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 36 Filters & Interceptors Ā§ļ‚§ā€Æ Invoked ONLY when/if entity processing occurs ā€“ā€Æ Performance boost Ā§ļ‚§ā€Æ Wrapping interceptor chain ā€“ā€Æ Each interceptor invokes the next one in the chain via context.proceed() Ā  Intercept entity providers Ā§ļ‚§ā€Æ MessageBodyReader interceptor ā€“ā€Æ ReaderInterceptor interface Ā§ļ‚§ā€Æ MessageBodyWriter interceptor ā€“ā€Æ WriterInterceptor interface
  • 37. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 37 Filters & Interceptors public class GzipInterceptor implements ReaderInterceptor { @Override Object aroundReadFrom(ReaderInterceptorContext ctx) { InputStream old = ctx.getInputStream(); ctx.setInputStream(new GZIPInputStream(old)); // wrapping => invokes the next interceptor Object entity = ctx.proceed(); ctx.setInputStream(old); return entity; } } A GZip Reader Interceptor Example
  • 38. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 38 Application Filters & Interceptors Request Filter Filter Network Transport ā€¦ ā€¦ Response Filter Filter write(ā€¦) Writer Interceptor ā€¦ MBW read(ā€¦) - optional ā€¦ MBR Writer Interceptor Reader Interceptor Reader Interceptor
  • 39. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 39 Response Application Filters & Interceptors Filter Filter Network ā€¦ Response Filter Filter write(ā€¦) ā€¦ MBW Writer Interceptor Writer Interceptor Filter Filter ā€¦ Request Request read(ā€¦) - optional Reader Interceptor ā€¦ MBR Reader Interceptor Filter Filter Resource Matching @PreMatching
  • 40. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 40 Bindings & Priorities Ā§ļ‚§ā€Æ Binding ā€“ā€Æ Associating filters and interceptors with resource methods ā€“ā€Æ Server-side concept Ā§ļ‚§ā€Æ Priority ā€“ā€Æ Declaring relative position in the execution chain ā€“ā€Æ @BindingPriority(int Ā priority) Ā  Ā§ļ‚§ā€Æ Shared concept by filters and interceptors Scoped Binding Global Binding Static @NameBinding (@Qualifier?) Default @PreMatching Dynamic DynamicFeature N/A
  • 41. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 41 Bindings @NameBinding // or @Qualifier ? @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(value = RetentionPolicy.RUNTIME) public @interface Logged {} @Provider @Logged @BindingPriority(USER) public class LoggingFilter implements ContainerRequestFilter, ContainerResponseFilter { ā€¦ }
  • 42. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 42 Bindings @Path("/greet/{name}") @Produces("text/plain") public class MyResourceClass { @Logged @GET public String hello(@PathParam("name") String name) { return "Hello " + name; } }
  • 43. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 43 A DynamicFeature example public void SecurityFeature implements DynamicFeature { public boolean configure(ResourceInfo ri, Configurable config) { String[] roles = getRolesAllowed(ri); if (roles != null) { config.register(new RolesAllowedFilter(roles)); } } ā€¦ } Server-side only
  • 44. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 44 JAX-RS 2.0 Ā§ļ‚§ā€ÆClient API Ā§ļ‚§ā€ÆCommon configuration Ā§ļ‚§ā€ÆAsynchronous processing Ā§ļ‚§ā€ÆFilters Ā§ļ‚§ā€ÆInterceptors Ā§ļ‚§ā€ÆHypermedia support Ā§ļ‚§ā€ÆServer-side content negotiation
  • 45. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 45 Hypermedia Ā§ļ‚§ā€Æ REST principles ā€“ā€Æ Identifiers and Links ā€“ā€Æ HATEOAS (Hypermedia As The Engine Of App State) Ā§ļ‚§ā€Æ Link types: ā€“ā€Æ Structural Links ā€“ā€Æ Transitional Links
  • 46. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 46 Hypermedia Link: <http://.../orders/1/ship>; rel=ship, <http://.../orders/1/cancel>; rel=cancel ... <order id="1"> <customer>http://.../customers/11</customer> <address>http://.../customers/11/address/1</address> <items> <item> <product>http://.../products/111</product> <quantity>2</quantity> </item> <items> ... </order> Transitional Links Structural Links
  • 47. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 47 Hypermedia Ā§ļ‚§ā€Æ Link and LinkBuilder classes ā€“ā€Æ RFC 5988: Web Linking Ā§ļ‚§ā€Æ Support for Link in ResponseBuilder and filters Ā  ā€“ā€Æ Transitional links (headers) Ā§ļ‚§ā€Æ Support for manual structural links ā€“ā€Æ Via Link.JaxbAdapter & Link.JaxbLink Ā§ļ‚§ā€Æ Create a resource target from a Link in Client API
  • 48. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 48 Hypermedia // Producer API (server-side) Link self = Link.fromResourceMethod(MyResource.class, ā€handleGetā€) .build(); Link update = Link.fromResourceMethod(MyResource.class, ā€œhandlePostā€) .rel(ā€updateā€) .build(); ... Response res = Response.ok(order) .link("http://.../orders/1/ship", "ship") .links(self, update) .build();
  • 49. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 49 Hypermedia Response order = client.target(ā€¦).request("application/xml").get(); // Consumer API (client-side) Link shipmentLink = order.getLink(ā€œshipā€); if (shipmentLink != null) { Response shipment = client.target(shipmentLink).post(null); ā€¦ }
  • 50. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 50 JAX-RS 2.0 Ā§ļ‚§ā€ÆClient API Ā§ļ‚§ā€ÆCommon configuration Ā§ļ‚§ā€ÆAsynchronous processing Ā§ļ‚§ā€ÆFilters Ā§ļ‚§ā€ÆInterceptors Ā§ļ‚§ā€ÆHypermedia support Ā§ļ‚§ā€ÆServer-side content negotiation
  • 51. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 51 Server Side Conneg GET http://.../widgets2 Accept: text/*; q=1 ā€¦ Path("widgets2") public class WidgetsResource2 { @GET @Produces("text/plain", "text/html") public Widgets getWidget() {...} }
  • 52. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 52 Server Side Conneg GET http://.../widgets2 Accept: text/*; q=1 ā€¦ Path("widgets2") public class WidgetsResource2 { @GET @Produces("text/plain; qs=0.5", "text/html; qs=0.75") public Widgets getWidget() {...} }
  • 53. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 53 JAX-RS 2.0 Summary Ā§ļ‚§ā€Æ Major new features ā€“ā€Æ Client API, Filters & Interceptors, Asynchronous Resources, Hypermedia Ā§ļ‚§ā€Æ Many minor API improvements and extensions ā€“ā€Æ Request / Response, URI builder, String Converters, @BeanParam, MultivaluedHashMap, GenericType, ā€¦ Ā§ļ‚§ā€Æ Improved TCK coverage = improved portability ā€“ā€Æ ~350 tests in JAX-RS 1.x, ~1700 tests in JAX-RS 2.0
  • 54. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 54 <a href=ā€œā€¦ā€ >JAX-RS 2.0</a> Ā§ļ‚§ā€Æ Project web site jax-rs-spec.java.net Ā§ļ‚§ā€Æ Users mailing list users@jax-rs-spec.java.net Ā§ļ‚§ā€Æ JSR-339 site jcp.org/en/jsr/detail?id=339 ā€“ā€Æ Latest specification text draft Ā§ļ‚§ā€Æ java.net/projects/jax-rs-spec/sources/git/content/spec/spec.pdf ā€“ā€Æ Latest API snapshot Ā§ļ‚§ā€Æ jax-rs-spec.java.net/nonav/2.0-SNAPSHOT/apidocs/index.html
  • 55. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 55 <a href=ā€œā€¦ā€ >Jersey 2.0</a> Ā§ļ‚§ā€Æ Project web site jersey.java.net Ā§ļ‚§ā€Æ Users mailing list users@jersey.java.net ā€“ā€Æ Latest users guide Ā§ļ‚§ā€Æ http://jersey.java.net/nonav/documentation/snapshot/index.html ā€“ā€Æ Latest API documentation Ā§ļ‚§ā€Æ http://jersey.java.net/nonav/apidocs/snapshot/jersey/index.html
  • 56. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 56
  • 57. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 57
  • 58. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 58 JAX-RS 2.0 Ā§ļ‚§ā€ÆDI (JSR-330) Integration Ā§ļ‚§ā€ÆBean Validation Ā§ļ‚§ā€ÆImproved Java EE Security Support Ā§ļ‚§ā€ÆPresentation Layer Ā§ļ‚§ā€ÆHigh-level Client API
  • 59. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 59 Dependency Injection Integration Ā§ļ‚§ā€Æ Support Java Dependency Injection API (JSR-330) ā€“ā€Æ Support Ā @Inject Ā and Ā @Qualifier ? ā€“ā€Æ @Qualifier Ā as a replacement for Ā @NamedBinding Ā ? ā€“ā€Æ Provider vs. Ā ContextResolver ? ā€“ā€Æ Support DI (JSR-330) or CDI (JSR-299)? Ā§ļ‚§ā€Æ Issues ā€“ā€Æ Interference with CDI providers ā€“ā€Æ EG does not see enough added value for DI Ā§ļ‚§ā€Æ DI-style injection support deferred
  • 60. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 60 Dependency Injection Integration Ā§ļ‚§ā€Æ Java EE Deployments ā€“ā€Æ Tight CDI integration makes sense (unification of Java EE component model) Ā§ļ‚§ā€Æ Java SE Deployments ā€“ā€Æ DI provides all the required features ā€“ā€Æ CDI is too heavy-weight Ā§ļ‚§ā€Æ Many redundant features ā€“ā€Æ method interceptors, decorators, stereotypes ā€¦ Ā§ļ‚§ā€Æ Additional limitations put on managed components Support DI (JSR-330) or CDI (JSR-299)?
  • 61. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 61 Bean Validation Ā§ļ‚§ā€Æ Dropped from JAX-RS 2.0 Public Review ā€“ā€Æ Difficulty aligning schedules Ā§ļ‚§ā€Æ Still supported via CDI 1.1 ā€“ā€Æ JAX-RS resource class must be CDI bean ā€“ā€Æ BV 1.1 now supports method validation Ā§ļ‚§ā€Æ May revisit current plan post Java EE 7
  • 62. Copyright Ā© 2012, Oracle and/or its affiliates. All rights reserved. 62 More Topicsā€¦ Ā§ļ‚§ā€Æ Improved Java EE security support ā€“ā€Æ @RolesAllowed, ā€¦ ā€“ā€Æ SecurityContext.authenticate(ā€¦) Ā§ļ‚§ā€Æ Pluggable Views ā€“ā€Æ Completes the MVC pattern Ā§ļ‚§ā€Æ High-level client API ā€“ā€Æ Hard to design it to be RESTful ā€“ā€Æ Jersey 2 provides an experimental support ā€“ā€Æ Donā€™t want to end-up with an RPC-style API