Browse Source

Merge 2c3425bf9a into be70822bc6

pull/15319/merge
Oleksandra Matviienko 3 days ago
committed by GitHub
parent
commit
cf557015a9
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java
  2. 2
      common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/util/sparkplug/MetricDataType.java
  3. 43
      common/transport/mqtt/src/test/java/org/thingsboard/server/transport/mqtt/util/sparkplug/MetricDataTypeTest.java

3
common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java

@ -1127,7 +1127,8 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
return (X509Certificate) certChain[0];
}
} catch (SSLPeerUnverifiedException e) {
log.warn(e.getMessage());
// Expected when client connects without a valid certificate — no stack trace needed
log.warn("SSL peer unverified: {}", e.getMessage());
return null;
}
return null;

2
common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/util/sparkplug/MetricDataType.java

@ -96,7 +96,7 @@ public enum MetricDataType {
*/
public void checkType(Object value) throws AdaptorException {
if (value != null && !clazz.isAssignableFrom(value.getClass())) {
String msgError = "Failed type check - " + clazz + " != " + ((value != null) ? value.getClass().toString() : "null");
String msgError = "Failed type check - " + clazz + " != " + value.getClass().toString();
log.debug(msgError);
throw new AdaptorException(msgError);
}

43
common/transport/mqtt/src/test/java/org/thingsboard/server/transport/mqtt/util/sparkplug/MetricDataTypeTest.java

@ -0,0 +1,43 @@
/**
* Copyright © 2016-2026 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.transport.mqtt.util.sparkplug;
import org.junit.jupiter.api.Test;
import org.thingsboard.server.common.adaptor.AdaptorException;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
class MetricDataTypeTest {
@Test
void checkType_noExceptionWhenValueMatchesExpectedType() {
assertThatNoException().isThrownBy(() -> MetricDataType.String.checkType("hello"));
}
@Test
void checkType_noExceptionWhenValueIsNull() {
assertThatNoException().isThrownBy(() -> MetricDataType.String.checkType(null));
}
@Test
void checkType_throwsAdaptorExceptionWithActualClassNameWhenTypeMismatch() {
assertThatThrownBy(() -> MetricDataType.String.checkType(42))
.isInstanceOf(AdaptorException.class)
.hasMessageContaining(Integer.class.toString());
}
}
Loading…
Cancel
Save