Updated Branches: refs/heads/master 52406a840 -> 07f73ec05
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 <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/07f73ec0 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/07f73ec0 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/07f73ec0 Branch: refs/heads/master Commit: 07f73ec05408d8ad9727f763826d862a23a040dd Parents: 52406a8 Author: Laszlo Hornyak <[email protected]> Authored: Thu Jan 16 23:17:45 2014 +0100 Committer: Laszlo Hornyak <[email protected]> Committed: Fri Jan 17 00:19:17 2014 +0100 ---------------------------------------------------------------------- .../cloudstack/network/opendaylight/api/resources/Action.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07f73ec0/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/Action.java ---------------------------------------------------------------------- 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 fb764ba..748b50b 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
