Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Munilla2019-06-25 10:37:51 -0400
committerChristophe Munilla2019-06-25 10:37:51 -0400
commitd3c952c6f566f67050c7a0d6d4e28e0a8e90a8ec (patch)
tree238bfa3a267c10eb7acc0f89602a327da5ebec8f
parent32f036fb38c298d8cf5554cb0b1a982b2f7a9dd3 (diff)
downloadorg.eclipse.sensinact.gateway-d3c952c6f566f67050c7a0d6d4e28e0a8e90a8ec.tar.gz
org.eclipse.sensinact.gateway-d3c952c6f566f67050c7a0d6d4e28e0a8e90a8ec.tar.xz
org.eclipse.sensinact.gateway-d3c952c6f566f67050c7a0d6d4e28e0a8e90a8ec.zip
Use Whiteboard pattern
update the rest-access module to use the whiteboard pattern instead of the deprecated HttpService and ExtHttpService Update tests and reactivate them
-rw-r--r--platform/northbound/rest-access/pom.xml161
-rw-r--r--platform/northbound/rest-access/src/main/java/org/eclipse/sensinact/gateway/nthbnd/rest/osgi/Activator.java202
-rw-r--r--platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestACTAccess.java7
-rw-r--r--platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestAccess.java67
-rw-r--r--platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestGETAccess.java16
-rw-r--r--platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestSETAccess.java8
-rw-r--r--platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestSUBSCRIBE_UNSUBSCRIBEAccess.java6
-rw-r--r--platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/server/JettyTestServer.java25
-rw-r--r--platform/northbound/rest-access/src/test/resources/sensinact.config3
9 files changed, 304 insertions, 191 deletions
diff --git a/platform/northbound/rest-access/pom.xml b/platform/northbound/rest-access/pom.xml
index e9ecaacd..c36c03ef 100644
--- a/platform/northbound/rest-access/pom.xml
+++ b/platform/northbound/rest-access/pom.xml
@@ -62,17 +62,25 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- <version>3.1.0</version>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.http.servlet-api</artifactId>
+ <version>1.1.2</version>
<scope>provided</scope>
</dependency>
+ <!--
<dependency>
<groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.http.jetty</artifactId>
+ <artifactId>org.apache.felix.http.api</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
+ -->
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.http.jetty</artifactId>
+ <version>4.0.8</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.main</artifactId>
@@ -156,34 +164,98 @@
<phase>generate-test-resources</phase>
<configuration>
<artifactItems>
+
+ <artifactItem>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.annotation</artifactId>
+ <version>6.0.1</version>
+ <outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
+ <destFileName>osgi.annotation.jar</destFileName>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.component</artifactId>
+ <version>1.4.0</version>
+ <outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
+ <destFileName>org.osgi.service.component.jar</destFileName>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.cm</artifactId>
+ <version>1.6.0</version>
+ <outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
+ <destFileName>org.osgi.service.cm.jar</destFileName>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.metatype</artifactId>
+ <version>1.3.0</version>
+ <outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
+ <destFileName>org.osgi.service.metatype.jar</destFileName>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.namespace.extender</artifactId>
+ <version>1.0.1</version>
+ <outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
+ <destFileName>org.osgi.namespace.extender.jar</destFileName>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.util.promise</artifactId>
+ <version>1.0.0</version>
+ <outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
+ <destFileName>org.osgi.util.promise.jar</destFileName>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.util.function</artifactId>
+ <version>1.0.0</version>
+ <outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
+ <destFileName>org.osgi.util.function.jar</destFileName>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.log</artifactId>
+ <version>1.3.0</version>
+ <outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
+ <destFileName>org.osgi.service.log.jar</destFileName>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.log</artifactId>
+ <version>1.2.0</version>
+ <outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
+ <destFileName>org.apache.felix.log.jar</destFileName>
+ </artifactItem>
<artifactItem>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.fileinstall</artifactId>
- <version>${felix.fileinstall.version}</version>
+ <version>3.6.4</version>
<outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
<destFileName>org.apache.felix.fileinstall.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.configadmin</artifactId>
- <version>${felix.configadmin.version}</version>
+ <version>1.9.12</version>
<outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
<destFileName>org.apache.felix.configadmin.jar</destFileName>
- </artifactItem>
- <artifactItem>
- <groupId>org.osgi</groupId>
- <artifactId>osgi.cmpn</artifactId>
- <version>${osgi.compendium.version}</version>
- <outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
- <destFileName>org.osgi.compendium.jar</destFileName>
- </artifactItem>
+ </artifactItem>
<artifactItem>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework.security</artifactId>
- <version>2.4.0</version>
+ <version>2.6.1</version>
<outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
<destFileName>org.apache.felix.framework.security.jar</destFileName>
</artifactItem>
+ <artifactItem>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr</artifactId>
+ <version>2.1.16</version>
+ <outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
+ <destFileName>org.apache.felix.scr.jar</destFileName>
+ </artifactItem>
<artifactItem>
<groupId>org.eclipse.sensinact.gateway</groupId>
<artifactId>sensinact-utils</artifactId>
@@ -206,6 +278,20 @@
<destFileName>sensinact-datastore-api.jar</destFileName>
</artifactItem>
<artifactItem>
+ <groupId>org.eclipse.sensinact.gateway.sthbnd.mqtt</groupId>
+ <artifactId>mqtt-utils</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ <outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
+ <destFileName>mqtt-utils.jar</destFileName>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.eclipse.paho</groupId>
+ <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
+ <version>1.2.0</version>
+ <outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
+ <destFileName>org.eclipse.paho.client.mqttv3.jar</destFileName>
+ </artifactItem>
+ <artifactItem>
<groupId>org.eclipse.sensinact.gateway</groupId>
<artifactId>sensinact-core</artifactId>
<version>${project.version}</version>
@@ -221,26 +307,12 @@
</artifactItem>
<artifactItem>
<groupId>org.eclipse.sensinact.gateway</groupId>
- <artifactId>sensinact-framework-extension</artifactId>
- <version>${project.version}</version>
- <outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
- <destFileName>sensinact-framework-extension.jar</destFileName>
- </artifactItem>
- <artifactItem>
- <groupId>org.eclipse.sensinact.gateway</groupId>
<artifactId>sensinact-security-none</artifactId>
<version>${project.version}</version>
<outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
<destFileName>sensinact-security-none.jar</destFileName>
</artifactItem>
<artifactItem>
- <groupId>org.eclipse.sensinact.gateway.tools</groupId>
- <artifactId>sensinact-test-configuration</artifactId>
- <version>${project.version}</version>
- <outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
- <destFileName>sensinact-test-configuration.jar</destFileName>
- </artifactItem>
- <artifactItem>
<groupId>org.eclipse.sensinact.gateway</groupId>
<artifactId>sensinact-generic</artifactId>
<version>${project.version}</version>
@@ -253,7 +325,21 @@
<version>${project.version}</version>
<outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
<destFileName>sensinact-northbound-access.jar</destFileName>
- </artifactItem>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.25</version>
+ <outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
+ <destFileName>slf4j-api.jar</destFileName>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.7.16</version>
+ <outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
+ <destFileName>slf4j-simple.jar</destFileName>
+ </artifactItem>
<artifactItem>
<groupId>org.eclipse.sensinact.gateway.protocol</groupId>
<artifactId>http</artifactId>
@@ -262,23 +348,16 @@
<destFileName>http.jar</destFileName>
</artifactItem>
<artifactItem>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- <version>3.1.0</version>
- <outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
- <destFileName>javax.servlet-api.jar</destFileName>
- </artifactItem>
- <artifactItem>
<groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.http.api</artifactId>
- <version>2.3.2</version>
+ <artifactId>org.apache.felix.http.servlet-api</artifactId>
+ <version>1.1.2</version>
<outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
- <destFileName>org.apache.felix.http.api.jar</destFileName>
+ <destFileName>org.apache.felix.http.servlet-api.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.http.jetty</artifactId>
- <version>3.0.0</version>
+ <version>4.0.8</version>
<outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
<destFileName>org.apache.felix.http.jetty.jar</destFileName>
</artifactItem>
diff --git a/platform/northbound/rest-access/src/main/java/org/eclipse/sensinact/gateway/nthbnd/rest/osgi/Activator.java b/platform/northbound/rest-access/src/main/java/org/eclipse/sensinact/gateway/nthbnd/rest/osgi/Activator.java
index 535dc3c0..4ddc47ab 100644
--- a/platform/northbound/rest-access/src/main/java/org/eclipse/sensinact/gateway/nthbnd/rest/osgi/Activator.java
+++ b/platform/northbound/rest-access/src/main/java/org/eclipse/sensinact/gateway/nthbnd/rest/osgi/Activator.java
@@ -10,12 +10,20 @@
*/
package org.eclipse.sensinact.gateway.nthbnd.rest.osgi;
-import org.apache.felix.http.api.ExtHttpService;
+import java.io.IOException;
+import java.util.Hashtable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.servlet.Filter;
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
import org.eclipse.sensinact.gateway.common.bundle.AbstractActivator;
-import org.eclipse.sensinact.gateway.common.bundle.Mediator;
-import org.eclipse.sensinact.gateway.common.execution.Executable;
import org.eclipse.sensinact.gateway.nthbnd.endpoint.NorthboundMediator;
import org.eclipse.sensinact.gateway.nthbnd.rest.internal.RestAccessConstants;
import org.eclipse.sensinact.gateway.nthbnd.rest.internal.http.CorsFilter;
@@ -23,35 +31,14 @@ import org.eclipse.sensinact.gateway.nthbnd.rest.internal.http.HttpEndpoint;
import org.eclipse.sensinact.gateway.nthbnd.rest.internal.http.HttpLoginEndpoint;
import org.eclipse.sensinact.gateway.nthbnd.rest.internal.http.HttpRegisteringEndpoint;
import org.eclipse.sensinact.gateway.nthbnd.rest.internal.ws.WebSocketConnectionFactory;
-import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.wiring.BundleWiring;
-import org.osgi.service.http.HttpContext;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
/**
* @see AbstractActivator
*/
public class Activator extends AbstractActivator<NorthboundMediator> {
- private static final ClassLoader getJettyBundleClassLoader(BundleContext context) {
- Bundle[] bundles = context.getBundles();
- int index = 0;
- int length = bundles == null ? 0 : bundles.length;
-
- ClassLoader loader = null;
-
- for (; index < length; index++) {
- if ("org.apache.felix.http.jetty".equals(bundles[index].getSymbolicName())) {
- BundleWiring wiring = bundles[index].adapt(BundleWiring.class);
- loader = wiring.getClassLoader();
- break;
- }
- }
- return loader;
- }
-
+
private CorsFilter corsFilter = null;
private boolean corsHeader = false;
@@ -60,72 +47,89 @@ public class Activator extends AbstractActivator<NorthboundMediator> {
* @see org.eclipse.sensinact.gateway.common.bundle.AbstractActivator#
* doStart()
*/
- public void doStart() throws Exception {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public void doStart() throws Exception {
this.corsHeader = Boolean.valueOf((String) super.mediator.getProperty(RestAccessConstants.CORS_HEADER));
- mediator.attachOnServiceAppearing(ExtHttpService.class, null, new Executable<ExtHttpService, Void>() {
- /**
- * @inheritDoc
- *
- * @see org.eclipse.sensinact.gateway.common.execution.Executable#execute(java.lang.Object)
- */
- public Void execute(ExtHttpService service) {
- if (Activator.this.corsHeader) {
- Activator.this.corsFilter = new CorsFilter(mediator);
- try {
- service.registerFilter(corsFilter, ".*", null, 0, null);
- Activator.this.mediator.info("CORS filter registered");
- } catch (Exception e) {
- mediator.error(e);
- }
+ if (Activator.this.corsHeader) {
+ Activator.this.corsFilter = new CorsFilter(mediator);
+ mediator.register(Activator.this.corsFilter, Filter.class, new Hashtable() {{
+ this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN, "/");
+ this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_DISPATCHER, HttpWhiteboardConstants.DISPATCHER_ASYNC);
}
- try {
- Dictionary<String, Object> params = new Hashtable<String, Object>();
- params.put(Mediator.class.getCanonicalName(), Activator.this.mediator);
-
- HttpContext context = service.createDefaultHttpContext();
- service.registerServlet(RestAccessConstants.LOGIN_ENDPOINT, new HttpLoginEndpoint(mediator), params, context);
- Activator.this.mediator.info(String.format("%s servlet registered", RestAccessConstants.LOGIN_ENDPOINT));
-
- params = new Hashtable<String, Object>();
- params.put(Mediator.class.getCanonicalName(), Activator.this.mediator);
-
- context = service.createDefaultHttpContext();
- service.registerServlet(RestAccessConstants.REGISTERING_ENDPOINT, new HttpRegisteringEndpoint(mediator), params, context);
- Activator.this.mediator.info(String.format("%s servlet registered", RestAccessConstants.REGISTERING_ENDPOINT));
-
- params = new Hashtable<String, Object>();
- params.put(Mediator.class.getCanonicalName(), Activator.this.mediator);
-
- context = service.createDefaultHttpContext();
- service.registerServlet(RestAccessConstants.HTTP_ROOT, new HttpEndpoint(mediator), params, context);
- Activator.this.mediator.info(String.format("%s servlet registered", RestAccessConstants.HTTP_ROOT));
-
- final WebSocketConnectionFactory sessionPool = new WebSocketConnectionFactory(Activator.this.mediator);
- //define the current thread classloader to avoid ServiceLoader error
- ClassLoader current = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(Activator.getJettyBundleClassLoader(mediator.getContext()));
- try {
- service.registerServlet(RestAccessConstants.WS_ROOT, new WebSocketServlet() {
- @Override
- public void configure(WebSocketServletFactory factory) {
- factory.getPolicy().setIdleTimeout(1000 * 3600);
- factory.setCreator(sessionPool);
- }
-
- ;
- }, params, context);
-
- } finally {
- Thread.currentThread().setContextClassLoader(current);
- }
- mediator.info(String.format("%s servlet registered", RestAccessConstants.WS_ROOT));
- } catch (Exception e) {
- mediator.error(e);
- }
- return null;
+ });
+ }
+ mediator.register(new HttpLoginEndpoint(mediator), Servlet.class, new Hashtable() {{
+ this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, RestAccessConstants.LOGIN_ENDPOINT);
+ this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED,true);
+ }
+ });
+ Activator.this.mediator.info(String.format("%s servlet registered", RestAccessConstants.LOGIN_ENDPOINT));
+ mediator.register(new HttpRegisteringEndpoint(mediator), Servlet.class, new Hashtable() {{
+ this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, RestAccessConstants.REGISTERING_ENDPOINT);
+ this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED,true);
+ }
+ });
+ Activator.this.mediator.info(String.format("%s servlet registered", RestAccessConstants.REGISTERING_ENDPOINT));
+ mediator.register(new HttpEndpoint(mediator), Servlet.class, new Hashtable() {{
+ this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, RestAccessConstants.HTTP_ROOT);
+ this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED,true);
+ }
+ });
+ Activator.this.mediator.info(String.format("%s servlet registered", RestAccessConstants.HTTP_ROOT));
+ mediator.register(new WebSocketServlet() {
+ private static final long serialVersionUID = 1L;
+ private WebSocketConnectionFactory sessionPool = new WebSocketConnectionFactory(Activator.this.mediator);
+
+ private final AtomicBoolean firstCall = new AtomicBoolean(true);
+
+ private final CountDownLatch initBarrier = new CountDownLatch(1);
+ @Override
+ public void init() throws ServletException {
+ mediator.info("The Echo servlet has been initialized, but we delay initialization until the first request so that a Jetty Context is available");
+ }
+
+ @Override
+ public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException {
+ if(firstCall.compareAndSet(true, false)) {
+ try {
+ delayedInit();
+ } finally {
+ initBarrier.countDown();
+ }
+ } else {
+ try {
+ initBarrier.await();
+ } catch (InterruptedException e) {
+ throw new ServletException("Timed out waiting for initialisation", e);
+ }
+ }
+
+ super.service(arg0, arg1);
+ }
+
+ private void delayedInit() throws ServletException {
+ Thread currentThread = Thread.currentThread();
+ ClassLoader tccl = currentThread.getContextClassLoader();
+ currentThread.setContextClassLoader(WebSocketServlet.class.getClassLoader());
+ try {
+ super.init();
+ } finally {
+ currentThread.setContextClassLoader(tccl);
+ }
+ }
+
+ @Override
+ public void configure(WebSocketServletFactory factory) {
+ factory.getPolicy().setIdleTimeout(1000 * 3600);
+ factory.setCreator(sessionPool);
+ };
+ }, Servlet.class, new Hashtable() {{
+ this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, RestAccessConstants.WS_ROOT);
+ this.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED,true);
}
});
+ mediator.info(String.format("%s servlet registered", RestAccessConstants.WS_ROOT));
}
/**
@@ -134,30 +138,6 @@ public class Activator extends AbstractActivator<NorthboundMediator> {
* doStop()
*/
public void doStop() throws Exception {
- mediator.callServices(ExtHttpService.class, new Executable<ExtHttpService, Void>() {
- @Override
- public Void execute(ExtHttpService service) throws Exception {
- try {
- service.unregister(RestAccessConstants.HTTP_ROOT);
-
- } catch (Exception e) {
- mediator.error(e);
- }
- try {
- service.unregister(RestAccessConstants.WS_ROOT);
-
- } catch (Exception e) {
- mediator.error(e);
- }
- try {
- service.unregisterFilter(corsFilter);
-
- } catch (Exception e) {
- mediator.error(e);
- }
- return null;
- }
- });
}
/**
diff --git a/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestACTAccess.java b/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestACTAccess.java
index e1efa436..c36ab7c8 100644
--- a/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestACTAccess.java
+++ b/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestACTAccess.java
@@ -14,13 +14,11 @@ import org.eclipse.sensinact.gateway.common.bundle.Mediator;
import org.eclipse.sensinact.gateway.nthbnd.rest.http.test.HttpServiceTestClient;
import org.eclipse.sensinact.gateway.nthbnd.rest.ws.test.WsServiceTestClient;
import org.json.JSONObject;
-import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-@Ignore
public class TestRestACTAccess extends TestRestAccess {
public TestRestACTAccess() throws Exception {
super();
@@ -28,6 +26,7 @@ public class TestRestACTAccess extends TestRestAccess {
@Test
public void testHttpACTWithoutParameters() throws Exception {
+ Thread.sleep(5000);
Mediator mediator = new Mediator(context);
String simulated = HttpServiceTestClient.newRequest(mediator, HTTP_ROOTURL + "/providers/light/services/switch/resources/status/GET", null, "GET");
//System.out.println(simulated);
@@ -50,6 +49,7 @@ public class TestRestACTAccess extends TestRestAccess {
@Test
public void testSimplifiedHttpACTWithoutParameters() throws Exception {
+ Thread.sleep(5000);
Mediator mediator = new Mediator(context);
String simulated = HttpServiceTestClient.newRequest(mediator, HTTP_ROOTURL + "/light/switch/status/GET", null, "GET");
@@ -73,6 +73,7 @@ public class TestRestACTAccess extends TestRestAccess {
@Test
public void testHttpACTWithParameters() throws Exception {
+ Thread.sleep(5000);
Mediator mediator = new Mediator(context);
String simulated = HttpServiceTestClient.newRequest(mediator, HTTP_ROOTURL + "/providers/light/services/switch/resources/brightness/GET", null, "GET");
@@ -98,6 +99,7 @@ public class TestRestACTAccess extends TestRestAccess {
@Test
public void testWsACTWithoutParameters() throws Exception {
+ Thread.sleep(5000);
JSONObject response;
String simulated;
WsServiceTestClient client = new WsServiceTestClient();
@@ -125,6 +127,7 @@ public class TestRestACTAccess extends TestRestAccess {
@Test
public void testWsACTWithParameters() throws Exception {
+ Thread.sleep(5000);
JSONObject response;
String simulated;
WsServiceTestClient client = new WsServiceTestClient();
diff --git a/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestAccess.java b/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestAccess.java
index babde18d..a0ed1b03 100644
--- a/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestAccess.java
+++ b/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestAccess.java
@@ -11,16 +11,18 @@
package org.eclipse.sensinact.gateway.nthbnd.rest;
import org.eclipse.sensinact.gateway.test.MidOSGiTest;
-import org.junit.Ignore;
+import org.eclipse.sensinact.gateway.util.IOUtils;
+import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
+import java.net.URL;
import java.util.Map;
/**
* @author <a href="mailto:christophe.munilla@cea.fr">Christophe Munilla</a>
*/
-@Ignore
public class TestRestAccess extends MidOSGiTest {
//********************************************************************//
// NESTED DECLARATIONS //
@@ -65,17 +67,60 @@ public class TestRestAccess extends MidOSGiTest {
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
protected void doInit(Map configuration) {
- configuration.put("felix.auto.start.1", "file:target/felix/bundle/org.osgi.compendium.jar " + "file:target/felix/bundle/org.apache.felix.configadmin.jar " + "file:target/felix/bundle/org.apache.felix.framework.security.jar ");
- configuration.put("felix.auto.install.2", "file:target/felix/bundle/sensinact-utils.jar " + "file:target/felix/bundle/sensinact-common.jar " + "file:target/felix/bundle/sensinact-datastore-api.jar " + "file:target/felix/bundle/sensinact-framework-extension.jar " + "file:target/felix/bundle/sensinact-security-none.jar " + "file:target/felix/bundle/sensinact-generic.jar");
-
- configuration.put("felix.auto.start.2", "file:target/felix/bundle/sensinact-test-configuration.jar " + "file:target/felix/bundle/sensinact-signature-validator.jar " + "file:target/felix/bundle/sensinact-core.jar ");
- configuration.put("felix.auto.start.3", "file:target/felix/bundle/javax.servlet-api.jar " + "file:target/felix/bundle/org.apache.felix.http.api.jar " + "file:target/felix/bundle/org.apache.felix.http.jetty.jar " + "file:target/felix/bundle/http.jar " + "file:target/felix/bundle/sensinact-northbound-access.jar " + "file:target/felix/bundle/dynamicBundle.jar");
- configuration.put("felix.auto.start.4", "file:target/felix/bundle/slider.jar " + "file:target/felix/bundle/light.jar ");
+ configuration.put("felix.auto.start.1",
+ "file:target/felix/bundle/org.osgi.service.component.jar "+
+ "file:target/felix/bundle/org.osgi.service.cm.jar "+
+ "file:target/felix/bundle/org.osgi.service.metatype.jar "+
+ "file:target/felix/bundle/org.osgi.namespace.extender.jar "+
+ "file:target/felix/bundle/org.osgi.util.promise.jar "+
+ "file:target/felix/bundle/org.osgi.util.function.jar "+
+ "file:target/felix/bundle/org.osgi.service.log.jar " +
+ "file:target/felix/bundle/org.apache.felix.log.jar " +
+ "file:target/felix/bundle/org.apache.felix.scr.jar " +
+ "file:target/felix/bundle/org.apache.felix.fileinstall.jar " +
+ "file:target/felix/bundle/org.apache.felix.configadmin.jar " +
+ "file:target/felix/bundle/org.apache.felix.framework.security.jar ");
+ configuration.put("felix.auto.install.2",
+ "file:target/felix/bundle/org.eclipse.paho.client.mqttv3.jar " +
+ "file:target/felix/bundle/mqtt-utils.jar " +
+ "file:target/felix/bundle/sensinact-utils.jar " +
+ "file:target/felix/bundle/sensinact-common.jar " +
+ "file:target/felix/bundle/sensinact-datastore-api.jar " +
+ "file:target/felix/bundle/sensinact-security-none.jar " +
+ "file:target/felix/bundle/sensinact-generic.jar " +
+ "file:target/felix/bundle/slf4j-api.jar " +
+ "file:target/felix/bundle/slf4j-simple.jar");
+ configuration.put("felix.auto.start.2",
+ "file:target/felix/bundle/sensinact-signature-validator.jar " +
+ "file:target/felix/bundle/sensinact-core.jar ");
+ configuration.put("felix.auto.start.3",
+ "file:target/felix/bundle/org.apache.felix.http.servlet-api.jar " +
+ "file:target/felix/bundle/org.apache.felix.http.jetty.jar " +
+ "file:target/felix/bundle/http.jar " +
+ "file:target/felix/bundle/sensinact-northbound-access.jar " +
+ "file:target/felix/bundle/dynamicBundle.jar ");
+ configuration.put("felix.auto.start.4",
+ "file:target/felix/bundle/slider.jar " +
+ "file:target/felix/bundle/light.jar ");
configuration.put("org.eclipse.sensinact.gateway.security.jks.filename", "target/felix/bundle/keystore.jks");
configuration.put("org.eclipse.sensinact.gateway.security.jks.password", "sensiNact_team");
+
+ configuration.put("org.eclipse.sensinact.gateway.location.latitude", "45.2d");
+ configuration.put("org.eclipse.sensinact.gateway.location.longitude", "5.7d");
+
configuration.put("org.osgi.service.http.port", "8898");
- //configuration.put("org.osgi.framework.security", "osgi");
- configuration.put("org.apache.felix.http.jettyEnabled", "true");
- configuration.put("org.apache.felix.http.whiteboardEnabled", "true");
+ configuration.put("org.apache.felix.http.jettyEnabled", true);
+ configuration.put("org.apache.felix.http.whiteboardEnabled", true);
+
+ try {
+ String fileName = "sensinact.config";
+ File testFile = new File(new File("src/test/resources"), fileName);
+ URL testFileURL = testFile.toURI().toURL();
+ FileOutputStream output = new FileOutputStream(new File(loadDir,fileName));
+ byte[] testCng = IOUtils.read(testFileURL.openStream(), true);
+ IOUtils.write(testCng, output);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
diff --git a/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestGETAccess.java b/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestGETAccess.java
index ff41ebbe..3b375c19 100644
--- a/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestGETAccess.java
+++ b/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestGETAccess.java
@@ -17,13 +17,14 @@ import org.eclipse.sensinact.gateway.simulated.slider.api.SliderSetterItf;
import org.eclipse.sensinact.gateway.test.MidProxy;
import org.json.JSONArray;
import org.json.JSONObject;
-import org.junit.Ignore;
import org.junit.Test;
+import org.osgi.framework.ServiceReference;
import org.skyscreamer.jsonassert.JSONAssert;
import static org.junit.Assert.assertTrue;
-@Ignore
+import java.util.Arrays;
+
public class TestRestGETAccess extends TestRestAccess {
public TestRestGETAccess() throws Exception {
super();
@@ -31,10 +32,10 @@ public class TestRestGETAccess extends TestRestAccess {
@Test
public void testHttpAccessMethodRawDescription() throws Exception {
- Mediator mediator = new Mediator(context);
+ Thread.sleep(5000);
+ Mediator mediator = new Mediator(context);
String simulated = HttpServiceTestClient.newRequest(mediator, HTTP_ROOTURL + "/providers?rawDescribe=true", null, "GET");
-
//System.out.println(simulated);
JSONArray response = new JSONArray("[\"slider\",\"light\"]");
@@ -44,6 +45,7 @@ public class TestRestGETAccess extends TestRestAccess {
@Test
public void testHttpAccessMethodGET() throws Exception {
+ Thread.sleep(5000);
Mediator mediator = new Mediator(context);
String simulated = HttpServiceTestClient.newRequest(mediator, HTTP_ROOTURL + "/providers", null, "GET");
@@ -86,7 +88,8 @@ public class TestRestGETAccess extends TestRestAccess {
@Test
public void testSimplifiedHttpAccessMethodGET() throws Exception {
- Mediator mediator = new Mediator(context);
+ Thread.sleep(5000);
+ Mediator mediator = new Mediator(context);
String simulated = HttpServiceTestClient.newRequest(mediator, HTTP_ROOTURL + "/slider", null, "GET");
//System.out.println(simulated);
@@ -121,6 +124,7 @@ public class TestRestGETAccess extends TestRestAccess {
@Test
public void testWsAccessMethodRawDescription() throws Exception {
+ Thread.sleep(5000);
String simulated;
WsServiceTestClient client = new WsServiceTestClient();
@@ -134,6 +138,7 @@ public class TestRestGETAccess extends TestRestAccess {
@Test
public void testWsAccessMethodGET() throws Exception {
+ Thread.sleep(5000);
JSONObject response;
String simulated;
WsServiceTestClient client = new WsServiceTestClient();
@@ -170,6 +175,7 @@ public class TestRestGETAccess extends TestRestAccess {
@Test
public void testSimplifiedWsAccessMethodGET() throws Exception {
+ Thread.sleep(5000);
JSONObject response;
String simulated;
WsServiceTestClient client = new WsServiceTestClient();
diff --git a/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestSETAccess.java b/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestSETAccess.java
index 99d82ec9..36307a46 100644
--- a/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestSETAccess.java
+++ b/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestSETAccess.java
@@ -14,12 +14,10 @@ import org.eclipse.sensinact.gateway.common.bundle.Mediator;
import org.eclipse.sensinact.gateway.nthbnd.rest.http.test.HttpServiceTestClient;
import org.eclipse.sensinact.gateway.nthbnd.rest.ws.test.WsServiceTestClient;
import org.json.JSONObject;
-import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
-@Ignore
public class TestRestSETAccess extends TestRestAccess {
public TestRestSETAccess() throws Exception {
super();
@@ -28,13 +26,14 @@ public class TestRestSETAccess extends TestRestAccess {
@Test
public void testHttpAccessMethodSET() throws Exception {
Mediator mediator = new Mediator(context);
+ Thread.sleep(5000);
String simulated = HttpServiceTestClient.newRequest(mediator, HTTP_ROOTURL + "/providers/slider/services/admin/resources/location/GET", null, "GET");
JSONObject response = new JSONObject(simulated);
assertTrue(response.get("statusCode").equals(200));
assertTrue(response.getString("uri").equals("/slider/admin/location"));
- assertTrue(response.getJSONObject("response").get("value").equals("45.19334890078532:5.706474781036377"));
+ assertTrue(response.getJSONObject("response").get("value").equals("45.2:5.7"));
simulated = HttpServiceTestClient.newRequest(mediator, HTTP_ROOTURL + "/providers/slider/services/admin/resources/location/SET", "{\"parameters\":[{\"name\": \"location\",\"value\": \"0.0,0.0\",\"type\": \"string\"}]}", "POST");
response = new JSONObject(simulated);
@@ -50,6 +49,7 @@ public class TestRestSETAccess extends TestRestAccess {
public void testWsAccessMethodSET() throws Exception {
JSONObject response;
String simulated;
+ Thread.sleep(5000);
WsServiceTestClient client = new WsServiceTestClient();
new Thread(client).start();
@@ -60,7 +60,7 @@ public class TestRestSETAccess extends TestRestAccess {
assertTrue(response.get("statusCode").equals(200));
assertTrue(response.getString("uri").equals("/slider/admin/location"));
- assertTrue(response.getJSONObject("response").get("value").equals("45.19334890078532:5.706474781036377"));
+ assertTrue(response.getJSONObject("response").get("value").equals("45.2:5.7"));
simulated = this.synchronizedRequest(client, WS_ROOTURL + "/providers/slider/services/admin/resources/location/SET", "[{\"name\": \"location\",\"value\": \"0.0,0.0\",\"type\": \"string\"}]");
response = new JSONObject(simulated);
diff --git a/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestSUBSCRIBE_UNSUBSCRIBEAccess.java b/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestSUBSCRIBE_UNSUBSCRIBEAccess.java
index b595a7aa..53aaab5d 100644
--- a/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestSUBSCRIBE_UNSUBSCRIBEAccess.java
+++ b/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/TestRestSUBSCRIBE_UNSUBSCRIBEAccess.java
@@ -20,13 +20,11 @@ import org.eclipse.sensinact.gateway.test.MidProxy;
import org.json.JSONObject;
import org.junit.AfterClass;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
-@Ignore
public class TestRestSUBSCRIBE_UNSUBSCRIBEAccess extends TestRestAccess {
private static JettyTestServer server = null;
@@ -60,6 +58,7 @@ public class TestRestSUBSCRIBE_UNSUBSCRIBEAccess extends TestRestAccess {
@Test
public void testHttpAccessMethodSUBSCRIBE_UNSUBSCIBE() throws Exception {
+ Thread.sleep(5000);
Mediator mediator = new Mediator(context);
JSONObject response;
String simulated;
@@ -119,6 +118,7 @@ public class TestRestSUBSCRIBE_UNSUBSCRIBEAccess extends TestRestAccess {
@Test
public void testHttpAccessMethodConditionalSUBSCRIBE_UNSUBSCIBE() throws Exception {
+ Thread.sleep(5000);
Mediator mediator = new Mediator(context);
JSONObject response;
String simulated;
@@ -180,6 +180,7 @@ public class TestRestSUBSCRIBE_UNSUBSCRIBEAccess extends TestRestAccess {
@Test
public void testWsAccessMethodSUBSCRIBE_UNSUBSCIBE() throws Exception {
+ Thread.sleep(5000);
MidProxy<SliderSetterItf> sliderProxy = new MidProxy<SliderSetterItf>(classloader, this, SliderSetterItf.class);
SliderSetterItf slider = sliderProxy.buildProxy();
JSONObject response;
@@ -231,6 +232,7 @@ public class TestRestSUBSCRIBE_UNSUBSCRIBEAccess extends TestRestAccess {
@Test
public void testWsAccessMethodConditionalSUBSCRIBE_UNSUBSCIBE() throws Exception {
+ Thread.sleep(5000);
MidProxy<SliderSetterItf> sliderProxy = new MidProxy<SliderSetterItf>(classloader, this, SliderSetterItf.class);
SliderSetterItf slider = sliderProxy.buildProxy();
JSONObject response;
diff --git a/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/server/JettyTestServer.java b/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/server/JettyTestServer.java
index 732e7d06..5ad6c03a 100644
--- a/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/server/JettyTestServer.java
+++ b/platform/northbound/rest-access/src/test/java/org/eclipse/sensinact/gateway/nthbnd/rest/server/JettyTestServer.java
@@ -11,7 +11,8 @@
package org.eclipse.sensinact.gateway.nthbnd.rest.server;
import java.io.IOException;
-import java.util.concurrent.Executors;
+import java.util.Arrays;
+import java.util.List;
import javax.servlet.AsyncContext;
import javax.servlet.WriteListener;
@@ -32,7 +33,6 @@ import org.eclipse.sensinact.gateway.util.IOUtils;
public class JettyTestServer implements Runnable {
-
private final Server server;
private ServerConnector connector ;
private int port;
@@ -42,7 +42,7 @@ public class JettyTestServer implements Runnable {
public JettyTestServer(int port) throws Exception {
this.port = port;
- this.server = new Server(new ExecutorThreadPool(Executors.newFixedThreadPool(10)));
+ this.server = new Server(new ExecutorThreadPool(10));
}
public boolean isStarted() {
@@ -68,10 +68,13 @@ public class JettyTestServer implements Runnable {
@Override
public Connection newConnection(Connector connector, EndPoint endpoint) {
- System.out.println(connector);
- System.out.println(endpoint);
return endpoint.getConnection();
}
+
+ @Override
+ public List<String> getProtocols() {
+ return Arrays.asList("HTTP");
+ }
});
server.setConnectors(new Connector[] { connector });
@@ -119,14 +122,11 @@ public class JettyTestServer implements Runnable {
} else {
asyncContext = request.startAsync(request, response);
}
- //System.out.println(request);
response.getOutputStream().setWriteListener(new WriteListener() {
@Override
public void onWritePossible() throws IOException {
HttpServletRequest request = (HttpServletRequest) asyncContext.getRequest();
HttpServletResponse response = (HttpServletResponse) asyncContext.getResponse();
- System.out.println("REQUEST " + request);
- System.out.println("RESPONSE " + response);
try {
JettyTestServer.this.message = null;
JettyTestServer.this.setAvailable(true);
@@ -139,8 +139,7 @@ public class JettyTestServer implements Runnable {
} finally {
if (request.isAsyncStarted()) {
asyncContext.complete();
- }
- System.out.println("...GOT");
+ }
}
}
@@ -160,7 +159,6 @@ public class JettyTestServer implements Runnable {
*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
- System.out.println("POSTING ...");
if (response.isCommitted()) {
return;
}
@@ -177,8 +175,6 @@ public class JettyTestServer implements Runnable {
public void onWritePossible() throws IOException {
HttpServletRequest request = (HttpServletRequest) asyncContext.getRequest();
HttpServletResponse response = (HttpServletResponse) asyncContext.getResponse();
- System.out.println("REQUEST " + request);
- System.out.println("RESPONSE " + response);
try {
JettyTestServer.this.message = null;
int length = request.getContentLength();
@@ -199,8 +195,7 @@ public class JettyTestServer implements Runnable {
} finally {
if (request.isAsyncStarted()) {
asyncContext.complete();
- }
- System.out.println("...POSTED");
+ }
}
}
diff --git a/platform/northbound/rest-access/src/test/resources/sensinact.config b/platform/northbound/rest-access/src/test/resources/sensinact.config
new file mode 100644
index 00000000..7b88e10e
--- /dev/null
+++ b/platform/northbound/rest-access/src/test/resources/sensinact.config
@@ -0,0 +1,3 @@
+namespace=SERVER
+broker=tcp://sensinact-cea.ddns.net:5269
+broker.topic.prefix=/ \ No newline at end of file

Back to the top