• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
Ranch Hand
Posts: 49
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
Marshal
Posts: 3180
466
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anirudh Gupta
Ranch Hand
Posts: 49
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ron McLeod
Marshal
Posts: 3180
466
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anirudh Gupta
Ranch Hand
Posts: 49
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ron McLeod
Marshal
Posts: 3180
466
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic