Skip to content

Commit d39b993

Browse files
committed
Fixed a few findbugs issues after the merge 0b83559
HttpUploadServerHandler.java:142, DM_BOXED_PRIMITIVE_FOR_PARSING NfsSecondaryStorageResource.java:2630, DM_BOXED_PRIMITIVE_FOR_PARSING NfsSecondaryStorageResource.java:2775, DM_DEFAULT_ENCODING EncryptionUtil.java:59, DM_DEFAULT_ENCODING
1 parent dc3c43e commit d39b993

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/HttpUploadServerHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Excep
139139
hostname = entry.getValue();
140140
break;
141141
case HttpHeaders.Names.CONTENT_LENGTH:
142-
contentLength = Long.valueOf(entry.getValue());
142+
contentLength = Long.parseLong(entry.getValue());
143143
break;
144144
}
145145
}

services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.io.FileWriter;
3333
import java.io.IOException;
3434
import java.io.InputStream;
35+
import java.io.UnsupportedEncodingException;
3536
import java.math.BigInteger;
3637
import java.net.InetAddress;
3738
import java.net.URI;
@@ -2627,7 +2628,7 @@ public UploadEntity createUploadEntity(String uuid, String metadata, long conten
26272628
}
26282629
throw new InvalidParameterValueException(errorMessage.toString());
26292630
}
2630-
int maxSizeInGB = Integer.valueOf(cmd.getMaxUploadSize());
2631+
int maxSizeInGB = Integer.parseInt(cmd.getMaxUploadSize());
26312632
int contentLengthInGB = getSizeInGB(contentLength);
26322633
if (contentLengthInGB > maxSizeInGB) {
26332634
String errorMessage = "Maximum file upload size exceeded. Content Length received: " + contentLengthInGB + "GB. Maximum allowed size: " + maxSizeInGB + "GB.";
@@ -2772,7 +2773,11 @@ public String postUpload(String uuid, String filename) {
27722773
if (extension.equals("iso")) {
27732774
templateName = uploadEntity.getUuid().trim().replace(" ", "_");
27742775
} else {
2775-
templateName = java.util.UUID.nameUUIDFromBytes((uploadEntity.getFilename() + System.currentTimeMillis()).getBytes()).toString();
2776+
try {
2777+
templateName = UUID.nameUUIDFromBytes((uploadEntity.getFilename() + System.currentTimeMillis()).getBytes("UTF-8")).toString();
2778+
} catch (UnsupportedEncodingException e) {
2779+
templateName = uploadEntity.getUuid().trim().replace(" ", "_");
2780+
}
27762781
}
27772782

27782783
// run script to mv the temporary template file to the final template

utils/src/com/cloud/utils/EncryptionUtil.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
*/
1919
package com.cloud.utils;
2020

21+
import com.cloud.utils.exception.CloudRuntimeException;
2122
import org.apache.commons.codec.binary.Base64;
2223
import org.apache.log4j.Logger;
2324
import org.jasypt.encryption.pbe.PBEStringEncryptor;
2425
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
2526

2627
import javax.crypto.Mac;
2728
import javax.crypto.spec.SecretKeySpec;
29+
import java.io.UnsupportedEncodingException;
2830
import java.security.InvalidKeyException;
2931
import java.security.NoSuchAlgorithmException;
3032

@@ -56,14 +58,14 @@ public static String decodeData(String encodedData, String key) {
5658
public static String generateSignature(String data, String key) {
5759
try {
5860
final Mac mac = Mac.getInstance("HmacSHA1");
59-
final SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "HmacSHA1");
61+
final SecretKeySpec keySpec = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA1");
6062
mac.init(keySpec);
6163
mac.update(data.getBytes());
6264
final byte[] encryptedBytes = mac.doFinal();
6365
return Base64.encodeBase64String(encryptedBytes);
64-
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
65-
s_logger.error("exception occurred which encoding the data.", e);
66-
return null;
66+
} catch (NoSuchAlgorithmException | InvalidKeyException | UnsupportedEncodingException e) {
67+
s_logger.error("exception occurred which encoding the data." + e.getMessage());
68+
throw new CloudRuntimeException("unable to generate signature", e);
6769
}
6870
}
6971
}

0 commit comments

Comments
 (0)