Forums Register Login

Bill Burke-JAX-RS URI "gotchas": Rreceive HTTP 200 instead of 405 response

+Pie Number of slices to send: Send
Hi All,

Bill Burke's book RESTful Java with JAX-RS2.0, Pages 53,54 suggest that the below code should throw a HTTP error 405.
Instead I keep getting response code 200.

Is it something I am doing wrong or is the book not in congruence with the specification?



Client Code:

+Pie Number of slices to send: Send
The books talks about receiving a 405 when you use the OPTIONS or PUT methods. You are using the GET method in your example, which is expected to return a status of 200.
+Pie Number of slices to send: Send
Ron,

Look at line 14 in the client code. Clearly using the OPTIONS method there. That is what I am referring to.

Thanks & Regards,
Anirudh
+Pie Number of slices to send: Send
Sorry Anirudh -- I didn't read far enough in to your code.

I think what is happening in this case is that since the implementation cannot find a handler for OPTIONS, that is generating an default automatic response, which is returns a 200. Your method in the Resource2 class is not being called. You should be able to confirm this by checking the console to see if shows your Resource2 options message or not.

Ron
+Pie Number of slices to send: Send
Ron,

Thanks again.

I was hoping, some one could throw some light from a holistic point of view on this particular behavior with JAX-RS, Jersey2.4, JDK1.7, and the URI mismatch scenario posed.

Right from,
1. How is HTTP supposed to work?
2. How a Java based HTTP container(eg. Tomcat) expected to behave under the circumstances?
3. What does the JAX-RS spec say about it, and
4. Is there some anomaly (specified or unspecified) by the Jersey reference implementation?

I would be grateful for the information/answers to the questions posed above or even a re-direction to any literature/blog/online learning tutorial etc.

Again, thanks in advance.

Regards,
Anirudh.
+Pie Number of slices to send: Send
You might want to read the JAX-RS: Java™ API for RESTful Web Services documentation for answers on how it is supposed to work. What you are asking about is detailed in sections 3.4 and 3.7. The default behaviour for HEAD and OPTIONS is explained in 3.3.5.

Jersey 2.x claims to be fully compliant to JSR 339.
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 660 times.
Similar Threads
Tree and drawing within the same panel
Drawing at nodes
REST Service - How to send XML Request from Chrome or Intellij's REST Explorer?
Confusing Maven Error
Jersey Client API Exception Handling issue
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:08:12.