简体   繁体   中英

Using Jax-Rs @Get @Post on same method

Is it allowed to have @Get @Post or other @HttpMethod on same method of REST service? I know that Jersey return exception, but I want to know only about JAX-RS API, nothing else.

Is it allowed by JAX-RS API to do so?

Edit: I ask this question, because I haven't found anything about this in specification or documentation.

The JAX-RS specification at http://download.oracle.com/otndocs/jcp/jaxrs-2_0_rev_A-mrel-spec/index.html does not seem to specify this situation at all. In section 3.3 it says that " Resource methods are methods of a resource class annotated with a request method designator " - my emphasis on the word "a". @Get and @POST are examples of request method designators. Section 3.7.2, which describes how to choose the method that responds to the request just says to filter out methods where " The request method is supported ".

So I think you've found a gray area in the spec, and apparently the creators of the reference implementation of JAX-RS chose to not to support your use case.

You need to refactor:

@GET
public void yourGetMethod() {
    yourMethod();
}

@POST
public void yourPostMethod() {
    yourMethod();
}

public void yourMethod(...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM