mehandih / grails-jaxrs

Automatically exported from code.google.com/p/grails-jaxrs
0 stars 0 forks source link

Unable to retrieve response from "OPTIONS" #62

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. Create a resource;
2. Create a annotated method (@OPTIONS);
3. Make a HTTP OPTIONS request to the resource;

What is the expected output? What do you see instead?

Resource:

@Path('/v1/category/{id}')
class CategoryResource {

    @GET
    @Produces(['application/xml', 'application/json'])
    Category getCategoryRepresentation(@PathParam('id') String id) {

        /*
         * method body 
         */

    }

    @OPTIONS
    @Produces(['text/plain'])
    Response options(){

        /*
         * method body 
         */

    }

}

Expected output: 
allow header = "Allow: GET, HEAD, OPTIONS"

Output:
allow header = "Allow: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS"

What version of the product are you using? On what operating system?
Grails 2.0.3
grails-jaxrs 0.6

Original issue reported on code.google.com by wilso...@gmail.com on 4 Jun 2012 at 5:44

GoogleCodeExporter commented 8 years ago
Do you see the same output when using Jersey alone i.e. independent of the 
grails-jaxrs plugin?

Original comment by krass...@googlemail.com on 6 Jun 2012 at 6:37

GoogleCodeExporter commented 8 years ago
Hello Martin.

Sorry for the delayed answer. After further investigation I've discovered that 
the GrailsDispatcherServlet was the responsable for the odd behavior.

The result using Jersey alone was exactly what I was expecting (a wadl xml for 
the resource and the allow header with the annotated http methods only).

I've forked the grails-jaxrs project and if everything works out fine I 
politely ask you to accept my pull request.

Sample Code:

@Path('/v1/category/{id}')
class CategoryResource {

    @GET
    @Produces(['application/xml', 'application/json'])
    Category getCategoryRepresentation(@PathParam('id') String id) {

        /*
         * method body 
         */

    }

    @OPTIONS
    @Produces(['text/plain'])
    Response options(){

        /*
         * method body 
         */

    }

}

200 OPTIONS http://localhost:8080/api/v1/category

Response:

Headers:

Date: Fri, 08 Jun 2012 20:14:51 GMT
Transfer-Encoding: chunked
Server: Apache-Coyote/1.1
Allow: OPTIONS,GET,HEAD
Content-Type: application/vnd.sun.wadl+xml

Body:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <application xmlns="http://research.sun.com/wadl/2006/10">
        <doc xmlns:jersey="http://jersey.java.net/" jersey:generatedBy="Jersey: 1.8 06/24/2011 12:17 PM"/>
        <resources base="http://10.1.0.30:8080/api/">
            <resource path="v1/category/">
                <method name="GET" id="getCategoryListRepresentation">
                    <response>
                        <representation mediaType="application/xml"/>
                        <representation mediaType="application/json"/>
                    </response>
                </method>
            </resource>
        </resources>
    </application>

Original comment by wilso...@gmail.com on 11 Jun 2012 at 6:44

GoogleCodeExporter commented 8 years ago
Hi Wilson, just merged your pull request. Thanks a lot for your contribution, 
highly appreciate it. Keep up the good work :)

Original comment by krass...@googlemail.com on 12 Jun 2012 at 5:59