Skip to content

Commit

Permalink
Fix NPE concerning connection events of unauthenticated devices.
Browse files Browse the repository at this point in the history
Signed-off-by: Carsten Lohmann <[email protected]>
  • Loading branch information
calohmn committed Feb 4, 2022
1 parent 36c04a3 commit 01506fa
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2021 Contributors to the Eclipse Foundation
* Copyright (c) 2016, 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -936,8 +936,10 @@ public void registerLivenessChecks(final HealthCheckHandler handler) {
*/
protected Future<Void> sendConnectedEvent(final String remoteId, final Device authenticatedDevice, final SpanContext context) {
if (this.connectionEventProducer != null) {
return getTenantClient().get(authenticatedDevice.getTenantId(), context)
.map(this::getEventSender)
return Optional.ofNullable(authenticatedDevice)
.map(device -> getTenantClient().get(device.getTenantId(), context)
.map(this::getEventSender))
.orElseGet(() -> Future.succeededFuture(null))
.compose(es -> this.connectionEventProducer.connected(
new ConnectionEventProducer.Context() {
@Override
Expand Down Expand Up @@ -972,8 +974,10 @@ public TenantClient getTenantClient() {
*/
protected Future<Void> sendDisconnectedEvent(final String remoteId, final Device authenticatedDevice, final SpanContext context) {
if (this.connectionEventProducer != null) {
return getTenantClient().get(authenticatedDevice.getTenantId(), context)
.map(this::getEventSender)
return Optional.ofNullable(authenticatedDevice)
.map(device -> getTenantClient().get(device.getTenantId(), context)
.map(this::getEventSender))
.orElseGet(() -> Future.succeededFuture(null))
.compose(es -> this.connectionEventProducer.disconnected(
new ConnectionEventProducer.Context() {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2021 Contributors to the Eclipse Foundation
* Copyright (c) 2016, 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.hono.adapter.monitoring;

import java.util.Optional;

import org.eclipse.hono.auth.Device;
import org.eclipse.hono.util.EventConstants;
import org.eclipse.hono.util.RegistrationAssertion;
Expand Down Expand Up @@ -84,13 +86,15 @@ private Future<Void> sendNotificationEvent(
payload.put("data", data);
}

return context.getMessageSenderClient().sendEvent(
tenant,
new RegistrationAssertion(deviceId),
EventConstants.EVENT_CONNECTION_NOTIFICATION_CONTENT_TYPE,
payload.toBuffer(),
null,
spanContext);
return Optional.ofNullable(context.getMessageSenderClient())
.map(client -> client.sendEvent(
tenant,
new RegistrationAssertion(deviceId),
EventConstants.EVENT_CONNECTION_NOTIFICATION_CONTENT_TYPE,
payload.toBuffer(),
null,
spanContext))
.orElseGet(Future::succeededFuture);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2021 Contributors to the Eclipse Foundation
* Copyright (c) 2016, 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -49,9 +49,13 @@ interface Context {

/**
* Gets the client for sending connection events downstream.
* <p>
* If no client is available in this context, {@code null} is returned.
* <p>
* A returned client here is required to be initialized and started.
*
* @return The instance of the message sender client which the {@link ConnectionEventProducer} should
* use. This client has to be initialized and started.
* use or {@code null} if no client is available.
*/
EventSender getMessageSenderClient();
/**
Expand Down
1 change: 1 addition & 0 deletions site/homepage/content/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ description = "Information about changes in recent Hono releases. Includes new f
password hashes were created in lowercase instead of uppercase. This has been fixed.
* The native executable of the Command Router component did not start when configured with an embedded cache.
This has been fixed.
* There was an issue trying to send connection events concerning unauthenticated MQTT/AMQP devices. This has been fixed.

## 1.11.1

Expand Down

0 comments on commit 01506fa

Please sign in to comment.