Skip to content

Commit 838c972

Browse files
committed
CLOUDSTACK-3748: AddS3Cmd NPE.
1 parent 8fe4c24 commit 838c972

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

  • api/src/org/apache/cloudstack/api/command/admin/storage

‎api/src/org/apache/cloudstack/api/command/admin/storage/AddS3Cmd.java‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public final class AddS3Cmd extends BaseCmd {
9191

9292
@Override
9393
public void execute() throws ResourceUnavailableException, InsufficientCapacityException,
94-
ServerApiException, ConcurrentOperationException, ResourceAllocationException,
95-
NetworkRuleConflictException {
94+
ServerApiException, ConcurrentOperationException, ResourceAllocationException,
95+
NetworkRuleConflictException {
9696

9797
AddImageStoreCmd cmd = new AddImageStoreCmd();
9898
cmd.setProviderName("S3");
@@ -101,19 +101,27 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
101101
details.put(ApiConstants.S3_SECRET_KEY, this.getSecretKey());
102102
details.put(ApiConstants.S3_END_POINT, this.getEndPoint());
103103
details.put(ApiConstants.S3_BUCKET_NAME, this.getBucketName());
104-
details.put(ApiConstants.S3_HTTPS_FLAG, this.getHttpsFlag().toString());
105-
details.put(ApiConstants.S3_CONNECTION_TIMEOUT, this.getConnectionTimeout().toString());
106-
details.put(ApiConstants.S3_MAX_ERROR_RETRY, this.getMaxErrorRetry().toString());
107-
details.put(ApiConstants.S3_SOCKET_TIMEOUT, this.getSocketTimeout().toString());
104+
if (this.getHttpsFlag() != null) {
105+
details.put(ApiConstants.S3_HTTPS_FLAG, this.getHttpsFlag().toString());
106+
}
107+
if (this.getConnectionTimeout() != null) {
108+
details.put(ApiConstants.S3_CONNECTION_TIMEOUT, this.getConnectionTimeout().toString());
109+
}
110+
if (this.getMaxErrorRetry() != null) {
111+
details.put(ApiConstants.S3_MAX_ERROR_RETRY, this.getMaxErrorRetry().toString());
112+
}
113+
if (this.getSocketTimeout() != null) {
114+
details.put(ApiConstants.S3_SOCKET_TIMEOUT, this.getSocketTimeout().toString());
115+
}
108116

109117
try{
110118
ImageStore result = _storageService.discoverImageStore(cmd);
111119
ImageStoreResponse storeResponse = null;
112120
if (result != null ) {
113-
storeResponse = _responseGenerator.createImageStoreResponse(result);
114-
storeResponse.setResponseName(getCommandName());
115-
storeResponse.setObjectName("secondarystorage");
116-
this.setResponseObject(storeResponse);
121+
storeResponse = _responseGenerator.createImageStoreResponse(result);
122+
storeResponse.setResponseName(getCommandName());
123+
storeResponse.setObjectName("secondarystorage");
124+
this.setResponseObject(storeResponse);
117125
} else {
118126
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage");
119127
}

0 commit comments

Comments
 (0)