Skip to content

Commit 6e426fa

Browse files
Revert "Merge pull request #825 from borisroman/charset"
This reverts commit a44e2bf, reversing changes made to 06cefaf. We are reverting the PR #825 because it breaks Master.
1 parent a44e2bf commit 6e426fa

File tree

8 files changed

+78
-67
lines changed

8 files changed

+78
-67
lines changed

plugins/hypervisors/hyperv/src/com/cloud/hypervisor/hyperv/discoverer/HypervServerDiscoverer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.net.InetAddress;
2020
import java.net.URI;
2121
import java.net.UnknownHostException;
22+
import java.nio.charset.Charset;
2223
import java.util.HashMap;
2324
import java.util.List;
2425
import java.util.Map;
@@ -42,8 +43,8 @@
4243
import com.cloud.agent.api.SetupCommand;
4344
import com.cloud.agent.api.StartupCommand;
4445
import com.cloud.agent.api.StartupRoutingCommand;
45-
import com.cloud.alert.AlertManager;
4646
import com.cloud.configuration.Config;
47+
import com.cloud.alert.AlertManager;
4748
import com.cloud.dc.ClusterVO;
4849
import com.cloud.dc.DataCenterVO;
4950
import com.cloud.dc.HostPodVO;
@@ -65,7 +66,6 @@
6566
import com.cloud.resource.ServerResource;
6667
import com.cloud.resource.UnableDeleteHostException;
6768
import com.cloud.storage.StorageLayer;
68-
import com.cloud.utils.StringUtils;
6969

7070
/**
7171
* Methods to discover and managem a Hyper-V agent. Prepares a
@@ -256,7 +256,7 @@ public final Map<? extends ServerResource, Map<String, String>> find(final long
256256
// pool in the database
257257
// This GUID may change.
258258
if (cluster.getGuid() == null) {
259-
cluster.setGuid(UUID.nameUUIDFromBytes(String.valueOf(clusterId).getBytes(StringUtils.getPreferredCharset())).toString());
259+
cluster.setGuid(UUID.nameUUIDFromBytes(String.valueOf(clusterId).getBytes(Charset.forName("UTF-8"))).toString());
260260
_clusterDao.update(clusterId, cluster);
261261
}
262262

@@ -322,7 +322,7 @@ public final Map<? extends ServerResource, Map<String, String>> find(final long
322322
* @return GUID in form of a string.
323323
*/
324324
public static String calcServerResourceGuid(final String uuidSeed) {
325-
String guid = UUID.nameUUIDFromBytes(uuidSeed.getBytes(StringUtils.getPreferredCharset())).toString();
325+
String guid = UUID.nameUUIDFromBytes(uuidSeed.getBytes(Charset.forName("UTF-8"))).toString();
326326
return guid;
327327
}
328328

plugins/hypervisors/hyperv/src/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.net.URISyntaxException;
2525
import java.net.URL;
2626
import java.nio.channels.SocketChannel;
27+
import java.nio.charset.Charset;
2728
import java.rmi.RemoteException;
2829
import java.security.KeyManagementException;
2930
import java.security.KeyStoreException;
@@ -42,7 +43,6 @@
4243
import javax.inject.Inject;
4344
import javax.naming.ConfigurationException;
4445

45-
import org.apache.cloudstack.storage.command.CopyCommand;
4646
import org.apache.commons.codec.binary.Base64;
4747
import org.apache.commons.lang.StringEscapeUtils;
4848
import org.apache.http.HttpResponse;
@@ -62,6 +62,11 @@
6262
import org.apache.http.util.EntityUtils;
6363
import org.apache.log4j.Logger;
6464

65+
import com.google.gson.Gson;
66+
import com.google.gson.reflect.TypeToken;
67+
68+
import org.apache.cloudstack.storage.command.CopyCommand;
69+
6570
import com.cloud.agent.api.Answer;
6671
import com.cloud.agent.api.CheckRouterAnswer;
6772
import com.cloud.agent.api.CheckRouterCommand;
@@ -151,8 +156,6 @@
151156
import com.cloud.vm.VirtualMachine;
152157
import com.cloud.vm.VirtualMachine.PowerState;
153158
import com.cloud.vm.VirtualMachineName;
154-
import com.google.gson.Gson;
155-
import com.google.gson.reflect.TypeToken;
156159

157160

158161
/**
@@ -650,7 +653,7 @@ public ExecutionResult executeInVR(String routerIP, String script, String args,
650653
public ExecutionResult createFileInVR(String routerIp, String filePath, String fileName, String content) {
651654
File keyFile = getSystemVMKeyFile();
652655
try {
653-
SshHelper.scpTo(routerIp, 3922, "root", keyFile, null, filePath, content.getBytes(StringUtils.getPreferredCharset()), fileName, null);
656+
SshHelper.scpTo(routerIp, 3922, "root", keyFile, null, filePath, content.getBytes(Charset.forName("UTF-8")), fileName, null);
654657
} catch (Exception e) {
655658
s_logger.warn("Fail to create file " + filePath + fileName + " in VR " + routerIp, e);
656659
return new ExecutionResult(false, e.getMessage());
@@ -1315,7 +1318,7 @@ protected Answer execute(final LoadBalancerConfigCommand cmd) {
13151318
}
13161319

13171320
try {
1318-
SshHelper.scpTo(controlIp, DEFAULT_DOMR_SSHPORT, "root", keyFile, null, "/tmp/", tmpCfgFileContents.toString().getBytes(StringUtils.getPreferredCharset()), routerIp.replace('.', '_') +
1321+
SshHelper.scpTo(controlIp, DEFAULT_DOMR_SSHPORT, "root", keyFile, null, "/tmp/", tmpCfgFileContents.toString().getBytes(Charset.forName("UTF-8")), routerIp.replace('.', '_') +
13191322
".cfg", null);
13201323

13211324
try {
@@ -1512,7 +1515,7 @@ protected Answer execute(VmDataCommand cmd) {
15121515
String json = new Gson().toJson(data);
15131516
s_logger.debug("VM data JSON IS:" + json);
15141517

1515-
json = Base64.encodeBase64String(json.getBytes(StringUtils.getPreferredCharset()));
1518+
json = Base64.encodeBase64String(json.getBytes(Charset.forName("UTF-8")));
15161519

15171520
String args = "-d " + json;
15181521

plugins/network-elements/bigswitch/src/com/cloud/network/bigswitch/BigSwitchBcfApi.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.lang.reflect.Type;
2525
import java.net.MalformedURLException;
2626
import java.net.URL;
27+
import java.nio.charset.Charset;
2728
import java.util.ArrayList;
2829
import java.util.Collections;
2930
import java.util.List;
@@ -48,7 +49,6 @@
4849
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
4950
import org.apache.log4j.Logger;
5051

51-
import com.cloud.utils.StringUtils;
5252
import com.google.gson.Gson;
5353
import com.google.gson.reflect.TypeToken;
5454

@@ -301,7 +301,7 @@ private void setHttpHeader(final HttpMethodBase m) {
301301
}
302302

303303
String authString = username + ":" + password;
304-
String encodedAuthString = "Basic " + Base64.encodeBase64String(authString.getBytes(StringUtils.getPreferredCharset()));
304+
String encodedAuthString = "Basic " + Base64.encodeBase64String(authString.getBytes(Charset.forName("UTF-8")));
305305
m.setRequestHeader("Authorization", encodedAuthString);
306306
}
307307

plugins/network-elements/brocade-vcs/src/com/cloud/network/brocade/BrocadeVcsApi.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import java.io.StringWriter;
2424
import java.net.MalformedURLException;
2525
import java.net.URL;
26+
import java.nio.charset.Charset;
2627

27-
import javax.persistence.Basic;
2828
import javax.xml.bind.JAXBContext;
2929
import javax.xml.bind.JAXBException;
3030
import javax.xml.bind.Marshaller;
@@ -45,9 +45,21 @@
4545
import org.apache.http.impl.client.DefaultHttpClient;
4646
import org.apache.log4j.Logger;
4747

48-
import com.cloud.dc.Vlan;
49-
import com.cloud.utils.StringUtils;
50-
import com.cloud.utils.cisco.n1kv.vsm.PortProfile;
48+
import com.cloud.network.schema.interfacevlan.InterfaceVlan;
49+
import com.cloud.network.schema.interfacevlan.Interface;
50+
import com.cloud.network.schema.interfacevlan.Vlan;
51+
import com.cloud.network.schema.portprofile.PortProfile;
52+
import com.cloud.network.schema.portprofile.PortProfile.Activate;
53+
import com.cloud.network.schema.portprofile.PortProfile.Static;
54+
import com.cloud.network.schema.portprofile.PortProfileGlobal;
55+
import com.cloud.network.schema.portprofile.VlanProfile;
56+
import com.cloud.network.schema.portprofile.VlanProfile.Switchport;
57+
import com.cloud.network.schema.portprofile.VlanProfile.Switchport.Mode;
58+
import com.cloud.network.schema.portprofile.VlanProfile.Switchport.Trunk;
59+
import com.cloud.network.schema.portprofile.VlanProfile.Switchport.Trunk.Allowed;
60+
import com.cloud.network.schema.portprofile.VlanProfile.SwitchportBasic;
61+
import com.cloud.network.schema.portprofile.VlanProfile.SwitchportBasic.Basic;
62+
import com.cloud.network.schema.showvcs.Output;
5163

5264
public class BrocadeVcsApi {
5365
private static final Logger s_logger = Logger.getLogger(BrocadeVcsApi.class);
@@ -449,7 +461,7 @@ protected Output executeRetreiveStatus(String uri) throws BrocadeVcsApiException
449461
throw new BrocadeVcsApiException("Failed to retreive status : " + errorMessage);
450462
}
451463

452-
try (BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), StringUtils.getPreferredCharset()))) {
464+
try (BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), Charset.forName("UTF-8")))) {
453465
sb = new StringBuffer();
454466

455467
while (((readLine = br.readLine()) != null)) {
@@ -519,7 +531,7 @@ private String responseToErrorMessage(HttpResponse response) throws IOException
519531

520532
if ("text/html".equals(response.getEntity().getContentType().getValue())) {
521533

522-
try (BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), StringUtils.getPreferredCharset()))) {
534+
try (BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), Charset.forName("UTF-8")))) {
523535

524536
StringBuffer result = new StringBuffer();
525537
String line = "";

plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package com.cloud.network.manager;
2121

22+
import java.nio.charset.Charset;
2223
import java.util.ArrayList;
2324
import java.util.HashMap;
2425
import java.util.List;
@@ -72,7 +73,6 @@
7273
import com.cloud.resource.ResourceManager;
7374
import com.cloud.resource.ResourceState;
7475
import com.cloud.resource.ServerResource;
75-
import com.cloud.utils.StringUtils;
7676
import com.cloud.utils.component.ManagerBase;
7777
import com.cloud.utils.db.Transaction;
7878
import com.cloud.utils.db.TransactionCallback;
@@ -159,7 +159,7 @@ public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd) {
159159
params.put("name", "Nuage VSD - " + cmd.getHostName());
160160
params.put("hostname", cmd.getHostName());
161161
params.put("cmsuser", cmd.getUserName());
162-
String cmsUserPasswordBase64 = org.apache.commons.codec.binary.StringUtils.newStringUtf8(Base64.encodeBase64(cmd.getPassword().getBytes(StringUtils.getPreferredCharset())));
162+
String cmsUserPasswordBase64 = org.apache.commons.codec.binary.StringUtils.newStringUtf8(Base64.encodeBase64(cmd.getPassword().getBytes(Charset.forName("UTF-8"))));
163163
params.put("cmsuserpass", cmsUserPasswordBase64);
164164
int port = cmd.getPort();
165165
if (0 == port) {
@@ -301,7 +301,6 @@ private void initNuageScheduledTasks() {
301301

302302
if (numOfSyncThreads != null && syncUpIntervalInMinutes != null) {
303303
ThreadFactory threadFactory = new ThreadFactory() {
304-
@Override
305304
public Thread newThread(Runnable runnable) {
306305
Thread thread = new Thread(runnable, "Nuage Vsp sync task");
307306
if (thread.isDaemon())

plugins/user-authenticators/saml2/src/org/apache/cloudstack/saml/SAMLUtils.java

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,7 @@
1919

2020
package org.apache.cloudstack.saml;
2121

22-
import java.io.ByteArrayInputStream;
23-
import java.io.ByteArrayOutputStream;
24-
import java.io.IOException;
25-
import java.io.StringWriter;
26-
import java.io.UnsupportedEncodingException;
27-
import java.math.BigInteger;
28-
import java.net.URLEncoder;
29-
import java.security.InvalidKeyException;
30-
import java.security.KeyFactory;
31-
import java.security.KeyPair;
32-
import java.security.KeyPairGenerator;
33-
import java.security.NoSuchAlgorithmException;
34-
import java.security.NoSuchProviderException;
35-
import java.security.PrivateKey;
36-
import java.security.PublicKey;
37-
import java.security.SecureRandom;
38-
import java.security.Security;
39-
import java.security.Signature;
40-
import java.security.SignatureException;
41-
import java.security.cert.CertificateEncodingException;
42-
import java.security.cert.X509Certificate;
43-
import java.security.spec.InvalidKeySpecException;
44-
import java.security.spec.PKCS8EncodedKeySpec;
45-
import java.security.spec.X509EncodedKeySpec;
46-
import java.util.List;
47-
import java.util.zip.Deflater;
48-
import java.util.zip.DeflaterOutputStream;
49-
50-
import javax.security.auth.x500.X500Principal;
51-
import javax.servlet.http.Cookie;
52-
import javax.servlet.http.HttpServletResponse;
53-
import javax.xml.parsers.DocumentBuilder;
54-
import javax.xml.parsers.DocumentBuilderFactory;
55-
import javax.xml.parsers.ParserConfigurationException;
56-
import javax.xml.stream.FactoryConfigurationError;
57-
22+
import com.cloud.utils.HttpUtils;
5823
import org.apache.cloudstack.api.ApiConstants;
5924
import org.apache.cloudstack.api.response.LoginCmdResponse;
6025
import org.apache.log4j.Logger;
@@ -98,8 +63,41 @@
9863
import org.w3c.dom.Element;
9964
import org.xml.sax.SAXException;
10065

101-
import com.cloud.utils.HttpUtils;
102-
import com.cloud.utils.StringUtils;
66+
import javax.security.auth.x500.X500Principal;
67+
import javax.servlet.http.Cookie;
68+
import javax.servlet.http.HttpServletResponse;
69+
import javax.xml.parsers.DocumentBuilder;
70+
import javax.xml.parsers.DocumentBuilderFactory;
71+
import javax.xml.parsers.ParserConfigurationException;
72+
import javax.xml.stream.FactoryConfigurationError;
73+
import java.io.ByteArrayInputStream;
74+
import java.io.ByteArrayOutputStream;
75+
import java.io.IOException;
76+
import java.io.StringWriter;
77+
import java.io.UnsupportedEncodingException;
78+
import java.math.BigInteger;
79+
import java.net.URLEncoder;
80+
import java.nio.charset.Charset;
81+
import java.security.InvalidKeyException;
82+
import java.security.KeyFactory;
83+
import java.security.KeyPair;
84+
import java.security.KeyPairGenerator;
85+
import java.security.NoSuchAlgorithmException;
86+
import java.security.NoSuchProviderException;
87+
import java.security.PrivateKey;
88+
import java.security.PublicKey;
89+
import java.security.SecureRandom;
90+
import java.security.Security;
91+
import java.security.Signature;
92+
import java.security.SignatureException;
93+
import java.security.cert.CertificateEncodingException;
94+
import java.security.cert.X509Certificate;
95+
import java.security.spec.InvalidKeySpecException;
96+
import java.security.spec.PKCS8EncodedKeySpec;
97+
import java.security.spec.X509EncodedKeySpec;
98+
import java.util.List;
99+
import java.util.zip.Deflater;
100+
import java.util.zip.DeflaterOutputStream;
103101

104102
public class SAMLUtils {
105103
public static final Logger s_logger = Logger.getLogger(SAMLUtils.class);
@@ -221,7 +219,7 @@ public static String encodeSAMLRequest(XMLObject authnRequest)
221219
Deflater deflater = new Deflater(Deflater.DEFLATED, true);
222220
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
223221
DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, deflater);
224-
deflaterOutputStream.write(requestMessage.getBytes(StringUtils.getPreferredCharset()));
222+
deflaterOutputStream.write(requestMessage.getBytes(Charset.forName("UTF-8")));
225223
deflaterOutputStream.close();
226224
String encodedRequestMessage = Base64.encodeBytes(byteArrayOutputStream.toByteArray(), Base64.DONT_BREAK_LINES);
227225
encodedRequestMessage = URLEncoder.encode(encodedRequestMessage, HttpUtils.UTF_8).trim();
@@ -265,7 +263,7 @@ public static String generateSAMLRequestSignature(final String urlEncodedString,
265263
String url = urlEncodedString + "&SigAlg=" + URLEncoder.encode(opensamlAlgoIdSignature, HttpUtils.UTF_8);
266264
Signature signature = Signature.getInstance(javaSignatureAlgorithmName);
267265
signature.initSign(signingKey);
268-
signature.update(url.getBytes(StringUtils.getPreferredCharset()));
266+
signature.update(url.getBytes(Charset.forName("UTF-8")));
269267
String signatureString = Base64.encodeBytes(signature.sign(), Base64.DONT_BREAK_LINES);
270268
if (signatureString != null) {
271269
return url + "&Signature=" + URLEncoder.encode(signatureString, HttpUtils.UTF_8);
@@ -289,7 +287,7 @@ public static String savePublicKey(PublicKey key) {
289287
KeyFactory keyFactory = SAMLUtils.getKeyFactory();
290288
if (keyFactory == null) return null;
291289
X509EncodedKeySpec spec = keyFactory.getKeySpec(key, X509EncodedKeySpec.class);
292-
return new String(org.bouncycastle.util.encoders.Base64.encode(spec.getEncoded()), StringUtils.getPreferredCharset());
290+
return new String(org.bouncycastle.util.encoders.Base64.encode(spec.getEncoded()), Charset.forName("UTF-8"));
293291
} catch (InvalidKeySpecException e) {
294292
s_logger.error("Unable to create KeyFactory:" + e.getMessage());
295293
}
@@ -302,7 +300,7 @@ public static String savePrivateKey(PrivateKey key) {
302300
if (keyFactory == null) return null;
303301
PKCS8EncodedKeySpec spec = keyFactory.getKeySpec(key,
304302
PKCS8EncodedKeySpec.class);
305-
return new String(org.bouncycastle.util.encoders.Base64.encode(spec.getEncoded()), StringUtils.getPreferredCharset());
303+
return new String(org.bouncycastle.util.encoders.Base64.encode(spec.getEncoded()), Charset.forName("UTF-8"));
306304
} catch (InvalidKeySpecException e) {
307305
s_logger.error("Unable to create KeyFactory:" + e.getMessage());
308306
}

utils/src/main/java/com/cloud/utils/ConstantTimeComparator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static boolean compareBytes(byte[] b1, byte[] b2) {
3636
}
3737

3838
public static boolean compareStrings(String s1, String s2) {
39-
final Charset encoding = StringUtils.getPreferredCharset();
39+
final Charset encoding = Charset.forName("UTF-8");
4040
return compareBytes(s1.getBytes(encoding), s2.getBytes(encoding));
4141
}
4242
}

utils/src/test/java/com/cloud/utils/storage/QCOW2UtilsTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@
2424
import java.io.IOException;
2525
import java.io.InputStream;
2626
import java.nio.ByteBuffer;
27+
import java.nio.charset.Charset;
2728

2829
import org.junit.Before;
2930
import org.junit.Test;
3031

31-
import com.cloud.utils.StringUtils;
32-
3332
public class QCOW2UtilsTest {
3433

3534
InputStream inputStream;
@@ -68,7 +67,7 @@ public void setup() {
6867
ByteBuffer byteBuffer = ByteBuffer.allocate(72);
6968

7069
// Magic
71-
byteBuffer.put("QFI".getBytes(StringUtils.getPreferredCharset()));
70+
byteBuffer.put("QFI".getBytes(Charset.forName("UTF-8")));
7271
byteBuffer.put((byte)0xfb);
7372

7473
// Version

0 commit comments

Comments
 (0)