Span | ||
---|---|---|
| ||
JAX-RS : Understanding the Basics |
Table of Contents |
---|
What is New in JAX-RS 2.0
...
Code Block | ||||
---|---|---|---|---|
| ||||
package org.apache.cxf.customverb; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @HttpMethod("PATCH") public @interface PATCH { } |
Default Http Method
CXF 3.0.4 introduces a new extension, a org.apache.cxf.jaxrs.ext.DefaultMethod annotation. It can be used to match arbitrary HTTP methods on a single resource method. This can be used in some advanced scenarious for integrating the CXF JAX-RS runtime into non-JAX-RS environments as well as in cases where it is awkward/difficult to have every HTTP method listed for a given path segment. CXF users need to be aware using this option will lead to a non-portable JAX-RS code.
Return types
Either javax.ws.rs.core.Response or custom type can be returned. javax.ws.rs.core.Response can be used to set the HTTP response code, headers and entity. JAX-RS MessageBodyWriters (see below) are in charge of serializing the response entities, those which are returned directly or as part of javax.ws.rs.core.Response.
...
Code Block | ||||
---|---|---|---|---|
| ||||
@Path("/") public class Test1 { @Path("/bar") @POST @Consumes({"application/json", "application/xml"}) @Produces({"application/json", "application/xml"}) public Order addOrder(OrderDetails details) {...} } |
Custom selection between multiple resources or operations
The JAX-RS selection algorithm has been designed with a lot of attention being paid to various possible cases, as far as the selection between multiple matching resource classes or methods is concerned.
...