Added some log message to better debug and remove the exception raise
This commit is contained in:
parent
da8ed52808
commit
bb3728c421
|
@ -206,26 +206,34 @@ public class OpenIdConnectRESTHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static byte[] getUserAvatar(URL avatarURL, JWTToken token) throws Exception {
|
||||
HttpURLConnection conn = (HttpURLConnection) avatarURL.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setDoOutput(false);
|
||||
conn.setDoInput(true);
|
||||
conn.setRequestProperty("Accept", "image/png, image/jpeg, image/gif");
|
||||
if (token != null) {
|
||||
String authorization = token.getAccessTokenAsBearer();
|
||||
logger.debug("Adding authorization header as: {}", authorization);
|
||||
conn.setRequestProperty("Authorization", authorization);
|
||||
}
|
||||
InputStream is = conn.getInputStream();
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
int nRead;
|
||||
byte[] data = new byte[1024];
|
||||
while ((nRead = is.read(data, 0, data.length)) != -1) {
|
||||
buffer.write(data, 0, nRead);
|
||||
}
|
||||
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);
|
||||
conn.setDoInput(true);
|
||||
conn.setRequestProperty("Accept", "image/png, image/jpeg, image/gif");
|
||||
if (token != null) {
|
||||
String authorization = token.getAccessTokenAsBearer();
|
||||
logger.debug("Adding authorization header as: {}", authorization);
|
||||
conn.setRequestProperty("Authorization", authorization);
|
||||
}
|
||||
logger.debug("Getting the resource opening the stream");
|
||||
InputStream is = conn.getInputStream();
|
||||
buffer = new ByteArrayOutputStream();
|
||||
int nRead;
|
||||
byte[] data = new byte[1024];
|
||||
while ((nRead = is.read(data, 0, data.length)) != -1) {
|
||||
buffer.write(data, 0, nRead);
|
||||
}
|
||||
|
||||
buffer.flush();
|
||||
return buffer.toByteArray();
|
||||
buffer.flush();
|
||||
return buffer.toByteArray();
|
||||
} catch (IOException e) {
|
||||
logger.debug("Can't download avatar", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue