javaeetutorial
  1. javaeetutorial
  2. JAVAEETUTORIAL-131

Web Services | JAX-RS: Advanced Topics and Example | Runtime Content Negotiation is misleading and contains errors

    Details

      Description

      The section on "Runtime Content Negotiation" contains an example where the resource class level @Produces annotation sets a default MIME type of text/plain. The method getEmployeeAddressXml has a @Produces annotation which makes the method listen to requests asking for a text/xml MIME type.
      From my understanding, the subsequent sections make false statements:

      The getEmployeeAddressText method is called for an HTTP request that looks as follows:
      
      GET /employee
      content-type: text/plain
      500 Oracle Parkway, Redwood Shores, CA
      
      The getEmployeeAddressXml method is called for an HTTP request that looks as follows:
      
      GET /employee
      content-type: text/xml
      <address street="500 Oracle Parkway, Redwood Shores, CA" country="USA"/>
      

      First, it is at least misleading to have a GET request containing a message body. Worse though, from my understanding, it should be the "Accept" header content that will be matched against the @Produces annotation value. The "Content-type" header should be matched against the @Consumes annotation.

      If I should be wrong, the explanation of @Produces and @Consumes earlier in the chapter is very misleading.

        Activity

        kombatkuehn created issue -
        Ian Evans made changes -
        Field Original Value New Value
        Assignee Ian Evans [ ievans ]
        Ian Evans made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Hide
        Ian Evans added a comment - - edited

        You are right, the example HTTP request should use an Accept header, not Content-type.

        The examples aren't intended to show a message body, although I agree that's what it looks like. It would be more clear to separate out the HTTP request fragment from the body of the response. E.g.
        Request:

        GET /employee
        Accept: text/plain
        

        Response:

        500 Oracle Parkway, Redwood Shores, CA
        

        Request:

        GET /employee
        Accept: text/xml
        

        Response:

        <address street="500 Oracle Parkway, Redwood Shores, CA" country="USA"/>
        
        Show
        Ian Evans added a comment - - edited You are right, the example HTTP request should use an Accept header, not Content-type. The examples aren't intended to show a message body, although I agree that's what it looks like. It would be more clear to separate out the HTTP request fragment from the body of the response. E.g. Request: GET /employee Accept: text/plain Response: 500 Oracle Parkway, Redwood Shores, CA Request: GET /employee Accept: text/xml Response: <address street= "500 Oracle Parkway, Redwood Shores, CA" country= "USA" />
        Hide
        Ian Evans added a comment -

        Fixed in source. Will be available in next published update.

        Show
        Ian Evans added a comment - Fixed in source. Will be available in next published update.
        Ian Evans made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Fix Version/s 6.0.7-6 [ 15852 ]
        Resolution Fixed [ 1 ]
        Ian Evans made changes -
        Affects Version/s 6.0.7-5 [ 15851 ]
        Affects Version/s 6 [ 10658 ]

          People

          • Assignee:
            Ian Evans
            Reporter:
            kombatkuehn
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: