From edc4edf06a983fa9d8471cf3711a397bb600d7c6 Mon Sep 17 00:00:00 2001 From: Simon Bernard Date: Mon, 16 Oct 2023 11:11:17 +0200 Subject: [PATCH] Add CoAP endpoint based on java-coap to leshan-server-demo --- leshan-server-demo/pom.xml | 4 ++++ .../leshan/server/demo/LeshanServerDemo.java | 9 ++++++++- .../server/demo/cli/LeshanServerDemoCLI.java | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/leshan-server-demo/pom.xml b/leshan-server-demo/pom.xml index 41d9f321f1..84e9af5c94 100644 --- a/leshan-server-demo/pom.xml +++ b/leshan-server-demo/pom.xml @@ -49,6 +49,10 @@ Contributors: org.eclipse.leshan leshan-server-redis + + org.eclipse.leshan + leshan-tl-javacoap-server + org.eclipse.californium californium-core diff --git a/leshan-server-demo/src/main/java/org/eclipse/leshan/server/demo/LeshanServerDemo.java b/leshan-server-demo/src/main/java/org/eclipse/leshan/server/demo/LeshanServerDemo.java index e9f194df38..778f684f69 100644 --- a/leshan-server-demo/src/main/java/org/eclipse/leshan/server/demo/LeshanServerDemo.java +++ b/leshan-server-demo/src/main/java/org/eclipse/leshan/server/demo/LeshanServerDemo.java @@ -61,6 +61,7 @@ import org.eclipse.leshan.server.redis.RedisSecurityStore; import org.eclipse.leshan.server.security.EditableSecurityStore; import org.eclipse.leshan.server.security.FileSecurityStore; +import org.eclipse.leshan.transport.javacoap.server.endpoint.JavaCoapServerEndpointsProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -249,8 +250,14 @@ public static LeshanServer createLeshanServer(LeshanServerDemoCLI cli) throws Ex : new InetSocketAddress(cli.main.secureLocalAddress, coapsPort); endpointsBuilder.addEndpoint(coapsAddr, Protocol.COAPS); + // Create CoAP endpoint based on java-coap + int jcoapPort = cli.main.jlocalPort; + InetSocketAddress jcoapAddr = cli.main.secureLocalAddress == null ? new InetSocketAddress(jcoapPort) + : new InetSocketAddress(cli.main.jlocalAddress, jcoapPort); + JavaCoapServerEndpointsProvider javacoapEndpointsProvider = new JavaCoapServerEndpointsProvider(jcoapAddr); + // Create LWM2M server - builder.setEndpointsProviders(endpointsBuilder.build()); + builder.setEndpointsProviders(endpointsBuilder.build(), javacoapEndpointsProvider); return builder.build(); } diff --git a/leshan-server-demo/src/main/java/org/eclipse/leshan/server/demo/cli/LeshanServerDemoCLI.java b/leshan-server-demo/src/main/java/org/eclipse/leshan/server/demo/cli/LeshanServerDemoCLI.java index a770a0b4e0..eca3391330 100644 --- a/leshan-server-demo/src/main/java/org/eclipse/leshan/server/demo/cli/LeshanServerDemoCLI.java +++ b/leshan-server-demo/src/main/java/org/eclipse/leshan/server/demo/cli/LeshanServerDemoCLI.java @@ -19,6 +19,7 @@ import org.eclipse.leshan.core.demo.cli.StandardHelpOptions; import org.eclipse.leshan.core.demo.cli.VersionProvider; +import org.eclipse.leshan.core.demo.cli.converters.PortConverter; import org.eclipse.leshan.server.core.demo.cli.DtlsSection; import org.eclipse.leshan.server.core.demo.cli.GeneralSection; import org.eclipse.leshan.server.core.demo.cli.IdentitySection; @@ -55,6 +56,19 @@ public class LeshanServerDemoCLI implements Runnable { public ServerGeneralSection main = new ServerGeneralSection(); public static class ServerGeneralSection extends GeneralSection { + @Option(names = { "-jh", "--java-coap-host" }, + description = { // + "Set the local CoAP address of endpoint based on java-coap library.", // + "Default: any local address." }) + public String jlocalAddress; + + @Option(names = { "-jp", "--java-coap-port" }, + description = { // + "Set the local CoAP port of endpoint based on java-coap library.", // + "Default: ${DEFAULT-VALUE}" }, + converter = PortConverter.class) + public Integer jlocalPort = 5685; + @Option(names = { "-r", "--redis" }, description = { // "Use redis to store registration and securityInfo.", //