Search in sources :

Example 1 with EntityException

use of it.spid.cie.oidc.exception.EntityException in project spid-cie-oidc-java by italia.

the class EntityHelper method doHttpGet.

/**
 * @param url
 * @return
 * @throws OIDCException
 */
private static String doHttpGet(String url) throws OIDCException {
    try {
        HttpRequest request = HttpRequest.newBuilder().uri(new URI(url)).GET().build();
        HttpResponse<String> response = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.NORMAL).build().send(request, BodyHandlers.ofString());
        if (logger.isDebugEnabled()) {
            logger.debug(url + " --> " + response.statusCode());
        }
        if (response.statusCode() != 200) {
            throw new EntityException.Generic(url + " gets " + response.statusCode());
        }
        return response.body();
    } catch (EntityException e) {
        throw e;
    } catch (Exception e) {
        throw new EntityException.Generic(e);
    }
}
Also used : HttpRequest(java.net.http.HttpRequest) EntityException(it.spid.cie.oidc.exception.EntityException) URI(java.net.URI) EntityException(it.spid.cie.oidc.exception.EntityException) OIDCException(it.spid.cie.oidc.exception.OIDCException)

Aggregations

EntityException (it.spid.cie.oidc.exception.EntityException)1 OIDCException (it.spid.cie.oidc.exception.OIDCException)1 URI (java.net.URI)1 HttpRequest (java.net.http.HttpRequest)1