JAX-RS Entity Providers - Quiz

Total: 26 questions

1. How are called components which provide the user-level extensibility?
- entity providers, - message body providers, - message body workers or -message body readers and writers.
2. 

Interfaces of JAX-RS extension API.

MessageBodyReader<T> and MessageBodyWriter<T>.

3. 

What MessageBodyReader<T> is used for?

For handling inbound entity representation-to-Java de-serialization.

4. 

What is MessageBodyWriter<T> used for?

For handling the outbound entity Java-to-representation serialization.

5. 

Where MessageBodyWriter<T> and MessageBodyReader<T> should be used - on client or server side?

On both.

6. 

Does Jersey support serialization of JAXB beans into XML by default?

Yes.

7. 

Methods of interface MessageBodyWriter<T>.

- long getSize(...)

- boolean isWriteable(...)

- void writeTo(...)

8. 

What a method isWriteable is used for?

To verify if the MessageBodyWriter<T> can write T type.

9. What parameter 'annotations' of MessageBodyWriter is used for?
It contains annotations which are attached to the resource method and the entity by building response.
10. 

Which annotation parameters will the MessageBodyWriter<T> receive for this response?

@Path("exams")
public class ExamResource {
    @GET
    public Response get() {
        Annotation annotation = AnnotatedResource.class
                            .getAnnotation(Path.class);
        return Response.ok()
                .entity("Entity", new Annotation[] {annotation}).build();
    }
}

@GET and @Path annotations.

11. 

Are classes level annotations included in 'annotations' parameter of MessageBodyWriter<T> methods?

No, only method levels annotations are included.

12. 

Which annotations will be returned to MessageBodyWriter<T> for this example?

@GET
@Produces("application/xml")
public ExamBean getExamBean() {
    return new ExamBean("Exam78", 78);
}

@GET and @Produces annotations.

13. 

What does 'mediaType' parameter of MessageBodyWriter<T>. isWriteable contain?

The media type attached to the response entity by annotating the resource method with a @Produces annotation or the request media type specified in the JAX-RS Client API.

14. 

What is the mediaType value for this example? 

@GET
@Produces("application/xml")
public ExamBean getExamBean() {
   return new ExamBean("OCEJWSD 6", 78);
}

"application/xml"

15. 

How to limit the number of execution of MessageBodyWriter.isWriteable method?

By declaring the @Produces annotation on the MessageBodyWriter<T>.

16. 

What does 'httpHeaders' parameter of MessageBodyWriter<T>. writeTo() contain?

HTTP headers associated with the outbound message.

17. 

Can headers be modified when a MessageBodyWriter<T> is called?

Yes.

18. 

What does parameter 'entityStream' of MessageBodyWriter<T>. writeTo() contain?

The entity output stream where the entity should be serialized.

19. 

Should the entityStream be closed at the end of MessageBodyWriter<T>. writeTo() method?

No, the stream will be closed by Jersey.

20. What MessageBodyWriter.getSize was used in JAX-RS 1.0 for?
In JAX-RS 1.0 the method could return the size of the entity that would be then used for "Content-Length" response header.
21. 

Methods of MessageBodyReader<T> interface.

- isReadable(...)

- readFrom(...)

22. What method isReadable() is used for?
It returns true if it is possible to de-serialize the given type.
23. What does mediaType parameter of MessageBodyReader. isReadable method contain?
The entity media type, that is specified by @Consumes annotation.
24. 

How to decrease number of isReadable executions?

The consumable media types should be defined correctly in the @Consumes annotation on the MessageBodyReader<T>.

25. What the entityStream parameter of MessageBodyReader .readFrom is used for?
It provides a handle to the entity input stream from which the entity bytes should be read and de-serialized into a Java entity which is then returned from the method.
26. 

Should entity input stream in MessageBodyReader<T> implementation be closed?

No, the stream will be automatically closed by Jersey runtime.

Page 1 of 1