JAX-RS - Quiz
Total: 33 questions
1. What are root resource classes?
2. What are resource methods?
What are resource methods?
Resource methods are methods of the resource class annotated with a request method designator and without @Path annotation.
3. What should be in the @Path annotation's value?
4. What are URI path templates?
5. Example of URI path template.
Example of URI path template.
@Path("/exams/{id}")
6. Should a @Path value begin and end with '/'?
Should a @Path value begin and end with '/'?
A @Path value may or may not begin and end with a '/', it makes no difference.
7. Which resource method designator annotations are defined by JAX-RS?
8. What @Produces annotation is used for?
9. Which levels @Produces can be applied at?
10. Which resource method is chosen if a resource class can produce several MIME media type?
11. Which method of this resource is invoked if the Accept header is "Accept: text/plain"?
@Path("exams")
public class ExamService {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getExams() {
...
}
@GET
@Produces(MediaType.TEXT_HTML)
public String getExamsHtml() {
...
}
}
Which method of this resource is invoked if the Accept header is "Accept: text/plain"?
@Path("exams")
public class ExamService {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getExams() {
...
}
@GET
@Produces(MediaType.TEXT_HTML)
public String getExamsHtml() {
...
}
}
The getExams.
12. Which method of this resource is invoked if the Accept header is "Accept: text/plain;q=0.9, text/html"?
@Path("exams")
public class ExamService {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getExams() {
...
}
@GET
@Produces(MediaType.TEXT_HTML)
public String getExamsHtml() {
...
}
}
Which method of this resource is invoked if the Accept header is "Accept: text/plain;q=0.9, text/html"?
@Path("exams")
public class ExamService {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getExams() {
...
}
@GET
@Produces(MediaType.TEXT_HTML)
public String getExamsHtml() {
...
}
}The getEXamsHtml().
13. How many media types can be declared in the @Produces declaration?
14. What quality factor is used for?
15. What the @Consumes annotation is used for?
16. Which response is returned to the client by addExam method?
@POST
@Consumes("text/plain")
public void addExam(String name) {
//...
}
Which response is returned to the client by addExam method?
@POST
@Consumes("text/plain")
public void addExam(String name) {
//...
}Response with a status code of 204 (no content).
17. Which levels @Consumes can be applied at?
18. How many media types can be defined for @Consumes?
19. Default life-cycle of root resource classes.
Default life-cycle of root resource classes.
It is per-request.
20. Enumerate resource scopes.
Enumerate resource scopes.
- Per-request scope;
- Per-session scope;
- Singleton scope;
21. Which annotation is used for per-request scope lifecycle?
Which annotation is used for per-request scope lifecycle?
@PerRequest or none.
22. Which annotation is used for per-session scope lifecycle?
Which annotation is used for per-session scope lifecycle?
@PerSession
23. Which annotation is used for Singleton scope lifecycle?
24. Describe per-session scope.
Describe per-session scope.
The resource instance is created per web session and stored as a session attribute.
25. Describe singleton scope.
26. Which Java types correspond to all media types (*/*)?
Which Java types correspond to all media types (*/*)?
1. byte[]
2. java.lang.String
3. java.io.Reader (inbound only)
4. java.io.File
5. javax.activation. DataSource
6. javax.ws.rs.core. StreamingOutput (outbound only)
27. Which Java types correspond to XML media types (text/xml, application/xml and application/...+xml)?
Which Java types correspond to XML media types (text/xml, application/xml and application/...+xml)?
1. javax.xml.transform.Source
2. javax.xml.bind.JAXBElement
3. Application supplied JAXB classes (types annotated with @XmlRootElement or@XmlType)
28. Which Java types correspond to Form content (application/x-www-form-urlencoded)?
Which Java types correspond to Form content (application/x-www-form-urlencoded)?
MultivaluedMap<String,String>
29. Which Java types correspond to Plain text (text/plain)?
30. How is called a method parameter without an annotation?
31. How many unannotated method parameter may exist?
32. Can Content-Type response header be set automatically?
Can Content-Type response header be set automatically?
Yes.
33. Describe request scope.
Describe request scope.
The resource instance is created for each new request and used for processing of this request. If the resource is used more than one time in the request processing, always the same instance will be used.