Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-3667

Content negotiation & ResponseBuilder without entity - wrong Content-Type

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.1
    • 2.4.2, 2.5
    • JAX-RS
    • None

    Description

      With creation of response without content, based on javax.ws.rs.core.Response.ResponseBuilder. I get wrong Content-Type.

      Sample of REST resource (This is not valid rest service, but I want only show strange behaviour)

      package com.sozix.rest.service;
      
      import javax.ws.rs.GET;
      import javax.ws.rs.Path;
      import javax.ws.rs.Produces;
      import javax.ws.rs.core.MediaType;
      import javax.ws.rs.core.Response;
      
      @Path("/hello")
      public class HelloResource {
      	// 1
      	@GET
      	// 2
      	@Produces(MediaType.APPLICATION_JSON)
      	public Response greeting() {
      		// 3
      		return Response.noContent().build();
      	}
      }
      

      At 1) No matter which kind of request (GET, POST, PUT, DELETE) i will invoke. Issiue is the same.
      At 2) I set that method produces ONLY Content-type: application/json
      At 3) Constructing response without content, using javax.ws.rs.core.Response.ResponseBuilder

      Invoking servcie

      $ curl --header "Accept: application/json" http://localhost:8080/hello -v
      I'm setting header that as client accept only JSON content type.

      $ curl --header "Accept: application/json" http://localhost:8080/hello -v
      * About to connect() to localhost port 8080 (#0)
      *   Trying 127.0.0.1... connected
      * Connected to localhost (127.0.0.1) port 8080 (#0)
      > GET /hello HTTP/1.1
      > User-Agent: curl/7.20.1 (i686-pc-cygwin) libcurl/7.20.1 OpenSSL/0.9.8q zlib/1.
      2.5 libidn/1.18 libssh2/1.2.5
      > Host: localhost:8080
      > Accept: application/json
      >
      < HTTP/1.1 204 No Content
      < Content-Type: text/xml
      < Date: Mon, 18 Jul 2011 21:19:19 GMT
      < Server: Jetty(7.4.2.v20110526)
      <
      * Connection #0 to host localhost left intact
      * Closing connection #0
      

      But as you can see at response i'm getting Content-Type: text/xml. Which is not i'm expecting.

      Attachments

        Activity

          People

            sergey_beryozkin Sergey Beryozkin
            lstrzelecki Ɓukasz Strzelecki
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: