private static PasswordAuthentication getSystemCreds(
final String protocol,
final AuthScope authscope,
final Authenticator.RequestorType requestorType,
final HttpClientContext context) {
final HttpRequest request = context != null ? context.getRequest() : null;
URL targetHostURL;
try {
final URI uri = request != null ? request.getUri() : null;
targetHostURL = uri != null ? uri.toURL() : null;
} catch (final URISyntaxException | MalformedURLException ignore) {
targetHostURL = null;
}
return Authenticator.requestPasswordAuthentication(
authscope.getHost(),
null,
authscope.getPort(),
protocol,
authscope.getRealm(),
translateAuthScheme(authscope.getAuthScheme()),
targetHostURL,
requestorType);
}