Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock Exam Doubts

 
Hany Shafik
Ranch Hand
Posts: 80
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone

I can find the below question recurrent in many mock exams

8. Given:
3: class MyServlet extends HttpServlet {
4: public void doPut(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException {
5: // servlet code here
...
26: }
27: }
If the DD contains a single security constraint associated with MyServlet and its only <httpmethod>
tags
and <authconstraint>
tags are:
<httpmethod>
GET</httpmethod>
<httpmethod>
PUT</httpmethod>
<authconstraint>
Admin</authconstraint>
Which four requests would be allowed by the container? (Choose four.)
A. A user whose role is Admin can perform a PUT.
B. A user whose role is Admin can perform a GET.
C. A user whose role is Admin can perform a POST.
D. A user whose role is Member can perform a PUT.
E. A user whose role is Member can perform a POST.
F. A user whose role is Member can perform a GET.
Answer: ABCE


I think that the answer is incorrect, because put method is the only http method implemented in MyServlet, All other methods regards of their security constraint will rely with http error 405 "Method is not supported"
So I guess the correct answer would be A only.
I know that the same question above has been posted before, however they were having different concerns than mine.

Please let me know, if my understanding is wrong.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the ranch ! Please don't forget to quote your sources when you have a question concerning a mock exam.
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
extends HttpServlet - it means that a couple of methods are inherited. Those methods are in your class. For example - default implementation of doHead(...) invokes doGet(...) method

EDIT
In this case it will not work. doPost and doGet should be implemented.
However it will not work, but because of the lack of implementation, not because authorization.
The answer is rather correct.
 
Hany Shafik
Ranch Hand
Posts: 80
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply.
I guess that most of the default implementation of the doXXX methods in HttpServlet returns 405 HTTP error code, I have searched the specs however I couldn't find the part that mandate a default behavior for these methods.
Anyway I guess that the question will be less confusing if they removed the MyServlet class declaration code.
 
Ankit Garg
Sheriff
Posts: 9496
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hany please QuoteYourSources for the question. We don't allow mock questions on javaranch which don't have proper sources quoted...
 
Hany Shafik
Ranch Hand
Posts: 80
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone

I can find the below question recurrent in many mock exams


8. Given:
3: class MyServlet extends HttpServlet {
4: public void doPut(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException {
5: // servlet code here
...
26: }
27: }
If the DD contains a single security constraint associated with MyServlet and its only <httpmethod>
tags
and <authconstraint>
tags are:
<httpmethod>
GET</httpmethod>
<httpmethod>
PUT</httpmethod>
<authconstraint>
Admin</authconstraint>
Which four requests would be allowed by the container? (Choose four.)
A. A user whose role is Admin can perform a PUT.
B. A user whose role is Admin can perform a GET.
C. A user whose role is Admin can perform a POST.
D. A user whose role is Member can perform a PUT.
E. A user whose role is Member can perform a POST.
F. A user whose role is Member can perform a GET.
Answer: ABCE


I think that the answer is incorrect, because put method is the only http method implemented in MyServlet, All other methods regards of their security constraint will rely with http error 405 "Method is not supported"
So I guess the correct answer would be A only.
I know that the same question above has been posted before, however they were having different concerns than mine.

Please let me know, if my understanding is wrong.
 
Hany Shafik
Ranch Hand
Posts: 80
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for not posting the source of this mock question earlier, but you can find it in Mock exam
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic