Sub-Resources - Quiz
Total: 10 questions
1. What is sub-resource method?
What is sub-resource method?
The sub-resource methods are methods of a resource class that are annotated with @Path and one of the request method designators (@GET, @PUT, @POST or @DELETE).
2. What is called sub-resource locator?
What is called sub-resource locator?
Sub-resource locators are methods that are annotated with @Path but without request method designator.
3. Can sub-resource locators return sub-type?
@Path("exam")
public class ExamResource {
@Path("/")
public Object getSomeResource() {
return new SomeResource();
}
}
Can sub-resource locators return sub-type?
@Path("exam")
public class ExamResource {
@Path("/")
public Object getSomeResource() {
return new SomeResource();
}
}Yes.
4. Is it possible to manage the life-cycle or inject any field on instances returned from sub-resource locator methods?
Is it possible to manage the life-cycle or inject any field on instances returned from sub-resource locator methods?
No.
5. Change the example to make the runtime manages the sub-resources as standard resources.
@Path("/exams")
public class ExamResource {
@Path("categories")
public CategoryResource getCategoryResource() {
// ....
}
}
@Singleton
public class CategoryResource {
// ...
}
Change the example to make the runtime manages the sub-resources as standard resources.
@Path("/exams")
public class ExamResource {
@Path("categories")
public CategoryResource getCategoryResource() {
// ....
}
}
@Singleton
public class CategoryResource {
// ...
}@Path("/exams")
public class ExamResource {
@Path("categories")
public Class<CategoryResource> getCategoryResource() {
return CategoryResource.class;
}
}
@Singleton
public class CategoryResource {
//...
}
6. Will the returned resource be managed as Singleton?
@Path("exams")
public class ExamResource {
@Path("categories")
public CategoryResource getCategoryResource() {
return CategoryResource.class;
}
}
@Singleton
public class CategoryResource {
//
}
Will the returned resource be managed as Singleton?
@Path("exams")
public class ExamResource {
@Path("categories")
public CategoryResource getCategoryResource() {
return CategoryResource.class;
}
}
@Singleton
public class CategoryResource {
//
}No, if the method return instance of the class, the Singleton annotation have no effect and the returned instance is used.
7. The difference between sub-resource methods and sub-resource locators.
The difference between sub-resource methods and sub-resource locators.
Sub-resource locators don't have request method designator.
8. Can sub-resource locators have the same parameters as resource methods?
Can sub-resource locators have the same parameters as resource methods?
They MUST NOT have an entity parameter.
9. Which method is a sub-resource method?
@Path("exams")
public class ExamService {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getExams() {
...
}
@GET
@Path("/categories")
@Produces(MediaType.TEXT_PLAIN)
public String getCategories() {
...
}
}
Which method is a sub-resource method?
@Path("exams")
public class ExamService {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getExams() {
...
}
@GET
@Path("/categories")
@Produces(MediaType.TEXT_PLAIN)
public String getCategories() {
...
}
}
getCategories()
10. What sub-resource locators are used for?
What sub-resource locators are used for?
The sub-resource locators return an object that will handle an HTTP request.