JAX-RS Entity Providers - Quiz
Total: 26 questions
1. How are called components which provide the user-level extensibility?
2. Interfaces of JAX-RS extension API.
Interfaces of JAX-RS extension API.
MessageBodyReader<T> and MessageBodyWriter<T>.
3. What MessageBodyReader<T> is used for?
What MessageBodyReader<T> is used for?
For handling inbound entity representation-to-Java de-serialization.
4. What is MessageBodyWriter<T> used for?
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?
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?
Does Jersey support serialization of JAXB beans into XML by default?
Yes.
7. Methods of interface MessageBodyWriter<T>.
Methods of interface MessageBodyWriter<T>.
- long getSize(...)
- boolean isWriteable(...)
- void writeTo(...)
8. What a method isWriteable is used for?
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?
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();
}
}
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?
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);
}
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?
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);
}
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?
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?
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?
Can headers be modified when a MessageBodyWriter<T> is called?
Yes.
18. What does parameter 'entityStream' of MessageBodyWriter<T>. writeTo() contain?
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?
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?
21. Methods of MessageBodyReader<T> interface.
Methods of MessageBodyReader<T> interface.
- isReadable(...)
- readFrom(...)
22. What method isReadable() is used for?
23. What does mediaType parameter of MessageBodyReader. isReadable method contain?
24. How to decrease number of isReadable executions?
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?
26. Should entity input stream in MessageBodyReader<T> implementation be closed?
Should entity input stream in MessageBodyReader<T> implementation be closed?
No, the stream will be automatically closed by Jersey runtime.