Hi,
We hard-coded the Status codes and messages like ex: 200(Success), 403(Forbidden), 404(Nt found). etc., Now we have to call the Status codes through JSON response.
Can anyone tell me how to do this and any code snippet will be helpful to me.
Thanks,
Ratna Kumar.
Solved! Go to Solution.
Views
Replies
Total Likes
Ratna Kumar wrote...
Hi,
We hard-coded the Status codes and messages like ex: 200(Success), 403(Forbidden), 404(Nt found). etc., Now we have to call the Status codes through JSON response.
Can anyone tell me how to do this and any code snippet will be helpful to me.
Thanks,
Ratna Kumar.
The issue has been resolved.
Views
Replies
Total Likes
Did you hard code the response code into JSON?
Views
Replies
Total Likes
Hi Ratna,
I am not very clear what exactly you mean by "We hard-coded the Status codes and messages " and "to call the Status codes through JSON response."
If the question is how to extract HTTP Status code, then Use the RestTemplate#exchange(..)
methods that return a ResponseEntity
. This gives you access to the status line and headers (and the body obviously).
Or Use HttpURLConnection:
//
URL url = new URL("http://example.com");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
int code = connection.getResponseCode();
Add the status code to Json before returning.
Reference Article:- http://stackoverflow.com/questions/4687271/jax-rs-how-to-return-json-and-http-status-code-together
I hope this will help you.
Thanks and Regards
Kautuk Sahni
Views
Replies
Total Likes
Ratna Kumar wrote...
Hi,
We hard-coded the Status codes and messages like ex: 200(Success), 403(Forbidden), 404(Nt found). etc., Now we have to call the Status codes through JSON response.
Can anyone tell me how to do this and any code snippet will be helpful to me.
Thanks,
Ratna Kumar.
The issue has been resolved.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Like
Replies