JAX-RS - Quiz

Total: 33 questions

1. What are root resource classes?
They are POJOs that are annotated with @Path and have at least one method annotated with @Path or a resource method designator annotation such as @GET, @PUT, @POST, @DELETE.
2. 

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?
A relative URI path.
4. What are URI path templates?
URIs with variables inserted within the URI syntax.
5. 

Example of URI path template.

@Path("/exams/{id}")

6. 

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?
@GET, @PUT, @POST, @DELETE, @HEAD, @OPTIONS
8. What @Produces annotation is used for?
It is used to specify the MIME media types of representations which a resource can produce and send to the client.
9. Which levels @Produces can be applied at?
At the class and method levels.
10. Which resource method is chosen if a resource class can produce several MIME media type?
It will correspond to the most acceptable 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() {
        ...
    }
}

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() {
        ...
    }
}

The getEXamsHtml().

13. How many media types can be declared in the @Produces declaration?
Many.
14. What quality factor is used for?
If client accepts several media types then a server sends method with bigger quality factor.
15. What the @Consumes annotation is used for?
To specify the MIME media types which can be consumed by a resource.
16. 

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?
The class and the method levels.
18. How many media types can be defined for @Consumes?
Many.
19. 

Default life-cycle of root resource classes.

It is per-request.

20. 

Enumerate resource scopes.

- Per-request scope;

- Per-session scope;

- Singleton scope;

21. 

Which annotation is used for per-request scope lifecycle?

@PerRequest or none.

22. 

Which annotation is used for per-session scope lifecycle?

@PerSession

23. Which annotation is used for Singleton scope lifecycle?
@Singleton
24. 

Describe per-session scope.

The resource instance is created per web session and stored as a session attribute.

25. Describe singleton scope.
In this scope there is only one instance per jax-rs application.
26. 

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)?

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)?

MultivaluedMap<String,String>

29. Which Java types correspond to Plain text (text/plain)?
1.java.lang.Boolean 2.java.lang.Character 3.java.lang.Number
30. How is called a method parameter without an annotation?
An entity.
31. How many unannotated method parameter may exist?
A maximum of one.
32. 

Can Content-Type response header be set automatically?

Yes.

33. 

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.

Page 1 of 1