From ff7c68939563b8ac1cc1b293b8195cd9801877c7 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Mon, 21 Sep 2020 10:39:06 +0200 Subject: fix possible nullpointer exception --- .../apache/commons/httpclient/MOAHttpClient.java | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'id/server/moa-id-commons/src/main/java/org') diff --git a/id/server/moa-id-commons/src/main/java/org/apache/commons/httpclient/MOAHttpClient.java b/id/server/moa-id-commons/src/main/java/org/apache/commons/httpclient/MOAHttpClient.java index 04e9a8ab9..751e27b95 100644 --- a/id/server/moa-id-commons/src/main/java/org/apache/commons/httpclient/MOAHttpClient.java +++ b/id/server/moa-id-commons/src/main/java/org/apache/commons/httpclient/MOAHttpClient.java @@ -45,6 +45,7 @@ public class MOAHttpClient extends HttpClient { public MOAHttpClient() { super(); + injectProxyCredentials(); } @@ -93,8 +94,12 @@ public class MOAHttpClient extends HttpClient { HttpState interalState = (state == null ? getState() : state); - if (requiresProxy(uri.getURI())) { - injectProxyCredentials(hostconfig, interalState); + if (!requiresProxy(uri.getURI()) + && MiscUtil.isNotEmpty(hostconfig.getProxyHost())) { + Logger.info("RequestURL is on proxy-ignore list. Remove proxy from request", null); + hostconfig.setProxyHost(null); + + } @@ -102,12 +107,12 @@ public class MOAHttpClient extends HttpClient { getHttpConnectionManager(), hostconfig, getParams(), - state); + interalState); methodDirector.executeMethod(method); return method.getStatusCode(); } - public void injectProxyCredentials(HostConfiguration hostconfig, HttpState interalState) { + public void injectProxyCredentials() { //set proxy functionality String host = System.getProperty("http.proxyHost"); //$NON-NLS-1$ String port = System.getProperty("http.proxyPort"); //$NON-NLS-1$ @@ -125,14 +130,14 @@ public class MOAHttpClient extends HttpClient { } } - Logger.debug("Set HTTP-Proxy to Host: " + host + " and port: " + p); - hostconfig.setProxy(host, p); + Logger.info("Set HTTP-Proxy to Host: " + host + " and port: " + p); + getHostConfiguration().setProxy(host, p); if (MiscUtil.isNotEmpty(user) && pass != null) { //set proxy credentials AuthScope authscope = new AuthScope(host, p); Credentials credentials = new UsernamePasswordCredentials(user, pass); - interalState.setProxyCredentials(authscope, credentials); - Logger.debug(" Use Proxy with Username: " + user + " and password: " + getState().setProxyCredentials(authscope, credentials); + Logger.info(" Use Proxy with Username: " + user + " and password: " + (Logger.isTraceEnabled() ? pass : "*******")); } @@ -150,8 +155,7 @@ public class MOAHttpClient extends HttpClient { { boolean requiresProxy = true; final String nonProxyHosts = System.getProperty("http.nonProxyHosts"); - if (nonProxyHosts != null) - { + if (nonProxyHosts != null) { StringTokenizer tokenizer = new StringTokenizer(nonProxyHosts, "|"); while (tokenizer.hasMoreTokens()) { -- cgit v1.2.3