DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Step-by-Step Guide: Application Using NestJs and Angular
  • Beyond Request-Response: Architecting Stateful Agentic Chatbots with the Command and State Patterns
  • A Beginner's Guide to Docker Compose
  • How to Identify the Underlying Causes of Connection Timeout Errors for MongoDB With Java

Trending

  • Giving AI Agents Safe Access to Legacy Systems: Introducing legacy2mcp
  • Google Cloud KMS vs. AWS KMS: Java Encryption Guide
  • The Self-Hosting Math Changed While We Were Still Arguing About Sovereignty
  • GenAI Security Gateway: An End-to-End Architecture

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. JAX-RS and HTTP ‘OPTIONS’

JAX-RS and HTTP ‘OPTIONS’

The JAX-RS specification defines sensible defaults for the HTTP OPTIONS command. I actually stumbled upon this by chance!

By 
Abhishek Gupta
DZone Core CORE ·
Jul. 13, 15 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
7.5K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

The JAX-RS specification defines sensible defaults for the HTTP OPTIONS command. I actually stumbled upon this by chance! Not sure of this is very obvious (if it is, be kind and don’t laugh at me !)

The Discovery

For the JAX-RS resource represented in the code snippet below, if you execute a HTTP OPTIONS command against the http://host:port/context-root/user URI, you will be surprised to not get a HTTP Status 404 – Not Found error message [ at least I was surprised, until I looked in the JAX-RS specification document of course ;-) ]

@Path("user")
public class UserResource {

    @GET
    @Path("{id}")
    public Response find(@PathParam("id") String id) {
        return Response.ok().build();
    }

    @PUT
    public Response create(/*User user*/) {
        return Response.ok().build();
    }

    @DELETE
    @Path("{id}")
    public Response delete(@PathParam("id") String id) {
        return Response.ok().build();
    }
}


It gave me back the WADL as a response. Sweet ! :-)

WADL returned by the JAX-RS runtime


To Be Noted

  • If there is an explicit resource method which is annotated with @OPTIONS, then the corresponding logic will be executed and the default behavior would get suppressed (now that’s obvious!)
  • This does not mean that you can execute the OPTIONS command at any random URI within your RESTful app. This kicks in after the request matching process and will be applicable only for a valid URI as defined by @Path annotations in your resource classes.
  • I tested with Jersey 2.10 on Glass Fish 4.1. This is standard feature mandated by the specification, hence it is applicable to ANY JAX-RS compliant implementation out there (e.g. RESTEasy)


Error message Command (computing) Uniform Resource Identifier app Snippet (programming) Requests Document Annotation Implementation Web Protocols

Published at DZone with permission of Abhishek Gupta. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Step-by-Step Guide: Application Using NestJs and Angular
  • Beyond Request-Response: Architecting Stateful Agentic Chatbots with the Command and State Patterns
  • A Beginner's Guide to Docker Compose
  • How to Identify the Underlying Causes of Connection Timeout Errors for MongoDB With Java

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook