users@jersey.java.net

[Jersey] Re: version 1.18.1 rest & Integer

From: Tomaz Majerhold <tomaz.majerhold_at_arnes.si>
Date: Tue, 22 Jul 2014 08:36:02 +0200

Yes I know that, but shouldn't the anotation

@Produces({"application/json"})
public Integer getInt();

do exectly that content-type header application/json

Regards, Tomaz

Dne 21.7.2014 16:59, piše Joe Mocker:
> The exception says it all. Jersey is trying to read it from a text/HTML input but doesn't have any way to do that. I'm guess you really just forgot to add a content-type header that is application/json.
>
>> On Jul 21, 2014, at 7:13 AM, "Tomaz Majerhold" <tomaz.majerhold_at_arnes.si> wrote:
>>
>> I have problem to read REST Integer response with jersey client, but if I try with browser it display it correctly.
>>
>>
>> 1) server side:
>>
>> maven:
>> -----------
>> <dependency>
>> <groupId>com.sun.jersey</groupId>
>> <artifactId>jersey-json</artifactId>
>> <version>1.18.1</version>
>> </dependency>
>>
>> rest:
>> ----------
>> @Path("/int")
>> @GET
>> @Produces({"application/json"})
>> public Integer getInt();
>>
>> And in javax.ws.rs.core.Application I add JacksonJsonProvider.class
>>
>> 2) client side:
>>
>> maven:
>> -----------
>> <dependency>
>> <groupId>com.sun.jersey</groupId>
>> <artifactId>jersey-json</artifactId>
>> <version>1.18.1</version>
>> </dependency>
>> <dependency>
>> <groupId>com.sun.jersey</groupId>
>> <artifactId>jersey-json</artifactId>
>> <version>1.18.1</version>
>> </dependency>
>>
>> rest:
>> ----------
>> ClientResponse clientResponse = webResource
>> .path(PATH_BASIC+"/"+"int")
>> .accept("application/json")
>> .get(ClientResponse.class);
>>
>> testInt = clientResponse.getEntity(Integer.class);
>>
>> HTTP Header:
>> ------------------
>> GET /aai-api-server/rest/wc/int HTTP/1.1
>> Accept: application/json
>> Authorization: Basic Ymxhei5kaXZqYWtAYXJuZXMuc2k6Ymxhei5kaXZqYWtAYXJuZXMuc2k=
>> Cache-Control: no-cache
>> Pragma: no-cache
>> User-Agent: Java/1.7.0_25
>> Host: localhost:8181
>> Connection: keep-alive
>>
>>
>> Error:
>> ----------
>> com.sun.jersey.api.client.ClientHandlerException: A message body reader for Java class java.lang.Integer, and Java type class java.lang.Integer, and MIME media type text/html; charset=ISO-8859-1 was not found
>>
>>
>> What I'm doing wrong?
>>
>> Regards, Tomaz