Java Reference
In-Depth Information
... the implementation ...
public StreamingOutput getCustomer ( int
int id )
... the implementation ...
public void
int id , InputStream is ) {
... the implementation ...
void updateCustomer ( int
As you can see, no JAX-RS annotations are needed within the implementing class. All our
metadata is confined to the CustomerResource interface.
If you need to, you can override the metadata defined in your interfaces by reapplying an-
notations within your implementation class. For example, maybe we want to enforce a spe-
cific character set for POST XML:
public class
class CustomerResourceService
CustomerResourceService implements
implements CustomerResource {
@Consumes ( "application/xml;charset=utf-8" )
public Response createCustomer ( InputStream is ) {
... the implementation ...
In this example, we are overriding the metadata defined in an interface for one specific meth-
od. When overriding metadata for a method, you must respecify all the annotation metadata
for that method even if you are changing only one small thing.
Overall, I do not recommend that you do this sort of thing. The whole point of using an inter-
face to apply your JAX-RS metadata is to isolate the information and define it in one place.
If your annotations are scattered about between your implementation class and interface,
your code becomes a lot harder to read and understand.
The JAX-RS specification also allows you to define class and interface hierarchies if you so
desire. For example, let's say we wanted to make our outputCustomer() and readCus-
tomer() methods abstract so that different implementations could transform XML how they
package com . restfully . shop . services ;
import ...
... ;
Search WWH ::

Custom Search