mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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>
This commit is contained in:
parent
52406a8401
commit
07f73ec054
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user