You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Łukasz Strzelecki (JIRA)" <ji...@apache.org> on 2011/07/18 23:36:58 UTC

[jira] [Updated] (CXF-3667) Content negotiation & ResponseBuilder

     [ https://issues.apache.org/jira/browse/CXF-3667?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Łukasz Strzelecki updated CXF-3667:
-----------------------------------

    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)
{code}
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();
	}
}
{code}

At 1) no matter which kind of request 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.

Invoking servcie

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

{code}
$ 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
{code}

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


  was:
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 weard behaviour)
{code}
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();
	}
}
{code}

At 1) no matter which kind of request 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.

Invoking servcie

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

{code}
$ 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
{code}

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



> Content negotiation & ResponseBuilder
> -------------------------------------
>
>                 Key: CXF-3667
>                 URL: https://issues.apache.org/jira/browse/CXF-3667
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.4.1
>            Reporter: Łukasz Strzelecki
>
> 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)
> {code}
> 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();
> 	}
> }
> {code}
> At 1) no matter which kind of request 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.
> Invoking servcie
> $ curl *--header "Accept: application/json"* http://localhost:8080/hello -v
> I'm setting header that as client accept only JSON content type.
> {code}
> $ 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
> {code}
> But as you can see at response i'm getting Content-Type: *text/xml*. Which is not i'm expecting.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira