/** * @return The Debug Properties */ public Properties getDebug() { final String strNull="null"; Properties p = new Properties(); p.put("MqttVersion", new Integer(getMqttVersion())); p.put("CleanSession", Boolean.valueOf(isCleanSession())); p.put("ConTimeout", new Integer(getConnectionTimeout())); p.put("KeepAliveInterval", new Integer(getKeepAliveInterval())); p.put("UserName", (getUserName() == null) ? strNull : getUserName()); p.put("WillDestination", (getWillDestination() == null) ? strNull : getWillDestination()); if (getSocketFactory()==null) { p.put("SocketFactory", strNull); } else { p.put("SocketFactory", getSocketFactory()); } if (getSSLProperties()==null) { p.put("SSLProperties", strNull); } else { p.put("SSLProperties", getSSLProperties()); } return p; }
private ContentValues getValues(Connection connection){ MqttConnectOptions conOpts = connection.getConnectionOptions(); MqttMessage lastWill = conOpts.getWillMessage(); ContentValues values = new ContentValues(); //put the column values object values.put(COLUMN_CLIENT_HANDLE, connection.handle()); values.put(COLUMN_HOST, connection.getHostName()); values.put(COLUMN_port, connection.getPort()); values.put(COLUMN_client_ID, connection.getId()); values.put(COLUMN_ssl, connection.isSSL()); values.put(COLUMN_KEEP_ALIVE, conOpts.getKeepAliveInterval()); values.put(COLUMN_TIME_OUT, conOpts.getConnectionTimeout()); values.put(COLUMN_USER_NAME, conOpts.getUserName()); values.put(COLUMN_TOPIC, conOpts.getWillDestination()); //uses "condition ? trueValue: falseValue" for in line converting of values char[] password = conOpts.getPassword(); values.put(COLUMN_CLEAN_SESSION, conOpts.isCleanSession() ? 1 : 0); //convert boolean to int and then put in values values.put(COLUMN_PASSWORD, password != null ? String.valueOf(password) : null); //convert char[] to String values.put(COLUMN_MESSAGE, lastWill != null ? new String(lastWill.getPayload()) : null); // convert byte[] to string values.put(COLUMN_QOS, lastWill != null ? lastWill.getQos() : 0); if (lastWill == null) { values.put(COLUMN_RETAINED, 0); } else { values.put(COLUMN_RETAINED, lastWill.isRetained() ? 1 : 0); //convert from boolean to int } return values; }
if (connectOptions != null && connectOptions.isCleanSession()) {
if (connectOptions != null && connectOptions.isCleanSession()) {
private synchronized void connectAndSubscribe() throws MqttException { MqttConnectOptions connectionOptions = this.clientFactory.getConnectionOptions(); this.cleanSession = connectionOptions.isCleanSession(); this.consumerStopAction = this.clientFactory.getConsumerStopAction(); if (this.consumerStopAction == null) {
/** * Get the clean session setting. * @return the value */ public boolean isCleanSession() { return options.isCleanSession(); }
cleanSession = options.isCleanSession(); if (connectOptions.isCleanSession()) { // if it's a clean session,
/** * Start the connect processing * @throws MqttPersistenceException if an error is thrown whilst setting up persistence */ public void connect() throws MqttPersistenceException { MqttToken token = new MqttToken(client.getClientId()); token.setActionCallback(this); token.setUserContext(this); persistence.open(client.getClientId(), client.getServerURI()); if (options.isCleanSession()) { persistence.clear(); } if (options.getMqttVersion() == MqttConnectOptions.MQTT_VERSION_DEFAULT) { options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1_1); } try { comms.connect(options, token); } catch (MqttException e) { onFailure(token, e); } }
@Test public void testConnectWebSocket() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); TestClientStatusCallback csb = new TestClientStatusCallback(); testClient.connect(new TestAwsCredentialsProvider(), csb); Thread.sleep(500); // connect is async, will return before callback is actually set in connect() mockClient.mockConnectSuccess(); assertEquals(1, mockClient.connectCalls); assertTrue(mockClient.mostRecentOptions.isCleanSession()); assertEquals(300, mockClient.mostRecentOptions.getKeepAliveInterval()); assertEquals(2, csb.statuses.size()); assertEquals(AWSIotMqttClientStatusCallback.AWSIotMqttClientStatus.Connecting, csb.statuses.get(0)); assertEquals(AWSIotMqttClientStatusCallback.AWSIotMqttClientStatus.Connected, csb.statuses.get(1)); assertEquals(MqttManagerConnectionState.Connected, testClient.getConnectionState()); }
conOptions.isCleanSession(), conOptions.getKeepAliveInterval(), conOptions.getUserName(), this.clientState.setCleanSession(conOptions.isCleanSession()); this.clientState.setMaxInflight(conOptions.getMaxInflight());
new Object[] { Boolean.valueOf(options.isCleanSession()), new Integer(options.getConnectionTimeout()), new Integer(options.getKeepAliveInterval()), options.getUserName(), ((null == options.getPassword()) ? "[null]" : "[notnull]"),
@Test public void testConnect() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); TestClientStatusCallback csb = new TestClientStatusCallback(); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); mockClient.mockConnectSuccess(); assertEquals(1, mockClient.connectCalls); assertTrue(mockClient.mostRecentOptions.isCleanSession()); assertEquals(300, mockClient.mostRecentOptions.getKeepAliveInterval()); assertEquals(2, csb.statuses.size()); assertEquals(AWSIotMqttClientStatusCallback.AWSIotMqttClientStatus.Connecting, csb.statuses.get(0)); assertEquals(AWSIotMqttClientStatusCallback.AWSIotMqttClientStatus.Connected, csb.statuses.get(1)); assertEquals(MqttManagerConnectionState.Connected, testClient.getConnectionState()); }
serverHostName = connection.getHostName(); serverPort = connection.getPort(); cleanSession = connection.getConnectionOptions().isCleanSession();
@Test public void testLostConnectUserDisconnect() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); TestClientStatusCallback csb = new TestClientStatusCallback(); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); mockClient.mockConnectSuccess(); assertEquals(1, mockClient.connectCalls); assertTrue(mockClient.mostRecentOptions.isCleanSession()); testClient.disconnect(); mockClient.mockCallback.connectionLost(new Exception("test")); assertEquals(1, mockClient.connectCalls); } /*
@Test public void testSetKeepAlive() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); testClient.setKeepAlive(20); TestClientStatusCallback csb = new TestClientStatusCallback(); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); mockClient.mockConnectSuccess(); assertEquals(1, mockClient.connectCalls); assertTrue(mockClient.mostRecentOptions.isCleanSession()); assertEquals(20, mockClient.mostRecentOptions.getKeepAliveInterval()); }
@Test public void testSetKeepAliveZero() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); testClient.setKeepAlive(0); TestClientStatusCallback csb = new TestClientStatusCallback(); KeyStore testKeystore = AWSIotKeystoreHelper.getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); mockClient.mockConnectSuccess(); assertEquals(1, mockClient.connectCalls); assertTrue(mockClient.mostRecentOptions.isCleanSession()); assertEquals(0, mockClient.mostRecentOptions.getKeepAliveInterval()); }
@Test public void testConnectWithLwt() throws Exception { MockMqttClient mockClient = new MockMqttClient(); AWSIotMqttManager testClient = new AWSIotMqttManager("test-client", Region.getRegion(Regions.US_EAST_1), TEST_ENDPOINT_PREFIX); testClient.setMqttClient(mockClient); AWSIotMqttLastWillAndTestament lwt = new AWSIotMqttLastWillAndTestament("test/lwt", "bye", AWSIotMqttQos.QOS0); testClient.setMqttLastWillAndTestament(lwt); TestClientStatusCallback csb = new TestClientStatusCallback(); KeyStore testKeystore = AWSIotKeystoreHelper .getIotKeystore(CERT_ID, KEYSTORE_PATH, KEYSTORE_NAME, KEYSTORE_PASSWORD); testClient.connect(testKeystore, csb); mockClient.mockConnectSuccess(); assertEquals(1, mockClient.connectCalls); assertTrue(mockClient.mostRecentOptions.isCleanSession()); assertEquals(300, mockClient.mostRecentOptions.getKeepAliveInterval()); assertEquals("test/lwt", mockClient.mostRecentOptions.getWillDestination()); assertEquals("bye", new String(mockClient.mostRecentOptions.getWillMessage().getPayload())); assertEquals(AWSIotMqttQos.QOS0.asInt(), mockClient.mostRecentOptions.getWillMessage().getQos()); assertFalse(mockClient.mostRecentOptions.getWillMessage().isRetained()); assertEquals(2, csb.statuses.size()); assertEquals(AWSIotMqttClientStatusCallback.AWSIotMqttClientStatus.Connecting, csb.statuses.get(0)); assertEquals(AWSIotMqttClientStatusCallback.AWSIotMqttClientStatus.Connected, csb.statuses.get(1)); assertEquals(MqttManagerConnectionState.Connected, testClient.getConnectionState()); }
public Properties getDebug() { Properties p = new Properties(); p.put("CleanSession", new Boolean(isCleanSession())); p.put("ConTimeout", new Integer(getConnectionTimeout())); p.put("KeepAliveInterval", new Integer(getKeepAliveInterval())); p.put("UserName", (getUserName()==null)?"null":getUserName()); p.put("WillDestination", (getWillDestination()==null)?"null":getWillDestination()); if (getSocketFactory()==null) { p.put("SocketFactory", "null"); } else { p.put("SocketFactory", getSocketFactory()); } if (getSSLProperties()==null) { p.put("SSLProperties", "null"); } else { p.put("SSLProperties", getSSLProperties()); } return p; }
assertTrue(mockClient.mostRecentOptions.isCleanSession()); assertEquals(15, mockClient.mostRecentOptions.getKeepAliveInterval()); assertEquals("test/lwt", mockClient.mostRecentOptions.getWillDestination());
/** * The connect failed, so try the next URI on the list. * If there are no more URIs, then fail the overall connect. * @throws MqttPersistenceException */ public void connect() throws MqttPersistenceException { MqttToken token = new MqttToken(client.getClientId()); token.setActionCallback(this); token.setUserContext(this); persistence.open(client.getClientId(), client.getServerURI()); if (options.isCleanSession()) { persistence.clear(); } try { comms.connect(options, token); } catch (MqttException e) { onFailure(token, e); } }