Repository: eclipse/leshan
Pull request #362 (2017-07-04 14:36:21)

Californium 2.0.0-M4 Integration


Patch:
diff --git a/leshan-client-cf/src/main/java/org/eclipse/leshan/client/californium/LeshanClient.java b/leshan-client-cf/src/main/java/org/eclipse/leshan/client/californium/LeshanClient.java
index e66116b5..96af5cc4 100644
--- a/leshan-client-cf/src/main/java/org/eclipse/leshan/client/californium/LeshanClient.java
+++ b/leshan-client-cf/src/main/java/org/eclipse/leshan/client/californium/LeshanClient.java
@@ -98,7 +98,7 @@ public class LeshanClient implements LwM2mClient {
             throw new IllegalArgumentException("Security object is mandatory");
         }
 
-        Builder builder = new DtlsConnectorConfig.Builder(localSecureAddress);
+        Builder builder = new DtlsConnectorConfig.Builder().setAddress(localSecureAddress);
         builder.setPskStore(new SecurityObjectPskStore(securityEnabler));
         builder.setMaxConnections(networkConfig.getInt(Keys.MAX_ACTIVE_PEERS));
         builder.setStaleConnectionThreshold(networkConfig.getLong(Keys.MAX_PEER_INACTIVITY_PERIOD));
diff --git a/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/CaliforniumLwM2mRequestSender.java b/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/CaliforniumLwM2mRequestSender.java
index aa8b65d3..0567d470 100644
--- a/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/CaliforniumLwM2mRequestSender.java
+++ b/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/CaliforniumLwM2mRequestSender.java
@@ -21,7 +21,7 @@ import java.util.SortedMap;
 import java.util.concurrent.ConcurrentNavigableMap;
 import java.util.concurrent.ConcurrentSkipListMap;
 
-import org.eclipse.californium.core.coap.MessageObserver;
+import org.eclipse.californium.core.coap.MessageObserverAdapter;
 import org.eclipse.californium.core.coap.Request;
 import org.eclipse.californium.core.coap.Response;
 import org.eclipse.californium.core.network.Endpoint;
@@ -176,7 +176,7 @@ public class CaliforniumLwM2mRequestSender implements LwM2mRequestSender {
         pendingRequests.remove(key, coapRequest);
     }
 
-    private class CleanerMessageObserver implements MessageObserver {
+    private class CleanerMessageObserver extends MessageObserverAdapter {
 
         private final String requestKey;
         private final Request coapRequest;
@@ -207,12 +207,7 @@ public class CaliforniumLwM2mRequestSender implements LwM2mRequestSender {
         }
 
         @Override
-        public void onReject() {
-            removePendingRequest(requestKey, coapRequest);
-        }
-
-        @Override
-        public void onTimeout() {
+        protected void failed() {
             removePendingRequest(requestKey, coapRequest);
         }
 
diff --git a/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/LeshanBootstrapServer.java b/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/LeshanBootstrapServer.java
index faed7373..96bdd0cd 100644
--- a/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/LeshanBootstrapServer.java
+++ b/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/LeshanBootstrapServer.java
@@ -77,7 +77,7 @@ public class LeshanBootstrapServer implements LwM2mBootstrapServer {
         coapServer.addEndpoint(nonSecureEndpoint);
 
         // init DTLS server
-        Builder builder = new DtlsConnectorConfig.Builder(localAddressSecure);
+        Builder builder = new DtlsConnectorConfig.Builder().setAddress(localAddressSecure);
         builder.setPskStore(new LwM2mBootstrapPskStore(this.bsSecurityStore));
         builder.setMaxConnections(networkConfig.getInt(Keys.MAX_ACTIVE_PEERS));
         builder.setStaleConnectionThreshold(networkConfig.getLong(Keys.MAX_PEER_INACTIVITY_PERIOD));
diff --git a/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/LeshanServer.java b/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/LeshanServer.java
index b2c99657..f18b50ac 100644
--- a/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/LeshanServer.java
+++ b/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/LeshanServer.java
@@ -185,7 +185,7 @@ public class LeshanServer implements LwM2mServer {
 
         // secure endpoint
         if (securityStore != null) {
-            Builder builder = new DtlsConnectorConfig.Builder(localSecureAddress);
+            Builder builder = new DtlsConnectorConfig.Builder().setAddress(localSecureAddress);
             builder.setPskStore(new LwM2mPskStore(this.securityStore, this.registrationService.getStore()));
 
             // synchronize network configuration and DTLS configuration
diff --git a/pom.xml b/pom.xml
index 77f119e9..aa0e5f4e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -105,7 +105,7 @@ Contributors:
 
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <californium.version>2.0.0-M3</californium.version>
+        <californium.version>2.0.0-M4</californium.version>
         <log4j.version>2.1</log4j.version>
         <slf4j.api.version>1.7.10</slf4j.api.version>
         <jetty.version>9.1.4.v20140401</jetty.version>


Test patch:
diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/SecureIntegrationTestHelper.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/SecureIntegrationTestHelper.java
index a4867ad5..6294c123 100644
--- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/SecureIntegrationTestHelper.java
+++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/SecureIntegrationTestHelper.java
@@ -196,7 +196,7 @@ public class SecureIntegrationTestHelper extends IntegrationTestHelper {
         objects.add(initializer.create(2));
 
         InetSocketAddress clientAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
-        DtlsConnectorConfig.Builder config = new DtlsConnectorConfig.Builder(clientAddress);
+        DtlsConnectorConfig.Builder config = new DtlsConnectorConfig.Builder().setAddress(clientAddress);
         // TODO we should read the config from the security object
         // TODO no way to provide a dynamic config with the current scandium API
         config.setIdentity(clientPrivateKey, clientPublicKey);
@@ -223,7 +223,7 @@ public class SecureIntegrationTestHelper extends IntegrationTestHelper {
         objects.add(initializer.create(2));
 
         InetSocketAddress clientAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
-        DtlsConnectorConfig.Builder config = new DtlsConnectorConfig.Builder(clientAddress);
+        DtlsConnectorConfig.Builder config = new DtlsConnectorConfig.Builder().setAddress(clientAddress);
         // TODO we should read the config from the security object
         config.setIdentity(privatekey, clientX509CertChain, false);
         config.setTrustStore(trustedCertificates);
diff --git a/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/CoapRequestBuilderTest.java b/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/CoapRequestBuilderTest.java
index a7183999..92fe362b 100644
--- a/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/CoapRequestBuilderTest.java
+++ b/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/CoapRequestBuilderTest.java
@@ -87,9 +87,8 @@ public class CoapRequestBuilderTest {
         Registration reg = newRegistration();
 
         // test
-        CoapRequestBuilder builder = new CoapRequestBuilder(
-                new InetSocketAddress(reg.getAddress(), reg.getPort()), reg.getRootPath(),
-                reg.getId(), reg.getEndpoint(), model, encoder);
+        CoapRequestBuilder builder = new CoapRequestBuilder(new InetSocketAddress(reg.getAddress(), reg.getPort()),
+                reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
         ReadRequest request = new ReadRequest(3, 0);
         builder.visit(request);
 
@@ -98,7 +97,7 @@ public class CoapRequestBuilderTest {
         assertEquals(CoAP.Code.GET, coapRequest.getCode());
         assertEquals("127.0.0.1", coapRequest.getDestination().getHostAddress());
         assertEquals(12354, coapRequest.getDestinationPort());
-        assertEquals("coap://localhost/3/0", coapRequest.getURI());
+        assertEquals("coap://127.0.0.1:12354/3/0", coapRequest.getURI());
     }
 
     @Test
@@ -106,15 +105,14 @@ public class CoapRequestBuilderTest {
         Registration reg = newRegistration("/lwm2m");
 
         // test
-        CoapRequestBuilder builder = new CoapRequestBuilder(
-                new InetSocketAddress(reg.getAddress(), reg.getPort()), reg.getRootPath(),
-                reg.getId(), reg.getEndpoint(), model, encoder);
+        CoapRequestBuilder builder = new CoapRequestBuilder(new InetSocketAddress(reg.getAddress(), reg.getPort()),
+                reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
         ReadRequest request = new ReadRequest(3, 0, 1);
         builder.visit(request);
 
         // verify
         Request coapRequest = builder.getRequest();
-        assertEquals("coap://localhost/lwm2m/3/0/1", coapRequest.getURI());
+        assertEquals("coap://127.0.0.1:12354/lwm2m/3/0/1", coapRequest.getURI());
     }
 
     @Test
@@ -122,15 +120,14 @@ public class CoapRequestBuilderTest {
         Registration reg = newRegistration("/");
 
         // test
-        CoapRequestBuilder builder = new CoapRequestBuilder(
-                new InetSocketAddress(reg.getAddress(), reg.getPort()), reg.getRootPath(),
-                reg.getId(), reg.getEndpoint(), model, encoder);
+        CoapRequestBuilder builder = new CoapRequestBuilder(new InetSocketAddress(reg.getAddress(), reg.getPort()),
+                reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
         ReadRequest request = new ReadRequest(3);
         builder.visit(request);
 
         // verify
         Request coapRequest = builder.getRequest();
-        assertEquals("coap://localhost/3", coapRequest.getURI());
+        assertEquals("coap://127.0.0.1:12354/3", coapRequest.getURI());
     }
 
     @Test
@@ -138,9 +135,8 @@ public class CoapRequestBuilderTest {
         Registration reg = newRegistration();
 
         // test
-        CoapRequestBuilder builder = new CoapRequestBuilder(
-                new InetSocketAddress(reg.getAddress(), reg.getPort()), reg.getRootPath(),
-                reg.getId(), reg.getEndpoint(), model, encoder);
+        CoapRequestBuilder builder = new CoapRequestBuilder(new InetSocketAddress(reg.getAddress(), reg.getPort()),
+                reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
         DiscoverRequest request = new DiscoverRequest(3, 0);
         builder.visit(request);
 
@@ -150,7 +146,7 @@ public class CoapRequestBuilderTest {
         assertEquals("127.0.0.1", coapRequest.getDestination().getHostAddress());
         assertEquals(12354, coapRequest.getDestinationPort());
         assertEquals(MediaTypeRegistry.APPLICATION_LINK_FORMAT, coapRequest.getOptions().getAccept());
-        assertEquals("coap://localhost/3/0", coapRequest.getURI());
+        assertEquals("coap://127.0.0.1:12354/3/0", coapRequest.getURI());
     }
 
     @Test
@@ -158,9 +154,8 @@ public class CoapRequestBuilderTest {
         Registration reg = newRegistration();
 
         // test
-        CoapRequestBuilder builder = new CoapRequestBuilder(
-                new InetSocketAddress(reg.getAddress(), reg.getPort()), reg.getRootPath(),
-                reg.getId(), reg.getEndpoint(), model, encoder);
+        CoapRequestBuilder builder = new CoapRequestBuilder(new InetSocketAddress(reg.getAddress(), reg.getPort()),
+                reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
         WriteRequest request = new WriteRequest(Mode.UPDATE, 3, 0, LwM2mSingleResource.newStringResource(4, "value"));
         builder.visit(request);
 
@@ -175,7 +170,7 @@ public class CoapRequestBuilderTest {
         Tlv[] tlvs = TlvDecoder.decode(ByteBuffer.wrap(coapRequest.getPayload()));
         assertEquals(TlvType.RESOURCE_VALUE, tlvs[0].getType());
         assertEquals("value", TlvDecoder.decodeString(tlvs[0].getValue()));
-        assertEquals("coap://localhost/3/0", coapRequest.getURI());
+        assertEquals("coap://127.0.0.1:12354/3/0", coapRequest.getURI());
     }
 
     @Test
@@ -183,9 +178,8 @@ public class CoapRequestBuilderTest {
         Registration reg = newRegistration();
 
         // test
-        CoapRequestBuilder builder = new CoapRequestBuilder(
-                new InetSocketAddress(reg.getAddress(), reg.getPort()), reg.getRootPath(),
-                reg.getId(), reg.getEndpoint(), model, encoder);
+        CoapRequestBuilder builder = new CoapRequestBuilder(new InetSocketAddress(reg.getAddress(), reg.getPort()),
+                reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
         WriteRequest request = new WriteRequest(3, 0, 14, "value");
         builder.visit(request);
 
@@ -199,9 +193,8 @@ public class CoapRequestBuilderTest {
         Registration reg = newRegistration();
 
         // test
-        CoapRequestBuilder builder = new CoapRequestBuilder(
-                new InetSocketAddress(reg.getAddress(), reg.getPort()), reg.getRootPath(),
-                reg.getId(), reg.getEndpoint(), model, encoder);
+        CoapRequestBuilder builder = new CoapRequestBuilder(new InetSocketAddress(reg.getAddress(), reg.getPort()),
+                reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
         WriteAttributesRequest request = new WriteAttributesRequest(3, 0, 14,
                 new ObserveSpec.Builder().minPeriod(10).maxPeriod(100).build());
         builder.visit(request);
@@ -211,7 +204,7 @@ public class CoapRequestBuilderTest {
         assertEquals(CoAP.Code.PUT, coapRequest.getCode());
         assertEquals("127.0.0.1", coapRequest.getDestination().getHostAddress());
         assertEquals(12354, coapRequest.getDestinationPort());
-        assertEquals("coap://localhost/3/0/14?pmin=10&pmax=100", coapRequest.getURI());
+        assertEquals("coap://127.0.0.1:12354/3/0/14?pmin=10&pmax=100", coapRequest.getURI());
     }
 
     @Test
@@ -219,9 +212,8 @@ public class CoapRequestBuilderTest {
         Registration reg = newRegistration();
 
         // test
-        CoapRequestBuilder builder = new CoapRequestBuilder(
-                new InetSocketAddress(reg.getAddress(), reg.getPort()), reg.getRootPath(),
-                reg.getId(), reg.getEndpoint(), model, encoder);
+        CoapRequestBuilder builder = new CoapRequestBuilder(new InetSocketAddress(reg.getAddress(), reg.getPort()),
+                reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
         ExecuteRequest request = new ExecuteRequest(3, 0, 12, "params");
         builder.visit(request);
 
@@ -230,7 +222,7 @@ public class CoapRequestBuilderTest {
         assertEquals(CoAP.Code.POST, coapRequest.getCode());
         assertEquals("127.0.0.1", coapRequest.getDestination().getHostAddress());
         assertEquals(12354, coapRequest.getDestinationPort());
-        assertEquals("coap://localhost/3/0/12", coapRequest.getURI());
+        assertEquals("coap://127.0.0.1:12354/3/0/12", coapRequest.getURI());
         assertEquals("params", coapRequest.getPayloadString());
     }
 
@@ -239,9 +231,8 @@ public class CoapRequestBuilderTest {
         Registration reg = newRegistration();
 
         // test
-        CoapRequestBuilder builder = new CoapRequestBuilder(
-                new InetSocketAddress(reg.getAddress(), reg.getPort()), reg.getRootPath(),
-                reg.getId(), reg.getEndpoint(), model, encoder);
+        CoapRequestBuilder builder = new CoapRequestBuilder(new InetSocketAddress(reg.getAddress(), reg.getPort()),
+                reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
         CreateRequest request = new CreateRequest(12, LwM2mSingleResource.newStringResource(0, "value"));
         builder.visit(request);
 
@@ -250,7 +241,7 @@ public class CoapRequestBuilderTest {
         assertEquals(CoAP.Code.POST, coapRequest.getCode());
         assertEquals("127.0.0.1", coapRequest.getDestination().getHostAddress());
         assertEquals(12354, coapRequest.getDestinationPort());
-        assertEquals("coap://localhost/12", coapRequest.getURI());
+        assertEquals("coap://127.0.0.1:12354/12", coapRequest.getURI());
         assertEquals(ContentFormat.TLV.getCode(), coapRequest.getOptions().getContentFormat());
         assertNotNull(coapRequest.getPayload());
         // assert it is encoded as array of resources TLV
@@ -263,9 +254,8 @@ public class CoapRequestBuilderTest {
         Registration reg = newRegistration();
 
         // test
-        CoapRequestBuilder builder = new CoapRequestBuilder(
-                new InetSocketAddress(reg.getAddress(), reg.getPort()), reg.getRootPath(),
-                reg.getId(), reg.getEndpoint(), model, encoder);
+        CoapRequestBuilder builder = new CoapRequestBuilder(new InetSocketAddress(reg.getAddress(), reg.getPort()),
+                reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
         CreateRequest request = new CreateRequest(12,
                 new LwM2mObjectInstance(26, LwM2mSingleResource.newStringResource(0, "value")));
         builder.visit(request);
@@ -275,7 +265,7 @@ public class CoapRequestBuilderTest {
         assertEquals(CoAP.Code.POST, coapRequest.getCode());
         assertEquals("127.0.0.1", coapRequest.getDestination().getHostAddress());
         assertEquals(12354, coapRequest.getDestinationPort());
-        assertEquals("coap://localhost/12", coapRequest.getURI());
+        assertEquals("coap://127.0.0.1:12354/12", coapRequest.getURI());
         assertEquals(ContentFormat.TLV.getCode(), coapRequest.getOptions().getContentFormat());
         assertNotNull(coapRequest.getPayload());
         // assert it is encoded as array of instance TLV
@@ -289,9 +279,8 @@ public class CoapRequestBuilderTest {
         Registration reg = newRegistration();
 
         // test
-        CoapRequestBuilder builder = new CoapRequestBuilder(
-                new InetSocketAddress(reg.getAddress(), reg.getPort()), reg.getRootPath(),
-                reg.getId(), reg.getEndpoint(), model, encoder);
+        CoapRequestBuilder builder = new CoapRequestBuilder(new InetSocketAddress(reg.getAddress(), reg.getPort()),
+                reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
         DeleteRequest request = new DeleteRequest(12, 0);
         builder.visit(request);
 
@@ -300,7 +289,7 @@ public class CoapRequestBuilderTest {
         assertEquals(CoAP.Code.DELETE, coapRequest.getCode());
         assertEquals("127.0.0.1", coapRequest.getDestination().getHostAddress());
         assertEquals(12354, coapRequest.getDestinationPort());
-        assertEquals("coap://localhost/12/0", coapRequest.getURI());
+        assertEquals("coap://127.0.0.1:12354/12/0", coapRequest.getURI());
     }
 
     @Test
@@ -308,9 +297,8 @@ public class CoapRequestBuilderTest {
         Registration reg = newRegistration();
 
         // test
-        CoapRequestBuilder builder = new CoapRequestBuilder(
-                new InetSocketAddress(reg.getAddress(), reg.getPort()), reg.getRootPath(),
-                reg.getId(), reg.getEndpoint(), model, encoder);
+        CoapRequestBuilder builder = new CoapRequestBuilder(new InetSocketAddress(reg.getAddress(), reg.getPort()),
+                reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
         ObserveRequest request = new ObserveRequest(12, 0);
         builder.visit(request);
 
@@ -320,6 +308,6 @@ public class CoapRequestBuilderTest {
         assertEquals(0, coapRequest.getOptions().getObserve().intValue());
         assertEquals("127.0.0.1", coapRequest.getDestination().getHostAddress());
         assertEquals(12354, coapRequest.getDestinationPort());
-        assertEquals("coap://localhost/12/0", coapRequest.getURI());
+        assertEquals("coap://127.0.0.1:12354/12/0", coapRequest.getURI());
     }
 }