Some logs added and 404 not found status support added

This commit is contained in:
Mauro Mugnaini 2020-09-04 18:31:46 +02:00
parent 9335a80b5a
commit 41ffb26bcd
1 changed files with 11 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package org.gcube.oidc.rest;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -195,7 +196,8 @@ public class OpenIdConnectRESTHelper {
params.put("client_id", Arrays.asList(URLEncoder.encode(clientId, "UTF-8")));
params.put("refresh_token", Arrays.asList(token.getRefreshTokenString()));
logger.info("Performing logut from OIDC server with URL: " + logoutUrl);
HttpURLConnection httpURLConnection = performURLEncodedPOSTSendData(logoutUrl, params, token.getAccessTokenAsBearer());
HttpURLConnection httpURLConnection = performURLEncodedPOSTSendData(logoutUrl, params,
token.getAccessTokenAsBearer());
int responseCode = httpURLConnection.getResponseCode();
if (responseCode == 204) {
logger.info("Logout performed correctly");
@ -223,7 +225,11 @@ public class OpenIdConnectRESTHelper {
logger.debug("Adding authorization header as: {}", authorization);
conn.setRequestProperty("Authorization", authorization);
}
logger.debug("Getting the resource opening the stream");
String contentType = conn.getContentType();
int contentLenght = conn.getContentLength();
logger.debug("Getting the stream to a %d bytes lenght resource with MIME: %s", contentLenght, contentType);
InputStream is = conn.getInputStream();
buffer = new ByteArrayOutputStream();
int nRead;
@ -234,8 +240,10 @@ public class OpenIdConnectRESTHelper {
buffer.flush();
return buffer.toByteArray();
} catch (FileNotFoundException e) {
logger.debug("User's avatar not found");
} catch (IOException e) {
logger.debug("Can't download avatar", e);
logger.warn("Downloading user's avatar", e);
}
return null;
}