server - предоставление услуг REST
client - потребляйте их через Spring Resttemplate < /p>
В дополнение к статусу http Наш сервер возвращает HTTP -тело с json, который подробно описывает ошибку. HTTP Body очень хорошо. Ошибка: < /p>
Код: Выделить всё
writeErrorToResponse(int status, String errMsg, HttpServletResponse resp) throws IOException {
response.setStatus(status);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
String message = String.format("{\"error\":\"%s\"}", StringUtils.escapeJson(errMsg));
resp.getWriter().println(message);
}
httpurlConnection.getInputStream()
Трассирование с помощью Fiddler.HTTP/1.1 402 Payment Required
X-Powered-By: Servlet/3.0
Content-Type: application/json
Content-Language: en-GB
Content-Length: 55
Connection: Close
Date: Sat, 25 May 2013 10:10:44 GMT
Server: WebSphere Application Server/8.0
{"error":"I cant find that user. Please try again."}
< /code>
и сообщение, которое является причиной исключения: < /p>
HTTP/1.1 401 Unauthorized
X-Powered-By: Servlet/3.0
Content-Type: application/json
Content-Language: en-GB
Content-Length: 55
Date: Sat, 25 May 2013 11:00:21 GMT
Server: WebSphere Application Server/8.0
{"error":"I cant find that user. Please try again."}
< /code>
Что может быть причиной java.net.httpretyexexception в этой ситуации? < /p>
Кроме того Но так как мы изменили много кода в приложении.
Подробнее здесь: https://stackoverflow.com/questions/167 ... n-in-strea