diff options
author | benalaya | 2017-09-12 12:31:18 +0000 |
---|---|---|
committer | benalaya | 2017-09-12 12:31:18 +0000 |
commit | 234fdca274cc4ef08402a7943f67bb95516cdb7b (patch) | |
tree | 0db58a0ab8b1a8b55b5f8a070ee3be6c9996ba95 | |
parent | 801b47e3c3b4f6325552c1d0c06a1545f50822ff (diff) | |
parent | 9a3283bdaa8f8abf9576d29230e5bd641fd79543 (diff) | |
download | org.eclipse.om2m-feature0.tar.gz org.eclipse.om2m-feature0.tar.xz org.eclipse.om2m-feature0.zip |
Merge branch 'dev' into feature0feature0
Conflicts:
org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/notifier/Notifier.java
org.eclipse.om2m.site.in-cse/om2m.product
org.eclipse.om2m.testsuite.flexcontainer/src/main/java/org/eclipse/om2m/testsuite/flexcontainer/AccessControlPolicyTest.java
56 files changed, 3629 insertions, 962 deletions
diff --git a/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/ACP.java b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/ACP.java new file mode 100644 index 00000000..367b959d --- /dev/null +++ b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/ACP.java @@ -0,0 +1,167 @@ +package org.eclipse.om2m.adn.tests; + +import static org.junit.Assert.*; + +import org.eclipse.om2m.adn.tools.HttpResponse; +import org.eclipse.om2m.adn.tools.RestHttpClient; +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class ACP extends TestConfig{ + private static String acpTestRU = "acpTestRU"; + private static String acpTestD = "aeTestD"; + private static String acpTestC = "acpTestC"; + private static String aeName = "aeTestRU"; + private static String cntName = "cntTest"; + private static String badOriginator = "guest:guest"; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + JSONObject obj = new JSONObject(); + obj.put("rn", aeName); + obj.put("api", 12345); + obj.put("rr", false); + JSONObject resource = new JSONObject(); + resource.put("m2m:ae", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 2); + + JSONArray acor = new JSONArray(); + acor.put("admin:admin"); + //acor.put("cae-admin"); + JSONObject item = new JSONObject(); + item.put("acor", acor); + item.put("acop", 63); + JSONArray acr1 = new JSONArray(); + acr1.put(item); + + acor = new JSONArray(); + acor.put("guest:guest"); + acor.put("admin:admin"); + //acor.put("cae-admin"); + item = new JSONObject(); + item.put("acor", acor); + item.put("acop", 34); + JSONArray acr2 = new JSONArray(); + acr2.put(item); + + JSONObject pv = new JSONObject(); + pv.put("acr",acr1); + pv.put("acr",acr2); + JSONObject pvs = new JSONObject(); + pvs.put("acr", acr1); + obj = new JSONObject(); + obj.put("rn", acpTestRU); + obj.put("pv", pv); + obj.put("pvs", pvs); + resource = new JSONObject(); + resource.put("m2m:acp", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName, resource.toString(), 1); + + obj = new JSONObject(); + obj.put("rn", acpTestD); + obj.put("pv", pv); + obj.put("pvs", pvs); + resource = new JSONObject(); + resource.put("m2m:acp", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName, resource.toString(), 1); + + JSONArray acpi = new JSONArray(); + acpi.put("/"+cseId+"/"+cseName+"/"+aeName+"/"+acpTestRU); + obj = new JSONObject(); + obj.put("acpi",acpi); + obj.put("rn", cntName); + resource = new JSONObject(); + resource.put("m2m:cnt", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName, resource.toString(), 3); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName); + } + + @Test + public void testCreate() { + JSONArray acor = new JSONArray(); + acor.put("admin:admin"); + //acor.put("cae-admin"); + + JSONObject item = new JSONObject(); + item.put("acor", acor); + item.put("acop", 63); + + JSONArray acr = new JSONArray(); + acr.put(item); + + JSONObject pv = new JSONObject(); + pv.put("acr",acr); + + JSONObject pvs = new JSONObject(); + pvs.put("acr", acr); + + JSONObject obj = new JSONObject(); + obj.put("rn", acpTestC); + obj.put("pv", pv); + obj.put("pvs", pv); + + JSONObject resource = new JSONObject(); + resource.put("m2m:acp", obj); + + HttpResponse httpResponse = RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName, resource.toString(), 1); + assertEquals(201, httpResponse.getStatusCode()); + } + + @Test + public void testRetreive() { + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+acpTestRU); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testUpdate() { + JSONArray acor = new JSONArray(); + //acor.put("cae-admin"); + acor.put("*"); + + JSONObject item = new JSONObject(); + item.put("acor", acor); + item.put("acop", 63); + + JSONArray acr = new JSONArray(); + acr.put(item); + + JSONObject pv = new JSONObject(); + pv.put("acr",acr); + + JSONObject pvs = new JSONObject(); + pvs.put("acr", acr); + + + JSONObject obj = new JSONObject(); + obj.put("pv", pv); + obj.put("pvs", pv); + + JSONObject resource = new JSONObject(); + resource.put("m2m:acp", obj); + + HttpResponse httpResponse = RestHttpClient.put(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+acpTestRU, resource.toString()); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testDelete() { + HttpResponse httpResponse = RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+acpTestD); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testNonAuthorizedOperation() { + HttpResponse httpResponse = RestHttpClient.delete(badOriginator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+cntName); + assertEquals(403, httpResponse.getStatusCode()); + } + +} + diff --git a/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/AE.java b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/AE.java new file mode 100644 index 00000000..718c346b --- /dev/null +++ b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/AE.java @@ -0,0 +1,77 @@ +package org.eclipse.om2m.adn.tests; + +import static org.junit.Assert.*; + +import org.eclipse.om2m.adn.tools.HttpResponse; +import org.eclipse.om2m.adn.tools.RestHttpClient; +import org.json.JSONObject; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class AE extends TestConfig{ + private static String aeTestRU = "aeTestRU"; + private static String aeTestD = "aeTestD"; + private static String aeTestC = "aeTestC"; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + JSONObject obj = new JSONObject(); + obj.put("rn", aeTestRU); + obj.put("api", 12345); + obj.put("rr", false); + JSONObject resource = new JSONObject(); + resource.put("m2m:ae", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 2); + + obj = new JSONObject(); + obj.put("rn", aeTestD); + obj.put("api", 12345); + obj.put("rr", false); + resource = new JSONObject(); + resource.put("m2m:ae", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 2); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeTestRU); + RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeTestD); + RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeTestC); + } + + @Test + public void testCreate() { + JSONObject obj = new JSONObject(); + obj.put("rn", aeTestC); + obj.put("api", 12345); + obj.put("rr", false); + JSONObject resource = new JSONObject(); + resource.put("m2m:ae", obj); + HttpResponse httpResponse = RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 2); + assertEquals(201, httpResponse.getStatusCode()); + } + + @Test + public void testRetreive() { + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeTestRU); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testUpdate() { + JSONObject obj = new JSONObject(); + obj.put("rr", true); + JSONObject resource = new JSONObject(); + resource.put("m2m:ae", obj); + HttpResponse httpResponse = RestHttpClient.put(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeTestRU, resource.toString()); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testDelete() { + HttpResponse httpResponse = RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeTestD); + assertEquals(200, httpResponse.getStatusCode()); + } + +} diff --git a/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/CSEBase.java b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/CSEBase.java new file mode 100644 index 00000000..34fc2b1e --- /dev/null +++ b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/CSEBase.java @@ -0,0 +1,17 @@ +package org.eclipse.om2m.adn.tests; + +import static org.junit.Assert.*; + +import org.eclipse.om2m.adn.tools.HttpResponse; +import org.eclipse.om2m.adn.tools.RestHttpClient; +import org.junit.Test; + +public class CSEBase extends TestConfig { + + @Test + public void testRetreive() { + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName); + assertEquals(200, httpResponse.getStatusCode()); + } + +} diff --git a/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/Container.java b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/Container.java new file mode 100644 index 00000000..be210298 --- /dev/null +++ b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/Container.java @@ -0,0 +1,81 @@ +package org.eclipse.om2m.adn.tests; + +import static org.junit.Assert.*; + +import org.eclipse.om2m.adn.tools.HttpResponse; +import org.eclipse.om2m.adn.tools.RestHttpClient; +import org.json.JSONObject; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class Container extends TestConfig { + + private static String aeC = "aeTestRU"; + private static String cnTestRU = "cnTestRU"; + private static String cnTestD = "cnTestD"; + private static String cnTestC = "cnTestC"; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + + JSONObject obj = new JSONObject(); + obj.put("rn", aeC); + obj.put("api", 12345); + obj.put("rr", false); + JSONObject resource = new JSONObject(); + resource.put("m2m:ae", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 2); + + + obj = new JSONObject(); + obj.put("rn", cnTestRU); + resource = new JSONObject(); + resource.put("m2m:cnt", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeC, resource.toString(), 3); + + + obj = new JSONObject(); + obj.put("rn", cnTestD); + resource = new JSONObject(); + resource.put("m2m:cnt", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeC, resource.toString(), 3); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeC); + } + + @Test + public void testCreate() { + JSONObject obj = new JSONObject(); + obj.put("rn", cnTestC); + JSONObject resource = new JSONObject(); + resource.put("m2m:cnt", obj); + HttpResponse httpResponse = RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeC, resource.toString(), 3); + assertEquals(201, httpResponse.getStatusCode()); + } + + @Test + public void testRetreive() { + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeC+"/"+cnTestRU); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testUpdate() { + JSONObject obj = new JSONObject(); + obj.put("et", "20181228T164835"); + JSONObject resource = new JSONObject(); + resource.put("m2m:cnt", obj); + HttpResponse httpResponse = RestHttpClient.put(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeC+"/"+cnTestRU, resource.toString()); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testDelete() { + HttpResponse httpResponse = RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeC+"/"+cnTestD); + assertEquals(200, httpResponse.getStatusCode()); + } +} diff --git a/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/ContentInstance.java b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/ContentInstance.java new file mode 100644 index 00000000..2f161be4 --- /dev/null +++ b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/ContentInstance.java @@ -0,0 +1,107 @@ +package org.eclipse.om2m.adn.tests; + +import static org.junit.Assert.*; + +import org.eclipse.om2m.adn.tools.HttpResponse; +import org.eclipse.om2m.adn.tools.RestHttpClient; +import org.json.JSONObject; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class ContentInstance extends TestConfig{ + + private static String aeName = "aeTestRU"; + private static String cntName = "cntTest"; + private static String cinTestRU = "cinTestRU"; + private static String cinTestD = "cinTestD"; + private static String cinTestC = "cinTestC"; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + + JSONObject obj = new JSONObject(); + obj.put("rn", aeName); + obj.put("api", 12345); + obj.put("rr", false); + JSONObject resource = new JSONObject(); + resource.put("m2m:ae", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 2); + + + obj = new JSONObject(); + obj.put("rn", cntName); + resource = new JSONObject(); + resource.put("m2m:cnt", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName, resource.toString(), 3); + + + + obj = new JSONObject(); + obj.put("rn", cinTestRU); + obj.put("cnf", "application/text"); + obj.put("con", 25); + resource = new JSONObject(); + resource.put("m2m:cin", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+cntName, resource.toString(), 4); + + + obj = new JSONObject(); + obj.put("rn", cinTestD); + obj.put("cnf", "application/text"); + obj.put("con", 35); + resource = new JSONObject(); + resource.put("m2m:cin", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+cntName, resource.toString(), 4); + } + + //@AfterClass + public static void tearDownAfterClass() throws Exception { + RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName); + } + + @Test + public void testCreate() { + JSONObject obj = new JSONObject(); + obj.put("rn", cinTestC); + obj.put("cnf", "application/text"); + obj.put("con", 30); + JSONObject resource = new JSONObject(); + resource.put("m2m:cin", obj); + HttpResponse httpResponse = RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+cntName, resource.toString(), 4); + assertEquals(201, httpResponse.getStatusCode()); + } + + @Test + public void testRetreive() { + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+cntName+"/"+cinTestRU); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testRetreiveLA() { + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+cntName+"/la"); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testRetreiveOL() { + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+cntName+"/ol"); + assertEquals(200, httpResponse.getStatusCode()); + } + + /*public void testUpdate() { + JSONObject obj = new JSONObject(); + obj.put("et", "20161228T164835"); + JSONObject resource = new JSONObject(); + resource.put("m2m:cin", obj); + HttpResponse httpResponse = RestHttpClient.put(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeCi+"/"+cnCi+"/"+cinTestRU, resource.toString()); + assertEquals(200, httpResponse.getStatusCode()); + }*/ + @Test + public void testDelete() { + HttpResponse httpResponse = RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+cntName+"/"+cinTestD); + assertEquals(200, httpResponse.getStatusCode()); + } + +} diff --git a/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/Discovery.java b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/Discovery.java new file mode 100644 index 00000000..d83b0cbb --- /dev/null +++ b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/Discovery.java @@ -0,0 +1,86 @@ +package org.eclipse.om2m.adn.tests; + +import static org.junit.Assert.*; + +import org.eclipse.om2m.adn.tools.HttpResponse; +import org.eclipse.om2m.adn.tools.RestHttpClient; +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class Discovery extends TestConfig { + + private static String aeName = "aeTest"; + + //@BeforeClass + public static void setUpBeforeClass() throws Exception { + JSONObject obj = new JSONObject(); + obj.put("rn", aeName); + obj.put("api", 12345); + obj.put("rr", false); + JSONArray array = new JSONArray(); + array.put("Type/Sensor"); + array.put("Category/Luminosity"); + array.put("Manufactor/Philips"); + obj.put("lbl", array); + JSONObject resource = new JSONObject(); + resource.put("m2m:ae", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 2); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName); + } + + @Test + public void testAllResources() { + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"?fu=1"); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void TestWithFilterCriteria() { + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"?fu=1&ty=2"); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void TestWithLimitFilterCriteria() { + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"?fu=1&lim=1"); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void TestWithLabelFilterCriteria() { + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"?fu=1&lbl=Manufactor/Philips"); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void TestWithMultipleFilterCriteria() { + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"?fu=1&ty=1&lbl=Type/Sensor"); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void TestWithLevelFilterCriteria() { + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"?fu=1&lvl=1"); + assertEquals(200, httpResponse.getStatusCode()); + httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"?fu=1&lvl=2"); + assertEquals(200, httpResponse.getStatusCode()); + httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"?fu=1&lvl=3"); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void TestWithOffsetFilterCriteria() { + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"?fu=1&ofst=3&lim=1"); + assertEquals(200, httpResponse.getStatusCode()); + httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"?fu=1&ofst=3"); + assertEquals(200, httpResponse.getStatusCode()); + } + +} diff --git a/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/FanoutPoint.java b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/FanoutPoint.java new file mode 100644 index 00000000..4ec53160 --- /dev/null +++ b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/FanoutPoint.java @@ -0,0 +1,144 @@ +package org.eclipse.om2m.adn.tests; + +import static org.junit.Assert.*; + +import org.eclipse.om2m.adn.tools.HttpResponse; +import org.eclipse.om2m.adn.tools.RestHttpClient; +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class FanoutPoint extends TestConfig { + + private static String groupC = "groupTest"; + private static String groupRU = "groupRU"; + private static String groupD = "groupD"; + + private static String cnTestC1 = "cnTestC1"; + private static String cnTestC2 = "cnTestC2"; + + private static String cnTestRU1 = "cnTestRU1"; + private static String cnTestRU2 = "cnTestRU2"; + + private static String cnTestD1 = "cnTestD1"; + private static String cnTestD2 = "cnTestD1"; + + private static String cinTest = "cinTest"; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + JSONObject obj = new JSONObject(); + obj.put("rn", cnTestRU1); + JSONObject resource = new JSONObject(); + resource.put("m2m:cnt", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 3); + + obj = new JSONObject(); + obj.put("rn", cnTestRU2); + resource = new JSONObject(); + resource.put("m2m:cnt", obj); + RestHttpClient.post(originator, csePoa+"/~/"+remoteCseId, resource.toString(), 3); + + JSONArray array = new JSONArray(); + array.put("/"+cseId+"/"+cseName+"/"+cnTestRU1); + array.put("/"+remoteCseId+"/"+remoteCseName+"/"+cnTestRU2); + obj = new JSONObject(); + obj.put("mid", array); + obj.put("rn", groupRU); + obj.put("mnm", 3); + resource = new JSONObject(); + resource.put("m2m:grp", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 9); + + obj = new JSONObject(); + obj.put("rn", cnTestD1); + resource = new JSONObject(); + resource.put("m2m:cnt", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 3); + + obj = new JSONObject(); + obj.put("rn", cnTestD2); + resource = new JSONObject(); + resource.put("m2m:cnt", obj); + RestHttpClient.post(originator, csePoa+"/~/"+remoteCseId, resource.toString(), 3); + + array = new JSONArray(); + array.put("/"+cseId+"/"+cseName+"/"+cnTestD1); + array.put("/"+remoteCseId+"/"+remoteCseName+"/"+cnTestD2); + obj = new JSONObject(); + obj.put("mid", array); + obj.put("rn", groupD); + obj.put("mnm", 3); + resource = new JSONObject(); + resource.put("m2m:grp", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 9); + + + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+groupC); + RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+groupRU); + } + + @Test + public void testCreate() { + JSONObject obj = new JSONObject(); + obj.put("rn", cnTestC1); + JSONObject resource = new JSONObject(); + resource.put("m2m:cnt", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 3); + + obj = new JSONObject(); + obj.put("rn", cnTestC2); + resource = new JSONObject(); + resource.put("m2m:cnt", obj); + RestHttpClient.post(originator, csePoa+"/~/"+remoteCseId, resource.toString(), 3); + + JSONArray array = new JSONArray(); + array.put("/"+cseId+"/"+cseName+"/"+cnTestC1); + array.put("/"+remoteCseId+"/"+remoteCseName+"/"+cnTestC2); + obj = new JSONObject(); + obj.put("mid", array); + obj.put("rn", groupC); + obj.put("mnm", 3); + resource = new JSONObject(); + resource.put("m2m:grp", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 9); + + obj = new JSONObject(); + obj.put("rn", cinTest); + obj.put("cnf", "application/text"); + obj.put("con", 25); + resource = new JSONObject(); + resource.put("m2m:cin", obj); + HttpResponse httpResponse = RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+groupC+"/fopt", resource.toString(), 4); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testRetreive() { + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+groupRU+"/fopt"); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testDelete() { + HttpResponse httpResponse = RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+groupD+"/fopt"); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testUpdate() { + JSONObject obj = new JSONObject(); + obj.put("et", "20181228T164835"); + JSONObject resource = new JSONObject(); + resource.put("m2m:cnt", obj); + HttpResponse httpResponse = RestHttpClient.put(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+groupRU+"/fopt", resource.toString()); + assertEquals(200, httpResponse.getStatusCode()); + } + +} diff --git a/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/Group.java b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/Group.java new file mode 100644 index 00000000..2e5b2a18 --- /dev/null +++ b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/Group.java @@ -0,0 +1,92 @@ +package org.eclipse.om2m.adn.tests; + +import static org.junit.Assert.*; + +import org.eclipse.om2m.adn.tools.HttpResponse; +import org.eclipse.om2m.adn.tools.RestHttpClient; +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class Group extends TestConfig { + + private static String groupTestRU = "groupTestRU"; + private static String groupTestD = "groupTestD"; + private static String groupTestC = "groupTestC"; + private static String aeName = "aeTest"; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + JSONObject obj = new JSONObject(); + obj.put("rn", aeName); + obj.put("api", 12345); + obj.put("rr", false); + JSONObject resource = new JSONObject(); + resource.put("m2m:ae", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 2); + + JSONArray array = new JSONArray(); + array.put("/"+cseId+"/"+cseName+"/"+aeName); + obj = new JSONObject(); + obj.put("mid", array); + obj.put("rn", groupTestRU); + obj.put("mnm", 3); + resource = new JSONObject(); + resource.put("m2m:grp", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 9); + + obj = new JSONObject(); + obj.put("mid", array); + obj.put("rn", groupTestD); + obj.put("mnm", 3); + resource = new JSONObject(); + resource.put("m2m:grp", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 9); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+groupTestC); + RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+groupTestRU); + RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName); + } + + @Test + public void testCreate() { + JSONArray array = new JSONArray(); + array.put("/"+cseId+"/"+cseName+"/"+aeName); + JSONObject obj = new JSONObject(); + obj.put("mid", array); + obj.put("rn", groupTestC); + obj.put("mnm", 3); + JSONObject resource = new JSONObject(); + resource.put("m2m:grp", obj); + HttpResponse httpResponse = RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 9); + assertEquals(201, httpResponse.getStatusCode()); + } + + @Test + public void testRetreive(){ + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+groupTestRU); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testUpdate(){ + JSONObject obj = new JSONObject(); + obj.put("et", "20171228T164835"); + JSONObject resource = new JSONObject(); + resource.put("m2m:grp", obj); + HttpResponse httpResponse = RestHttpClient.put(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+groupTestRU, resource.toString()); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testDelete() { + HttpResponse httpResponse = RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+groupTestD); + assertEquals(200, httpResponse.getStatusCode()); + } + +} diff --git a/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/LongPolling.java b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/LongPolling.java new file mode 100644 index 00000000..902dc46d --- /dev/null +++ b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/LongPolling.java @@ -0,0 +1,80 @@ +package org.eclipse.om2m.adn.tests; + +import static org.junit.Assert.*; + +import org.eclipse.om2m.adn.tools.HttpResponse; +import org.eclipse.om2m.adn.tools.RestHttpClient; +import org.json.JSONObject; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class LongPolling extends TestConfig { + + private static String lpTestRU = "lpRU"; + private static String lpTestD = "lpD"; + private static String lpTestC = "lpC"; + private static String aeName = "ae_test"; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + JSONObject obj = new JSONObject(); + obj.put("rn", aeName); + obj.put("api", 12345); + obj.put("rr", false); + JSONObject resource = new JSONObject(); + resource.put("m2m:ae", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 2); + + obj = new JSONObject(); + obj.put("rn", lpTestRU); + resource = new JSONObject(); + resource.put("m2m:pch", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName, resource.toString(), 15); + + obj = new JSONObject(); + obj.put("rn", lpTestD); + resource = new JSONObject(); + resource.put("m2m:pch", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName, resource.toString(), 15); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+lpTestC); + RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+lpTestRU); + } + + @Test + public void testCreate() { + JSONObject obj = new JSONObject(); + obj.put("rn", lpTestC); + JSONObject resource = new JSONObject(); + resource.put("m2m:pch", obj); + HttpResponse httpResponse = RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName, resource.toString(), 15); + assertEquals(201, httpResponse.getStatusCode()); + } + + @Test + public void testRetreive() { + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+lpTestRU); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testUpdate(){ + JSONObject obj = new JSONObject(); + obj.put("et", "20181228T164835"); + JSONObject resource = new JSONObject(); + resource.put("m2m:pch", obj); + HttpResponse httpResponse = RestHttpClient.put(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+lpTestRU, resource.toString()); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testDelete() { + HttpResponse httpResponse = RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+lpTestD); + assertEquals(200, httpResponse.getStatusCode()); + } + +} diff --git a/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/Node.java b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/Node.java new file mode 100644 index 00000000..d309f7c2 --- /dev/null +++ b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/Node.java @@ -0,0 +1,74 @@ +package org.eclipse.om2m.adn.tests; + +import static org.junit.Assert.*; + +import org.eclipse.om2m.adn.tools.HttpResponse; +import org.eclipse.om2m.adn.tools.RestHttpClient; +import org.json.JSONObject; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class Node extends TestConfig { + + private static String nodeTestRU = "nodeRU"; + private static String nodeTestD = "nodeD"; + private static String nodeTestC = "nodeC"; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + JSONObject obj = new JSONObject(); + obj.put("rn", nodeTestRU); + obj.put("ni", "node-test"); + JSONObject resource = new JSONObject(); + resource.put("m2m:nod", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 14); + + obj = new JSONObject(); + obj.put("rn", nodeTestD); + obj.put("ni", "node-test2"); + resource = new JSONObject(); + resource.put("m2m:nod", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 14); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+nodeTestC); + RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+nodeTestRU); + } + + @Test + public void testCreate() { + JSONObject obj = new JSONObject(); + obj.put("rn", nodeTestC); + obj.put("ni", "node-test3"); + JSONObject resource = new JSONObject(); + resource.put("m2m:nod", obj); + HttpResponse httpResponse = RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 14); + assertEquals(201, httpResponse.getStatusCode()); + } + + @Test + public void testRetreive() { + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+nodeTestRU); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testUpdate(){ + JSONObject obj = new JSONObject(); + obj.put("et", "20181228T164835"); + JSONObject resource = new JSONObject(); + resource.put("m2m:nod", obj); + HttpResponse httpResponse = RestHttpClient.put(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+nodeTestRU, resource.toString()); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testDelete() { + HttpResponse httpResponse = RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+nodeTestD); + assertEquals(200, httpResponse.getStatusCode()); + } + +} diff --git a/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/RemoteCSE.java b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/RemoteCSE.java new file mode 100644 index 00000000..523a966e --- /dev/null +++ b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/RemoteCSE.java @@ -0,0 +1,93 @@ +package org.eclipse.om2m.adn.tests; + +import static org.junit.Assert.*; + +import org.eclipse.om2m.adn.tools.HttpResponse; +import org.eclipse.om2m.adn.tools.RestHttpClient; +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class RemoteCSE extends TestConfig { + + private static String remoteCSETestRU = "remoteCSETestRU"; + private static String remoteCSETestD = "remoteCSETestD"; + private static String remoteCSETestC = "remoteCSETestC"; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + JSONObject obj = new JSONObject(); + obj.put("cb", remoteCSETestRU); + obj.put("rn", remoteCSETestRU); + obj.put("csi", remoteCSETestRU); + obj.put("rr", true); + JSONArray array = new JSONArray(); + array.put(remoteCsePoa+"/"); + obj.put("poa", array); + JSONObject resource = new JSONObject(); + resource.put("m2m:csr", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 16); + + obj = new JSONObject(); + obj.put("cb", remoteCSETestD); + obj.put("rn", remoteCSETestD); + obj.put("csi", remoteCSETestD); + obj.put("rr", true); + array = new JSONArray(); + array.put(remoteCsePoa+"/"); + obj.put("poa", array); + resource = new JSONObject(); + resource.put("m2m:csr", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 16); + + + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+remoteCSETestRU); + RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+remoteCSETestC); + } + + @Test + public void testCreate() { + JSONObject obj = new JSONObject(); + obj.put("cb", remoteCSETestC); + obj.put("rn", remoteCSETestC); + obj.put("csi", remoteCSETestC); + obj.put("rr", true); + JSONArray array = new JSONArray(); + array.put(remoteCsePoa+"/"); + obj.put("poa", array); + JSONObject resource = new JSONObject(); + resource.put("m2m:csr", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 16); + } + + @Test + public void testRetreive() { + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+remoteCSETestRU); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testDelete() { + HttpResponse httpResponse = RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+remoteCSETestD); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testUpdate(){ + JSONObject obj = new JSONObject(); + JSONArray array = new JSONArray(); + array.put("http://127.0.0.1:8585/"); + obj.put("poa", array); + JSONObject resource = new JSONObject(); + resource.put("m2m:csr", obj); + HttpResponse httpResponse = RestHttpClient.put(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+remoteCSETestRU, resource.toString()); + assertEquals(200, httpResponse.getStatusCode()); + } + +} diff --git a/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/Subscription.java b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/Subscription.java new file mode 100644 index 00000000..c1b384d7 --- /dev/null +++ b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/Subscription.java @@ -0,0 +1,161 @@ +package org.eclipse.om2m.adn.tests; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.util.concurrent.Executors; + +import org.eclipse.om2m.adn.tools.HttpResponse; +import org.eclipse.om2m.adn.tools.RestHttpClient; +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; + +public class Subscription extends TestConfig { + + private static String aeName = "aeTest"; + private static String cntName = "cntTest"; + private static String subTestRU = "subTestRU"; + private static String subTestD = "subTestD"; + private static String subTestC = "subTestC"; + + private static String aeProtocol="http"; + private static String aeIp = "127.0.0.1"; + private static int aePort = 1401; + private static String notificationURI = aeProtocol+"://"+aeIp+":"+aePort; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + //Starting Server + HttpServer server = null; + try { + server = HttpServer.create(new InetSocketAddress(aePort), 0); + } catch (IOException e) { + e.printStackTrace(); + } + server.createContext("/", new MyHandler()); + server.setExecutor(Executors.newCachedThreadPool()); + server.start(); + + + JSONObject obj = new JSONObject(); + obj.put("rn", aeName); + obj.put("api", 12345); + obj.put("rr", false); + JSONObject resource = new JSONObject(); + resource.put("m2m:ae", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName, resource.toString(), 2); + + + obj = new JSONObject(); + obj.put("rn", cntName); + resource = new JSONObject(); + resource.put("m2m:cnt", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName, resource.toString(), 3); + + + + JSONArray array = new JSONArray(); + array.put(notificationURI); + obj = new JSONObject(); + obj.put("nu", array); + obj.put("rn", subTestRU); + obj.put("nct", 2); + resource = new JSONObject(); + resource.put("m2m:sub", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+cntName, resource.toString(), 23); + + + array = new JSONArray(); + array.put(notificationURI); + obj = new JSONObject(); + obj.put("nu", array); + obj.put("rn", subTestD); + obj.put("nct", 2); + resource = new JSONObject(); + resource.put("m2m:sub", obj); + RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+cntName, resource.toString(), 23); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName); + } + + @Test + public void testCreate() { + JSONArray array = new JSONArray(); + array.put(notificationURI); + JSONObject obj = new JSONObject(); + obj.put("nu", array); + obj.put("rn", subTestC); + obj.put("nct", 2); + JSONObject resource = new JSONObject(); + resource.put("m2m:sub", obj); + HttpResponse httpResponse = RestHttpClient.post(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+cntName, resource.toString(), 23); + assertEquals(201, httpResponse.getStatusCode()); + } + + @Test + public void testRetreive() { + HttpResponse httpResponse = RestHttpClient.get(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+cntName+"/"+subTestRU); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void testUpdate() { + JSONObject obj = new JSONObject(); + obj.put("et", "20181228T164835"); + JSONObject resource = new JSONObject(); + resource.put("m2m:sub", obj); + HttpResponse httpResponse = RestHttpClient.put(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+cntName+"/"+subTestRU, resource.toString()); + assertEquals(200, httpResponse.getStatusCode()); + } + + @Test + public void TestDelete() { + HttpResponse httpResponse = RestHttpClient.delete(originator, csePoa+"/~/"+cseId+"/"+cseName+"/"+aeName+"/"+cntName+"/"+subTestD); + assertEquals(200, httpResponse.getStatusCode()); + } + + + static class MyHandler implements HttpHandler { + + public void handle(HttpExchange httpExchange) { + System.out.println("Event Recieved!"); + + try{ + InputStream in = httpExchange.getRequestBody(); + + String requestBody = ""; + int i;char c; + while ((i = in.read()) != -1) { + c = (char) i; + requestBody = (String) (requestBody+c); + } + + System.out.println(requestBody); + + String responseBudy =""; + byte[] out = responseBudy.getBytes("UTF-8"); + httpExchange.sendResponseHeaders(200, out.length); + OutputStream os = httpExchange.getResponseBody(); + os.write(out); + os.close(); + + } catch(Exception e){ + e.printStackTrace(); + } + } + } + +} diff --git a/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/TestConfig.java b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/TestConfig.java new file mode 100644 index 00000000..adf80070 --- /dev/null +++ b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tests/TestConfig.java @@ -0,0 +1,22 @@ +package org.eclipse.om2m.adn.tests; + +public class TestConfig { + + public final static String originator="admin:admin"; + public final static String cseProtocol="http"; + + public final static String cseIp = "127.0.0.1"; + public final static int csePort = 8080; + + public final static String cseId = "in-cse"; + public final static String cseName = "in-name"; + + public final static String remoteCseIp = "127.0.0.1"; + public final static int remoteCSEPort = 8282; + + public final static String remoteCseId = "mn-cse"; + public final static String remoteCseName = "mn-name"; + + public final static String csePoa = cseProtocol+"://"+cseIp+":"+csePort; + public final static String remoteCsePoa = cseProtocol+"://"+remoteCseIp+":"+remoteCSEPort; +} diff --git a/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tools/HttpResponse.java b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tools/HttpResponse.java new file mode 100644 index 00000000..d9289d24 --- /dev/null +++ b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tools/HttpResponse.java @@ -0,0 +1,22 @@ +package org.eclipse.om2m.adn.tools; + +public class HttpResponse { + private int statusCode; + private String body; + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getBody() { + return body; + } + + public void setBody(String body) { + this.body = body; + } +} diff --git a/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tools/RestHttpClient.java b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tools/RestHttpClient.java new file mode 100644 index 00000000..081e3717 --- /dev/null +++ b/org.eclipse.om2m.adntest/src/test/java/org/eclipse/om2m/adn/tools/RestHttpClient.java @@ -0,0 +1,214 @@ +/***************************************************************************************** +* SENSINOV ("COMPANY") CONFIDENTIAL +* Copyright (c) 2016 SENSINOV, All Rights Reserved. +* +* NOTICE: All information contained herein is, and remains the property of COMPANY. +* The intellectual and technical concepts contained herein are proprietary to COMPANY +* and may be covered by France and Foreign Patents, patents in process, and are protected +* by trade secret or copyright law. Dissemination of this information or reproduction +* of this material is strictly forbidden unless prior written permission is obtained +* from COMPANY. Access to the source code contained herein is hereby forbidden to +* anyone except current COMPANY employees, managers or contractors who have executed +* Confidentiality and Non-disclosure agreements explicitly covering such access. +* +* The copyright notice above does not evidence any actual or intended publication or +* disclosure of this source code, which includes * information that is confidential +* and/or proprietary, and is a trade secret, of COMPANY. ANY REPRODUCTION, MODIFICATION, +* DISTRIBUTION, PUBLIC PERFORMANCE, OR PUBLIC DISPLAY OF OR THROUGH USE OF THIS SOURCE +* CODE WITHOUT THE EXPRESS WRITTEN CONSENT OF COMPANY IS STRICTLY PROHIBITED, AND IN +* VIOLATION OF APPLICABLE * LAWS AND INTERNATIONAL TREATIES. THE RECEIPT OR POSSESSION OF +* THIS SOURCE CODE AND/OR RELATED INFORMATION DOES NOT CONVEY OR IMPLY ANY RIGHTS TO +* REPRODUCE, DISCLOSE OR DISTRIBUTE ITS CONTENTS, OR TO MANUFACTURE, USE, OR SELL ANYTHING +* THAT IT MAY DESCRIBE, IN WHOLE OR IN PART. +*******************************************************************************************/ + +package org.eclipse.om2m.adn.tools; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; +import javax.net.ssl.HostnameVerifier; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.methods.*; +import org.apache.http.conn.scheme.Scheme; +import org.apache.http.conn.ssl.SSLSocketFactory; +import org.apache.http.conn.ssl.X509HostnameVerifier; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.eclipse.om2m.adn.tests.TestConfig; + + +public class RestHttpClient { + static DefaultHttpClient httpclient=null; + + public static void init(){ + + httpclient = new DefaultHttpClient(); + + if(TestConfig.cseProtocol.equals("https")){ + try{ + KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); + FileInputStream instream = new FileInputStream(new File("keystore.jks")); + try { + trustStore.load(instream, "keystore".toCharArray()); + }catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + }catch (CertificateException e) { + e.printStackTrace(); + }finally { + try { instream.close(); } catch (Exception ignore) {} + } + SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore, "keystore",trustStore); + socketFactory.setHostnameVerifier((X509HostnameVerifier) SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); + Scheme sch = new Scheme("https", 8443, socketFactory); + httpclient.getConnectionManager().getSchemeRegistry().register(sch); + }catch (Exception e){ + e.printStackTrace(); + } + } + + } + + + public static HttpResponse get(String originator, String uri) { + if(httpclient==null){ + init(); + } + System.out.println("HTTP GET "+uri); + + HttpGet httpGet= new HttpGet(uri); + + httpGet.addHeader("x-m2m-ri",generateRI()); + httpGet.addHeader("x-m2m-origin",originator); + httpGet.addHeader("Accept","application/json"); + + HttpResponse httpResponse = new HttpResponse(); + + try { + CloseableHttpResponse closeableHttpResponse = httpclient.execute(httpGet); + try{ + httpResponse.setStatusCode(closeableHttpResponse.getStatusLine().getStatusCode()); + httpResponse.setBody(EntityUtils.toString(closeableHttpResponse.getEntity())); + }finally{ + closeableHttpResponse.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println("HTTP Response "+httpResponse.getStatusCode()+"\n"+httpResponse.getBody()); + return httpResponse; + } + public static HttpResponse put(String originator, String uri, String body) { + if(httpclient==null){ + init(); + } + System.out.println("HTTP PUT "+uri+"\n"+body); + + HttpPut httpPut= new HttpPut(uri); + + httpPut.addHeader("X-M2M-RI",generateRI()); + httpPut.addHeader("X-M2M-Origin",originator); + httpPut.addHeader("Content-Type","application/json"); + httpPut.addHeader("Accept","application/json"); + + HttpResponse httpResponse = new HttpResponse(); + try { + CloseableHttpResponse closeableHttpResponse =null; + try { + httpPut.setEntity(new StringEntity(body)); + closeableHttpResponse= httpclient.execute(httpPut); + httpResponse.setStatusCode(closeableHttpResponse.getStatusLine().getStatusCode()); + httpResponse.setBody(EntityUtils.toString(closeableHttpResponse.getEntity())); + + }finally{ + closeableHttpResponse.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println("HTTP Response "+httpResponse.getStatusCode()+"\n"+httpResponse.getBody()); + + return httpResponse ; + } + + public static HttpResponse post(String originator, String uri, String body, int ty) { + if(httpclient==null){ + init(); + } + System.out.println("HTTP POST "+uri+"\n"+body); + + + final HttpPost httpPost = new HttpPost(uri); + + httpPost.addHeader("X-M2M-RI",generateRI()); + httpPost.addHeader("X-M2M-Origin",originator); + httpPost.addHeader("Accept","application/json"); + + httpPost.addHeader("Content-Type","application/json;ty="+ty); + + final HttpResponse httpResponse = new HttpResponse(); + + try{ + httpPost.setEntity(new StringEntity(body)); + try { + CloseableHttpResponse closeableHttpResponse=null; + closeableHttpResponse = httpclient.execute(httpPost); + httpResponse.setStatusCode(closeableHttpResponse.getStatusLine().getStatusCode()); + httpResponse.setBody(EntityUtils.toString(closeableHttpResponse.getEntity())); + } catch (ClientProtocolException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println("HTTP Response "+httpResponse.getStatusCode()+"\n"+httpResponse.getBody()); + return httpResponse ; + } + + public static HttpResponse delete(String originator, String uri) { + if(httpclient==null){ + init(); + } + System.out.println("HTTP DELETE "+uri); + + HttpDelete httpDelete = new HttpDelete(uri); + + httpDelete.addHeader("X-M2M-RI",generateRI()); + httpDelete.addHeader("X-M2M-Origin",originator); + httpDelete.addHeader("Accept","application/json"); + + + HttpResponse httpResponse = new HttpResponse(); + try { + CloseableHttpResponse closeableHttpResponse = httpclient.execute(httpDelete); + try { + httpResponse.setStatusCode(closeableHttpResponse.getStatusLine().getStatusCode()); + httpResponse.setBody(EntityUtils.toString(closeableHttpResponse.getEntity())); + }finally{ + closeableHttpResponse.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println("HTTP Response "+httpResponse.getStatusCode()+"\n"+httpResponse.getBody()); + return httpResponse ; + } + + public static String generateRI(){ + Integer random = (int)(Math.random()*1000)+100000; + return random.toString(); + } +}
\ No newline at end of file diff --git a/org.eclipse.om2m.binding.coap/.project b/org.eclipse.om2m.binding.coap/.project index 7fc31047..22688b79 100644 --- a/org.eclipse.om2m.binding.coap/.project +++ b/org.eclipse.om2m.binding.coap/.project @@ -11,17 +11,17 @@ </arguments> </buildCommand> <buildCommand> - <name>org.eclipse.m2e.core.maven2Builder</name> + <name>org.eclipse.pde.ManifestBuilder</name> <arguments> </arguments> </buildCommand> <buildCommand> - <name>org.eclipse.pde.ManifestBuilder</name> + <name>org.eclipse.pde.SchemaBuilder</name> <arguments> </arguments> </buildCommand> <buildCommand> - <name>org.eclipse.pde.SchemaBuilder</name> + <name>org.eclipse.m2e.core.maven2Builder</name> <arguments> </arguments> </buildCommand> diff --git a/org.eclipse.om2m.binding.http/src/main/java/org/eclipse/om2m/binding/http/RestHttpClient.java b/org.eclipse.om2m.binding.http/src/main/java/org/eclipse/om2m/binding/http/RestHttpClient.java index 165151f3..4062106e 100644 --- a/org.eclipse.om2m.binding.http/src/main/java/org/eclipse/om2m/binding/http/RestHttpClient.java +++ b/org.eclipse.om2m.binding.http/src/main/java/org/eclipse/om2m/binding/http/RestHttpClient.java @@ -39,7 +39,7 @@ import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.conn.HttpHostConnectException; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.client.HttpClientBuilder; import org.eclipse.om2m.binding.http.constants.HttpHeaders; import org.eclipse.om2m.binding.http.constants.HttpParameters; import org.eclipse.om2m.binding.service.RestClientService; @@ -79,11 +79,12 @@ public class RestHttpClient implements RestClientService { */ public ResponsePrimitive sendRequest(RequestPrimitive requestPrimitive) { LOGGER.info("Sending request: " + requestPrimitive); - CloseableHttpClient httpClient = HttpClients.createDefault(); + CloseableHttpClient httpClient = HttpClientBuilder.create() + .disableAutomaticRetries() + .build(); ResponsePrimitive responsePrimitive = new ResponsePrimitive(requestPrimitive); HttpUriRequest method = null; - // Retrieve the url String url = requestPrimitive.getTo(); if(!url.startsWith(protocol+"://")){ @@ -208,7 +209,6 @@ public class RestHttpClient implements RestClientService { responsePrimitive.setLocation(contentHeader); } LOGGER.info("Http Client response: " + responsePrimitive); - httpClient.close(); } catch(HttpHostConnectException e){ LOGGER.info("Target is not reachable: " + requestPrimitive.getTo()); responsePrimitive.setResponseStatusCode(ResponseStatusCode.TARGET_NOT_REACHABLE); @@ -217,7 +217,14 @@ public class RestHttpClient implements RestClientService { } catch (IOException e){ LOGGER.error(url + " not found", e); responsePrimitive.setResponseStatusCode(ResponseStatusCode.TARGET_NOT_REACHABLE); - } + } finally { + try { + httpClient.close(); + } catch (IOException e) { + // Silently fail + LOGGER.trace("Fail closing the http client", e); + } + } return responsePrimitive; } diff --git a/org.eclipse.om2m.binding.mqtt/.classpath b/org.eclipse.om2m.binding.mqtt/.classpath new file mode 100644 index 00000000..f7edce6b --- /dev/null +++ b/org.eclipse.om2m.binding.mqtt/.classpath @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry exported="true" kind="lib" path="libs/org.eclipse.paho.client.mqttv3-1.0.2.jar"/> + <classpathentry kind="src" path="src/main/java/"/> + <classpathentry kind="output" path="target/classes"/> +</classpath> diff --git a/org.eclipse.om2m.testsuite.flexcontainer/.project b/org.eclipse.om2m.binding.mqtt/.project index a2c11cca..fed26a33 100644 --- a/org.eclipse.om2m.testsuite.flexcontainer/.project +++ b/org.eclipse.om2m.binding.mqtt/.project @@ -1,34 +1,34 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.om2m.testsuite.flexcontaienr</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.ManifestBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.SchemaBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.m2e.core.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.m2e.core.maven2Nature</nature>
- <nature>org.eclipse.pde.PluginNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
+<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.om2m.binding.mqtt</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.m2e.core.maven2Builder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.m2e.core.maven2Nature</nature> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/org.eclipse.om2m.binding.mqtt/META-INF/MANIFEST.MF b/org.eclipse.om2m.binding.mqtt/META-INF/MANIFEST.MF new file mode 100644 index 00000000..a09741c6 --- /dev/null +++ b/org.eclipse.om2m.binding.mqtt/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: MQTT Binding +Bundle-SymbolicName: org.eclipse.om2m.binding.mqtt +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.eclipse.om2m.binding.mqtt.Activator +Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Import-Package: org.apache.commons.logging, + org.eclipse.om2m.binding.service, + org.eclipse.om2m.commons.constants, + org.eclipse.om2m.commons.resource, + org.eclipse.om2m.core.service, + org.eclipse.om2m.datamapping.service, + org.osgi.framework;version="1.3.0", + org.osgi.util.tracker;version="1.5.1" +Bundle-ActivationPolicy: lazy +Bundle-ClassPath: libs/org.eclipse.paho.client.mqttv3-1.0.2.jar, + . diff --git a/org.eclipse.om2m.binding.mqtt/README b/org.eclipse.om2m.binding.mqtt/README new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/org.eclipse.om2m.binding.mqtt/README diff --git a/org.eclipse.om2m.binding.mqtt/build.properties b/org.eclipse.om2m.binding.mqtt/build.properties new file mode 100644 index 00000000..65cee246 --- /dev/null +++ b/org.eclipse.om2m.binding.mqtt/build.properties @@ -0,0 +1,4 @@ +source.. = src/main/java/ +bin.includes = META-INF/,\ + .,\ + libs/org.eclipse.paho.client.mqttv3-1.0.2.jar diff --git a/org.eclipse.om2m.binding.mqtt/libs/org.eclipse.paho.client.mqttv3-1.0.2.jar b/org.eclipse.om2m.binding.mqtt/libs/org.eclipse.paho.client.mqttv3-1.0.2.jar Binary files differnew file mode 100644 index 00000000..9a881627 --- /dev/null +++ b/org.eclipse.om2m.binding.mqtt/libs/org.eclipse.paho.client.mqttv3-1.0.2.jar diff --git a/org.eclipse.om2m.binding.mqtt/pom.xml b/org.eclipse.om2m.binding.mqtt/pom.xml new file mode 100644 index 00000000..46e30e61 --- /dev/null +++ b/org.eclipse.om2m.binding.mqtt/pom.xml @@ -0,0 +1,30 @@ +<!-- + Copyright (c) 2013-2016 LAAS-CNRS (www.laas.fr) + 7 Colonel Roche 31077 Toulouse - France + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + which accompanies this distribution, and is available at + http://www.eclipse.org/legal/epl-v10.html + + Initial Contributors: + Thierry Monteil : Project manager, technical co-manager + Mahdi Ben Alaya : Technical co-manager + Samir Medjiah : Technical co-manager + Khalil Drira : Strategy expert + Guillaume Garzone : Developer + François Aïssaoui : Developer + + New contributors : + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <artifactId>org.eclipse.om2m.binding.mqtt</artifactId> + <packaging>eclipse-plugin</packaging> + <parent> + <groupId>org.eclipse.om2m</groupId> + <artifactId>org.eclipse.om2m</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> +</project>
\ No newline at end of file diff --git a/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/Activator.java b/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/Activator.java new file mode 100644 index 00000000..c8f126f0 --- /dev/null +++ b/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/Activator.java @@ -0,0 +1,170 @@ +/******************************************************************************* + * Copyright (c) 2013-2016 LAAS-CNRS (www.laas.fr) + * 7 Colonel Roche 31077 Toulouse - France + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributors: + * Thierry Monteil : Project manager, technical co-manager + * Mahdi Ben Alaya : Technical co-manager + * Samir Medjiah : Technical co-manager + * Khalil Drira : Strategy expert + * Guillaume Garzone : Developer + * François Aïssaoui : Developer + * + * New contributors : + *******************************************************************************/ +package org.eclipse.om2m.binding.mqtt; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.om2m.binding.mqtt.util.DataMapperRegistry; +import org.eclipse.om2m.binding.service.RestClientService; +import org.eclipse.om2m.core.service.CseService; +import org.eclipse.om2m.datamapping.service.DataMapperService; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.util.tracker.ServiceTracker; +import org.osgi.util.tracker.ServiceTrackerCustomizer; + +public class Activator implements BundleActivator { + + private static BundleContext context; + + static BundleContext getContext() { + return context; + } + + private static final Log LOGGER = LogFactory.getLog(Activator.class); + + /** {@link DataMapperServiceTracker} reference */ + private static ServiceTracker<DataMapperService, DataMapperService> dataMapperServiceTracker; + /** {@link CseService} reference */ + private static ServiceTracker<CseService, CseService> cseServiceTracker; + + /** MQTT Request Handler that connects to the MQTT Broker */ + private static MqttRequestHandler mqttRequestHandler; + + public void start(BundleContext bundleContext) throws Exception { + Activator.context = bundleContext; + + // Listening on Cse Service + cseServiceTracker = new ServiceTracker<CseService, CseService>( + bundleContext, CseService.class, + new CseServiceTrackerCustomizer()); + cseServiceTracker.open(); + + // Listening on DataMapper Service + dataMapperServiceTracker = new ServiceTracker<DataMapperService, DataMapperService>( + bundleContext, DataMapperService.class, + new DataMapperServiceTracker()); + dataMapperServiceTracker.open(); + + // Registering RestClientService of MQTT + getContext().registerService(RestClientService.class, new MqttRestClient(), null); + } + + public void stop(BundleContext bundleContext) throws Exception { + Activator.context = null; + if (cseServiceTracker != null) { + cseServiceTracker.close(); + cseServiceTracker = null; + } + if (dataMapperServiceTracker != null) { + dataMapperServiceTracker.close(); + dataMapperServiceTracker = null; + } + if (mqttRequestHandler != null){ + mqttRequestHandler.close(); + mqttRequestHandler = null; + } + } + + private static class CseServiceTrackerCustomizer implements + ServiceTrackerCustomizer<CseService, CseService> { + + @Override + public CseService addingService(ServiceReference<CseService> reference) { + if (reference == null) { + return null; + } + Object service = Activator.getContext().getService(reference); + if (service != null && service instanceof CseService) { + LOGGER.debug("New CseService discovered"); + CseService cse = (CseService) service; + MqttRequestHandler.setCseService(cse); + if (mqttRequestHandler == null) { + new Thread() { + public void run() { + LOGGER.info("Creating MQTT Request Handler"); + mqttRequestHandler = new MqttRequestHandler(); + }; + }.start(); + } + return cse; + } + return null; + } + + @Override + public void modifiedService(ServiceReference<CseService> reference, + CseService service) { + if (service != null) { + LOGGER.info("CseService modified"); + MqttRequestHandler.setCseService(service); + } + } + + @Override + public void removedService(ServiceReference<CseService> reference, + CseService service) { + MqttRequestHandler.setCseService(null); + } + + } + + private static class DataMapperServiceTracker implements + ServiceTrackerCustomizer<DataMapperService, DataMapperService> { + + @Override + public DataMapperService addingService( + ServiceReference<DataMapperService> reference) { + if (reference == null) { + return null; + } + Object service = Activator.getContext().getService(reference); + if (service != null && service instanceof DataMapperService) { + DataMapperService dms = (DataMapperService) service; + LOGGER.debug("New DataMapper Service discovered: " + + dms.getServiceDataType()); + DataMapperRegistry.register(dms); + return dms; + } + return null; + } + + @Override + public void modifiedService( + ServiceReference<DataMapperService> reference, + DataMapperService service) { + if (service != null) { + DataMapperRegistry.register(service); + } + } + + @Override + public void removedService( + ServiceReference<DataMapperService> reference, + DataMapperService service) { + if (service != null) { + DataMapperRegistry.remove(service); + } + } + + } + +} diff --git a/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/MqttRequestHandler.java b/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/MqttRequestHandler.java new file mode 100644 index 00000000..779e4dee --- /dev/null +++ b/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/MqttRequestHandler.java @@ -0,0 +1,274 @@ +/******************************************************************************* + * Copyright (c) 2013-2016 LAAS-CNRS (www.laas.fr) + * 7 Colonel Roche 31077 Toulouse - France + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributors: + * Thierry Monteil : Project manager, technical co-manager + * Mahdi Ben Alaya : Technical co-manager + * Samir Medjiah : Technical co-manager + * Khalil Drira : Strategy expert + * Guillaume Garzone : Developer + * François Aïssaoui : Developer + * + * New contributors : + *******************************************************************************/ +package org.eclipse.om2m.binding.mqtt; + +import java.math.BigInteger; +import java.util.regex.Matcher; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.om2m.binding.mqtt.util.DataMapperRegistry; +import org.eclipse.om2m.binding.mqtt.util.MqttConstants; +import org.eclipse.om2m.binding.mqtt.util.QueueSender; +import org.eclipse.om2m.commons.constants.Constants; +import org.eclipse.om2m.commons.constants.MimeMediaType; +import org.eclipse.om2m.commons.constants.ResponseStatusCode; +import org.eclipse.om2m.commons.resource.PrimitiveContent; +import org.eclipse.om2m.commons.resource.RequestPrimitive; +import org.eclipse.om2m.commons.resource.ResponsePrimitive; +import org.eclipse.om2m.core.service.CseService; +import org.eclipse.om2m.datamapping.service.DataMapperService; +import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; +import org.eclipse.paho.client.mqttv3.MqttCallback; +import org.eclipse.paho.client.mqttv3.MqttClient; +import org.eclipse.paho.client.mqttv3.MqttConnectOptions; +import org.eclipse.paho.client.mqttv3.MqttException; +import org.eclipse.paho.client.mqttv3.MqttMessage; +import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; + +/** + * MQTT Request Handler class that subscribe to oneM2M request topic. + * When a request is received in the request topic, it is de-serialized and send + * to the CseService implementation available. Then the response from the service + * is serialized and sent to the oneM2M response topic. + */ +public class MqttRequestHandler implements MqttCallback { + + // Static attributes of the class + + /** MQTT Client ID */ + private static final String CLIENT_ID = Constants.CSE_ID; + /** Logger reference */ + private static final Log LOGGER = LogFactory.getLog(MqttRequestHandler.class); + /** MQTT Request Topic */ + private static final String REQUEST_TOPIC = "/oneM2M/req/+/" + Constants.CSE_ID + "/+"; + + + /** Reference to the current cseService implementation*/ + private static CseService cseService; + + /** + * Set the current CseService used when a request is + * received on the oneM2M request topic. + * @param cse the CseService implementation to use + */ + public static void setCseService(CseService cse) { + cseService = cse; + } + + // Private attributes + + /** MQTT Client from the Paho library */ + private MqttClient mainMqttClient; + + /** The MQTT connection options to use */ + private MqttConnectOptions connOpts; + + /** Tell the thread to keep retrying or not */ + private boolean retry = true; + /** Connection retry thread */ + private Thread retryThread; + + /** + * Default constructor of the Request Handler + */ + public MqttRequestHandler() { + MemoryPersistence persistence = new MemoryPersistence(); + String url = "tcp://" + MqttConstants.MQTT_BROKER_HOSTNAME + ":" + + MqttConstants.MQTT_BROKER_PORT; + this.connOpts = new MqttConnectOptions(); + connOpts.setCleanSession(true); + if(MqttConstants.MQTT_BROKER_USERNAME != null && MqttConstants.MQTT_BROKER_PASSWORD != null){ + connOpts.setUserName(MqttConstants.MQTT_BROKER_USERNAME); + connOpts.setPassword(MqttConstants.MQTT_BROKER_PASSWORD.toCharArray()); + } + try { + LOGGER.debug("Connecting MQTT client to: " + url); + this.mainMqttClient = new MqttClient(url, CLIENT_ID, persistence); + this.mainMqttClient.setCallback(MqttRequestHandler.this); + this.connect(this.connOpts); + } catch (MqttException e) { + LOGGER.error("Error in MQTT Client creation", e); + } + } + + /** + * Connect and retry if the connection fails + * @param connOpts + */ + private void connect(final MqttConnectOptions connOpts){ + if(retry && retryThread == null){ + retryThread = new Thread("mqtt-connection-retrier"){ + public void run() { + while(retry && !MqttRequestHandler.this.mainMqttClient.isConnected()){ + try { + MqttRequestHandler.this.mainMqttClient.connect(connOpts); + + LOGGER.info("Subscribing on MQTT topic: " + REQUEST_TOPIC); + MqttRequestHandler.this.mainMqttClient.subscribe(REQUEST_TOPIC, 2); + } catch (MqttException e) { + LOGGER.warn("Cannot connect to MQTT Broker, retrying in 10s. Cause: " + e.getMessage()); + } + if(!MqttRequestHandler.this.mainMqttClient.isConnected()){ + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + // Ignore + } + } + } + MqttRequestHandler.this.retryThread = null; + }; + }; + } + retryThread.start(); + } + + @Override + public void connectionLost(Throwable throwable) { + LOGGER.warn("Connection lost on MQTT Broker at " + MqttConstants.MQTT_BROKER_HOSTNAME + ":" + MqttConstants.MQTT_BROKER_PORT); + this.connect(this.connOpts); + } + + @Override + public void deliveryComplete(IMqttDeliveryToken token) { + // Empty + } + + @Override + public void messageArrived(String topic, MqttMessage message) + throws Exception { + Matcher matcher = MqttConstants.REQUEST_PATTERN_IN.matcher(topic); + if (matcher.matches()) { + String aeId = matcher.group(1); + String format = matcher.group(2); + String responseTopic = "/oneM2M/resp/" + Constants.CSE_ID + "/" + aeId + "/" + format; + + if (message.getPayload() == null) { + LOGGER.info("Null message received on " + topic); + sendErrorResponse("The message is null", responseTopic, aeId, format); + return; + } + String payload = new String(message.getPayload()); + LOGGER.debug("(" + topic + ") Message received (qos: " + message.getQos() + "):\n" + payload); + DataMapperService dms = DataMapperRegistry.getFromMqttFormat(format); + + if (dms == null) { + LOGGER.warn("MQTT Request received with unhandled content type: " + format); + sendErrorResponse("The format type is not handled", + responseTopic.replace("/" + format, "/" + MqttConstants.MQTT_XML), + aeId, MqttConstants.MQTT_XML); + return; + } + Object objectPayload = dms.stringToObj(payload); + if(objectPayload == null || !(objectPayload instanceof RequestPrimitive)){ + LOGGER.info("Invalid content provided in MQTT request"); + sendErrorResponse("Invalid content provided in request primitive", responseTopic, aeId, format); + return; + } + RequestPrimitive requestPrimitive = (RequestPrimitive) objectPayload; + requestPrimitive.setRequestContentType(MimeMediaType.OBJ); + requestPrimitive.setReturnContentType(MimeMediaType.OBJ); + // Primitive content handling + if(requestPrimitive.getPrimitiveContent() != null && + !requestPrimitive.getPrimitiveContent().getAny().isEmpty() && + requestPrimitive.getContent() == null){ + requestPrimitive.setContent(requestPrimitive.getPrimitiveContent().getAny().get(0)); + } + + ResponsePrimitive responsePrimitive = null; + + if(cseService != null){ + // Sending the request to the CSE + responsePrimitive = cseService.doRequest(requestPrimitive); + + // Handling the custom "content" field and map it to PrimitiveContent for serialization + if(responsePrimitive.getContent() != null && + responsePrimitive.getPrimitiveContent() == null){ + PrimitiveContent pc = new PrimitiveContent(); + pc.getAny().add(responsePrimitive.getContent()); + responsePrimitive.setPrimitiveContent(pc); + } + + // Building and sending response + final String responsePayload = dms.objToString(responsePrimitive); + LOGGER.debug("Response to be sent on topic: " + responseTopic + ". Payload:\n" + responsePayload); + + // Sending the request in another thread otherwise it blocks the reception thread of Paho + QueueSender.queue(mainMqttClient, responseTopic, responsePayload.getBytes()); + } else { + sendErrorResponse("/" + Constants.CSE_ID + " is not available", responseTopic, aeId, format, ResponseStatusCode.SERVICE_UNAVAILABLE); + } + + } else { + LOGGER.debug("The topic is not well formed. (" + topic + ")"); + } + } + + /** + * Util method that send an error message to the client + * @param message the message to send + * @param responseTopic the response topic to reply on + * @param aeId the id of the client + * @param format the format of exchange + */ + private void sendErrorResponse(String message, String responseTopic, + String aeId, String format, BigInteger responseStatusCode) { + ResponsePrimitive responsePrimitive = new ResponsePrimitive(); + responsePrimitive.setTo(aeId); + responsePrimitive.setFrom("/" + Constants.CSE_ID); + responsePrimitive.setResponseStatusCode(responseStatusCode); + responsePrimitive.setPrimitiveContent(new PrimitiveContent()); + responsePrimitive.getPrimitiveContent().getAny().add(message); + DataMapperService dms = DataMapperRegistry.getFromMqttFormat(format); + byte[] errorPayload = dms.objToString(responsePrimitive).getBytes(); + QueueSender.queue(mainMqttClient, responseTopic, errorPayload); + } + + /** + * Send a bad request response to the client + * @param message the message + * @param responseTopic the response topic + * @param aeId the id of the client + * @param format the format of exchange + */ + private void sendErrorResponse(String message, String responseTopic, + String aeId, String format){ + sendErrorResponse(message, responseTopic, aeId, format, ResponseStatusCode.BAD_REQUEST); + } + + /** + * Disconnecting and closing the MQTT Client. + */ + public void close(){ + // Disconnect the MQTT Client + try { + this.mainMqttClient.disconnect(); + } catch (MqttException e) { + LOGGER.debug("Error disconnecting the MQTT Client", e); + } + // Prevent on any reconnection retry + retry = false; + // Wake up the retry thread after the false on "retry" has been set + if(retryThread != null && retryThread.isAlive()){ + retryThread.interrupt(); + } + } +} diff --git a/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/MqttRestClient.java b/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/MqttRestClient.java new file mode 100644 index 00000000..95ba01ce --- /dev/null +++ b/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/MqttRestClient.java @@ -0,0 +1,174 @@ +/******************************************************************************* + * Copyright (c) 2013-2016 LAAS-CNRS (www.laas.fr) + * 7 Colonel Roche 31077 Toulouse - France + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributors: + * Thierry Monteil : Project manager, technical co-manager + * Mahdi Ben Alaya : Technical co-manager + * Samir Medjiah : Technical co-manager + * Khalil Drira : Strategy expert + * Guillaume Garzone : Developer + * François Aïssaoui : Developer + * + * New contributors : + *******************************************************************************/ +package org.eclipse.om2m.binding.mqtt; + +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.om2m.binding.mqtt.util.DataMapperRegistry; +import org.eclipse.om2m.binding.mqtt.util.MqttConstants; +import org.eclipse.om2m.binding.mqtt.util.QueueSender; +import org.eclipse.om2m.binding.mqtt.util.ResponseRegistry; +import org.eclipse.om2m.binding.mqtt.util.ResponseSemaphore; +import org.eclipse.om2m.binding.service.RestClientService; +import org.eclipse.om2m.commons.constants.Constants; +import org.eclipse.om2m.commons.constants.MimeMediaType; +import org.eclipse.om2m.commons.constants.ResponseStatusCode; +import org.eclipse.om2m.commons.resource.PrimitiveContent; +import org.eclipse.om2m.commons.resource.RequestPrimitive; +import org.eclipse.om2m.commons.resource.ResponsePrimitive; +import org.eclipse.om2m.datamapping.service.DataMapperService; +import org.eclipse.paho.client.mqttv3.MqttClient; +import org.eclipse.paho.client.mqttv3.MqttException; +import org.eclipse.paho.client.mqttv3.MqttMessage; +import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; + +public class MqttRestClient implements RestClientService { + + private static final Log LOGGER = LogFactory.getLog(MqttRestClient.class); + + @Override + public ResponsePrimitive sendRequest(RequestPrimitive requestPrimitive) { + if(requestPrimitive.getContent() != null){ + PrimitiveContent pc = new PrimitiveContent(); + switch(requestPrimitive.getRequestContentType()){ + case MimeMediaType.XML: + pc.getAny().add(DataMapperRegistry.get(MimeMediaType.XML).stringToObj((String)requestPrimitive.getContent())); + break; + case MimeMediaType.JSON: + pc.getAny().add(DataMapperRegistry.get(MimeMediaType.JSON).stringToObj((String)requestPrimitive.getContent())); + break; + case MimeMediaType.OBJ: case MimeMediaType.TEXT_PLAIN: + pc.getAny().add(requestPrimitive.getContent()); + break; + default: + break; + } + if(!pc.getAny().isEmpty()){ + requestPrimitive.setPrimitiveContent(pc); + } + } + + ResponsePrimitive responsePrimitive = new ResponsePrimitive(requestPrimitive); + + if(requestPrimitive.getMqttTopic() == null || requestPrimitive.getMqttUri() == null){ + responsePrimitive.setResponseStatusCode(ResponseStatusCode.BAD_REQUEST); + return responsePrimitive; + } + + if(requestPrimitive.getRequestIdentifier() == null){ + requestPrimitive.setRequestIdentifier(UUID.randomUUID().toString()); + } + + String uri = requestPrimitive.getMqttUri(); + if(uri.startsWith("mqtt://")){ + uri = uri.replaceFirst("mqtt://", "tcp://"); + } + + if(requestPrimitive.getTo().startsWith("mqtt://")){ + Pattern mqttUriPatter = Pattern.compile("(mqtt://[^:/]*(:[0-9]{1,5})?)(/.*)"); + Matcher matcher = mqttUriPatter.matcher(requestPrimitive.getTo()); + if(matcher.matches()){ + requestPrimitive.setTo(matcher.group(3)); + } + } + + String topic = requestPrimitive.getMqttTopic(); + String payload = null; + String format = null; + if (topic.endsWith("/json")){ + payload = DataMapperRegistry.get(MimeMediaType.JSON).objToString(requestPrimitive); + format = "json"; + } else { + // Case of XML and default + payload = DataMapperRegistry.get(MimeMediaType.XML).objToString(requestPrimitive); + format = "xml"; + } + + try { + MqttClient mqttClient = new MqttClient(uri, requestPrimitive.getRequestIdentifier(), new MemoryPersistence()); + mqttClient.connect(); + LOGGER.debug("Sending request on topic: " + topic + " with payload:\n" + payload); + ResponseSemaphore responseSemaphore = null; + if(requestPrimitive.isMqttResponseExpected()){ + Matcher matcher = MqttConstants.REQUEST_PATTERN_OUT.matcher(topic); + if(matcher.matches()){ + String responseTopic = "/oneM2M/resp/" + matcher.group(1) + "/"+ Constants.CSE_ID + "/" + format; + responseSemaphore = ResponseRegistry.createSemaphore(requestPrimitive.getRequestIdentifier(), mqttClient, responseTopic); + } else { + responsePrimitive.setResponseStatusCode(ResponseStatusCode.TARGET_NOT_REACHABLE); + } + } else { + mqttClient.publish(topic, new MqttMessage(payload.getBytes())); + responsePrimitive.setResponseStatusCode(ResponseStatusCode.OK); + } + if(responseSemaphore != null){ + QueueSender.queue(mqttClient, topic, payload.getBytes()); + LOGGER.debug("Waiting for response... (" + MqttConstants.TIME_OUT_DURATION + "s)"); + boolean released = responseSemaphore.getSemaphore().tryAcquire(1, MqttConstants.TIME_OUT_DURATION, TimeUnit.SECONDS); + if(released){ + responsePrimitive = responseSemaphore.getResponsePrimitive(); + fillAndConvertContent(requestPrimitive, responsePrimitive); + LOGGER.debug("Response received: " + responsePrimitive); + } else { + responsePrimitive.setResponseStatusCode(ResponseStatusCode.TARGET_NOT_REACHABLE); + } + } + mqttClient.disconnect(); + mqttClient.close(); + } catch (MqttException e) { + LOGGER.warn("Cannot connect to: " + requestPrimitive.getMqttUri()); + responsePrimitive.setResponseStatusCode(ResponseStatusCode.TARGET_NOT_REACHABLE); + return responsePrimitive; + } catch (InterruptedException e) { + LOGGER.error("Interrupted exception caught in MqttRestClient: " + e.getMessage()); + responsePrimitive.setResponseStatusCode(ResponseStatusCode.TARGET_NOT_REACHABLE); + return responsePrimitive; + } + + return responsePrimitive; + } + + private void fillAndConvertContent(RequestPrimitive requestPrimitive, + ResponsePrimitive responsePrimitive) { + if(responsePrimitive.getPrimitiveContent() != null && + !responsePrimitive.getPrimitiveContent().getAny().isEmpty() && + responsePrimitive.getContent() == null){ + if(requestPrimitive.getReturnContentType().equals(MimeMediaType.OBJ)){ + responsePrimitive.setContent(responsePrimitive.getPrimitiveContent().getAny().get(0)); + } else { + DataMapperService dms = DataMapperRegistry.get(requestPrimitive.getReturnContentType()); + String content = dms.objToString(responsePrimitive.getPrimitiveContent().getAny().get(0)); + responsePrimitive.setContent(content); + responsePrimitive.setContentType(requestPrimitive.getReturnContentType()); + } + } + } + + @Override + public String getProtocol() { + return MqttConstants.PROTOCOL; + } + +} diff --git a/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/util/DataMapperRegistry.java b/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/util/DataMapperRegistry.java new file mode 100644 index 00000000..d4e4741a --- /dev/null +++ b/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/util/DataMapperRegistry.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2013-2016 LAAS-CNRS (www.laas.fr) + * 7 Colonel Roche 31077 Toulouse - France + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributors: + * Thierry Monteil : Project manager, technical co-manager + * Mahdi Ben Alaya : Technical co-manager + * Samir Medjiah : Technical co-manager + * Khalil Drira : Strategy expert + * Guillaume Garzone : Developer + * François Aïssaoui : Developer + * + * New contributors : + *******************************************************************************/ +package org.eclipse.om2m.binding.mqtt.util; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.om2m.commons.constants.MimeMediaType; +import org.eclipse.om2m.datamapping.service.DataMapperService; + +/** + * This class is used to store instances of {@link DataMapperService} classes. + * + */ +public class DataMapperRegistry { + + /** Private constructor to avoid creation */ + private DataMapperRegistry(){} + + /** + * Service registry classified by data type handled. + */ + private static Map<String, DataMapperService> serviceRegistery = new HashMap<String, DataMapperService>(); + + /** + * Add a new {@link DataMapperService} to the registery. + * @param dms the service to register + */ + public static void register(DataMapperService dms){ + if(dms != null && dms.getServiceDataType() != null){ + serviceRegistery.put(dms.getServiceDataType(), dms); + } + } + + /** + * Retrieve a {@link DataMapperService} from a data type. + * @param dataType the + * @return the {@link DataMapperService} that handle the data type or null if none + */ + public static DataMapperService get(String dataType){ + return serviceRegistery.get(dataType); + } + + /** + * Remove the {@link DataMapperService} from the registry + * @param dataType the data type of the service to remove + */ + public static void remove(String dataType){ + serviceRegistery.remove(dataType); + } + + /** + * Remove the {@link DataMapperService} from the registry + * @param dms the service to remove from the registry + */ + public static void remove(DataMapperService dms){ + remove(dms.getServiceDataType()); + } + + /** + * Retrieve the {@link DataMapperService} from the registry + * from the MQTT format String + * @param format the format of the DMS + * @return the DMS with the specified format or null + */ + public static DataMapperService getFromMqttFormat(String format){ + switch (format) { + case "xml": + return DataMapperRegistry.get(MimeMediaType.XML); + case "json": + return DataMapperRegistry.get(MimeMediaType.JSON); + default: + return null; + } + } + +} diff --git a/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/util/MqttConstants.java b/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/util/MqttConstants.java new file mode 100644 index 00000000..5f0f546c --- /dev/null +++ b/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/util/MqttConstants.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2013-2016 LAAS-CNRS (www.laas.fr) + * 7 Colonel Roche 31077 Toulouse - France + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributors: + * Thierry Monteil : Project manager, technical co-manager + * Mahdi Ben Alaya : Technical co-manager + * Samir Medjiah : Technical co-manager + * Khalil Drira : Strategy expert + * Guillaume Garzone : Developer + * François Aïssaoui : Developer + * + * New contributors : + *******************************************************************************/ +package org.eclipse.om2m.binding.mqtt.util; + +import java.util.regex.Pattern; + +import org.eclipse.om2m.commons.constants.Constants; + +/** + * A set of MQTT constants retrieved from the System.getProperty method. + * + */ +public final class MqttConstants { + + private MqttConstants(){} + + /** Hostname of the main broker */ + public static final String MQTT_BROKER_HOSTNAME = System.getProperty("org.eclipse.om2m.mqtt.ip", "127.0.0.1"); + + /** IP of the main broker */ + public static final int MQTT_BROKER_PORT = Integer.valueOf(System.getProperty("org.eclipse.om2m.mqtt.port", "1883")); + + /** Username to connect to broker */ + public static final String MQTT_BROKER_USERNAME = System.getProperty("org.eclipse.om2m.mqtt.username"); + + /** Password to connect to broker */ + public static final String MQTT_BROKER_PASSWORD = System.getProperty("org.eclipse.om2m.mqtt.password"); + + /** MQTT Protocol prefix */ + public static final String PROTOCOL = "mqtt"; + + /** Size of the request sender queue */ + public static final int MQTT_QUEUE_SENDER_SIZE = Integer.valueOf(System.getProperty("org.eclipse.om2m.mqtt.queue.size", "8")); + + /** Request pattern to parse the request topic on message reception */ + public static final Pattern REQUEST_PATTERN_IN = Pattern.compile("/oneM2M/req/([^/]+)/" + Constants.CSE_ID + "/(.*)"); + + /** Request pattern when sending a message. */ + public static final Pattern REQUEST_PATTERN_OUT = Pattern.compile("/oneM2M/req/" + Constants.CSE_ID+ "/([^/]+)+/(.*)"); + + /** Time out duration when waiting for a response. Unit in second. */ + public static final long TIME_OUT_DURATION = Long.valueOf(System.getProperty("org.eclipse.om2m.mqtt.timeout", "20")); + + /** MQTT format for XML in topic */ + public static final String MQTT_XML = "xml"; + + /** MQTT format for JSON in topic */ + public static final String MQTT_JSON = "json"; + +} diff --git a/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/util/QueueSender.java b/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/util/QueueSender.java new file mode 100644 index 00000000..d6db3593 --- /dev/null +++ b/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/util/QueueSender.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2013-2016 LAAS-CNRS (www.laas.fr) + * 7 Colonel Roche 31077 Toulouse - France + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributors: + * Thierry Monteil : Project manager, technical co-manager + * Mahdi Ben Alaya : Technical co-manager + * Samir Medjiah : Technical co-manager + * Khalil Drira : Strategy expert + * Guillaume Garzone : Developer + * François Aïssaoui : Developer + * + * New contributors : + *******************************************************************************/ +package org.eclipse.om2m.binding.mqtt.util; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.paho.client.mqttv3.MqttClient; +import org.eclipse.paho.client.mqttv3.MqttException; + +public final class QueueSender { + + private static final Log LOGGER = LogFactory.getLog(QueueSender.class); + private static ExecutorService threadPool; + + static { + int queueSize = MqttConstants.MQTT_QUEUE_SENDER_SIZE <= 2 ? 2 + : MqttConstants.MQTT_QUEUE_SENDER_SIZE; + threadPool = new ThreadPoolExecutor(2, queueSize, 1, TimeUnit.MINUTES, + new SynchronousQueue<Runnable>()); + } + + public static void queue(MqttClient mqttClient, String topic, byte[] payload){ + LOGGER.debug("Sending MQTT message to " + mqttClient.getServerURI() + " topic: " + topic); + threadPool.execute(new MqttSender(mqttClient, topic, payload)); + } + + private static class MqttSender implements Runnable { + + private MqttClient mqttClient; + private String topic; + private byte[] payload; + + public MqttSender(MqttClient mqttClient, String topic, byte[] payload) { + super(); + this.mqttClient = mqttClient; + this.topic = topic; + this.payload = payload; + } + + @Override + public void run() { + try { + this.mqttClient.publish(topic, payload, 1, false); + } catch (MqttException e) { + LOGGER.warn("Error publishing on topic: " + this.topic + + " of broker " + this.mqttClient.getServerURI() + + ". Error: " + e.getMessage()); + } + } + + } + + private QueueSender(){ + // Empty and private constructor to avoid class creation + } + +} diff --git a/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/util/ResponseRegistry.java b/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/util/ResponseRegistry.java new file mode 100644 index 00000000..b77bf73b --- /dev/null +++ b/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/util/ResponseRegistry.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2013-2016 LAAS-CNRS (www.laas.fr) + * 7 Colonel Roche 31077 Toulouse - France + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributors: + * Thierry Monteil : Project manager, technical co-manager + * Mahdi Ben Alaya : Technical co-manager + * Samir Medjiah : Technical co-manager + * Khalil Drira : Strategy expert + * Guillaume Garzone : Developer + * François Aïssaoui : Developer + * + * New contributors : + *******************************************************************************/ +package org.eclipse.om2m.binding.mqtt.util; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Semaphore; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.om2m.commons.constants.Constants; +import org.eclipse.om2m.commons.constants.MimeMediaType; +import org.eclipse.om2m.commons.resource.ResponsePrimitive; +import org.eclipse.om2m.datamapping.service.DataMapperService; +import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; +import org.eclipse.paho.client.mqttv3.MqttCallback; +import org.eclipse.paho.client.mqttv3.MqttClient; +import org.eclipse.paho.client.mqttv3.MqttException; +import org.eclipse.paho.client.mqttv3.MqttMessage; + +public final class ResponseRegistry { + + private ResponseRegistry() { + // Empty and private constructor to avoid instantiation of this class + } + + private static final Map<String, ResponseSemaphore> responseMap = new HashMap<String, ResponseSemaphore>(); + + public static ResponseSemaphore createSemaphore(String requestIdentifier, MqttClient mqttClient, + String responseTopic) throws MqttException{ + synchronized (responseMap) { + mqttClient.setCallback(new ResponseCallback()); + mqttClient.subscribe(responseTopic, 1); + if(!responseMap.containsKey(requestIdentifier)){ + ResponseSemaphore respSemaphore = new ResponseSemaphore(new Semaphore(0)); + responseMap.put(requestIdentifier, respSemaphore); + return respSemaphore; + } + return null; + } + } + + private static void responseReceived(ResponsePrimitive responsePrimitive){ + synchronized (responseMap) { + if(responseMap.containsKey(responsePrimitive.getRequestIdentifier())){ + ResponseSemaphore responseSemanphore = responseMap.get(responsePrimitive.getRequestIdentifier()); + responseSemanphore.setResponsePrimitive(responsePrimitive); + responseSemanphore.getSemaphore().release(); + responseMap.remove(responsePrimitive.getRequestIdentifier()); + } + } + } + + private static class ResponseCallback implements MqttCallback { + + private static Pattern responsePattern = Pattern.compile("/oneM2M/resp/([^/]+)/" + Constants.CSE_ID + "/(.*)"); + + @Override + public void connectionLost(Throwable cause) { + // Ignore + } + + @Override + public void deliveryComplete(IMqttDeliveryToken token) { + // Ignore + } + + @Override + public void messageArrived(String topic, MqttMessage message) + throws Exception { + Matcher matcher = responsePattern.matcher(topic); + if(!matcher.matches()){ + return; + } + String format = matcher.group(2); + DataMapperService dms = null; + switch (format) { + case "xml": + dms = DataMapperRegistry.get(MimeMediaType.XML); + break; + case "json": + dms = DataMapperRegistry.get(MimeMediaType.JSON); + break; + default: + break; + } + if(dms == null){ + // The format is not handled here + return; + } + String payload = new String(message.getPayload()); + ResponsePrimitive resp = (ResponsePrimitive) dms.stringToObj(payload); + if(resp == null || resp.getRequestIdentifier() == null){ + return; + } + responseReceived(resp); + } + + } + +} diff --git a/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/util/ResponseSemaphore.java b/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/util/ResponseSemaphore.java new file mode 100644 index 00000000..037c3360 --- /dev/null +++ b/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/util/ResponseSemaphore.java @@ -0,0 +1,51 @@ +/*******************************************************************************
+ * Copyright (c) 2013-2016 LAAS-CNRS (www.laas.fr)
+ * 7 Colonel Roche 31077 Toulouse - France
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Initial Contributors:
+ * Thierry Monteil : Project manager, technical co-manager
+ * Mahdi Ben Alaya : Technical co-manager
+ * Samir Medjiah : Technical co-manager
+ * Khalil Drira : Strategy expert
+ * Guillaume Garzone : Developer
+ * François Aïssaoui : Developer
+ *
+ * New contributors :
+ *******************************************************************************/
+package org.eclipse.om2m.binding.mqtt.util;
+
+import java.util.concurrent.Semaphore;
+
+import org.eclipse.om2m.commons.resource.ResponsePrimitive;
+
+public class ResponseSemaphore {
+
+ private Semaphore semaphore;
+ private ResponsePrimitive responsePrimitive;
+
+ public ResponseSemaphore(Semaphore semaphore) {
+ this.semaphore = semaphore;
+ }
+
+ public Semaphore getSemaphore() {
+ return semaphore;
+ }
+
+ public void setSemaphore(Semaphore semaphore) {
+ this.semaphore = semaphore;
+ }
+
+ public ResponsePrimitive getResponsePrimitive() {
+ return responsePrimitive;
+ }
+
+ public void setResponsePrimitive(ResponsePrimitive responsePrimitive) {
+ this.responsePrimitive = responsePrimitive;
+ }
+
+}
diff --git a/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/util/Utils.java b/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/util/Utils.java new file mode 100644 index 00000000..56766fd7 --- /dev/null +++ b/org.eclipse.om2m.binding.mqtt/src/main/java/org/eclipse/om2m/binding/mqtt/util/Utils.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2013-2016 LAAS-CNRS (www.laas.fr) + * 7 Colonel Roche 31077 Toulouse - France + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributors: + * Thierry Monteil : Project manager, technical co-manager + * Mahdi Ben Alaya : Technical co-manager + * Samir Medjiah : Technical co-manager + * Khalil Drira : Strategy expert + * Guillaume Garzone : Developer + * François Aïssaoui : Developer + * + * New contributors : + *******************************************************************************/ +package org.eclipse.om2m.binding.mqtt.util; + +import org.eclipse.om2m.commons.resource.ResponsePrimitive; + +public final class Utils { + + public static void fillPrimitiveContent(){ + + } + + public static void fillContent(ResponsePrimitive requestPrimitive){ + if(requestPrimitive.getPrimitiveContent() != null && + !requestPrimitive.getPrimitiveContent().getAny().isEmpty() && + requestPrimitive.getContent() == null){ + requestPrimitive.setContent(requestPrimitive.getPrimitiveContent().getAny().get(0)); + } + } + +} diff --git a/org.eclipse.om2m.commons/.classpath b/org.eclipse.om2m.commons/.classpath index 851b630d..848ca71e 100644 --- a/org.eclipse.om2m.commons/.classpath +++ b/org.eclipse.om2m.commons/.classpath @@ -1,8 +1,8 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry exported="true" kind="lib" path="libs/javax.persistence.jar"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src/main/java"/> + <classpathentry exported="true" kind="lib" path="libs/javax.persistence.jar"/> + <classpathentry kind="output" path="target/classes"/> +</classpath> diff --git a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/constants/Constants.java b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/constants/Constants.java index 183c960e..8f0d5f93 100644 --- a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/constants/Constants.java +++ b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/constants/Constants.java @@ -1,97 +1,100 @@ -/*******************************************************************************
- * Copyright (c) 2013-2016 LAAS-CNRS (www.laas.fr)
- * 7 Colonel Roche 31077 Toulouse - France
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Initial Contributors:
- * Thierry Monteil : Project manager, technical co-manager
- * Mahdi Ben Alaya : Technical co-manager
- * Samir Medjiah : Technical co-manager
- * Khalil Drira : Strategy expert
- * Guillaume Garzone : Developer
- * François Aïssaoui : Developer
- *
- * New contributors :
- *******************************************************************************/
-package org.eclipse.om2m.commons.constants;
-
-import java.math.BigInteger;
-
-/**
- * Initializes platform properties
- */
-public class Constants {
- //CseBase resource properties
- /** CSE Type */
- public static final String CSE_TYPE = System.getProperty("org.eclipse.om2m.cseType","IN-CSE");
- /** CseBase id. */
- public static final String CSE_ID = System.getProperty("org.eclipse.om2m.cseBaseId","in-cse");
- /** CseBase name. */
- public static final String CSE_NAME = System.getProperty("org.eclipse.om2m.cseBaseName", "in-name");
-
- /** Default admin access right profile */
- public static final String ADMIN_PROFILE_ID = "acp_admin";
- /** Default admin requesting entity. (username/password) */
- public static final String ADMIN_REQUESTING_ENTITY = System.getProperty("org.eclipse.om2m.adminRequestingEntity","admin:admin");
- /** Default guest access right profile */
- public static final String GUEST_PROFILE_ID = "ACP_GUEST";
- /** Default guest requesting entity. (username/password) */
- public static final String GUEST_REQUESTING_ENTITY = System.getProperty("org.eclipse.om2m.guestRequestingEntity","guest:guest");
- /** Default resources expiration time. */
- public static final long EXPIRATION_TIME = 999999999;
- //CseBase communication properties
- /** CseBase default communication protocol. */
- public static final String CSE_DEFAULT_PROTOCOL = System.getProperty("org.eclipse.om2m.cseBaseProtocol.default","http");
- /** CseBase ip address. */
- public static final String CSE_IP = System.getProperty("org.eclipse.om2m.cseBaseAddress","127.0.0.1");
- /** CseBase listening port. */
- public static final int CSE_PORT = Integer.parseInt(System.getProperty("org.eclipse.equinox.http.jetty.http.port","8080"));
- /** CseBase coap port. */
- public static final int COAP_PORT = Integer.parseInt(System.getProperty("org.eclipse.om2m.coap.port","5684"));
- /** listening context. Not oneM2M compliant */
- @Deprecated
- public static final String CSE_CONTEXT = System.getProperty("org.eclipse.om2m.cseBaseContext","/api");
- /** M2M Service Provider identifier */
- public static final String M2M_SP_ID = System.getProperty("org.eclipse.om2m.m2mSpId", "om2m.org");
-
- //The following properties are required only for ASN or MN to perform authentication on a remote IN or MN
- /** Connect to the remote CSE (if not IN) */
- public static final boolean CSE_AUTHENTICATION = Boolean.valueOf(System.getProperty("org.eclipse.om2m.cseAuthentication", "true"));
- /** Remote Cse Id. (Required only for MN or ASN)*/
- public static final String REMOTE_CSE_ID = System.getProperty("org.eclipse.om2m.remoteCseId","in-cse");
- /** Remote Cse ip address. (Required only for MN or ASN)*/
- public static final String REMOTE_CSE_IP = System.getProperty("org.eclipse.om2m.remoteCseAddress","127.0.0.1");
- /** Remote Cse listening port. (Required only for MN or ASN)*/
- public static final int REMOTE_CSE_PORT = Integer.parseInt(System.getProperty("org.eclipse.om2m.remoteCsePort","8080"));
- /** Remote Cse listening port. (Required only for MN or ASN)*/
- public static final int REMOTE_CSE_COAP_PORT = Integer.parseInt(System.getProperty("org.eclipse.om2m.remoteCseCoapPort","5683"));
- /** Remote Cse listening context. */
- public static final String REMOTE_CSE_CONTEXT = System.getProperty("org.eclipse.om2m.remoteCseContext","/api");
- /** Remote Cse Name */
- public static final String REMOTE_CSE_NAME = System.getProperty("org.eclipse.om2m.remoteCseName", "in-name");
-
- // Default values for container creation
- /** Default ContentInstances collection maximum number of instance. */
- public static final BigInteger MAX_NBR_OF_INSTANCES = new BigInteger(System.getProperty("org.eclipse.om2m.maxNrOfInstances","10"));
- /** Default max byte size for a container */
- public static final BigInteger MAX_BYTE_SIZE = new BigInteger(System.getProperty("org.eclipse.om2m.maxByteSize", "10000"));
-
- // Regular expressions
- /** Regular expression for ID of resources */
- public static final String ID_REGEXPR = "^[A-Za-z0-9_-]*$" ;
- /** Prefix separator for IDs */
- public static final String PREFIX_SEPERATOR = System.getProperty("org.eclipse.om2m.resource.idseparator", "-");
-
- // Non blocking supported boolean
- public static final boolean NON_BLOCKING_SUPPORTED = Boolean.parseBoolean(System.getProperty("org.eclipse.om2m.nonblocking", "true"));
-
- public static final String SP_RELATIVE_URI_SEPARATOR = "~";
- public static final String ABSOLUTE_URI_SEPARATOR = "_";
-
- public static final Integer MAX_THREAD_POOL_SIZE = Integer.valueOf(System.getProperty("org.eclipse.om2m.maxThreadPoolSize", "50"));
-
+/******************************************************************************* + * Copyright (c) 2013-2016 LAAS-CNRS (www.laas.fr) + * 7 Colonel Roche 31077 Toulouse - France + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributors: + * Thierry Monteil : Project manager, technical co-manager + * Mahdi Ben Alaya : Technical co-manager + * Samir Medjiah : Technical co-manager + * Khalil Drira : Strategy expert + * Guillaume Garzone : Developer + * François Aïssaoui : Developer + * + * New contributors : + *******************************************************************************/ +package org.eclipse.om2m.commons.constants; + +import java.math.BigInteger; + +/** + * Initializes platform properties + */ +public class Constants { + //CseBase resource properties + /** CSE Type */ + public static final String CSE_TYPE = System.getProperty("org.eclipse.om2m.cseType","IN-CSE"); + /** CseBase id. */ + public static final String CSE_ID = System.getProperty("org.eclipse.om2m.cseBaseId","in-cse"); + /** CseBase name. */ + public static final String CSE_NAME = System.getProperty("org.eclipse.om2m.cseBaseName", "in-name"); + + /** Default admin access right profile */ + public static final String ADMIN_PROFILE_ID = "acp_admin"; + /** Default admin requesting entity. (username/password) */ + public static final String ADMIN_REQUESTING_ENTITY = System.getProperty("org.eclipse.om2m.adminRequestingEntity","admin:admin"); + /** Default guest access right profile */ + public static final String GUEST_PROFILE_ID = "ACP_GUEST"; + /** Default guest requesting entity. (username/password) */ + public static final String GUEST_REQUESTING_ENTITY = System.getProperty("org.eclipse.om2m.guestRequestingEntity","guest:guest"); + /** Default resources expiration time. */ + public static final long EXPIRATION_TIME = 999999999; + //CseBase communication properties + /** CseBase default communication protocol. */ + public static final String CSE_DEFAULT_PROTOCOL = System.getProperty("org.eclipse.om2m.cseBaseProtocol.default","http"); + /** CseBase ip address. */ + public static final String CSE_IP = System.getProperty("org.eclipse.om2m.cseBaseAddress","127.0.0.1"); + /** CseBase listening port. */ + public static final int CSE_PORT = Integer.parseInt(System.getProperty("org.eclipse.equinox.http.jetty.http.port","8080")); + /** CseBase coap port. */ + public static final int COAP_PORT = Integer.parseInt(System.getProperty("org.eclipse.om2m.coap.port","5684")); + /** listening context. Not oneM2M compliant */ + @Deprecated + public static final String CSE_CONTEXT = System.getProperty("org.eclipse.om2m.cseBaseContext","/api"); + /** M2M Service Provider identifier */ + public static final String M2M_SP_ID = System.getProperty("org.eclipse.om2m.m2mSpId", "om2m.org"); + + //The following properties are required only for ASN or MN to perform authentication on a remote IN or MN + /** Connect to the remote CSE (if not IN) */ + public static final boolean CSE_AUTHENTICATION = Boolean.valueOf(System.getProperty("org.eclipse.om2m.cseAuthentication", "true")); + /** Remote Cse Id. (Required only for MN or ASN)*/ + public static final String REMOTE_CSE_ID = System.getProperty("org.eclipse.om2m.remoteCseId","in-cse"); + /** Remote Cse ip address. (Required only for MN or ASN)*/ + public static final String REMOTE_CSE_IP = System.getProperty("org.eclipse.om2m.remoteCseAddress","127.0.0.1"); + /** Remote Cse listening port. (Required only for MN or ASN)*/ + public static final int REMOTE_CSE_PORT = Integer.parseInt(System.getProperty("org.eclipse.om2m.remoteCsePort","8080")); + /** Remote Cse listening port. (Required only for MN or ASN)*/ + public static final int REMOTE_CSE_COAP_PORT = Integer.parseInt(System.getProperty("org.eclipse.om2m.remoteCseCoapPort","5683")); + /** Remote Cse listening context. */ + public static final String REMOTE_CSE_CONTEXT = System.getProperty("org.eclipse.om2m.remoteCseContext","/api"); + /** Remote Cse Name */ + public static final String REMOTE_CSE_NAME = System.getProperty("org.eclipse.om2m.remoteCseName", "in-name"); + + // Default values for container creation + /** Default ContentInstances collection maximum number of instance. */ + public static final BigInteger MAX_NBR_OF_INSTANCES = new BigInteger(System.getProperty("org.eclipse.om2m.maxNrOfInstances","10")); + /** Default max byte size for a container */ + public static final BigInteger MAX_BYTE_SIZE = new BigInteger(System.getProperty("org.eclipse.om2m.maxByteSize", "10000")); + + // Regular expressions + /** Regular expression for ID of resources */ + public static final String ID_REGEXPR = "^[A-Za-z0-9_-]*$" ; + /** Prefix separator for IDs */ + public static final String PREFIX_SEPERATOR = System.getProperty("org.eclipse.om2m.resource.idseparator", "-"); + + // Non blocking supported boolean + public static final boolean NON_BLOCKING_SUPPORTED = Boolean.parseBoolean(System.getProperty("org.eclipse.om2m.nonblocking", "true")); + + public static final String SP_RELATIVE_URI_SEPARATOR = "~"; + public static final String ABSOLUTE_URI_SEPARATOR = "_"; + + public static final Integer MAX_THREAD_POOL_SIZE = Integer.valueOf(System.getProperty("org.eclipse.om2m.maxThreadPoolSize", "50")); + + // The MimeMediaType to use to serialize a notification + public static final String NOTIFICATION_MMT = System.getProperty("org.eclipse.om2m.notification.mmt", MimeMediaType.XML); + }
\ No newline at end of file diff --git a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/entities/AccessControlPolicyEntity.java b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/entities/AccessControlPolicyEntity.java index f5fa0034..1dd9a487 100644 --- a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/entities/AccessControlPolicyEntity.java +++ b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/entities/AccessControlPolicyEntity.java @@ -499,14 +499,7 @@ public class AccessControlPolicyEntity extends AnnounceableSubordinateEntity { this.linkedDynamicAuthorizationConsultation = linkedDynamicAuthorizationConsultation; } - @Override - public List<AccessControlPolicyEntity> getAccessControlPolicies() { - return new ArrayList<>(); - } - - @Override - public void setAccessControlPolicies(List<AccessControlPolicyEntity> accessControlPolicies) { - } + @Override public List<DynamicAuthorizationConsultationEntity> getDynamicAuthorizationConsultations() { @@ -520,6 +513,16 @@ public class AccessControlPolicyEntity extends AnnounceableSubordinateEntity { public void setDynamicAuthorizationConsultations(List<DynamicAuthorizationConsultationEntity> list) { dynamicConsultationAuthorizations = list; } + + @Override + public List<AccessControlPolicyEntity> getAccessControlPolicies() { + return null; + } + + @Override + public void setAccessControlPolicies( + List<AccessControlPolicyEntity> accessControlPolicies) { + } diff --git a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/entities/LabelEntity.java b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/entities/LabelEntity.java index e6623a02..6cee0367 100644 --- a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/entities/LabelEntity.java +++ b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/entities/LabelEntity.java @@ -191,6 +191,7 @@ public class LabelEntity { return linkedAe; } + /** * @param linkedAe the linkedAe to set */ diff --git a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/RequestPrimitive.java b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/RequestPrimitive.java index 48c60dbc..f5932255 100644 --- a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/RequestPrimitive.java +++ b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/RequestPrimitive.java @@ -133,7 +133,15 @@ public class RequestPrimitive { protected String requestContentType; @XmlTransient protected Map<String,List<String>> queryStrings; - + @XmlTransient + protected String targetId; + @XmlTransient + protected String mqttTopic; + @XmlTransient + protected String mqttUri; + @XmlTransient + protected boolean mqttResponseExpected = true; + /** * @return the queryStrings */ @@ -536,7 +544,7 @@ public class RequestPrimitive { * @return the targetId */ public String getTargetId() { - return this.getTo(); + return this.targetId; } /** @@ -544,7 +552,7 @@ public class RequestPrimitive { * the targetId to set */ public void setTargetId(String targetId) { - this.setTo(targetId); + this.targetId= targetId; } /** @@ -575,6 +583,38 @@ public class RequestPrimitive { this.requestContentType = requestContentType; } + public PrimitiveContent getPrimitiveContent() { + return primitiveContent; + } + + public void setPrimitiveContent(PrimitiveContent primitiveContent) { + this.primitiveContent = primitiveContent; + } + + public String getMqttTopic() { + return mqttTopic; + } + + public void setMqttTopic(String mqttTopic) { + this.mqttTopic = mqttTopic; + } + + public String getMqttUri() { + return mqttUri; + } + + public void setMqttUri(String mqttUri) { + this.mqttUri = mqttUri; + } + + public boolean isMqttResponseExpected() { + return mqttResponseExpected; + } + + public void setMqttResponseExpected(boolean mqttResponseExpected) { + this.mqttResponseExpected = mqttResponseExpected; + } + /* (non-Javadoc) * @see java.lang.Object#toString() */ @@ -651,5 +691,5 @@ public class RequestPrimitive { result.to = this.to; return result; } - + } diff --git a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/ResponsePrimitive.java b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/ResponsePrimitive.java index 93b6b1b0..d6ad846b 100644 --- a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/ResponsePrimitive.java +++ b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/ResponsePrimitive.java @@ -331,7 +331,7 @@ public class ResponsePrimitive { this.content = content; } - public PrimitiveContent getPritimitiveContent(){ + public PrimitiveContent getPrimitiveContent(){ return content; } diff --git a/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/controller/ContentInstanceController.java b/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/controller/ContentInstanceController.java index 246d7c32..a8e5505d 100644 --- a/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/controller/ContentInstanceController.java +++ b/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/controller/ContentInstanceController.java @@ -216,9 +216,11 @@ public class ContentInstanceController extends Controller { if (container.getMaxNrOfInstances() != null && (cinList.size() == container.getMaxNrOfInstances().intValue())) { LOGGER.info("Deleting oldest content instance due to container size limit: " + container.getChildContentInstances().get(0).getHierarchicalURI()); + String hierarchicalUriToDelete = container.getChildContentInstances().get(0).getHierarchicalURI(); dbs.getDAOFactory().getContentInstanceDAO().delete(transaction, container.getChildContentInstances().get(0)); transaction.commit(); transaction.close(); + UriMapper.deleteUri(hierarchicalUriToDelete); transaction = dbs.getDbTransaction(); transaction.open(); container = (ContainerEntity)dao.find(transaction, request.getTargetId()); diff --git a/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/controller/FanOutPointController.java b/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/controller/FanOutPointController.java index 1fc142a4..424ea3fb 100644 --- a/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/controller/FanOutPointController.java +++ b/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/controller/FanOutPointController.java @@ -158,7 +158,7 @@ public class FanOutPointController extends Controller { public ResponsePrimitive call() throws Exception { ResponsePrimitive resp = new Router().doRequest(request); resp.setPrimitiveContent(new PrimitiveContent()); - resp.getPritimitiveContent().getAny().add(resp.getContent()); + resp.getPrimitiveContent().getAny().add(resp.getContent()); return resp; } diff --git a/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/notifier/Notifier.java b/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/notifier/Notifier.java index e20b7ba5..4a909c24 100644 --- a/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/notifier/Notifier.java +++ b/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/notifier/Notifier.java @@ -1,83 +1,86 @@ -/*******************************************************************************
- * Copyright (c) 2013-2016 LAAS-CNRS (www.laas.fr)
- * 7 Colonel Roche 31077 Toulouse - France
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Initial Contributors:
- * Thierry Monteil : Project manager, technical co-manager
- * Mahdi Ben Alaya : Technical co-manager
- * Samir Medjiah : Technical co-manager
- * Khalil Drira : Strategy expert
- * Guillaume Garzone : Developer
- * François Aïssaoui : Developer
- *
- * New contributors :
- *******************************************************************************/
-package org.eclipse.om2m.core.notifier;
-
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.eclipse.om2m.commons.constants.Constants;
-import org.eclipse.om2m.commons.constants.MimeMediaType;
-import org.eclipse.om2m.commons.constants.NotificationContentType;
-import org.eclipse.om2m.commons.constants.Operation;
-import org.eclipse.om2m.commons.constants.ResourceStatus;
-import org.eclipse.om2m.commons.constants.ResourceType;
-import org.eclipse.om2m.commons.constants.ResponseStatusCode;
-import org.eclipse.om2m.commons.constants.ResultContent;
-import org.eclipse.om2m.commons.entities.AccessControlPolicyEntity;
-import org.eclipse.om2m.commons.entities.AeEntity;
-import org.eclipse.om2m.commons.entities.CSEBaseEntity;
-import org.eclipse.om2m.commons.entities.ContainerEntity;
-import org.eclipse.om2m.commons.entities.GroupEntity;
-import org.eclipse.om2m.commons.entities.MgmtObjEntity;
-import org.eclipse.om2m.commons.entities.RemoteCSEEntity;
-import org.eclipse.om2m.commons.entities.ResourceEntity;
-import org.eclipse.om2m.commons.entities.ScheduleEntity;
-import org.eclipse.om2m.commons.entities.SubscriptionEntity;
-import org.eclipse.om2m.commons.exceptions.Om2mException;
-import org.eclipse.om2m.commons.resource.Notification;
-import org.eclipse.om2m.commons.resource.Notification.NotificationEvent;
+/******************************************************************************* + * Copyright (c) 2013-2016 LAAS-CNRS (www.laas.fr) + * 7 Colonel Roche 31077 Toulouse - France + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributors: + * Thierry Monteil : Project manager, technical co-manager + * Mahdi Ben Alaya : Technical co-manager + * Samir Medjiah : Technical co-manager + * Khalil Drira : Strategy expert + * Guillaume Garzone : Developer + * François Aïssaoui : Developer + * + * New contributors : + *******************************************************************************/ +package org.eclipse.om2m.core.notifier; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.om2m.commons.constants.Constants; +import org.eclipse.om2m.commons.constants.MimeMediaType; +import org.eclipse.om2m.commons.constants.NotificationContentType; +import org.eclipse.om2m.commons.constants.Operation; +import org.eclipse.om2m.commons.constants.ResourceStatus; +import org.eclipse.om2m.commons.constants.ResourceType; +import org.eclipse.om2m.commons.constants.ResponseStatusCode; +import org.eclipse.om2m.commons.constants.ResultContent; +import org.eclipse.om2m.commons.entities.AccessControlPolicyEntity; +import org.eclipse.om2m.commons.entities.AeEntity; +import org.eclipse.om2m.commons.entities.CSEBaseEntity; +import org.eclipse.om2m.commons.entities.ContainerEntity; +import org.eclipse.om2m.commons.entities.GroupEntity; +import org.eclipse.om2m.commons.entities.MgmtObjEntity; +import org.eclipse.om2m.commons.entities.RemoteCSEEntity; +import org.eclipse.om2m.commons.entities.ResourceEntity; +import org.eclipse.om2m.commons.entities.ScheduleEntity; +import org.eclipse.om2m.commons.entities.SubscriptionEntity; +import org.eclipse.om2m.commons.exceptions.Om2mException; +import org.eclipse.om2m.commons.resource.Notification; +import org.eclipse.om2m.commons.resource.Notification.NotificationEvent; import org.eclipse.om2m.commons.resource.Notification.NotificationEvent.Representation; -import org.eclipse.om2m.commons.resource.RequestPrimitive;
-import org.eclipse.om2m.commons.resource.Resource;
-import org.eclipse.om2m.commons.resource.ResponsePrimitive;
-import org.eclipse.om2m.core.comm.RestClient;
-import org.eclipse.om2m.core.datamapper.DataMapperSelector;
-import org.eclipse.om2m.core.entitymapper.EntityMapper;
-import org.eclipse.om2m.core.entitymapper.EntityMapperFactory;
-import org.eclipse.om2m.core.persistence.PersistenceService;
-import org.eclipse.om2m.core.router.Patterns;
-import org.eclipse.om2m.core.router.Router;
-import org.eclipse.om2m.core.thread.CoreExecutor;
-import org.eclipse.om2m.core.urimapper.UriMapper;
-import org.eclipse.om2m.persistence.service.DAO;
-import org.eclipse.om2m.persistence.service.DBService;
-import org.eclipse.om2m.persistence.service.DBTransaction;
-
-/**
- * Notifies subscribers when a change occurs on a resource according to their subscriptions.
- */
-public class Notifier {
- /** Logger */
- private static Log LOGGER = LogFactory.getLog(Notifier.class);
-
- private static final Integer NB_OF_FAILED_NOTIFS_BEFORE_DELETION = Integer.valueOf(System.getProperty("org.eclipse.om2m.subscriptions.nbOfFailedNotificationsBeforeDeletion", "5"));
-
- /**
- * Finds all resource subscribers and notifies them.
- * @param statusCode - Notification status code
- * @param resource - Notification resource
- */
- public static void notify(List<SubscriptionEntity> listSubscription, ResourceEntity resource, int resourceStatus) {
+import org.eclipse.om2m.commons.resource.RequestPrimitive; +import org.eclipse.om2m.commons.resource.Resource; +import org.eclipse.om2m.commons.resource.ResponsePrimitive; +import org.eclipse.om2m.core.comm.RestClient; +import org.eclipse.om2m.core.datamapper.DataMapperSelector; +import org.eclipse.om2m.core.entitymapper.EntityMapper; +import org.eclipse.om2m.core.entitymapper.EntityMapperFactory; +import org.eclipse.om2m.core.persistence.PersistenceService; +import org.eclipse.om2m.core.router.Patterns; +import org.eclipse.om2m.core.router.Router; +import org.eclipse.om2m.core.thread.CoreExecutor; +import org.eclipse.om2m.core.urimapper.UriMapper; +import org.eclipse.om2m.persistence.service.DAO; +import org.eclipse.om2m.persistence.service.DBService; +import org.eclipse.om2m.persistence.service.DBTransaction; + +/** + * Notifies subscribers when a change occurs on a resource according to their subscriptions. + */ +public class Notifier { + /** Logger */ + private static Log LOGGER = LogFactory.getLog(Notifier.class); + + private static final Integer NB_OF_FAILED_NOTIFS_BEFORE_DELETION = Integer.valueOf(System.getProperty("org.eclipse.om2m.subscriptions.nbOfFailedNotificationsBeforeDeletion", "5")); + + /** + * Finds all resource subscribers and notifies them. + * @param statusCode - Notification status code + * @param resource - Notification resource + */ + public static void notify(List<SubscriptionEntity> listSubscription, ResourceEntity resource, int resourceStatus) { + notify(listSubscription, resource, null, resourceStatus); } @@ -89,265 +92,265 @@ public class Notifier { * @param resourceStatus */ public static void notify(List<SubscriptionEntity> listSubscription, ResourceEntity resource, Resource modifiedOnlyResource, int resourceStatus) { - if (listSubscription != null){
- for(SubscriptionEntity sub : listSubscription){
+ if (listSubscription != null){ + for(SubscriptionEntity sub : listSubscription){ NotificationWorker worker = new NotificationWorker(sub, resourceStatus, resource, modifiedOnlyResource); - CoreExecutor.postThread(worker);
- }
- }
- }
-
- /**
- * Used in DELETE procedure when a resource is deleted. It notifies the subscribed resource
- * and the parent resource subscribed entities.
- * @param listSubs
- * @param resourceDeleted
- */
- public static void notifyDeletion(List<SubscriptionEntity> listSubs, ResourceEntity resourceDeleted){
- List<SubscriptionEntity> parentSubscriptions = getParentSubscriptions(resourceDeleted);
- if(parentSubscriptions != null){
- notify(parentSubscriptions, resourceDeleted, ResourceStatus.CHILD_DELETED);
- }
- if(listSubs != null){
- notify(listSubs, resourceDeleted, ResourceStatus.DELETED);
- }
- }
-
- public static void performVerificationRequest(RequestPrimitive request,
- SubscriptionEntity subscriptionEntity) {
- String notificationPayloadContentType = subscriptionEntity.getNotificationPayloadContentType();
- for(String uri : subscriptionEntity.getNotificationURI()){
- if(!uri.equals(request.getFrom())){
- Notification notification = new Notification();
- notification.setCreator(subscriptionEntity.getCreator());
- notification.setVerificationRequest(true);
- notification.setSubscriptionReference(subscriptionEntity.getHierarchicalURI());
- notification.setSubscriptionDeletion(false);
- RequestPrimitive notifRequest = new RequestPrimitive();
- if (!MimeMediaType.OBJ.equals(notificationPayloadContentType)) {
- notifRequest.setContent(DataMapperSelector.getDataMapperList().get(notificationPayloadContentType).objToString(notification));
- } else {
- notifRequest.setContent(notification);
- }
- notifRequest.setFrom("/" + Constants.CSE_ID);
- notifRequest.setTo(uri);
- notifRequest.setOperation(Operation.NOTIFY);
- notifRequest.setRequestContentType(notificationPayloadContentType);
- notifRequest.setReturnContentType(notificationPayloadContentType);
- ResponsePrimitive resp = notify(notifRequest, uri);
- if(resp.getResponseStatusCode().equals(ResponseStatusCode.TARGET_NOT_REACHABLE)){
- throw new Om2mException("Error during the verification request",
- ResponseStatusCode.SUBSCRIPTION_VERIFICATION_INITIATION_FAILED);
- }
- if(resp.getResponseStatusCode().equals(ResponseStatusCode.SUBSCRIPTION_CREATOR_HAS_NO_PRIVILEGE)
- || resp.getResponseStatusCode().equals(ResponseStatusCode.SUBSCRIPTION_HOST_HAS_NO_PRIVILEGE)){
- throw new Om2mException(resp.getResponseStatusCode());
- }
- }
- }
- }
-
- public static ResponsePrimitive notify(RequestPrimitive request, String contact){
- // Check whether the subscription contact is protocol-dependent or not.
- LOGGER.info("Sending notify request to: " + contact);
- if(contact.matches(".*://.*")){
- // Contact = protocol-dependent -> direct notification using the rest client.
- request.setTo(contact);
- return RestClient.sendRequest(request);
- }else{
- request.setTargetId(contact);
- request.setFrom(Constants.ADMIN_REQUESTING_ENTITY);
- LOGGER.info("Sending notify request...");
- return new Router().doRequest(request);
- }
- }
-
- /**
- * Used to retrieve the subscription list of the parent resource
- * @param resource
- * @return
- */
- private static List<SubscriptionEntity> getParentSubscriptions(
- ResourceEntity resourceDeleted) {
- List<SubscriptionEntity> result;
- // Get parent id
- String[] ids = resourceDeleted.getHierarchicalURI().split("/");
- String parentHierarchicalId = resourceDeleted.getHierarchicalURI().replace("/" + ids[ids.length - 1], "");
- String parentId = UriMapper.getNonHierarchicalUri(parentHierarchicalId);
- // get parent entity
- DBService dbs = PersistenceService.getInstance().getDbService();
-
- DAO<?> dao = Patterns.getDAO(parentId, dbs);
- DBTransaction transaction = dbs.getDbTransaction();
- transaction.open();
- ResourceEntity parentEntity = (ResourceEntity) dao.find(transaction, parentId);
- // get the sub list from parent
- switch(parentEntity.getResourceType().intValue()){
- case ResourceType.ACCESS_CONTROL_POLICY:
- AccessControlPolicyEntity acp = (AccessControlPolicyEntity) parentEntity;
- result = acp.getChildSubscriptions();
- break;
- case ResourceType.AE:
- AeEntity ae = (AeEntity) parentEntity;
- result = ae.getSubscriptions();
- break;
- case ResourceType.CONTAINER:
- ContainerEntity cnt = (ContainerEntity) parentEntity;
- result = cnt.getSubscriptions();
- break;
- case ResourceType.CSE_BASE:
- CSEBaseEntity csb = (CSEBaseEntity) parentEntity;
- result = csb.getSubscriptions();
- break;
- case ResourceType.GROUP:
- GroupEntity group = (GroupEntity) parentEntity;
- result = group.getSubscriptions();
- break;
- case ResourceType.REMOTE_CSE:
- RemoteCSEEntity csr = (RemoteCSEEntity) parentEntity;
- result = csr.getSubscriptions();
- break;
- case ResourceType.SCHEDULE:
- ScheduleEntity schedule = (ScheduleEntity) parentEntity;
- result = schedule.getSubscriptions();
- break;
- default:
- result = new ArrayList<SubscriptionEntity>();
- }
- transaction.close();
- return result;
- }
-
- /**
- * Worker that perform the notification task for a subscription
- *
- */
- static class NotificationWorker implements Runnable {
- /** resource status of the notification */
- private int resourceStatus;
- /** the subscription to handle */
- private SubscriptionEntity sub;
- /** the resource to be sent */
- private ResourceEntity resource;
+ CoreExecutor.postThread(worker); + } + } + } + + /** + * Used in DELETE procedure when a resource is deleted. It notifies the subscribed resource + * and the parent resource subscribed entities. + * @param listSubs + * @param resourceDeleted + */ + public static void notifyDeletion(List<SubscriptionEntity> listSubs, ResourceEntity resourceDeleted){ + List<SubscriptionEntity> parentSubscriptions = getParentSubscriptions(resourceDeleted); + if(parentSubscriptions != null){ + notify(parentSubscriptions, resourceDeleted, ResourceStatus.CHILD_DELETED); + } + if(listSubs != null){ + notify(listSubs, resourceDeleted, ResourceStatus.DELETED); + } + } + + public static void performVerificationRequest(RequestPrimitive request, + SubscriptionEntity subscriptionEntity) { + String notificationPayloadContentType = subscriptionEntity.getNotificationPayloadContentType(); + for(String uri : subscriptionEntity.getNotificationURI()){ + if(!uri.equals(request.getFrom())){ + Notification notification = new Notification(); + notification.setCreator(subscriptionEntity.getCreator()); + notification.setVerificationRequest(true); + notification.setSubscriptionReference(subscriptionEntity.getHierarchicalURI()); + notification.setSubscriptionDeletion(false); + RequestPrimitive notifRequest = new RequestPrimitive(); + if (!MimeMediaType.OBJ.equals(notificationPayloadContentType)) { + notifRequest.setContent(DataMapperSelector.getDataMapperList().get(notificationPayloadContentType).objToString(notification)); + } else { + notifRequest.setContent(notification); + } + notifRequest.setFrom("/" + Constants.CSE_ID); + notifRequest.setTo(uri); + notifRequest.setOperation(Operation.NOTIFY); + notifRequest.setRequestContentType(notificationPayloadContentType); + notifRequest.setReturnContentType(notificationPayloadContentType); + ResponsePrimitive resp = notify(notifRequest, uri); + if(resp.getResponseStatusCode().equals(ResponseStatusCode.TARGET_NOT_REACHABLE)){ + throw new Om2mException("Error during the verification request", + ResponseStatusCode.SUBSCRIPTION_VERIFICATION_INITIATION_FAILED); + } + if(resp.getResponseStatusCode().equals(ResponseStatusCode.SUBSCRIPTION_CREATOR_HAS_NO_PRIVILEGE) + || resp.getResponseStatusCode().equals(ResponseStatusCode.SUBSCRIPTION_HOST_HAS_NO_PRIVILEGE)){ + throw new Om2mException(resp.getResponseStatusCode()); + } + } + } + } + + public static ResponsePrimitive notify(RequestPrimitive request, String contact){ + // Check whether the subscription contact is protocol-dependent or not. + LOGGER.info("Sending notify request to: " + contact); + if(contact.matches(".*://.*")){ + // Contact = protocol-dependent -> direct notification using the rest client. + request.setTo(contact); + return RestClient.sendRequest(request); + }else{ + request.setTargetId(contact); + request.setFrom(Constants.ADMIN_REQUESTING_ENTITY); + LOGGER.info("Sending notify request..."); + return new Router().doRequest(request); + } + } + + /** + * Used to retrieve the subscription list of the parent resource + * @param resource + * @return + */ + private static List<SubscriptionEntity> getParentSubscriptions( + ResourceEntity resourceDeleted) { + List<SubscriptionEntity> result; + // Get parent id + String[] ids = resourceDeleted.getHierarchicalURI().split("/"); + String parentHierarchicalId = resourceDeleted.getHierarchicalURI().replace("/" + ids[ids.length - 1], ""); + String parentId = UriMapper.getNonHierarchicalUri(parentHierarchicalId); + // get parent entity + DBService dbs = PersistenceService.getInstance().getDbService(); + + DAO<?> dao = Patterns.getDAO(parentId, dbs); + DBTransaction transaction = dbs.getDbTransaction(); + transaction.open(); + ResourceEntity parentEntity = (ResourceEntity) dao.find(transaction, parentId); + // get the sub list from parent + switch(parentEntity.getResourceType().intValue()){ + case ResourceType.ACCESS_CONTROL_POLICY: + AccessControlPolicyEntity acp = (AccessControlPolicyEntity) parentEntity; + result = acp.getChildSubscriptions(); + break; + case ResourceType.AE: + AeEntity ae = (AeEntity) parentEntity; + result = ae.getSubscriptions(); + break; + case ResourceType.CONTAINER: + ContainerEntity cnt = (ContainerEntity) parentEntity; + result = cnt.getSubscriptions(); + break; + case ResourceType.CSE_BASE: + CSEBaseEntity csb = (CSEBaseEntity) parentEntity; + result = csb.getSubscriptions(); + break; + case ResourceType.GROUP: + GroupEntity group = (GroupEntity) parentEntity; + result = group.getSubscriptions(); + break; + case ResourceType.REMOTE_CSE: + RemoteCSEEntity csr = (RemoteCSEEntity) parentEntity; + result = csr.getSubscriptions(); + break; + case ResourceType.SCHEDULE: + ScheduleEntity schedule = (ScheduleEntity) parentEntity; + result = schedule.getSubscriptions(); + break; + default: + result = new ArrayList<SubscriptionEntity>(); + } + transaction.close(); + return result; + } + + /** + * Worker that perform the notification task for a subscription + * + */ + static class NotificationWorker implements Runnable { + /** resource status of the notification */ + private int resourceStatus; + /** the subscription to handle */ + private SubscriptionEntity sub; + /** the resource to be sent */ + private ResourceEntity resource; /** the resource to be sent - modified attribute */ private Resource modifiedOnlyResource; -
+ public NotificationWorker(SubscriptionEntity sub, int resourceStatus, ResourceEntity resource, Resource modifiedOnlyResource) { - this.resourceStatus = resourceStatus;
- this.sub = sub;
- this.resource = resource;
+ this.resourceStatus = resourceStatus; + this.sub = sub; + this.resource = resource; this.modifiedOnlyResource = modifiedOnlyResource; - }
-
- @SuppressWarnings("unchecked")
- @Override
- public void run() {
- final RequestPrimitive request = new RequestPrimitive();
- Notification notification = new Notification();
- NotificationEvent notifEvent = new NotificationEvent();
- notification.setNotificationEvent(notifEvent);
-
- // Set attributes of notification object
- notifEvent.setResourceStatus(BigInteger.valueOf(resourceStatus));
- notification.setCreator(sub.getCreator());
-
- // Set request parameters
- request.setOperation(Operation.NOTIFY);
- request.setFrom("/" + Constants.CSE_ID);
-
- if(resourceStatus == ResourceStatus.DELETED){
- notification.setSubscriptionDeletion(true);
- } else {
- notification.setSubscriptionDeletion(false);
- }
-
- notification.setSubscriptionReference(sub.getResourceID());
-
- // Get the representation of the content
- Resource serializableResource;
- EntityMapper mapper ;
- if (sub.getNotificationContentType() != null){
- if (resource.getResourceType().equals(ResourceType.MGMT_OBJ)) {
- mapper = EntityMapperFactory.getMapperForMgmtObj((MgmtObjEntity) resource);
- } else {
- mapper = EntityMapperFactory.
- getMapperFromResourceType(resource.getResourceType().intValue());
- }
- if(sub.getNotificationContentType().equals(NotificationContentType.MODIFIED_ATTRIBUTES)){
- Representation representation = new Representation();
- if (modifiedOnlyResource != null) {
- // Gregory BONNARDEL - 26 Avril 2016
- // as all Controllers have not been modified
- // for modified controllers, use the resource provided by the controller
- representation.setResource(modifiedOnlyResource);
- } else {
- // for non modified controllers, send the ResourceEntity
- // but it is not compliant with the specs
- serializableResource = (Resource) mapper
- .mapEntityToResource(resource, ResultContent.ATTRIBUTES, 0, 0);
- representation.setResource(serializableResource);
- }
- notification.getNotificationEvent().setRepresentation(representation);
- request.setRequestContentType(sub.getNotificationPayloadContentType());
- } else if(sub.getNotificationContentType().equals(NotificationContentType.WHOLE_RESOURCE)){
- serializableResource = (Resource) mapper.mapEntityToResource(resource, ResultContent.ATTRIBUTES, 0, 0);
+ } + + @SuppressWarnings("unchecked") + @Override + public void run() { + final RequestPrimitive request = new RequestPrimitive(); + Notification notification = new Notification(); + NotificationEvent notifEvent = new NotificationEvent(); + notification.setNotificationEvent(notifEvent); + + // Set attributes of notification object + notifEvent.setResourceStatus(BigInteger.valueOf(resourceStatus)); + notification.setCreator(sub.getCreator()); + + // Set request parameters + request.setOperation(Operation.NOTIFY); + request.setFrom("/" + Constants.CSE_ID); + + if(resourceStatus == ResourceStatus.DELETED){ + notification.setSubscriptionDeletion(true); + } else { + notification.setSubscriptionDeletion(false); + } + + notification.setSubscriptionReference(sub.getResourceID()); + + // Get the representation of the content + Resource serializableResource; + EntityMapper mapper ; + if (sub.getNotificationContentType() != null){ + if (resource.getResourceType().equals(ResourceType.MGMT_OBJ)) { + mapper = EntityMapperFactory.getMapperForMgmtObj((MgmtObjEntity) resource); + } else { + mapper = EntityMapperFactory. + getMapperFromResourceType(resource.getResourceType().intValue()); + } + if(sub.getNotificationContentType().equals(NotificationContentType.MODIFIED_ATTRIBUTES)){ + Representation representation = new Representation(); + if (modifiedOnlyResource != null) { + // Gregory BONNARDEL - 26 Avril 2016 + // as all Controllers have not been modified + // for modified controllers, use the resource provided by the controller + representation.setResource(modifiedOnlyResource); + } else { + // for non modified controllers, send the ResourceEntity + // but it is not compliant with the specs + serializableResource = (Resource) mapper + .mapEntityToResource(resource, ResultContent.ATTRIBUTES, 0, 0); + representation.setResource(serializableResource); + } + notification.getNotificationEvent().setRepresentation(representation); + request.setRequestContentType(sub.getNotificationPayloadContentType()); + } else if(sub.getNotificationContentType().equals(NotificationContentType.WHOLE_RESOURCE)){ + serializableResource = (Resource) mapper.mapEntityToResource(resource, ResultContent.ATTRIBUTES, 0, 0); Representation representation = new Representation(); representation.setResource(serializableResource); notification.getNotificationEvent().setRepresentation(representation); - request.setRequestContentType(sub.getNotificationPayloadContentType());
- }
- }
- // Set the content
- request.setContent(DataMapperSelector.getDataMapperList().get(sub.getNotificationPayloadContentType()).objToString(notification));
- // For each notification URI: send the notify request
- for(final String uri : sub.getNotificationURI()){
- CoreExecutor.postThread(new Runnable(){
- public void run() {
- ResponsePrimitive response = Notifier.notify(request, uri);
- if (ResponseStatusCode.OK.equals(response.getResponseStatusCode())) {
- // notify ok
- updateSubscription(sub.getResourceID(), 0);
- LOGGER.debug("notify OK for subscription " + sub.getResourceID());
- } else {
- // notify KO
- Integer nbOfFailed = sub.getNbOfFailedNotifications();
- if (nbOfFailed == null) {
- nbOfFailed = 0;
- }
- if (nbOfFailed > NB_OF_FAILED_NOTIFS_BEFORE_DELETION) {
- // delete notification
- deleteSubscription(sub.getResourceID());
- LOGGER.error("Reach the limit of failed notifs --> delete subscription " + sub.getResourceID());
- } else {
- updateSubscription(sub.getResourceID(), nbOfFailed+1);
- LOGGER.warn("unable to notify, increase failed notifs(" + nbOfFailed +") for subscription " + sub.getResourceID());
- }
- }
- };
- });
- }
- }
- }
-
- private static void deleteSubscription(String resourceId) {
- DBService dbs = PersistenceService.getInstance().getDbService();
- DBTransaction dbTransaction = dbs.getDbTransaction();
- dbTransaction.open();
- SubscriptionEntity subscriptionEntityToBeDeleted = dbs.getDAOFactory().getSubsciptionDAO().find(dbTransaction, resourceId);
- dbs.getDAOFactory().getSubsciptionDAO().delete(dbTransaction, subscriptionEntityToBeDeleted);
- dbTransaction.commit();
- dbTransaction.close();
- }
-
- private static void updateSubscription(String resourceId, Integer nbOfFailedNotification) {
- DBService dbs = PersistenceService.getInstance().getDbService();
- DBTransaction dbTransaction = dbs.getDbTransaction();
- dbTransaction.open();
- SubscriptionEntity subscriptionEntityToBeUpdated = dbs.getDAOFactory().getSubsciptionDAO().find(dbTransaction, resourceId);
- subscriptionEntityToBeUpdated.setNbOfFailedNotifications(nbOfFailedNotification);
- dbs.getDAOFactory().getSubsciptionDAO().update(dbTransaction, subscriptionEntityToBeUpdated);
- dbTransaction.commit();
- dbTransaction.close();
- }
-
-}
+ request.setRequestContentType(sub.getNotificationPayloadContentType()); + } + } + // Set the content + request.setContent(DataMapperSelector.getDataMapperList().get(sub.getNotificationPayloadContentType()).objToString(notification)); + // For each notification URI: send the notify request + for(final String uri : sub.getNotificationURI()){ + CoreExecutor.postThread(new Runnable(){ + public void run() { + ResponsePrimitive response = Notifier.notify(request, uri); + if (ResponseStatusCode.OK.equals(response.getResponseStatusCode())) { + // notify ok + updateSubscription(sub.getResourceID(), 0); + LOGGER.debug("notify OK for subscription " + sub.getResourceID()); + } else { + // notify KO + Integer nbOfFailed = sub.getNbOfFailedNotifications(); + if (nbOfFailed == null) { + nbOfFailed = 0; + } + if (nbOfFailed > NB_OF_FAILED_NOTIFS_BEFORE_DELETION) { + // delete notification + deleteSubscription(sub.getResourceID()); + LOGGER.error("Reach the limit of failed notifs --> delete subscription " + sub.getResourceID()); + } else { + updateSubscription(sub.getResourceID(), nbOfFailed+1); + LOGGER.warn("unable to notify, increase failed notifs(" + nbOfFailed +") for subscription " + sub.getResourceID()); + } + } + }; + }); + } + } + } + + private static void deleteSubscription(String resourceId) { + DBService dbs = PersistenceService.getInstance().getDbService(); + DBTransaction dbTransaction = dbs.getDbTransaction(); + dbTransaction.open(); + SubscriptionEntity subscriptionEntityToBeDeleted = dbs.getDAOFactory().getSubsciptionDAO().find(dbTransaction, resourceId); + dbs.getDAOFactory().getSubsciptionDAO().delete(dbTransaction, subscriptionEntityToBeDeleted); + dbTransaction.commit(); + dbTransaction.close(); + } + + private static void updateSubscription(String resourceId, Integer nbOfFailedNotification) { + DBService dbs = PersistenceService.getInstance().getDbService(); + DBTransaction dbTransaction = dbs.getDbTransaction(); + dbTransaction.open(); + SubscriptionEntity subscriptionEntityToBeUpdated = dbs.getDAOFactory().getSubsciptionDAO().find(dbTransaction, resourceId); + subscriptionEntityToBeUpdated.setNbOfFailedNotifications(nbOfFailedNotification); + dbs.getDAOFactory().getSubsciptionDAO().update(dbTransaction, subscriptionEntityToBeUpdated); + dbTransaction.commit(); + dbTransaction.close(); + } + +} diff --git a/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/redirector/Redirector.java b/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/redirector/Redirector.java index 1c1fa867..e4695507 100644 --- a/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/redirector/Redirector.java +++ b/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/redirector/Redirector.java @@ -19,6 +19,9 @@ *******************************************************************************/
package org.eclipse.om2m.core.redirector;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.om2m.commons.constants.CSEType;
@@ -120,16 +123,34 @@ public class Redirector { if (url.endsWith("/")) {
LOGGER.debug("Removing / at the end of poa: " + url);
url = url.substring(0, url.length() - 1);
- }
+ } - if (request.getTo().startsWith("//")) {
- url += request.getTo().replaceFirst("//", "/_/");
- } else if (request.getTo().startsWith("/")) {
- url += request.getTo().replaceFirst("/", "/~/");
+ if(url.startsWith("mqtt://")){
+ url += request.getTo();
+ Pattern mqttUriPattern = Pattern.compile("(mqtt://[^:/]*(:[0-9]{1,5})?)(/.*)");
+ Matcher matcher = mqttUriPattern.matcher(url);
+ if(matcher.matches()){
+ // FIXME we need a response but not yet implemented in MQTT binding
+ request.setMqttResponseExpected(true);
+ // TODO Format type can be enhanced
+ request.setMqttTopic("/oneM2M/req/" + Constants.CSE_ID + "/" + csrEntity.getRemoteCseId().replaceAll("/", "") + "/xml");
+ request.setMqttUri(matcher.group(1));
+ } else {
+ LOGGER.warn("Incorrect MQTT URI specified in remoteCSE: " + url);
+ i++;
+ continue;
+ }
} else {
- url += "/" + request.getTo();
+ if(request.getTo().startsWith("//")){
+ url += request.getTo().replaceFirst("//", "/_/");
+ } else if(request.getTo().startsWith("/")){
+ url += request.getTo().replaceFirst("/", "/~/");
+ } else {
+ url+= "/" + request.getTo();
+ }
}
-
+
+ request.setTo(url);
// modify the request if content type is OBJ.
@@ -230,6 +251,26 @@ public class Redirector { done = true;
} else {
request.setTo(poa);
+ if(poa.startsWith("mqtt://")){
+ Pattern mqttUriPattern = Pattern.compile("(mqtt://[^:/]*(:[0-9]{1,5})?)(/.*)?");
+ Matcher matcher = mqttUriPattern.matcher(poa);
+ if(matcher.matches()){
+ String topic = matcher.group(3);
+ String aeId = ae.getAeid();
+ if(topic != null){
+ request.setMqttTopic(topic);
+ request.setMqttResponseExpected(false);
+ } else {
+ request.setMqttTopic("/oneM2M/req/" + Constants.CSE_ID + "/" + aeId + "/xml");
+ request.setMqttResponseExpected(true);
+ }
+ request.setMqttUri(matcher.group(1));
+ } else {
+ LOGGER.warn("POA is incorrect for MQTT: " + poa);
+ i++;
+ continue;
+ }
+ }
response = RestClient.sendRequest(request);
if (!response.getResponseStatusCode().equals(ResponseStatusCode.TARGET_NOT_REACHABLE)) {
done = true;
diff --git a/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/router/Router.java b/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/router/Router.java index 96e3b5f8..9fcc97dd 100644 --- a/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/router/Router.java +++ b/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/router/Router.java @@ -132,6 +132,10 @@ public class Router implements CseService { } // URI Handling + if(request.getTo() == null && request.getTargetId() == null){ + throw new BadRequestException("No To parameter provided provided"); + } + if(request.getTargetId() == null){ request.setTargetId(request.getTo()); } @@ -400,8 +404,10 @@ public class Router implements CseService { if(request.getTo() == null){ request.setTo(request.getTargetId().split("\\?")[0]); - request.setTargetId(request.getTo()); + } else { + request.setTo(request.getTo().split("\\?")[0]); } + request.setTargetId(request.getTo()); } } diff --git a/org.eclipse.om2m.das.testsuite/.project b/org.eclipse.om2m.das.testsuite/.project index 1ec250be..42c8752b 100644 --- a/org.eclipse.om2m.das.testsuite/.project +++ b/org.eclipse.om2m.das.testsuite/.project @@ -11,17 +11,17 @@ </arguments>
</buildCommand>
<buildCommand>
- <name>org.eclipse.m2e.core.maven2Builder</name>
+ <name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
- <name>org.eclipse.pde.ManifestBuilder</name>
+ <name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
- <name>org.eclipse.pde.SchemaBuilder</name>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
diff --git a/org.eclipse.om2m.datamapping.jaxb/src/main/resources/xml-binding.xml b/org.eclipse.om2m.datamapping.jaxb/src/main/resources/xml-binding.xml index 86c1e3d2..af996311 100644 --- a/org.eclipse.om2m.datamapping.jaxb/src/main/resources/xml-binding.xml +++ b/org.eclipse.om2m.datamapping.jaxb/src/main/resources/xml-binding.xml @@ -46,6 +46,19 @@ </java-attributes> </java-type> + <!-- Request and Response Descriptions --> + <java-type name="RequestPrimitive"> + <xml-root-element name="m2m:rqp"/> + </java-type> + + <java-type name="PrimitiveContent"> + <xml-root-element name="pc"/> + </java-type> + + <java-type name="ResponsePrimitive"> + <xml-root-element name="m2m:rsp"/> + </java-type> + <!-- CSE Descriptions --> <java-type name="CSEBase"> <java-attributes> diff --git a/org.eclipse.om2m.persistence.mongodb/.classpath b/org.eclipse.om2m.persistence.mongodb/.classpath index d0ee0e35..00834bcb 100644 --- a/org.eclipse.om2m.persistence.mongodb/.classpath +++ b/org.eclipse.om2m.persistence.mongodb/.classpath @@ -1,9 +1,9 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry exported="true" kind="lib" path="libs/gson-2.2.4.jar"/>
- <classpathentry exported="true" kind="lib" path="libs/mongo-java-driver-3.4.2.jar"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src/main/java/"/> + <classpathentry exported="true" kind="lib" path="libs/gson-2.2.4.jar"/> + <classpathentry exported="true" kind="lib" path="libs/mongo-java-driver-3.4.2.jar"/> + <classpathentry kind="output" path="target/classes"/> +</classpath> diff --git a/org.eclipse.om2m.persistence.mongodb/.project b/org.eclipse.om2m.persistence.mongodb/.project index 5d1ce526..0ff31333 100644 --- a/org.eclipse.om2m.persistence.mongodb/.project +++ b/org.eclipse.om2m.persistence.mongodb/.project @@ -11,17 +11,17 @@ </arguments>
</buildCommand>
<buildCommand>
- <name>org.eclipse.m2e.core.maven2Builder</name>
+ <name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
- <name>org.eclipse.pde.ManifestBuilder</name>
+ <name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
- <name>org.eclipse.pde.SchemaBuilder</name>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
diff --git a/org.eclipse.om2m.sdt/org.eclipse.om2m.sdt.home.lifx/.classpath b/org.eclipse.om2m.sdt/org.eclipse.om2m.sdt.home.lifx/.classpath index 4b1a0198..b82e5828 100644 --- a/org.eclipse.om2m.sdt/org.eclipse.om2m.sdt.home.lifx/.classpath +++ b/org.eclipse.om2m.sdt/org.eclipse.om2m.sdt.home.lifx/.classpath @@ -1,14 +1,8 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="src" path="src/test/java"/>
- <classpathentry exported="true" kind="lib" path="lib/json-simple-1.1.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.2/junit-3.8.2.jar"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src/main/java/"/> + <classpathentry exported="true" kind="lib" path="lib/json-simple-1.1.1.jar"/> + <classpathentry kind="output" path="target/classes"/> +</classpath> diff --git a/org.eclipse.om2m.sdt/org.eclipse.om2m.sdt.home.netatmo/.classpath b/org.eclipse.om2m.sdt/org.eclipse.om2m.sdt.home.netatmo/.classpath index 4b1a0198..b82e5828 100644 --- a/org.eclipse.om2m.sdt/org.eclipse.om2m.sdt.home.netatmo/.classpath +++ b/org.eclipse.om2m.sdt/org.eclipse.om2m.sdt.home.netatmo/.classpath @@ -1,14 +1,8 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="src" path="src/test/java"/>
- <classpathentry exported="true" kind="lib" path="lib/json-simple-1.1.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.2/junit-3.8.2.jar"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src/main/java/"/> + <classpathentry exported="true" kind="lib" path="lib/json-simple-1.1.1.jar"/> + <classpathentry kind="output" path="target/classes"/> +</classpath> diff --git a/org.eclipse.om2m.sdt/org.eclipse.om2m.sdt.home.smartercoffee/.classpath b/org.eclipse.om2m.sdt/org.eclipse.om2m.sdt.home.smartercoffee/.classpath index 99516b1b..98ddc48e 100644 --- a/org.eclipse.om2m.sdt/org.eclipse.om2m.sdt.home.smartercoffee/.classpath +++ b/org.eclipse.om2m.sdt/org.eclipse.om2m.sdt.home.smartercoffee/.classpath @@ -1,13 +1,7 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="src" path="src/test/java"/>
- <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.2/junit-3.8.2.jar"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src/main/java/"/> + <classpathentry kind="output" path="target/classes"/> +</classpath> diff --git a/org.eclipse.om2m.site.in-cse/om2m.product b/org.eclipse.om2m.site.in-cse/om2m.product index 86997e95..8970d530 100644 --- a/org.eclipse.om2m.site.in-cse/om2m.product +++ b/org.eclipse.om2m.site.in-cse/om2m.product @@ -1,135 +1,135 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<?pde version="3.5"?>
-
-<product uid="in-cse" version="1.0.0" useFeatures="false" includeLaunchers="false">
-
- <configIni use="default">
- </configIni>
-
- <launcherArgs>
- <programArgs>-console -noExit --launcher.secondThread
- </programArgs>
- <vmArgs>-ea -Declipse.ignoreApp=true -Dosgi.clean=true -Ddebug=true
- </vmArgs>
- <vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts
- </vmArgsMac>
- </launcherArgs>
-
- <windowImages/>
-
- <launcher name="in-cse">
- <win useIco="false">
- <bmp/>
- </win>
- </launcher>
-
- <vm>
- <linux include="false">org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7</linux>
- <windows include="false">org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7</windows>
- </vm>
-
- <plugins>
- <plugin id="javax.servlet"/>
- <plugin id="javax.xml"/>
- <plugin id="org.apache.commons.codec"/>
- <plugin id="org.apache.commons.logging"/>
- <plugin id="org.apache.felix.gogo.command"/>
- <plugin id="org.apache.felix.gogo.runtime"/>
- <plugin id="org.apache.felix.gogo.shell"/>
- <plugin id="org.apache.httpcomponents.httpclient"/>
- <plugin id="org.apache.httpcomponents.httpcore"/>
- <plugin id="org.eclipse.equinox.cm"/>
- <plugin id="org.eclipse.equinox.console"/>
- <plugin id="org.eclipse.equinox.ds"/>
- <plugin id="org.eclipse.equinox.event"/>
- <plugin id="org.eclipse.equinox.http.jetty"/>
- <plugin id="org.eclipse.equinox.http.servlet"/>
- <plugin id="org.eclipse.equinox.launcher"/>
- <plugin id="org.eclipse.jetty.continuation"/>
- <plugin id="org.eclipse.jetty.http"/>
- <plugin id="org.eclipse.jetty.io"/>
- <plugin id="org.eclipse.jetty.security"/>
- <plugin id="org.eclipse.jetty.server"/>
- <plugin id="org.eclipse.jetty.servlet"/>
- <plugin id="org.eclipse.jetty.util"/>
- <plugin id="org.eclipse.om2m.binding.coap"/>
- <plugin id="org.eclipse.om2m.binding.http"/>
- <plugin id="org.eclipse.om2m.binding.service"/>
- <plugin id="org.eclipse.om2m.commons"/>
- <plugin id="org.eclipse.om2m.commons.logging" fragment="true"/>
- <plugin id="org.eclipse.om2m.core"/>
- <plugin id="org.eclipse.om2m.core.service"/>
- <plugin id="org.eclipse.om2m.das.testsuite"/>
- <plugin id="org.eclipse.om2m.datamapping.jaxb"/>
- <plugin id="org.eclipse.om2m.datamapping.service"/>
- <plugin id="org.eclipse.om2m.ipe.sdt"/>
- <!--plugin id="org.eclipse.om2m.ipe.sdt.testsuite"/-->
- <plugin id="org.eclipse.om2m.persistence.eclipselink"/>
- <plugin id="org.eclipse.om2m.persistence.mongodb"/>
- <plugin id="org.eclipse.om2m.persistence.service"/>
- <plugin id="org.eclipse.om2m.sdt.api"/>
- <plugin id="org.eclipse.om2m.sdt.home"/>
- <plugin id="org.eclipse.om2m.sdt.home.driver"/>
- <plugin id="org.eclipse.om2m.sdt.home.mocked.devices"/>
- <plugin id="org.eclipse.om2m.sdt.home.monitoring"/>
- <plugin id="org.eclipse.om2m.sdt.comparator.xml"/>
- <!--plugin id="org.eclipse.om2m.testsuite.flexcontainer"/-->
- <plugin id="org.eclipse.om2m.webapp.resourcesbrowser.json"/>
- <plugin id="org.eclipse.om2m.webapp.resourcesbrowser.xml"/>
- <plugin id="org.eclipse.osgi"/>
- <plugin id="org.eclipse.osgi.services"/>
- </plugins>
-
- <configurations>
- <plugin id="org.apache.felix.gogo.command" autoStart="true" startLevel="0" />
- <plugin id="org.apache.felix.gogo.runtime" autoStart="true" startLevel="0" />
- <plugin id="org.apache.felix.gogo.shell" autoStart="true" startLevel="0" />
- <plugin id="org.eclipse.equinox.cm" autoStart="true" startLevel="1" />
- <plugin id="org.eclipse.equinox.console" autoStart="true" startLevel="0" />
- <plugin id="org.eclipse.equinox.ds" autoStart="true" startLevel="1" />
- <plugin id="org.eclipse.equinox.event" autoStart="true" startLevel="1" />
- <plugin id="org.eclipse.equinox.http.jetty" autoStart="true" startLevel="1" />
- <plugin id="org.eclipse.om2m.binding.coap" autoStart="true" startLevel="2" />
- <plugin id="org.eclipse.om2m.binding.http" autoStart="true" startLevel="2" />
- <plugin id="org.eclipse.om2m.core" autoStart="true" startLevel="3" />
- <plugin id="org.eclipse.om2m.das.testsuite" autoStart="false" startLevel="6" />
- <plugin id="org.eclipse.om2m.datamapping.jaxb" autoStart="true" startLevel="1" />
- <plugin id="org.eclipse.om2m.ipe.sdt" autoStart="true" startLevel="6" />
- <!--plugin id="org.eclipse.om2m.ipe.sdt.testsuite" autoStart="false" startLevel="6" /-->
- <plugin id="org.eclipse.om2m.persistence.eclipselink" autoStart="true" startLevel="2" />
- <plugin id="org.eclipse.om2m.persistence.mongodb" autoStart="false" startLevel="2" />
- <plugin id="org.eclipse.om2m.sdt.api" autoStart="true" startLevel="5" />
- <plugin id="org.eclipse.om2m.sdt.home" autoStart="true" startLevel="5" />
- <plugin id="org.eclipse.om2m.sdt.home.driver" autoStart="true" startLevel="5" />
- <plugin id="org.eclipse.om2m.sdt.home.mocked.devices" autoStart="false" startLevel="5" />
- <plugin id="org.eclipse.om2m.sdt.home.monitoring" autoStart="false" startLevel="5" />
- <plugin id="org.eclipse.om2m.sdt.comparator.xml" autoStart="false" startLevel="5"/>
- <!--plugin id="org.eclipse.om2m.testsuite.flexcontainer" autoStart="false" startLevel="6" /-->
- <plugin id="org.eclipse.om2m.webapp.resourcesbrowser.json" autoStart="true" startLevel="4" />
- <plugin id="org.eclipse.om2m.webapp.resourcesbrowser.xml" autoStart="false" startLevel="4" />
- <property name="log4j.configuration" value="file:./log4j.configuration" />
- <property name="org.apache.commons.logging.Log" value="org.apache.commons.logging.impl.Log4JLogger" />
- <property name="org.eclipse.equinox.http.jetty.http.port" value="8080" />
- <property name="org.eclipse.om2m.adminRequestingEntity" value="admin:admin" />
- <property name="org.eclipse.om2m.coap.port" value="5683" />
- <property name="org.eclipse.om2m.cseBaseAddress" value="127.0.0.1" />
- <property name="org.eclipse.om2m.cseBaseContext" value="/" />
- <property name="org.eclipse.om2m.cseBaseId" value="in-cse" />
- <property name="org.eclipse.om2m.cseBaseName" value="in-name" />
- <property name="org.eclipse.om2m.cseBaseProtocol.default" value="http" />
- <property name="org.eclipse.om2m.cseType" value="IN-CSE" />
- <property name="org.eclipse.om2m.dbDriver" value="org.h2.Driver" />
- <property name="org.eclipse.om2m.dbPassword" value="om2m" />
- <property name="org.eclipse.om2m.dbReset" value="true" />
- <property name="org.eclipse.om2m.dbUrl" value="jdbc:h2:./data/mndb" />
- <property name="org.eclipse.om2m.dbUrl_mongodb" value="127.0.0.1" />
- <property name="org.eclipse.om2m.dbUser" value="om2m" />
- <property name="org.eclipse.om2m.globalContext" value="" />
- <property name="org.eclipse.om2m.guestRequestingEntity" value="guest:guest" />
- <property name="org.eclipse.om2m.m2mSpId" value="om2m.org" />
- <property name="org.eclipse.om2m.resource.idseparator" value="-" />
- <property name="org.eclipse.om2m.subscriptions.nbOfFailedNotificationsBeforeDeletion" value="3" />
- <property name="org.eclipse.om2m.webInterfaceContext" value="/webpage" />
- </configurations>
-
-</product>
+<?xml version="1.0" encoding="UTF-8"?> +<?pde version="3.5"?> + +<product uid="in-cse" version="1.0.0" useFeatures="false" includeLaunchers="false"> + + <configIni use="default"> + </configIni> + + <launcherArgs> + <programArgs>-console -noExit --launcher.secondThread + </programArgs> + <vmArgs>-ea -Declipse.ignoreApp=true -Dosgi.clean=true -Ddebug=true + </vmArgs> + <vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts + </vmArgsMac> + </launcherArgs> + + <windowImages/> + + <launcher name="in-cse"> + <win useIco="false"> + <bmp/> + </win> + </launcher> + + <vm> + <linux include="false">org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7</linux> + <windows include="false">org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7</windows> + </vm> + + <plugins> + <plugin id="javax.servlet"/> + <plugin id="javax.xml"/> + <plugin id="org.apache.commons.codec"/> + <plugin id="org.apache.commons.logging"/> + <plugin id="org.apache.felix.gogo.command"/> + <plugin id="org.apache.felix.gogo.runtime"/> + <plugin id="org.apache.felix.gogo.shell"/> + <plugin id="org.apache.httpcomponents.httpclient"/> + <plugin id="org.apache.httpcomponents.httpcore"/> + <plugin id="org.eclipse.equinox.cm"/> + <plugin id="org.eclipse.equinox.console"/> + <plugin id="org.eclipse.equinox.ds"/> + <plugin id="org.eclipse.equinox.event"/> + <plugin id="org.eclipse.equinox.http.jetty"/> + <plugin id="org.eclipse.equinox.http.servlet"/> + <plugin id="org.eclipse.equinox.launcher"/> + <plugin id="org.eclipse.jetty.continuation"/> + <plugin id="org.eclipse.jetty.http"/> + <plugin id="org.eclipse.jetty.io"/> + <plugin id="org.eclipse.jetty.security"/> + <plugin id="org.eclipse.jetty.server"/> + <plugin id="org.eclipse.jetty.servlet"/> + <plugin id="org.eclipse.jetty.util"/> + <plugin id="org.eclipse.om2m.binding.coap"/> + <plugin id="org.eclipse.om2m.binding.http"/> + <plugin id="org.eclipse.om2m.binding.service"/> + <plugin id="org.eclipse.om2m.commons"/> + <plugin id="org.eclipse.om2m.commons.logging" fragment="true"/> + <plugin id="org.eclipse.om2m.core"/> + <plugin id="org.eclipse.om2m.core.service"/> + <plugin id="org.eclipse.om2m.das.testsuite"/> + <plugin id="org.eclipse.om2m.datamapping.jaxb"/> + <plugin id="org.eclipse.om2m.datamapping.service"/> + <plugin id="org.eclipse.om2m.ipe.sdt"/> + <!--plugin id="org.eclipse.om2m.ipe.sdt.testsuite"/--> + <plugin id="org.eclipse.om2m.persistence.eclipselink"/> + <plugin id="org.eclipse.om2m.persistence.mongodb"/> + <plugin id="org.eclipse.om2m.persistence.service"/> + <plugin id="org.eclipse.om2m.sdt.api"/> + <plugin id="org.eclipse.om2m.sdt.home"/> + <plugin id="org.eclipse.om2m.sdt.home.driver"/> + <plugin id="org.eclipse.om2m.sdt.home.mocked.devices"/> + <plugin id="org.eclipse.om2m.sdt.home.monitoring"/> + <plugin id="org.eclipse.om2m.sdt.comparator.xml"/> + <!--plugin id="org.eclipse.om2m.testsuite.flexcontainer"/--> + <plugin id="org.eclipse.om2m.webapp.resourcesbrowser.json"/> + <plugin id="org.eclipse.om2m.webapp.resourcesbrowser.xml"/> + <plugin id="org.eclipse.osgi"/> + <plugin id="org.eclipse.osgi.services"/> + </plugins> + + <configurations> + <plugin id="org.apache.felix.gogo.command" autoStart="true" startLevel="0" /> + <plugin id="org.apache.felix.gogo.runtime" autoStart="true" startLevel="0" /> + <plugin id="org.apache.felix.gogo.shell" autoStart="true" startLevel="0" /> + <plugin id="org.eclipse.equinox.cm" autoStart="true" startLevel="1" /> + <plugin id="org.eclipse.equinox.console" autoStart="true" startLevel="0" /> + <plugin id="org.eclipse.equinox.ds" autoStart="true" startLevel="1" /> + <plugin id="org.eclipse.equinox.event" autoStart="true" startLevel="1" /> + <plugin id="org.eclipse.equinox.http.jetty" autoStart="true" startLevel="1" /> + <plugin id="org.eclipse.om2m.binding.coap" autoStart="true" startLevel="2" /> + <plugin id="org.eclipse.om2m.binding.http" autoStart="true" startLevel="2" /> + <plugin id="org.eclipse.om2m.core" autoStart="true" startLevel="3" /> + <plugin id="org.eclipse.om2m.das.testsuite" autoStart="false" startLevel="6" /> + <plugin id="org.eclipse.om2m.datamapping.jaxb" autoStart="true" startLevel="1" /> + <plugin id="org.eclipse.om2m.ipe.sdt" autoStart="true" startLevel="6" /> + <!--plugin id="org.eclipse.om2m.ipe.sdt.testsuite" autoStart="false" startLevel="6" /--> + <plugin id="org.eclipse.om2m.persistence.eclipselink" autoStart="true" startLevel="2" /> + <plugin id="org.eclipse.om2m.persistence.mongodb" autoStart="false" startLevel="2" /> + <plugin id="org.eclipse.om2m.sdt.api" autoStart="true" startLevel="5" /> + <plugin id="org.eclipse.om2m.sdt.home" autoStart="true" startLevel="5" /> + <plugin id="org.eclipse.om2m.sdt.home.driver" autoStart="true" startLevel="5" /> + <plugin id="org.eclipse.om2m.sdt.home.mocked.devices" autoStart="false" startLevel="5" /> + <plugin id="org.eclipse.om2m.sdt.home.monitoring" autoStart="false" startLevel="5" /> + <plugin id="org.eclipse.om2m.sdt.comparator.xml" autoStart="false" startLevel="5"/> + <!--plugin id="org.eclipse.om2m.testsuite.flexcontainer" autoStart="false" startLevel="6" /--> + <plugin id="org.eclipse.om2m.webapp.resourcesbrowser.json" autoStart="true" startLevel="4" /> + <plugin id="org.eclipse.om2m.webapp.resourcesbrowser.xml" autoStart="false" startLevel="4" /> + <property name="log4j.configuration" value="file:./log4j.configuration" /> + <property name="org.apache.commons.logging.Log" value="org.apache.commons.logging.impl.Log4JLogger" /> + <property name="org.eclipse.equinox.http.jetty.http.port" value="8080" /> + <property name="org.eclipse.om2m.adminRequestingEntity" value="admin:admin" /> + <property name="org.eclipse.om2m.coap.port" value="5683" /> + <property name="org.eclipse.om2m.cseBaseAddress" value="127.0.0.1" /> + <property name="org.eclipse.om2m.cseBaseContext" value="/" /> + <property name="org.eclipse.om2m.cseBaseId" value="in-cse" /> + <property name="org.eclipse.om2m.cseBaseName" value="in-name" /> + <property name="org.eclipse.om2m.cseBaseProtocol.default" value="http" /> + <property name="org.eclipse.om2m.cseType" value="IN-CSE" /> + <property name="org.eclipse.om2m.dbDriver" value="org.h2.Driver" /> + <property name="org.eclipse.om2m.dbPassword" value="om2m" /> + <property name="org.eclipse.om2m.dbReset" value="true" /> + <property name="org.eclipse.om2m.dbUrl" value="jdbc:h2:./data/mndb" /> + <property name="org.eclipse.om2m.dbUrl_mongodb" value="127.0.0.1" /> + <property name="org.eclipse.om2m.dbUser" value="om2m" /> + <property name="org.eclipse.om2m.globalContext" value="" /> + <property name="org.eclipse.om2m.guestRequestingEntity" value="guest:guest" /> + <property name="org.eclipse.om2m.m2mSpId" value="om2m.org" /> + <property name="org.eclipse.om2m.resource.idseparator" value="-" /> + <property name="org.eclipse.om2m.subscriptions.nbOfFailedNotificationsBeforeDeletion" value="3" /> + <property name="org.eclipse.om2m.webInterfaceContext" value="/webpage" /> + </configurations> + +</product> diff --git a/org.eclipse.om2m.testsuite.flexcontainer/src/main/java/org/eclipse/om2m/testsuite/flexcontainer/AccessControlPolicyTest.java b/org.eclipse.om2m.testsuite.flexcontainer/src/main/java/org/eclipse/om2m/testsuite/flexcontainer/AccessControlPolicyTest.java index 1bfd494d..b35e3320 100644 --- a/org.eclipse.om2m.testsuite.flexcontainer/src/main/java/org/eclipse/om2m/testsuite/flexcontainer/AccessControlPolicyTest.java +++ b/org.eclipse.om2m.testsuite.flexcontainer/src/main/java/org/eclipse/om2m/testsuite/flexcontainer/AccessControlPolicyTest.java @@ -1,269 +1,270 @@ -/*******************************************************************************
- * Copyright (c) 2014, 2016 Orange.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *******************************************************************************/
-package org.eclipse.om2m.testsuite.flexcontainer;
-
-import org.eclipse.om2m.commons.constants.AccessControl;
-import org.eclipse.om2m.commons.constants.Constants;
-import org.eclipse.om2m.commons.constants.ResponseStatusCode;
-import org.eclipse.om2m.commons.resource.AccessControlPolicy;
-import org.eclipse.om2m.commons.resource.AccessControlRule;
-import org.eclipse.om2m.commons.resource.CustomAttribute;
-import org.eclipse.om2m.commons.resource.ResponsePrimitive;
-import org.eclipse.om2m.commons.resource.SetOfAcrs;
-import org.eclipse.om2m.commons.resource.flexcontainerspec.BinarySwitchFlexContainer;
-import org.eclipse.om2m.core.service.CseService;
-import org.eclipse.om2m.testsuite.flexcontainer.TestReport.Status;
-
-public class AccessControlPolicyTest extends FlexContainerTestSuite {
-
- public AccessControlPolicyTest(final CseService pCseService) {
- super(pCseService);
- }
-
- @Override
- protected String getTestSuiteName() {
- return "AccessControlPolicyTest";
- }
-
- public void testCreateAccessControlPolicy() {
-
- String acpName = "acp_" + System.currentTimeMillis();
- AccessControlPolicy acp = new AccessControlPolicy();
- acp.setName(acpName);
- SetOfAcrs privileges = new SetOfAcrs();
- AccessControlRule accessControlRule = new AccessControlRule();
- accessControlRule.getAccessControlOriginators().add("greg:greg");
- // accessControlRule.getAccessControlOriginators().add("admin:admin");
- accessControlRule.setAccessControlOperations(AccessControl.ALL);
- privileges.getAccessControlRule().add(accessControlRule);
- acp.setPrivileges(privileges);
-
- SetOfAcrs selfPrivileges = new SetOfAcrs();
- AccessControlRule selfAccessControlRule = new AccessControlRule();
- selfAccessControlRule.getAccessControlOriginators().add("admin:admin");
- selfAccessControlRule.setAccessControlOperations(AccessControl.ALL);
- selfPrivileges.getAccessControlRule().add(selfAccessControlRule);
- acp.setSelfPrivileges(selfPrivileges);
-
- String baseLocation = "/" + Constants.CSE_ID + "/" + Constants.CSE_NAME;
-
- String acpLocation = baseLocation + "/" + acpName;
-
- ResponsePrimitive response = sendCreateAccessControlPolicyRequest(acp, baseLocation);
- if (!response.getResponseStatusCode().equals(ResponseStatusCode.CREATED)) {
- // KO
- createTestReport("testAccessControlPolicy", Status.KO, "unable to create a new acp", null);
- return;
- }
- // here are sure the ACP has been created
- AccessControlPolicy returnedAcp = (AccessControlPolicy) response.getContent();
-
- // init a new FlexContainer
- BinarySwitchFlexContainer flexContainer = new BinarySwitchFlexContainer();
- CustomAttribute ca = new CustomAttribute();
- ca.setCustomAttributeName("powSe");
- ca.setCustomAttributeValue("false");
- flexContainer.getCustomAttributes().add(ca);
- String flexContainerName = "flexContainerACPTest_" + System.currentTimeMillis();
- flexContainer.setName(flexContainerName);
- String flexContainerLocation = baseLocation + "/" + flexContainerName;
-
- // set acp
- flexContainer.getAccessControlPolicyIDs().add(returnedAcp.getResourceID());
-
- // send create FlexContainer request
- response = sendCreateFlexContainerRequest(flexContainer, baseLocation, Constants.ADMIN_REQUESTING_ENTITY);
- BinarySwitchFlexContainer createdFlexContainer = null;
- if (!response.getResponseStatusCode().equals(ResponseStatusCode.CREATED)) {
- // KO
- createTestReport("testAccessControlPolicy", Status.KO, "unable to create a FlexContainer", null);
- return;
- } else {
- createdFlexContainer = (BinarySwitchFlexContainer) response.getContent();
- }
-
- // retrieve the flexContainer with greg:greg credentials
- response = sendRetrieveRequest(flexContainerLocation, "greg:greg");
- if (!response.getResponseStatusCode().equals(ResponseStatusCode.OK)) {
- // KO
- createTestReport("testAccessControlPolicy", Status.KO, "unable to retrieve the FlexContainer", null);
- return;
- } else {
- BinarySwitchFlexContainer toBeRetrieved = (BinarySwitchFlexContainer) response.getContent();
- try {
- checkFlexContainer(createdFlexContainer, toBeRetrieved);
- } catch (Exception e) {
- // KO
- createTestReport("testAccessControlPolicy", Status.KO, "flexContainer are differents", null);
- return;
- }
- }
-
- // retrieve the flexContainer with admin:admin, expected FORBIDDEN
- response = sendRetrieveRequest(flexContainerLocation, Constants.ADMIN_REQUESTING_ENTITY);
- if (!response.getResponseStatusCode().equals(ResponseStatusCode.ACCESS_DENIED)) {
- // KO
- createTestReport("testAccessControlPolicy", Status.KO,
- "expected " + ResponseStatusCode.ACCESS_DENIED + ", received:" + response.getResponseStatusCode(),
- null);
- return;
- }
-
- createTestReport("testAccessControlPolicy", Status.OK, null, null);
-
- }
-
- public void testCreateFlexContainerWithNoRight() {
- // create an ACP for greg:greg with RETRIEVE rights
- String acpName = "acp_" + System.currentTimeMillis();
- AccessControlPolicy acp = new AccessControlPolicy();
- acp.setName(acpName);
- SetOfAcrs privileges = new SetOfAcrs();
- AccessControlRule accessControlRule = new AccessControlRule();
- accessControlRule.getAccessControlOriginators().add("greg:greg");
- // accessControlRule.getAccessControlOriginators().add("admin:admin");
- accessControlRule.setAccessControlOperations(AccessControl.RETRIEVE);
- privileges.getAccessControlRule().add(accessControlRule);
- acp.setPrivileges(privileges);
-
- SetOfAcrs selfPrivileges = new SetOfAcrs();
- AccessControlRule selfAccessControlRule = new AccessControlRule();
- selfAccessControlRule.getAccessControlOriginators().add("admin:admin");
- selfAccessControlRule.setAccessControlOperations(AccessControl.ALL);
- selfPrivileges.getAccessControlRule().add(selfAccessControlRule);
- acp.setSelfPrivileges(selfPrivileges);
-
- String baseLocation = "/" + Constants.CSE_ID + "/" + Constants.CSE_NAME;
-
- String acpLocation = baseLocation + "/" + acpName;
-
- ResponsePrimitive response = sendCreateAccessControlPolicyRequest(acp, baseLocation);
- if (!response.getResponseStatusCode().equals(ResponseStatusCode.CREATED)) {
- // KO
- createTestReport("testCreateFlexContainerWithNoRight", Status.KO, "unable to create a new acp", null);
- return;
- }
- // here are sure the ACP has been created
- AccessControlPolicy returnedAcp = (AccessControlPolicy) response.getContent();
-
- // init a new FlexContainer
- String flexContainerName = "flexContainerACPTest_" + System.currentTimeMillis();
- BinarySwitchFlexContainer flexContainer = new BinarySwitchFlexContainer();
- flexContainer.setName(flexContainerName);
- CustomAttribute ca = new CustomAttribute();
- ca.setCustomAttributeName("powSe");
- ca.setCustomAttributeValue("false");
- flexContainer.getCustomAttributes().add(ca);
-
- String flexContainerLocation = baseLocation + "/" + flexContainerName;
-
- // try to create a FlexContainer using greg:greg credentials => expect
- // ACCESS DENIED
- response = sendCreateFlexContainerRequest(flexContainer, baseLocation, "greg:greg");
- if (!response.getResponseStatusCode().equals(ResponseStatusCode.ACCESS_DENIED)) {
- // KO
- createTestReport(
- "testCreateFlexContainerWithNoRight", Status.KO, "error : expected "
- + ResponseStatusCode.ACCESS_DENIED + ", received:" + response.getResponseStatusCode(),
- null);
- return;
- }
-
- createTestReport("testCreateFlexContainerWithNoRight", Status.OK, null, null);
- }
-
- public void testDeleteFlexContainerWithNoRight() {
- // create an ACP for greg:greg with RETRIEVE rights
- String acpName = "acp_" + System.currentTimeMillis();
- AccessControlPolicy acp = new AccessControlPolicy();
- acp.setName(acpName);
- SetOfAcrs privileges = new SetOfAcrs();
- AccessControlRule accessControlRule = new AccessControlRule();
- accessControlRule.getAccessControlOriginators().add("greg:greg");
- // accessControlRule.getAccessControlOriginators().add("admin:admin");
- accessControlRule.setAccessControlOperations(AccessControl.RETRIEVE);
- privileges.getAccessControlRule().add(accessControlRule);
- acp.setPrivileges(privileges);
-
- SetOfAcrs selfPrivileges = new SetOfAcrs();
- AccessControlRule selfAccessControlRule = new AccessControlRule();
- selfAccessControlRule.getAccessControlOriginators().add("admin:admin");
- selfAccessControlRule.setAccessControlOperations(AccessControl.ALL);
- selfPrivileges.getAccessControlRule().add(selfAccessControlRule);
- acp.setSelfPrivileges(selfPrivileges);
-
- String baseLocation = "/" + Constants.CSE_ID + "/" + Constants.CSE_NAME;
-
- String acpLocation = baseLocation + "/" + acpName;
-
- ResponsePrimitive response = sendCreateAccessControlPolicyRequest(acp, baseLocation);
- if (!response.getResponseStatusCode().equals(ResponseStatusCode.CREATED)) {
- // KO
- createTestReport("testDeleteFlexContainerWithNoRight", Status.KO, "unable to create a new acp", null);
- return;
- }
- // here are sure the ACP has been created
- AccessControlPolicy returnedAcp = (AccessControlPolicy) response.getContent();
-
- // init a new FlexContainer
- String flexContainerName = "flexContainerACPTest_" + System.currentTimeMillis();
- BinarySwitchFlexContainer flexContainer = new BinarySwitchFlexContainer();
- flexContainer.setName(flexContainerName);
- flexContainer.setContainerDefinition("org.onem2m.home.moduleclass.binaryswitch");
- CustomAttribute ca = new CustomAttribute();
- ca.setCustomAttributeName("powSe");
- ca.setCustomAttributeValue("false");
- flexContainer.getCustomAttributes().add(ca);
-
- String flexContainerLocation = baseLocation + "/" + flexContainerName;
-
- // try to create a FlexContainer using admin:admin credentials
- BinarySwitchFlexContainer createdFlexContainer = null;
- response = sendCreateFlexContainerRequest(flexContainer, baseLocation,
- Constants.ADMIN_REQUESTING_ENTITY);
- if (!response.getResponseStatusCode().equals(ResponseStatusCode.CREATED)) {
- // KO
- createTestReport("testDeleteFlexContainerWithNoRight", Status.KO,
- "error : expected " + ResponseStatusCode.CREATED + ", received:" + response.getResponseStatusCode(),
- null);
- return;
- } else {
- createdFlexContainer = (BinarySwitchFlexContainer) response.getContent();
- }
-
- // try to delete the flexContainer with greg:greg ==> expect
- // ACCESS_DENIED
- response = sendDeleteRequest(flexContainerLocation, "greg:greg");
- if (!response.getResponseStatusCode().equals(ResponseStatusCode.ACCESS_DENIED)) {
- createTestReport(
- "testDeleteFlexContainerWithNoRight", Status.KO, "error : expected "
- + ResponseStatusCode.ACCESS_DENIED + ", received:" + response.getResponseStatusCode(),
- null);
- return;
- }
-
- // try to retrieve the FlexContainer using greg:greg credentials ==> ok
- response = sendRetrieveRequest(flexContainerLocation, "greg:greg");
- if (!response.getResponseStatusCode().equals(ResponseStatusCode.OK)) {
- createTestReport("testDeleteFlexContainerWithNoRight", Status.KO,
- "error : expected " + ResponseStatusCode.OK + ", received:" + response.getResponseStatusCode(),
- null);
- return;
- } else {
- try {
- checkFlexContainer(createdFlexContainer, (BinarySwitchFlexContainer) response.getContent());
- } catch (Exception e) {
- // KO
- createTestReport("testDeleteFlexContainerWithNoRight", Status.KO,
- "flexContainers are differents:" + e.getMessage(), e);
- }
- }
-
- createTestReport("testDeleteFlexContainerWithNoRight", Status.OK, null, null);
- }
-}
+/******************************************************************************* + * Copyright (c) 2014, 2016 Orange. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.om2m.testsuite.flexcontainer; + +import org.eclipse.om2m.commons.constants.AccessControl; +import org.eclipse.om2m.commons.constants.Constants; +import org.eclipse.om2m.commons.constants.ResponseStatusCode; +import org.eclipse.om2m.commons.resource.AccessControlPolicy; +import org.eclipse.om2m.commons.resource.AccessControlRule; +import org.eclipse.om2m.commons.resource.CustomAttribute; +import org.eclipse.om2m.commons.resource.ResponsePrimitive; +import org.eclipse.om2m.commons.resource.SetOfAcrs; +import org.eclipse.om2m.commons.resource.flexcontainerspec.BinarySwitchFlexContainer; +import org.eclipse.om2m.core.service.CseService; +import org.eclipse.om2m.testsuite.flexcontainer.TestReport.Status; + +public class AccessControlPolicyTest extends FlexContainerTestSuite { + + public AccessControlPolicyTest(final CseService pCseService) { + super(pCseService); + } + + @Override + protected String getTestSuiteName() { + return "AccessControlPolicyTest"; + } + + public void testCreateAccessControlPolicy() { + + String acpName = "acp_" + System.currentTimeMillis(); + AccessControlPolicy acp = new AccessControlPolicy(); + acp.setName(acpName); + SetOfAcrs privileges = new SetOfAcrs(); + AccessControlRule accessControlRule = new AccessControlRule(); + accessControlRule.getAccessControlOriginators().add("greg:greg"); + // accessControlRule.getAccessControlOriginators().add("admin:admin"); + accessControlRule.setAccessControlOperations(AccessControl.ALL); + privileges.getAccessControlRule().add(accessControlRule); + acp.setPrivileges(privileges); + + SetOfAcrs selfPrivileges = new SetOfAcrs(); + AccessControlRule selfAccessControlRule = new AccessControlRule(); + selfAccessControlRule.getAccessControlOriginators().add("admin:admin"); + selfAccessControlRule.setAccessControlOperations(AccessControl.ALL); + selfPrivileges.getAccessControlRule().add(selfAccessControlRule); + acp.setSelfPrivileges(selfPrivileges); + + String baseLocation = "/" + Constants.CSE_ID + "/" + Constants.CSE_NAME; + + String acpLocation = baseLocation + "/" + acpName; + + ResponsePrimitive response = sendCreateAccessControlPolicyRequest(acp, baseLocation); + if (!response.getResponseStatusCode().equals(ResponseStatusCode.CREATED)) { + // KO + createTestReport("testAccessControlPolicy", Status.KO, "unable to create a new acp", null); + return; + } + // here are sure the ACP has been created + AccessControlPolicy returnedAcp = (AccessControlPolicy) response.getContent(); + + // init a new FlexContainer + BinarySwitchFlexContainer flexContainer = new BinarySwitchFlexContainer(); + CustomAttribute ca = new CustomAttribute(); + ca.setCustomAttributeName("powSe"); + ca.setCustomAttributeValue("false"); + flexContainer.getCustomAttributes().add(ca); + String flexContainerName = "flexContainerACPTest_" + System.currentTimeMillis(); + flexContainer.setName(flexContainerName); + String flexContainerLocation = baseLocation + "/" + flexContainerName; + + // set acp + flexContainer.getAccessControlPolicyIDs().add(returnedAcp.getResourceID()); + + // send create FlexContainer request + response = sendCreateFlexContainerRequest(flexContainer, baseLocation, Constants.ADMIN_REQUESTING_ENTITY); + BinarySwitchFlexContainer createdFlexContainer = null; + if (!response.getResponseStatusCode().equals(ResponseStatusCode.CREATED)) { + // KO + createTestReport("testAccessControlPolicy", Status.KO, "unable to create a FlexContainer", null); + return; + } else { + createdFlexContainer = (BinarySwitchFlexContainer) response.getContent(); + } + + // retrieve the flexContainer with greg:greg credentials + response = sendRetrieveRequest(flexContainerLocation, "greg:greg"); + if (!response.getResponseStatusCode().equals(ResponseStatusCode.OK)) { + // KO + createTestReport("testAccessControlPolicy", Status.KO, "unable to retrieve the FlexContainer", null); + return; + } else { + BinarySwitchFlexContainer toBeRetrieved = (BinarySwitchFlexContainer) response.getContent(); + try { + checkFlexContainer(createdFlexContainer, toBeRetrieved); + } catch (Exception e) { + // KO + createTestReport("testAccessControlPolicy", Status.KO, "flexContainer are differents", null); + return; + } + } + + // retrieve the flexContainer with admin:admin, expected FORBIDDEN + response = sendRetrieveRequest(flexContainerLocation, Constants.ADMIN_REQUESTING_ENTITY); + if (!response.getResponseStatusCode().equals(ResponseStatusCode.ACCESS_DENIED)) { + // KO + createTestReport("testAccessControlPolicy", Status.KO, + "expected " + ResponseStatusCode.ACCESS_DENIED + ", received:" + response.getResponseStatusCode(), + null); + return; + } + + createTestReport("testAccessControlPolicy", Status.OK, null, null); + + } + + public void testCreateFlexContainerWithNoRight() { + // create an ACP for greg:greg with RETRIEVE rights + String acpName = "acp_" + System.currentTimeMillis(); + AccessControlPolicy acp = new AccessControlPolicy(); + acp.setName(acpName); + SetOfAcrs privileges = new SetOfAcrs(); + AccessControlRule accessControlRule = new AccessControlRule(); + accessControlRule.getAccessControlOriginators().add("greg:greg"); + // accessControlRule.getAccessControlOriginators().add("admin:admin"); + accessControlRule.setAccessControlOperations(AccessControl.RETRIEVE); + privileges.getAccessControlRule().add(accessControlRule); + acp.setPrivileges(privileges); + + SetOfAcrs selfPrivileges = new SetOfAcrs(); + AccessControlRule selfAccessControlRule = new AccessControlRule(); + selfAccessControlRule.getAccessControlOriginators().add("admin:admin"); + selfAccessControlRule.setAccessControlOperations(AccessControl.ALL); + selfPrivileges.getAccessControlRule().add(selfAccessControlRule); + acp.setSelfPrivileges(selfPrivileges); + + String baseLocation = "/" + Constants.CSE_ID + "/" + Constants.CSE_NAME; + + String acpLocation = baseLocation + "/" + acpName; + + ResponsePrimitive response = sendCreateAccessControlPolicyRequest(acp, baseLocation); + if (!response.getResponseStatusCode().equals(ResponseStatusCode.CREATED)) { + // KO + createTestReport("testCreateFlexContainerWithNoRight", Status.KO, "unable to create a new acp", null); + return; + } + // here are sure the ACP has been created + AccessControlPolicy returnedAcp = (AccessControlPolicy) response.getContent(); + + // init a new FlexContainer + String flexContainerName = "flexContainerACPTest_" + System.currentTimeMillis(); + BinarySwitchFlexContainer flexContainer = new BinarySwitchFlexContainer(); + flexContainer.setName(flexContainerName); + CustomAttribute ca = new CustomAttribute(); + ca.setCustomAttributeName("powSe"); + ca.setCustomAttributeValue("false"); + flexContainer.getCustomAttributes().add(ca); + + String flexContainerLocation = baseLocation + "/" + flexContainerName; + + // try to create a FlexContainer using greg:greg credentials => expect + // ACCESS DENIED + response = sendCreateFlexContainerRequest(flexContainer, baseLocation, "greg:greg"); + if (!response.getResponseStatusCode().equals(ResponseStatusCode.ACCESS_DENIED)) { + // KO + createTestReport( + "testCreateFlexContainerWithNoRight", Status.KO, "error : expected " + + ResponseStatusCode.ACCESS_DENIED + ", received:" + response.getResponseStatusCode(), + null); + return; + } + + createTestReport("testCreateFlexContainerWithNoRight", Status.OK, null, null); + } + + public void testDeleteFlexContainerWithNoRight() { + // create an ACP for greg:greg with RETRIEVE rights + String acpName = "acp_" + System.currentTimeMillis(); + AccessControlPolicy acp = new AccessControlPolicy(); + acp.setName(acpName); + SetOfAcrs privileges = new SetOfAcrs(); + AccessControlRule accessControlRule = new AccessControlRule(); + accessControlRule.getAccessControlOriginators().add("greg:greg"); + // accessControlRule.getAccessControlOriginators().add("admin:admin"); + accessControlRule.setAccessControlOperations(AccessControl.RETRIEVE); + privileges.getAccessControlRule().add(accessControlRule); + acp.setPrivileges(privileges); + + SetOfAcrs selfPrivileges = new SetOfAcrs(); + AccessControlRule selfAccessControlRule = new AccessControlRule(); + selfAccessControlRule.getAccessControlOriginators().add("admin:admin"); + selfAccessControlRule.setAccessControlOperations(AccessControl.ALL); + selfPrivileges.getAccessControlRule().add(selfAccessControlRule); + acp.setSelfPrivileges(selfPrivileges); + + String baseLocation = "/" + Constants.CSE_ID + "/" + Constants.CSE_NAME; + + String acpLocation = baseLocation + "/" + acpName; + + ResponsePrimitive response = sendCreateAccessControlPolicyRequest(acp, baseLocation); + if (!response.getResponseStatusCode().equals(ResponseStatusCode.CREATED)) { + // KO + createTestReport("testDeleteFlexContainerWithNoRight", Status.KO, "unable to create a new acp", null); + return; + } + // here are sure the ACP has been created + AccessControlPolicy returnedAcp = (AccessControlPolicy) response.getContent(); + + // init a new FlexContainer + String flexContainerName = "flexContainerACPTest_" + System.currentTimeMillis(); + BinarySwitchFlexContainer flexContainer = new BinarySwitchFlexContainer(); + flexContainer.setName(flexContainerName); + flexContainer.setContainerDefinition("org.onem2m.home.moduleclass.binaryswitch"); + CustomAttribute ca = new CustomAttribute(); + ca.setCustomAttributeName("powSe"); + ca.setCustomAttributeValue("false"); + flexContainer.getCustomAttributes().add(ca); + + String flexContainerLocation = baseLocation + "/" + flexContainerName; + + // try to create a FlexContainer using admin:admin credentials + BinarySwitchFlexContainer createdFlexContainer = null; + response = sendCreateFlexContainerRequest(flexContainer, baseLocation, + Constants.ADMIN_REQUESTING_ENTITY); + if (!response.getResponseStatusCode().equals(ResponseStatusCode.CREATED)) { + // KO + createTestReport("testDeleteFlexContainerWithNoRight", Status.KO, + "error : expected " + ResponseStatusCode.CREATED + ", received:" + response.getResponseStatusCode(), + null); + return; + } else { + createdFlexContainer = (BinarySwitchFlexContainer) response.getContent(); + } + + // try to delete the flexContainer with greg:greg ==> expect + // ACCESS_DENIED + response = sendDeleteRequest(flexContainerLocation, "greg:greg"); + if (!response.getResponseStatusCode().equals(ResponseStatusCode.ACCESS_DENIED)) { + createTestReport( + "testDeleteFlexContainerWithNoRight", Status.KO, "error : expected " + + ResponseStatusCode.ACCESS_DENIED + ", received:" + response.getResponseStatusCode(), + null); + return; + } + + // try to retrieve the FlexContainer using greg:greg credentials ==> ok + response = sendRetrieveRequest(flexContainerLocation, "greg:greg"); + if (!response.getResponseStatusCode().equals(ResponseStatusCode.OK)) { + createTestReport("testDeleteFlexContainerWithNoRight", Status.KO, + "error : expected " + ResponseStatusCode.OK + ", received:" + response.getResponseStatusCode(), + null); + return; + } else { + try { + checkFlexContainer(createdFlexContainer, (BinarySwitchFlexContainer) response.getContent()); + } catch (Exception e) { + // KO + createTestReport("testDeleteFlexContainerWithNoRight", Status.KO, + "flexContainers are differents:" + e.getMessage(), e); + } + } + + createTestReport("testDeleteFlexContainerWithNoRight", Status.OK, null, null); + } +} + diff --git a/org.eclipse.om2m.testsuite.flexcontainer/src/main/java/org/eclipse/om2m/testsuite/flexcontainer/Activator.java b/org.eclipse.om2m.testsuite.flexcontainer/src/main/java/org/eclipse/om2m/testsuite/flexcontainer/Activator.java index 696101b2..415794de 100644 --- a/org.eclipse.om2m.testsuite.flexcontainer/src/main/java/org/eclipse/om2m/testsuite/flexcontainer/Activator.java +++ b/org.eclipse.om2m.testsuite.flexcontainer/src/main/java/org/eclipse/om2m/testsuite/flexcontainer/Activator.java @@ -169,6 +169,7 @@ public class Activator implements BundleActivator { subscriptionTest.executeTestsAndPrintReports();
}
+
AccessControlPolicyTest acpTest = new AccessControlPolicyTest(currentCseService);
acpTest.executeTestsAndPrintReports();
tests.add(acpTest);
diff --git a/org.eclipse.om2m.testsuite.flexcontainer/src/main/java/org/eclipse/om2m/testsuite/flexcontainer/SubscriptionTest.java b/org.eclipse.om2m.testsuite.flexcontainer/src/main/java/org/eclipse/om2m/testsuite/flexcontainer/SubscriptionTest.java index 9cfab539..99ccffe7 100644 --- a/org.eclipse.om2m.testsuite.flexcontainer/src/main/java/org/eclipse/om2m/testsuite/flexcontainer/SubscriptionTest.java +++ b/org.eclipse.om2m.testsuite.flexcontainer/src/main/java/org/eclipse/om2m/testsuite/flexcontainer/SubscriptionTest.java @@ -9,7 +9,6 @@ package org.eclipse.om2m.testsuite.flexcontainer; import java.util.List;
-import javax.servlet.ServletException;
import org.eclipse.om2m.commons.constants.Constants;
import org.eclipse.om2m.commons.constants.NotificationContentType;
@@ -26,6 +25,8 @@ import org.eclipse.om2m.datamapping.service.DataMapperService; import org.eclipse.om2m.testsuite.flexcontainer.TestReport.Status;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
+import javax.servlet.ServletException;
+
public class SubscriptionTest extends FlexContainerTestSuite {
@@ -127,6 +127,7 @@ <module>org.eclipse.om2m.commons.logging</module> <module>org.eclipse.om2m.binding.http</module> <module>org.eclipse.om2m.binding.coap</module> + <module>org.eclipse.om2m.binding.mqtt</module> <module>org.eclipse.om2m.binding.service</module> <module>org.eclipse.om2m.core.service</module> <module>org.eclipse.om2m.datamapping.jaxb</module> |