File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes Rest Response adding extra characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Rest Response adding extra characters" Watch "Rest Response adding extra characters" New topic
Author

Rest Response adding extra characters

David McWilliams
Ranch Hand

Joined: Mar 14, 2009
Posts: 73
Hi all,

I have written a very basic Restful web service using Jersey and Mule 2.2.1. The service returns the string 'hello' when a GET is sent to the service.



When I use a poster application like Google Poster to send a GET request, I get the string 'hello' back but when I use a simple PHP client to call the service, I get the following:

5
Hello
0

It seems the the service is adding the length of the string. I have the string to '1234567890' and it added a 'b' to the response (hex?)

I have used Fiddler to check the Http Response and I can see the extra characters.

Does anyone know why this is happening?

David
David McWilliams
Ranch Hand

Joined: Mar 14, 2009
Posts: 73
It seems that the extra characters is not content length. I tested it with more characters.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Why are you saying:


when you are obviously not returning JSON but text.

Bill
David McWilliams
Ranch Hand

Joined: Mar 14, 2009
Posts: 73
William Brogden wrote:Why are you saying:


when you are obviously not returning JSON but text.

Bill


I will be returning a JSON object. I have removed the JSON to simplify the example. Extra characters are still sent when I change to:
@Produces("text/plain").

I believe the issue is to do with encoding. The response is sent with Chunked Transfer Encoding. I will need to decode this but no idea how.
David McWilliams
Ranch Hand

Joined: Mar 14, 2009
Posts: 73
I got my PHP client to decode the encode response from my service. I did not write the client but apparently there is some library you can you.
Patrick Yeh
Greenhorn

Joined: Feb 22, 2013
Posts: 1

It is an effect of Chucked Transfer Encoding.

http://stackoverflow.com/questions/2502155/http-post-data-adding-extra-characters-in-response/15037723#15037723
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Rest Response adding extra characters
 
Similar Threads
REST, Basic Authentication, Jersey, Poster, and Sharepoint
Character Encoding in Servlet
[jersey/jax-rs] json object value string has extra quotes, jsonp, service chaining‏
Unable to access tomcat protected resource using Cookie manager for JSessionID
Cannot input % characters in textfield