-
Notifications
You must be signed in to change notification settings - Fork 165
Description
Hi All,
I am using aws-iot-device-sdk-java-1.1.1 and org.eclipse.paho.client.mqttv3-1.1.0.jar. I am able to connect to AWS MQTT broker using awsAccessKeyId and awsSecretAccessKey.
But when i try to use certificateFile and privateKeyFile, i am getting below errors consistently:
Cert file:696f7b626b-certificate.pem.crt Private key: 696f7b626b-private.pem.key
Oct 11, 2017 10:44:45 AM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
Connection lost (32109) - java.io.EOFException
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:146)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:267)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:65)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:107)
... 1 more
Oct 11, 2017 10:44:45 AM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Oct 11, 2017 10:44:45 AM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: sampleopc2
Oct 11, 2017 10:44:48 AM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
After following few threads i decided to upgrade paho jar to org.eclipse.paho.client.mqttv3-1.2.0.jar (Java Client), but getting same error consistently.
After eclipse paho jar upgrade even websocket connectivity stops working and getting error as below:
Oct 11, 2017 10:42:32 AM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
MqttException (0) - java.io.IOException: WebSocket Response header: Incorrect upgrade.
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:715)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: WebSocket Response header: Incorrect upgrade.
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.receiveHandshakeResponse(WebSocketHandshake.java:148)
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.execute(WebSocketHandshake.java:76)
at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketSecureNetworkModule.start(WebSocketSecureNetworkModule.java:63)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:701)
... 7 more
Oct 11, 2017 10:42:32 AM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionFailure
INFO: Connection temporarily lost
Oct 11, 2017 10:42:32 AM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionFailure
INFO: Client connection lost: sampleopc2
Oct 11, 2017 10:42:35 AM com.amazonaws.services.iot.client.core.AwsIotConnection$1 run
INFO: Connection is being retried
For the time being i can live with org.eclipse.paho.client.mqttv3-1.1.0.jar since atleast awsAccessKeyId and awsSecretAccessKey works.
Sample Code:
String clientEndpoint = arguments.getNotNull("clientEndpoint", SampleUtil.getConfig("clientEndpoint"));
String clientId = arguments.getNotNull("clientId", SampleUtil.getConfig("clientId"));
String certificateFile = arguments.get("certificateFile", SampleUtil.getConfig("certificateFile"));
String privateKeyFile = arguments.get("privateKeyFile", SampleUtil.getConfig("privateKeyFile"));
if (awsIotClient == null && certificateFile != null && privateKeyFile != null) {
String algorithm = arguments.get("keyAlgorithm", SampleUtil.getConfig("keyAlgorithm"));
KeyStorePasswordPair pair = SampleUtil.getKeyStorePasswordPair(certificateFile, privateKeyFile, algorithm);
awsIotClient = new AWSIotMqttClient(clientEndpoint, clientId, pair.keyStore, pair.keyPassword);
awsIotClient.setKeepAliveInterval(30000);
}
if (awsIotClient == null) {
String awsAccessKeyId = arguments.get("awsAccessKeyId", SampleUtil.getConfig("awsAccessKeyId"));
String awsSecretAccessKey = arguments.get("awsSecretAccessKey", SampleUtil.getConfig("awsSecretAccessKey"));
String sessionToken = arguments.get("sessionToken", SampleUtil.getConfig("sessionToken"));
if (awsAccessKeyId != null && awsSecretAccessKey != null) {
awsIotClient = new AWSIotMqttClient(clientEndpoint, clientId, awsAccessKeyId, awsSecretAccessKey,
sessionToken);
}
}
if (awsIotClient == null) {
throw new IllegalArgumentException("Failed to construct client due to missing certificate or credentials.");
}
awsIotClient.connect();
AWSIotTopic topic = new TestTopicListener(TestTopic, TestTopicQos);
awsIotClient.subscribe(topic, true);
Certificate as :

