Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] (no subject)

I am using emqttd broker

On Apr 10, 2017 4:17 PM, "James Sutton1" <james.sutton@xxxxxxxxxx> wrote:
Hi,
 
I can't see any issues with your code, it's exactly what I would do. What MQTT Broker are you using? I tested the following against mosquitto which worked fine:
 

import org.eclipse.paho.client.mqttv3.IMqttToken;

import org.eclipse.paho.client.mqttv3.MqttAsyncClient;

import org.eclipse.paho.client.mqttv3.MqttConnectOptions;

import org.eclipse.paho.client.mqttv3.MqttException;

import org.eclipse.paho.client.mqttv3.MqttMessage;

import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;

 

public class AuthTest {

public static void main( String[] args )

    {

 

      String topic        = "auth_test";

        String content      = "Message from MqttPublishSample";

        int qos             = 0;

        String broker       = "tcp://localhost";

        String clientId     = "auth_test";

        MemoryPersistence persistence = new MemoryPersistence();

 

        try {

            MqttAsyncClient sampleClient = new MqttAsyncClient(broker, clientId, persistence);

            MqttConnectOptions connOpts = new MqttConnectOptions();

            connOpts.setCleanSession(true);

            connOpts.setMaxInflight(1000);

            connOpts.setUserName("USERNAME");

            connOpts.setPassword("PASSWORD".toCharArray());

            System.out.println("Connecting to broker: "+broker);

            IMqttToken conToken = sampleClient.connect(connOpts);

            conToken.waitForCompletion();

            System.out.println("Connected");

            System.out.println("Publishing message: "+content);

            System.out.println("About to send messages");

            for(int i = 0; i < 10; i++){

            sampleClient.publish(topic, new MqttMessage(content.getBytes()));

            }

            sampleClient.disconnect();

            System.out.println("Disconnected");

            System.exit(0);

        } catch(MqttException me) {

            System.out.println("reason "+me.getReasonCode());

            System.out.println("msg "+me.getMessage());

            System.out.println("loc "+me.getLocalizedMessage());

            System.out.println("cause "+me.getCause());

            System.out.println("excep "+me);

            me.printStackTrace();

        }

    }

}

 
 
Kind regards,
 
James Sutton
Software Engineer - IoT Foundation - MQTT Open Source Projects
Ops Team - Wimbledon Project

Phone: 01962 815438 | Extension: x372454
E-mail: james.sutton@xxxxxx.com
Personal Website: www.jsutton.co.uk
Find me on:     
IBM

Hursley Park
HursleySO212JN
United Kingdom
 
IBM United Kingdom Limited Registered in England and Wales with number 741598 Registered office: PO Box 41, North Harbour, Portsmouth, Hants. PO6 3AU
 
 
----- Original message -----
From: manish kumar <mkj.online@xxxxxxxxx>
Sent by: paho-dev-bounces@xxxxxxxxxxx
To: General development discussions for paho project <paho-dev@xxxxxxxxxxx>
Cc:
Subject: [paho-dev] (no subject)
Date: Mon, Apr 10, 2017 9:50 AM
 
 

Is there some issue with java client when connecting with username & password ???

paho JS client it works but from java client it doesn't.
I have this code

    MqttConnectOptions conOpt = new MqttConnectOptions();
    conOpt.setCleanSession(false);
    conOpt.setUserName("test5");
    conOpt.setPassword("123".toCharArray());
    MqttDefaultFilePersistence filePersistence = new MqttDefaultFilePersistence("/home/manish/Downloads/mqttPersist");
    client = new MqttAsyncClient(appProps.getProperty("mqtt.broker"),
            appProps.getProperty("mqtt.clientId"), filePersistence);
    client.setCallback(this);
    client.connect(conOpt, new IMqttActionListener() {
        @Override
        public void onSuccess(IMqttToken imt) {
            try {
                client.subscribe(Constants.INTERNAL_TOPICS, Constants.INTERNAL_TOPIC_QOS);
            } catch (MqttException ex) {
                ex.printStackTrace();
            }
        }

        @Override
        public void onFailure(IMqttToken imt, Throwable thrwbl) {
            thrwbl.printStackTrace();
        }
    });

i am getting this exception

Bad user name or password (4)
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:28)
at org.eclipse.paho.client.mqttv3.internal.ClientState.notifyReceivedAck(ClientState.java:885)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:118)
at java.lang.Thread.run(Thread.java:745)

emqt console

06:47:36.456 [error] Client(notification_subs_bot@127.0.0.1:50741): Username 'undefined' login failed for username_or_password_undefined
06:47:36.463 [error] Client(notification_subs_bot@127.0.0.1:50742): Username 'undefined' login failed for username_or_password_undefined

According paho documentation public void setPassword(char[] password) So here i am passing char[] as paasword

--
Thanks,
Manish Kumar
_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev
 
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU


_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev

Back to the top