eclipse / paho.mqtt.java

Eclipse Paho Java MQTT client library. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
2.1k stars 880 forks source link

Getting Exception Caused by: MqttException (0) - java.io.IOException: WebSocket Response header: Incorrect upgrade. #992

Open harialgat opened 1 year ago

harialgat commented 1 year ago

Please fill out the form below before submitting, thank you!

While connecting to mqtt broker getting this Exception.

Version : 1.2.5

Gradle dependency : implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5'

code being used to connect

  private MqttAsyncClient instantiateNewMqttConnection()  {
        logger.info("Intantiate new MQTT connection....");
        logger.info("Connecting to MQTT Broker: " + this.params.url);
        MqttAsyncClient client = null;
        try {
            client = new MqttAsyncClient(this.params.url, this.params.clientId, new MemoryPersistence());
            client.setCallback(new MqttConnectionCallBack(this.params.clientId));
            MqttConnectOptions options = new MqttConnectOptions();
           // options.setSkipPortDuringHandshake(true);        
            options.setCleanSession(true);
            client.connect(options).waitForCompletion();
        } catch (MqttException e) {
            logger.info("MQTT Connection Failed");
            logger.info(e.getMessage());
            logger.info(e.getCause().toString());
            logger.info(e.getStackTrace().toString());
            Assert.fail("Failed due to MQTT connection could not be made");
        }
        return client;
    }

Same result with below code

    private MqttClient instantiateNewMqttConnection()  {
        logger.info("Intantiate new MQTT connection....");
        logger.info("Connecting to MQTT Broker: " + this.params.url);
        MqttClient client = null;
        try {
            client = new MqttClient(this.params.url, this.params.clientId, new MemoryPersistence());
            client.setCallback(new MqttConnectionCallBack(this.params.clientId));
            MqttConnectOptions options = new MqttConnectOptions();
           // options.setSkipPortDuringHandshake(true);
            options.setCleanSession(true);
            client.connect(options);
        } catch (MqttException e) {
            logger.info("MQTT Connection Failed");
            logger.info(e.getMessage());
            logger.info(e.getCause().toString());
            logger.info(e.getStackTrace().toString());
            Assert.fail("Failed due to MQTT connection could not be made");
        }
        return client;
    }

Note: URL starts with wss:// and it is being used to connect with AWSIOTMQTT broker.