I am trying to send JSON object as parameter.
localhost:8080/HelloWorldApplication/webresources/helloworld/get/{param}
During this process I am sending a big JSON object, similar to :
{"follow_request_sent": false, "profile_use_background_image": true, "contributors_enabled": false, "id": 200, "verified": false, "profile_image_url_https": "https://si0.twimg.com/sticky/default_profile_images/default_profile_4_normal.png", "profile_sidebar_fill_color": "e0ff92", "is_translator": false, "profile_text_color": "000000", "followers_count": 869, "profile_sidebar_border_color": "87bc44", "id_str": "200", "default_profile_image": true, "listed_count": 0, "status": {"favorited": false, "contributors": null, "truncated": false, "text": "https://google.com", "created_at": "2010-12-07T05:58:01", "retweeted": false, "in_reply_to_status_id": null, "coordinates": null, "source_url": "http://mobile.twitter.com", "source": "Mobile Web", "in_reply_to_status_id_str": null, "in_reply_to_screen_name": null, "in_reply_to_user_id": null, "id": 12023002585628672, "place": null, "retweet_count": 0, "geo": null, "in_reply_to_user_id_str": null, "possibly_sensitive": false, "id_str": "12023002585628672"}, "utc_offset": -28800, "statuses_count": 6, "description": "", "friends_count": 4, "location": "", "profile_link_color": "0000ff", "profile_image_url": "http://a0.twimg.com/sticky/default_profile_images/default_profile_4_normal.png", "notifications": false, "show_all_inline_media": false, "geo_enabled": true, "profile_background_color": "9ae4e8", "profile_background_image_url": "http://a0.twimg.com/images/themes/theme1/bg.png", "name": "Dalbir Singh", "lang": "en", "profile_background_tile": false, "favourites_count": 0, "screen_name": "dalbirsingh", "url": null, "created_at": "2006-04-29T01:00:27", "profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme1/bg.png", "time_zone": "Pacific Time (US & Canada)", "protected": false, "default_profile": false, "following": false}
my code works well until few number of parameters but not with as large object as mentioned above . Is there any limit to the length of JSONobject or other parameter to be sent over http request , If yes, then how to modify it.
Code:
@GET
@Path("/get/{empno}")// this method process GET request from client
@Produces("application/json") // sends JSON
public String getJson(@PathParam("empno") JSONObject p) { // empno represents the empno sent from client
JSONObject obj = p;
String x = obj.toString();
System.out.println(x);
//some function
return "x";
}
Yes there is a limit to urls length. It is however dependent on the browser and the web server (it is usually configurable, but I think it is a bad idea to change it...).
Usually if your url is less than 2000 characters it should always work. You can also have a look at this thread What is the maximum length of a URL in different browsers? And some other links maximum length of HTTP GET request?, http://www.boutell.com/newfaq/misc/urllength.html.
Anyway what you are doing is a bad practice. You should not pass json in the url, json should be used as the body of post requests. Having json as request parameter is not really REST style, there are discussions if url parameters is ok for REST apis, but it is discutable...
EDIT An example for jersey with post and using a library having databinding support:
Download genson library http://code.google.com/p/genson/, when it is in your classpath json databinding will be automatically enabled for jersey. Define classes corresponding to the json input (I called it ARequestBean) and AResponseBean containing the response that will be serialized to json.
@POST
@Path("/post")
@Consumes(("application/json") // consumes JSON
@Produces("application/json") // sends JSON
public AResponseBean getJson(ARequestBean request) {
return ...;
}