public void setUserName(String userName) { this.setUserName(utf8(userName)); } public void setUserName(UTF8Buffer userName) {
main.mqtt.setClientId(shift(argl)); } else if ("-u".equals(arg)) { main.mqtt.setUserName(shift(argl)); } else if ("-p".equals(arg)) { main.mqtt.setPassword(shift(argl));
main.mqtt.setClientId(shift(argl)); } else if ("-u".equals(arg)) { main.mqtt.setUserName(shift(argl)); } else if ("-p".equals(arg)) { main.mqtt.setPassword(shift(argl));
client.setUserName(options.getUserName()); client.setPassword(options.getPassword()); client.setTracer(new MqttLogger());
public void setUserName(String userName) { this.setUserName(utf8(userName)); } public void setUserName(UTF8Buffer userName) {
public void init(String host, int port) throws Exception { mqtt = new MQTT(); mqtt.setHost(host, port); mqtt.setUserName(uid); mqtt.setPassword(pwd); mqtt.setClientId(uid); }
private void connect() throws Exception { mqttClient.setHost(baseUrl.getHost(), port); mqttClient.setTracer(new Tracer() { @Override public void onReceive(MQTTFrame frame) { log.debug("receive:{}", frame); } @Override public void onSend(MQTTFrame frame) { log.debug("send:{}", frame); } }); mqttClient.setUserName(username); mqttClient.setPassword(password); connection = mqttClient.blockingConnection(); connection.connect(); }
mqtt.setUserName(component.getUsername());
private CallbackConnection createConnection(String host, String clientId, boolean durable, String user, String password) throws URISyntaxException { MQTT client = new MQTT(); client.setHost(host); client.setClientId(clientId); client.setUserName(user); client.setPassword(password); client.setCleanSession(!durable); return client.callbackConnection(); }
private FutureConnection createConnection(String host,String clientId,String user, String password) { try { MQTT client = new MQTT(); client.setHost(host); client.setUserName(user); client.setPassword(password); client.setClientId(clientId); return client.futureConnection(); } catch (URISyntaxException e) { getLogger().error(e.getMessage()); return null; } }
@Override public FuseChannel build() throws Exception { final URI broker = Objects.requireNonNull(broker(), "Broker must be set"); final String clientId = Strings.nonEmptyText(clientId(), "clientId"); final MqttNamespace namespace = Objects.requireNonNull(namespace(), "Namespace must be set"); final BinaryPayloadCodec codec = Objects.requireNonNull(codec(), "Codec must be set"); final MQTT mqtt = new MQTT(); mqtt.setCleanSession(false); mqtt.setHost(broker); mqtt.setClientId(clientId); final Object credentials = credentials(); if (credentials == null) { // none } else if (credentials instanceof UserAndPassword) { final UserAndPassword userAndPassword = (UserAndPassword) credentials; mqtt.setUserName(userAndPassword.getUsername()); mqtt.setPassword(userAndPassword.getPasswordAsString()); } else { throw new IllegalStateException( String.format("Unknown credentials type: %s", credentials.getClass().getName())); } final CallbackConnection connection = mqtt.callbackConnection(); final FuseChannel result = new FuseChannel(clientId, namespace, codec, connection); return result; } }
@Override public FuseChannel build() throws Exception { final URI broker = Objects.requireNonNull(broker(), "Broker must be set"); final String clientId = Strings.nonEmptyText(clientId(), "clientId"); final MqttNamespace namespace = Objects.requireNonNull(namespace(), "Namespace must be set"); final BinaryPayloadCodec codec = Objects.requireNonNull(codec(), "Codec must be set"); final MQTT mqtt = new MQTT(); mqtt.setCleanSession(false); mqtt.setHost(broker); mqtt.setClientId(clientId); final Object credentials = credentials(); if (credentials == null) { // none } else if (credentials instanceof UserAndPassword) { final UserAndPassword userAndPassword = (UserAndPassword) credentials; mqtt.setUserName(userAndPassword.getUsername()); mqtt.setPassword(userAndPassword.getPasswordAsString()); } else { throw new IllegalStateException( String.format("Unknown credentials type: %s", credentials.getClass().getName())); } final CallbackConnection connection = mqtt.callbackConnection(); final FuseChannel result = new FuseChannel(clientId, namespace, codec, connection); return result; } }
mqtt.setUserName(component.getUsername());
@Test public void testConnectWithLargePassword() throws Exception { for (String version : Arrays.asList("3.1", "3.1.1")) { String longString = new String(new char[65535]); BlockingConnection connection = null; try { MQTT mqtt = createMQTTConnection("test-" + version, true); mqtt.setUserName(longString); mqtt.setPassword(longString); mqtt.setConnectAttemptsMax(1); mqtt.setVersion(version); connection = mqtt.blockingConnection(); connection.connect(); BlockingConnection finalConnection = connection; assertTrue("Should be connected", Wait.waitFor(() -> finalConnection.isConnected(), 5000, 100)); } finally { if (connection != null && connection.isConnected()) connection.disconnect(); } } }
@Test(timeout = 30000, expected = EOFException.class) public void testConnectionWithNullPassword() throws Exception { for (String version : Arrays.asList("3.1", "3.1.1")) { BlockingConnection connection = null; try { MQTT mqtt = createMQTTConnection("test-" + version, true); mqtt.setUserName(fullUser); mqtt.setPassword((String) null); mqtt.setConnectAttemptsMax(1); mqtt.setVersion(version); connection = mqtt.blockingConnection(); connection.connect(); fail("Connect should fail"); } finally { if (connection != null && connection.isConnected()) connection.disconnect(); } } } }
client.setUserName(mqttClientConfig.getUserName());
@Test(timeout = 30000) public void testConnection() throws Exception { for (String version : Arrays.asList("3.1", "3.1.1")) { BlockingConnection connection = null; try { MQTT mqtt = createMQTTConnection("test-" + version, true); mqtt.setUserName(fullUser); mqtt.setPassword(fullPass); mqtt.setConnectAttemptsMax(1); mqtt.setVersion(version); connection = mqtt.blockingConnection(); connection.connect(); BlockingConnection finalConnection = connection; assertTrue("Should be connected", Wait.waitFor(() -> finalConnection.isConnected(), 5000, 100)); } finally { if (connection != null && connection.isConnected()) connection.disconnect(); } } }
client.setUserName(mqttClientConfig.getUserName());
@Override public void setup(OperatorContext context) { try { client = new MQTT(); if (mqttClientConfig.getClientId() != null) { client.setClientId(mqttClientConfig.getClientId()); } client.setCleanSession(mqttClientConfig.isCleanSession()); client.setConnectAttemptsMax(mqttClientConfig.getConnectAttemptsMax()); client.setHost(mqttClientConfig.getHost(), mqttClientConfig.getPort()); client.setKeepAlive(mqttClientConfig.getKeepAliveInterval()); if (mqttClientConfig.getPassword() != null) { client.setPassword(mqttClientConfig.getPassword()); } if (mqttClientConfig.getUserName() != null) { client.setUserName(mqttClientConfig.getUserName()); } if (mqttClientConfig.getWillMessage() != null) { client.setWillMessage(mqttClientConfig.getWillMessage()); client.setWillQos(mqttClientConfig.getWillQos()); client.setWillRetain(mqttClientConfig.isWillRetain()); client.setWillTopic(mqttClientConfig.getWillTopic()); } connection = client.blockingConnection(); connection.connect(); } catch (Throwable t) { throw new RuntimeException(t); } }
Topic outputTopic = new Topic(TOPIC_OUTPUT, QoS.AT_LEAST_ONCE); MQTT mqtt = new MQTT(); mqtt.setUserName(USER_NAME); mqtt.setPassword(PASSWORD); subscribeConnection = mqtt.blockingConnection();