Use of @Context - Quiz

Total: 10 questions

1. 

Write example of receiving general map of URI path and query parameters.

@GET
public String get(@Context UriInfo ui) { 
    MultivaluedMap<String, String> queryParams = ui.getQueryParameters(); 
    MultivaluedMap<String, String> pathParams = ui.getPathParameters(); 
}
2. 

Example of receiving general map of header and cookie parameters.

@GET
public String get(@Context HttpHeaders httpHeaders) {
     MultivaluedMap<String, String> headerParams = httpHeaders.getRequestHeaders();
     Map<String, Cookie> cookies = httpHeaders.getCookies();
     ...
}
3. 

Example of using UriInfo to return resource absolute path.

@Path("exams")
public class ExamService {
    @GET
    public String get(@Context UriInfo uriInfo) {
        return  uriInfo.getAbsolutePath().toASCIIString();
    }
}
4. 

What UriBuilder is used for?

To build new URIs.

5. 

What UriInfo is used for?

The UriInfo object gives the possibility to find or build URI information of a request.

6. 

What SecurityContext is used for?

The SecurityContext provides security information of the current request, for example: the current user principal, information about roles assumed by the requester, whether the request arrived over a secure channel and the authentication scheme used.

7. 

What UriInfo, HttpHeaders, Request and SecurityContext are used for?

To receive and process the application deployment context and the context of individual requests.

8. 

How the instances of UriInfo, HttpHeaders, Request and SecurityContext are injected?

With the help of @Context annotation.

9. 

The place for injection UriInfo, HttpHeaders, Request and SecurityContext.

A class field or method parameter.

10. 

What the HttpHeaders is used for?

HttpHeaders provides access to request header information.

Page 1 of 1