5

I'm using jersey client to make a request to a webservice.

Client client = ClientBuilder.newClient(new ClientConfig()); Invocation.Builder builder = client.target("http://someurl.com").request(); String result = builder.get(String.class); 

Then I got the response

<?xml version="1.0" encoding="ISO-8859-1" ?> <DATA>some data with é è à characters</DATA> 

But in my String result, response looks like that

<?xml version="1.0" encoding="ISO-8859-1" ?> <DATA>some data with � � � characters</DATA> 

How can I tell jersey to properly decode the webservice response ?

2 Answers 2

3

Thanks Wizbot, I was having exactly the same problem today.

I wanted to post my java 8 solution without having Guava dependency:

Client client = ClientBuilder.newClient(new ClientConfig()); Invocation.Builder builder = client.target("http://someurl.com").request(); Response response = builder.get(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader((InputStream) response.getEntity(), StandardCharsets.ISO_8859_1)); String result = bufferedReader.lines().collect(Collectors.joining("")); 
Sign up to request clarification or add additional context in comments.

Comments

1

I did find a workaround for the moment

Client client = ClientBuilder.newClient(new ClientConfig()); Invocation.Builder builder = client.target("http://someurl.com").request(); Response response = builder.get(); String result = CharStreams.toString(new InputStreamReader((InputStream) response.getEntity(), Charsets.ISO_8859_1)); 

CharStreams is a Guava class but there are other way to transform an InputStream into a String with the right Charset.

Comments