Added some log message to better debug and remove the exception raise

This commit is contained in:
Mauro Mugnaini 2020-08-13 20:47:37 +02:00
parent da8ed52808
commit bb3728c421
1 changed files with 28 additions and 20 deletions

View File

@ -206,7 +206,10 @@ public class OpenIdConnectRESTHelper {
return false;
}
public static byte[] getUserAvatar(URL avatarURL, JWTToken token) throws Exception {
public static byte[] getUserAvatar(URL avatarURL, JWTToken token) {
logger.debug("Getting user avatar from URL: {}", avatarURL);
ByteArrayOutputStream buffer;
try {
HttpURLConnection conn = (HttpURLConnection) avatarURL.openConnection();
conn.setRequestMethod("GET");
conn.setDoOutput(false);
@ -217,8 +220,9 @@ public class OpenIdConnectRESTHelper {
logger.debug("Adding authorization header as: {}", authorization);
conn.setRequestProperty("Authorization", authorization);
}
logger.debug("Getting the resource opening the stream");
InputStream is = conn.getInputStream();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[1024];
while ((nRead = is.read(data, 0, data.length)) != -1) {
@ -227,5 +231,9 @@ public class OpenIdConnectRESTHelper {
buffer.flush();
return buffer.toByteArray();
} catch (IOException e) {
logger.debug("Can't download avatar", e);
}
return null;
}
}