jersey
  1. jersey
  2. JERSEY-1007

QueryParam and HeaderParam are inhereted which in inconsistent with the WADL specification

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.9
    • Fix Version/s: backlog
    • Component/s: tools
    • Labels:
      None

      Description

      So I have a very simple nested resource which looks like this:

      @Path("/root")
      public class RootResource {
          
          @Path("/sub")
          public SubResource get(@QueryParam("rootQ") String rootQ, @HeaderParam("rootH") String rootH) {
              return new SubResource (rootQ, rootH);
          }
      }
      

      and

      public class SubResource {
          
          String rootQ, rootH;
          
          public SubResource(String rootQ, String rootH) {
              this.rootQ = rootQ;
              this.rootH = rootH;
          }
          
          
          @GET
          public String get(@QueryParam("subQ") String subQ, @HeaderParam("subH") String subH) {
              StringBuilder sb = new StringBuilder();
              new Formatter(sb).format(
               "rootQ %s, rootH %s\n" +
               "subQ %s, subH %s", rootQ, rootH, subQ, subH);
              return sb.toString();
          }
      }
      

      Now to be consistent with the WADL spec (See WADL-32) we wouldn't expect the query and header parameters to be inherited by the sub resource. Indeed the WADL generated would seem to agree with this:

      <?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-SNAPSHOT 06/01/2011 07:09 PM"/>
         <resources base="http://localhost:7101/Nested/jersey/">
            <resource path="root">
               <resource path="/sub">
                  <method id="get" name="GET">
                     <request>
                        <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="subQ" style="query" type="xs:string"/>
                        <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="subH" style="header" type="xs:string"/>
                     </request>
                     <response>
                        <representation mediaType="*/*"/>
                     </response>
                  </method>
               </resource>
            </resource>
         </resources>
      </application>
      

      But when you send a suitably crafted message to the resource (http://localhost:7101/Nested/jersey/root/sub?subQ=sub&rootQ=root and with the HTTP headers) the response is as follows:

      rootQ root, rootH rootH
      subQ sub, subH subH

      The root values should be null in all cases if we are going to be consistent with the WADL specification.

        Activity

        Hide
        Martin Matula added a comment -

        Marek, what does the JAX-RS spec say for this case (if anything)?

        Show
        Martin Matula added a comment - Marek, what does the JAX-RS spec say for this case (if anything)?
        Hide
        Marek Potociar added a comment -

        My interpretation of the JAX-RS spec (section 3.2 + related javadoc) is that injection of header & query parameters are request scoped. Since root resource and sub-resource classes participate in satisfying the same request, the behavior of Jeresy in this case seems correct to me.

        I guess this is an issue of the WADL specification or it's interpretation in context of JAX-RS resource classes, where the 1-1 mapping is not applicable in general. E.g. in the example above I would even argue that from REST (and WADL) point of view there is only one resource exposed - the one located at "/root/sub" URI. Trying to access just "/root" yields 404, since there are no resource methods on the root resource class. All the request-scoped parameters, including query and header ones, are thus targeted for the single exposed resource.

        As for the WADL spec resource element definition , seems to me that there is no conflict. Indeed the WADL spec can construct resource trees that are not implementable via a combination of JAX-RS root resource - sub-resource classes, but that's all. The proper WADL generated for the JAX-RS resource construct above would be e.g.:

        <?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-SNAPSHOT 06/01/2011 07:09 PM"/>
            <resources base="http://localhost:7101/Nested/jersey/">
                <resource path="root/sub">
                    <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="rootQ" style="query" type="xs:string"/>
                    <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="rootH" style="header" type="xs:string"/>
                    <method id="get" name="GET">
                        <request>
                            <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="subQ" style="query" type="xs:string"/>
                            <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="subH" style="header" type="xs:string"/>
                        </request>
                        <response>
                            <representation mediaType="/"/>
                        </response>
                    </method>
                </resource>
            </resources>
        </application>
        

        or

        <?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-SNAPSHOT 06/01/2011 07:09 PM"/>
            <resources base="http://localhost:7101/Nested/jersey/">
                <resource path="root/sub">
                    <method id="get" name="GET">
                        <request>
                            <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="rootQ" style="query" type="xs:string"/>
                            <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="rootH" style="header" type="xs:string"/>
                            <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="subQ" style="query" type="xs:string"/>
                            <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="subH" style="header" type="xs:string"/>
                        </request>
                        <response>
                            <representation mediaType="/"/>
                        </response>
                    </method>
                </resource>
            </resources>
        </application>
        

        And vice-versa: In order to satisfy the WADL above, the JAX-RS resource structure would have to look e.g like this:

        @Path("/root")
        public class RootResource {
            @Path("/sub")
            public SubResource get() { 
                return new SubResource (); 
            }
        }
        
        public class SubResource {
            @GET
            public String get(@QueryParam("subQ") String subQ, @HeaderParam("subH") String subH) { 
                StringBuilder sb = new StringBuilder();
                new Formatter(sb).format("subQ %s, subH %s", subQ, subH);
                return sb.toString();
            }
        }
        

        Or simply:

        @Path("/root/sub")
        public class RootResource {
            @GET
            public String get(@QueryParam("subQ") String subQ, @HeaderParam("subH") String subH) { 
                StringBuilder sb = new StringBuilder();
                new Formatter(sb).format("subQ %s, subH %s", subQ, subH);
                return sb.toString();
            }
        }
        

        In summary, I believe the issue is in how the WADL is currently generated from the JAX-RS resource classes (resource class != resource).

        Show
        Marek Potociar added a comment - My interpretation of the JAX-RS spec (section 3.2 + related javadoc) is that injection of header & query parameters are request scoped. Since root resource and sub-resource classes participate in satisfying the same request, the behavior of Jeresy in this case seems correct to me. I guess this is an issue of the WADL specification or it's interpretation in context of JAX-RS resource classes, where the 1-1 mapping is not applicable in general. E.g. in the example above I would even argue that from REST (and WADL) point of view there is only one resource exposed - the one located at "/root/sub" URI. Trying to access just "/root" yields 404, since there are no resource methods on the root resource class. All the request-scoped parameters, including query and header ones, are thus targeted for the single exposed resource. As for the WADL spec resource element definition , seems to me that there is no conflict. Indeed the WADL spec can construct resource trees that are not implementable via a combination of JAX-RS root resource - sub-resource classes, but that's all. The proper WADL generated for the JAX-RS resource construct above would be e.g.: <?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-SNAPSHOT 06/01/2011 07:09 PM" /> <resources base= "http://localhost:7101/Nested/jersey/" > <resource path= "root/sub" > <param xmlns:xs = "http://www.w3.org/2001/XMLSchema" name= "rootQ" style= "query" type= "xs:string" /> <param xmlns:xs = "http://www.w3.org/2001/XMLSchema" name= "rootH" style= "header" type= "xs:string" /> <method id= "get" name= "GET" > <request> <param xmlns:xs = "http://www.w3.org/2001/XMLSchema" name= "subQ" style= "query" type= "xs:string" /> <param xmlns:xs = "http://www.w3.org/2001/XMLSchema" name= "subH" style= "header" type= "xs:string" /> </request> <response> <representation mediaType= "/" /> </response> </method> </resource> </resources> </application> or <?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-SNAPSHOT 06/01/2011 07:09 PM" /> <resources base= "http://localhost:7101/Nested/jersey/" > <resource path= "root/sub" > <method id= "get" name= "GET" > <request> <param xmlns:xs = "http://www.w3.org/2001/XMLSchema" name= "rootQ" style= "query" type= "xs:string" /> <param xmlns:xs = "http://www.w3.org/2001/XMLSchema" name= "rootH" style= "header" type= "xs:string" /> <param xmlns:xs = "http://www.w3.org/2001/XMLSchema" name= "subQ" style= "query" type= "xs:string" /> <param xmlns:xs = "http://www.w3.org/2001/XMLSchema" name= "subH" style= "header" type= "xs:string" /> </request> <response> <representation mediaType= "/" /> </response> </method> </resource> </resources> </application> And vice-versa: In order to satisfy the WADL above, the JAX-RS resource structure would have to look e.g like this: @Path( "/root" ) public class RootResource { @Path( "/sub" ) public SubResource get() { return new SubResource (); } } public class SubResource { @GET public String get(@QueryParam( "subQ" ) String subQ, @HeaderParam( "subH" ) String subH) { StringBuilder sb = new StringBuilder(); new Formatter(sb).format( "subQ %s, subH %s" , subQ, subH); return sb.toString(); } } Or simply: @Path( "/root/sub" ) public class RootResource { @GET public String get(@QueryParam( "subQ" ) String subQ, @HeaderParam( "subH" ) String subH) { StringBuilder sb = new StringBuilder(); new Formatter(sb).format( "subQ %s, subH %s" , subQ, subH); return sb.toString(); } } In summary, I believe the issue is in how the WADL is currently generated from the JAX-RS resource classes (resource class != resource).
        Hide
        Marek Potociar added a comment -

        Seems that the real issue is in the way WADL is generated from the JAX-RS resources (see other comments). Reassigning the issue.

        Show
        Marek Potociar added a comment - Seems that the real issue is in the way WADL is generated from the JAX-RS resources (see other comments). Reassigning the issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            gdavison
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Time Tracking

              Estimated:
              Original Estimate - 3 hours
              3h
              Remaining:
              Remaining Estimate - 3 hours
              3h
              Logged:
              Time Spent - 0 minutes
              0m