Thursday 6 December 2018

// // Leave a Comment

REST-Annotations @Provider & @Context


@Provider:


@Provider is used to register the provider classes with the JAX-RS Runtime.

Different provider interfaces/classes where we can use @Provider Annotation:
There are some list of provider interfaces/classes are there which are going to registed using @Provider annotation which are given below

1. ParamConverterProvider-Contract for a provider of ParamConverter instances
2. MessageBodyReader-Contract for a provider that supports the conversion of a stream to a Java type
3. MessageBodyWriter-Contract for a provider that supports the conversion of a Java type to a stream
4. ContextResolver-Contract for a provider that supplies context information to resource classes and other providers 

 @Context: 

Purpose of @Context:
In order to access the predefined obj's there are there with the JAX-RS we need to use @Context annotaion so that JAX-RS Runtime will injects into our Resource class.

Different places where we can use @Contex Annotation:

There are predefined obj's that are there in JAX-RS API where if we wanted to access those obj so let the JAX-RS Runtime to inject those predefined obj's (like UriInfo obj) into pur Resource class for this we need to annotate with @Context annotation.

We can use @Context to get the predefined obj's that are there in JAX-RS API some of them are
1. UriInfo-An injectable interface that provides access to application and request URI information
2. HttpHeaders-An injectable interface that provides access to HTTP header information
3. Providers interface-An injectable interface providing runtime lookup of provider instances
4. SecurityContext
5. Request [For caching purpose]

0 comments:

Post a Comment