Last active
December 21, 2015 15:39
-
-
Save thesurlydev/6328562 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
feign.Response convertResponse(HttpURLConnection connection) throws IOException { | |
int status = connection.getResponseCode(); | |
String reason = connection.getResponseMessage(); | |
Map<String, Collection<String>> headers = new LinkedHashMap<String, Collection<String>>(); | |
for (Map.Entry<String, List<String>> field : connection.getHeaderFields().entrySet()) { | |
// response message | |
if (field.getKey() != null) | |
headers.put(field.getKey(), field.getValue()); | |
} | |
Integer length = connection.getContentLength(); | |
if (length == -1) | |
length = null; | |
InputStream stream; | |
if (status >= 400) { | |
stream = connection.getErrorStream(); | |
} else { | |
stream = connection.getInputStream(); | |
} | |
Reader body; | |
if (stream != null) { | |
String string = CharStreams.toString(new InputStreamReader(stream, "UTF-8")); | |
String fixed = string.replace("throw 'allowIllegalResourceCall is false.';", ""); | |
stream = new ByteArrayInputStream(fixed.getBytes()); | |
body = new InputStreamReader(stream); | |
} | |
else { | |
body = null; | |
} | |
return feign.Response.create(status, reason, headers, body, length); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment