Skip to content

Commit 07f73ec

Browse files
committed
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 <laszlo.hornyak@gmail.com>
1 parent 52406a8 commit 07f73ec

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

  • plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources

plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/Action.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException;
3232
import org.apache.cloudstack.network.opendaylight.api.NeutronRestFactory;
3333
import org.apache.commons.codec.binary.Base64;
34+
import org.apache.commons.httpclient.Header;
3435
import org.apache.commons.httpclient.HttpMethodBase;
3536
import org.apache.commons.httpclient.HttpStatus;
3637
import org.apache.commons.httpclient.NameValuePair;
@@ -270,7 +271,8 @@ private String encodeCredentials() {
270271
private String responseToErrorMessage(final HttpMethodBase method) {
271272
assert method.isRequestSent() : "no use getting an error message unless the request is sent";
272273

273-
if (TEXT_HTML_CONTENT_TYPE.equals(method.getResponseHeader(CONTENT_TYPE).getValue())) {
274+
final Header contentTypeHeader = method.getResponseHeader(CONTENT_TYPE);
275+
if (contentTypeHeader != null && TEXT_HTML_CONTENT_TYPE.equals(contentTypeHeader.getValue())) {
274276
// The error message is the response content
275277
// Safety margin of 1024 characters, anything longer is probably
276278
// useless and will clutter the logs

0 commit comments

Comments
 (0)