refactored CoAP Server component (#4497)
* refactored ce code base needed for coap-integration in pe * added anotation TbCoapServerComponent on CoapTransportService * license updated
This commit is contained in:
parent
e3292e89c1
commit
b34198f30c
@ -621,9 +621,9 @@ transport:
|
||||
key_password: "${COAP_DTLS_KEY_PASSWORD:server_key_password}"
|
||||
# Key alias
|
||||
key_alias: "${COAP_DTLS_KEY_ALIAS:serveralias}"
|
||||
# Skip certificate validity check for client certificates.
|
||||
skip_validity_check_for_client_cert: "${COAP_DTLS_SKIP_VALIDITY_CHECK_FOR_CLIENT_CERT:false}"
|
||||
x509:
|
||||
# Skip certificate validity check for client certificates.
|
||||
skip_validity_check_for_client_cert: "${TB_COAP_X509_DTLS_SKIP_VALIDITY_CHECK_FOR_CLIENT_CERT:false}"
|
||||
dtls_session_inactivity_timeout: "${TB_COAP_X509_DTLS_SESSION_INACTIVITY_TIMEOUT:86400000}"
|
||||
dtls_session_report_timeout: "${TB_COAP_X509_DTLS_SESSION_REPORT_TIMEOUT:1800000}"
|
||||
# Local LwM2M transport parameters
|
||||
|
||||
@ -19,11 +19,10 @@ import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Slf4j
|
||||
@ConditionalOnExpression("'${service.type:null}'=='tb-transport' || ('${service.type:null}'=='monolith' && '${transport.api_enabled:true}'=='true' && '${transport.coap.enabled}'=='true')")
|
||||
@TbCoapServerComponent
|
||||
@Component
|
||||
public class CoapServerContext {
|
||||
|
||||
|
||||
@ -23,7 +23,6 @@ import org.eclipse.californium.core.server.resources.Resource;
|
||||
import org.eclipse.californium.scandium.DTLSConnector;
|
||||
import org.eclipse.californium.scandium.config.DtlsConnectorConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
@ -39,7 +38,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@ConditionalOnExpression("'${service.type:null}'=='tb-transport' || ('${service.type:null}'=='monolith' && '${transport.api_enabled:true}'=='true' && '${transport.coap.enabled}'=='true')")
|
||||
@TbCoapServerComponent
|
||||
public class DefaultCoapServerService implements CoapServerService {
|
||||
|
||||
@Autowired
|
||||
|
||||
@ -39,7 +39,6 @@ import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
|
||||
@Slf4j
|
||||
@ConditionalOnExpression("'${transport.coap.enabled}'=='true'")
|
||||
@ConditionalOnProperty(prefix = "transport.coap.dtls", value = "enabled", havingValue = "true", matchIfMissing = false)
|
||||
@Component
|
||||
public class TbCoapDtlsSettings {
|
||||
@ -50,7 +49,7 @@ public class TbCoapDtlsSettings {
|
||||
@Value("${transport.coap.dtls.bind_port}")
|
||||
private Integer port;
|
||||
|
||||
@Value("${transport.coap.dtls.mode}")
|
||||
@Value("${transport.coap.dtls.mode:NO_AUTH}")
|
||||
private String mode;
|
||||
|
||||
@Value("${transport.coap.dtls.key_store}")
|
||||
@ -65,13 +64,13 @@ public class TbCoapDtlsSettings {
|
||||
@Value("${transport.coap.dtls.key_alias}")
|
||||
private String keyAlias;
|
||||
|
||||
@Value("${transport.coap.dtls.skip_validity_check_for_client_cert}")
|
||||
@Value("${transport.coap.dtls.x509.skip_validity_check_for_client_cert:false}")
|
||||
private boolean skipValidityCheckForClientCert;
|
||||
|
||||
@Value("${transport.coap.dtls.x509.dtls_session_inactivity_timeout}")
|
||||
@Value("${transport.coap.dtls.x509.dtls_session_inactivity_timeout:86400000}")
|
||||
private long dtlsSessionInactivityTimeout;
|
||||
|
||||
@Value("${transport.coap.dtls.x509.dtls_session_report_timeout}")
|
||||
@Value("${transport.coap.dtls.x509.dtls_session_report_timeout:1800000}")
|
||||
private long dtlsSessionReportTimeout;
|
||||
|
||||
@Autowired
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright © 2016-2021 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.coapserver;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ConditionalOnExpression("'${service.type:null}'=='tb-transport' || ('${service.type:null}'=='monolith' && '${transport.api_enabled:true}'=='true' && '${transport.coap.enabled}'=='true')")
|
||||
public @interface TbCoapServerComponent {
|
||||
}
|
||||
@ -23,6 +23,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thingsboard.server.common.data.TbTransportService;
|
||||
import org.thingsboard.server.coapserver.CoapServerService;
|
||||
import org.thingsboard.server.coapserver.TbCoapServerComponent;
|
||||
import org.thingsboard.server.transport.coap.efento.CoapEfentoTransportResource;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
@ -30,7 +31,7 @@ import javax.annotation.PreDestroy;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
@Service("CoapTransportService")
|
||||
@ConditionalOnExpression("'${service.type:null}'=='tb-transport' || ('${service.type:null}'=='monolith' && '${transport.api_enabled:true}'=='true' && '${transport.coap.enabled}'=='true')")
|
||||
@TbCoapServerComponent
|
||||
@Slf4j
|
||||
public class CoapTransportService implements TbTransportService {
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Created by Valerii Sosliuk on 5/12/2017.
|
||||
@ -66,6 +67,15 @@ public class JacksonUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static JsonNode fromBytes(byte[] bytes) {
|
||||
try {
|
||||
return OBJECT_MAPPER.readTree(bytes);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException("The given byte[] value: "
|
||||
+ Arrays.toString(bytes) + " cannot be transformed to Json object", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String toString(Object value) {
|
||||
try {
|
||||
return value != null ? OBJECT_MAPPER.writeValueAsString(value) : null;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user