From 07f73ec05408d8ad9727f763826d862a23a040dd Mon Sep 17 00:00:00 2001 From: Laszlo Hornyak Date: Thu, 16 Jan 2014 23:17:45 +0100 Subject: [PATCH] Null-safety in http header handling The http Content-Type header may not always be present in the response, in such cases the getResponseHeader will return null and this leads to NPE, therefore the presence of the header must be checked. Signed-off-by: Laszlo Hornyak --- .../cloudstack/network/opendaylight/api/resources/Action.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/Action.java b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/Action.java index fb764bad4a8..748b50b00b6 100644 --- a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/Action.java +++ b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/Action.java @@ -31,6 +31,7 @@ import org.apache.cloudstack.network.opendaylight.api.NeutronRestApi; import org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException; import org.apache.cloudstack.network.opendaylight.api.NeutronRestFactory; import org.apache.commons.codec.binary.Base64; +import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair; @@ -270,7 +271,8 @@ public abstract class Action { private String responseToErrorMessage(final HttpMethodBase method) { assert method.isRequestSent() : "no use getting an error message unless the request is sent"; - if (TEXT_HTML_CONTENT_TYPE.equals(method.getResponseHeader(CONTENT_TYPE).getValue())) { + final Header contentTypeHeader = method.getResponseHeader(CONTENT_TYPE); + if (contentTypeHeader != null && TEXT_HTML_CONTENT_TYPE.equals(contentTypeHeader.getValue())) { // The error message is the response content // Safety margin of 1024 characters, anything longer is probably // useless and will clutter the logs