ARTEMIS-2320 Standard Charset object can be used
This commit is contained in:
parent
781e4c460d
commit
f508a25566
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
package org.apache.activemq.artemis.core.protocol.mqtt;
|
package org.apache.activemq.artemis.core.protocol.mqtt;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufAllocator;
|
import io.netty.buffer.ByteBufAllocator;
|
||||||
|
@ -268,15 +268,11 @@ public class MQTTPublishManager {
|
||||||
ByteBuf payload;
|
ByteBuf payload;
|
||||||
switch (message.getType()) {
|
switch (message.getType()) {
|
||||||
case Message.TEXT_TYPE:
|
case Message.TEXT_TYPE:
|
||||||
try {
|
SimpleString text = message.getDataBuffer().readNullableSimpleString();
|
||||||
SimpleString text = message.getDataBuffer().readNullableSimpleString();
|
byte[] stringPayload = text.toString().getBytes(StandardCharsets.UTF_8);
|
||||||
byte[] stringPayload = text.toString().getBytes("UTF-8");
|
payload = ByteBufAllocator.DEFAULT.buffer(stringPayload.length);
|
||||||
payload = ByteBufAllocator.DEFAULT.buffer(stringPayload.length);
|
payload.writeBytes(stringPayload);
|
||||||
payload.writeBytes(stringPayload);
|
break;
|
||||||
break;
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
log.warn("Unable to send message: " + message.getMessageID() + " Cause: " + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
ActiveMQBuffer bodyBuffer = message.getDataBuffer();
|
ActiveMQBuffer bodyBuffer = message.getDataBuffer();
|
||||||
payload = ByteBufAllocator.DEFAULT.buffer(bodyBuffer.writerIndex());
|
payload = ByteBufAllocator.DEFAULT.buffer(bodyBuffer.writerIndex());
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.transport.amqp.client;
|
package org.apache.activemq.transport.amqp.client;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -58,12 +58,7 @@ public final class AmqpTransferTagGenerator {
|
||||||
rc = iterator.next();
|
rc = iterator.next();
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
} else {
|
} else {
|
||||||
try {
|
rc = Long.toHexString(nextTagId++).getBytes(StandardCharsets.UTF_8);
|
||||||
rc = Long.toHexString(nextTagId++).getBytes("UTF-8");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
// This should never happen since we control the input.
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ package org.apache.activemq.transport.amqp.client.sasl;
|
||||||
import javax.crypto.Mac;
|
import javax.crypto.Mac;
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import javax.security.sasl.SaslException;
|
import javax.security.sasl.SaslException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@ import java.security.NoSuchAlgorithmException;
|
||||||
*/
|
*/
|
||||||
public class CramMD5Mechanism extends AbstractMechanism {
|
public class CramMD5Mechanism extends AbstractMechanism {
|
||||||
|
|
||||||
private static final String ASCII = "ASCII";
|
|
||||||
private static final String HMACMD5 = "HMACMD5";
|
private static final String HMACMD5 = "HMACMD5";
|
||||||
private boolean sentResponse;
|
private boolean sentResponse;
|
||||||
|
|
||||||
|
@ -53,7 +52,7 @@ public class CramMD5Mechanism extends AbstractMechanism {
|
||||||
public byte[] getChallengeResponse(byte[] challenge) throws SaslException {
|
public byte[] getChallengeResponse(byte[] challenge) throws SaslException {
|
||||||
if (!sentResponse && challenge != null && challenge.length != 0) {
|
if (!sentResponse && challenge != null && challenge.length != 0) {
|
||||||
try {
|
try {
|
||||||
SecretKeySpec key = new SecretKeySpec(getPassword().getBytes(ASCII), HMACMD5);
|
SecretKeySpec key = new SecretKeySpec(getPassword().getBytes(StandardCharsets.US_ASCII), HMACMD5);
|
||||||
Mac mac = Mac.getInstance(HMACMD5);
|
Mac mac = Mac.getInstance(HMACMD5);
|
||||||
mac.init(key);
|
mac.init(key);
|
||||||
|
|
||||||
|
@ -70,9 +69,7 @@ public class CramMD5Mechanism extends AbstractMechanism {
|
||||||
}
|
}
|
||||||
|
|
||||||
sentResponse = true;
|
sentResponse = true;
|
||||||
return hash.toString().getBytes(ASCII);
|
return hash.toString().getBytes(StandardCharsets.US_ASCII);
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
throw new SaslException("Unable to utilise required encoding", e);
|
|
||||||
} catch (InvalidKeyException e) {
|
} catch (InvalidKeyException e) {
|
||||||
throw new SaslException("Unable to utilise key", e);
|
throw new SaslException("Unable to utilise key", e);
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
|
|
@ -261,7 +261,7 @@ public class StompTest extends StompTestBase {
|
||||||
byte[] mqttPayload = clientProvider.receive(10000);
|
byte[] mqttPayload = clientProvider.receive(10000);
|
||||||
clientProvider.disconnect();
|
clientProvider.disconnect();
|
||||||
|
|
||||||
assertEquals(stompPayload, new String(mqttPayload, "UTF-8"));
|
assertEquals(stompPayload, new String(mqttPayload, StandardCharsets.UTF_8));
|
||||||
clientProvider.disconnect();
|
clientProvider.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue