Skip to content

Instantly share code, notes, and snippets.

@thesurlydev
Last active December 21, 2015 15:39
Show Gist options
  • Save thesurlydev/6328562 to your computer and use it in GitHub Desktop.
Save thesurlydev/6328562 to your computer and use it in GitHub Desktop.
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