Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Munilla2019-06-25 10:38:41 -0400
committerChristophe Munilla2019-06-25 10:38:41 -0400
commitaf871539c51667af69a3540f634e2bf1767fbb7c (patch)
treeeffc46f9a5e855fddbf46b0280812faad25c36e2
parentd3c952c6f566f67050c7a0d6d4e28e0a8e90a8ec (diff)
downloadorg.eclipse.sensinact.gateway-af871539c51667af69a3540f634e2bf1767fbb7c.tar.gz
org.eclipse.sensinact.gateway-af871539c51667af69a3540f634e2bf1767fbb7c.tar.xz
org.eclipse.sensinact.gateway-af871539c51667af69a3540f634e2bf1767fbb7c.zip
Use Whiteboard pattern
update the http-tools module to use the whiteboard pattern instead of the deprecated HttpService and ExtHttpService Update tests and reactivate them
-rw-r--r--platform/northbound/http-tools/extra-src/test/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/test/bundle1/ForwardingServiceImpl.java135
-rw-r--r--platform/northbound/http-tools/extra-src/test/resources/MANIFEST.MF2
-rw-r--r--platform/northbound/http-tools/extra-src2/test/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/test/bundle1/CallbackServiceImpl.java40
-rw-r--r--platform/northbound/http-tools/pom.xml195
-rw-r--r--platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/CallbackService.java2
-rw-r--r--platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackFactory.java73
-rw-r--r--platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackServlet.java41
-rw-r--r--platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/ForwardingService.java37
-rw-r--r--platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/internal/ForwardingFactory.java74
-rw-r--r--platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/internal/ForwardingFilter.java482
-rw-r--r--platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/tools/internal/FactoryFactory.java86
-rw-r--r--platform/northbound/http-tools/src/test/java/org/eclipse/sensinact/gateway/nthbnd/forward/test/TestForwardingService.java93
-rw-r--r--platform/northbound/http-tools/src/test/resources/sensinact.config3
13 files changed, 677 insertions, 586 deletions
diff --git a/platform/northbound/http-tools/extra-src/test/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/test/bundle1/ForwardingServiceImpl.java b/platform/northbound/http-tools/extra-src/test/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/test/bundle1/ForwardingServiceImpl.java
index 92d6fae3..30451e06 100644
--- a/platform/northbound/http-tools/extra-src/test/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/test/bundle1/ForwardingServiceImpl.java
+++ b/platform/northbound/http-tools/extra-src/test/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/test/bundle1/ForwardingServiceImpl.java
@@ -3,13 +3,13 @@
*/
package org.eclipse.sensinact.gateway.nthbnd.http.forward.test.bundle1;
-import org.eclipse.jetty.server.Request;
-import org.eclipse.sensinact.gateway.common.execution.Executable;
-import org.eclipse.sensinact.gateway.nthbnd.http.forward.ForwardingService;
-
import java.util.Dictionary;
import java.util.Hashtable;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.sensinact.gateway.nthbnd.http.forward.ForwardingService;
+
/**
*
*/
@@ -25,8 +25,7 @@ public class ForwardingServiceImpl implements ForwardingService {
*/
@Override
public String getPattern() {
-
- return "/forwardingTest1/.*";
+ return "/forwardingTest1/*";
}
/* (non-Javadoc)
@@ -35,77 +34,71 @@ public class ForwardingServiceImpl implements ForwardingService {
@Override
public Dictionary getProperties() {
return new Hashtable() {{
- this.put("pattern", "/forwardingTest1/.*");
+ this.put("osgi.http.whiteboard.filter.pattern", getPattern());
}};
}
- /* (non-Javadoc)
- * @see org.eclipse.sensinact.gateway.nthbnd.forward.http.ForwardingService#getUriBuilder()
- */
- @Override
- public Executable<Request, String> getUriBuilder() {
- return new Executable<Request, String>() {
- @Override
- public String execute(Request request) throws Exception {
- String uri = null;
- String uriContext = "/sensinact";
- String path = request.getUri().getPath();
- String restPath = path.substring(17);
+ @Override
+ public String getQuery(HttpServletRequest request) {
+ String query = null;
+ String path = request.getRequestURI();
+ String restPath = path.substring(17);
- try {
- int val = Integer.parseInt(restPath);
- switch (val) {
- case 0:
- uri = uriContext.concat("/providers");
- break;
- case 1:
- uri = uriContext.concat("/providers/slider");
- break;
- case 2:
- uri = uriContext.concat("/providers/light");
- break;
- case 3:
- uri = uriContext.concat("/providers/slider/cursor/position/GET");
- break;
- }
- } catch (NumberFormatException e) {
- uri = "/sensinact";
- }
- return uri;
+ try {
+ int val = Integer.parseInt(restPath);
+ switch (val) {
+ case 0:
+ query = "rawDescribe=true";
+ break;
+ case 1:
+ ;
+ case 2:
+ ;
+ case 3:
+ ;
+ break;
}
- };
- }
+ } catch (NumberFormatException e) {
+ }
+ return query;
+ }
- /* (non-Javadoc)
- * @see org.eclipse.sensinact.gateway.nthbnd.forward.http.ForwardingService#getUriBuilder()
- */
- @Override
- public Executable<Request, String> getQueryBuilder() {
- return new Executable<Request, String>() {
- @Override
- public String execute(Request request) throws Exception {
- String query = null;
- String path = request.getUri().getPath();
- String restPath = path.substring(17);
+ @Override
+ public String getUri(HttpServletRequest request) {
+ String uri = null;
+ String uriContext = "/sensinact";
+ String path = request.getRequestURI();
+ String restPath = path.substring(17);
- try {
- int val = Integer.parseInt(restPath);
- switch (val) {
- case 0:
- query = "rawDescribe=true";
- break;
- case 1:
- ;
- case 2:
- ;
- case 3:
- ;
- break;
- }
- } catch (NumberFormatException e) {
- }
- return query;
+ try {
+ int val = Integer.parseInt(restPath);
+ switch (val) {
+ case 0:
+ uri = uriContext.concat("/providers");
+ break;
+ case 1:
+ uri = uriContext.concat("/providers/slider");
+ break;
+ case 2:
+ uri = uriContext.concat("/providers/light");
+ break;
+ case 3:
+ uri = uriContext.concat("/providers/slider/cursor/position/GET");
+ break;
}
- };
- }
+ } catch (NumberFormatException e) {
+ uri = "/sensinact";
+ }
+ return uri;
+ }
+
+ @Override
+ public String getParam(HttpServletRequest baseRequest) {
+ return null;
+ }
+
+ @Override
+ public String getFragment(HttpServletRequest baseRequest) {
+ return null;
+ }
}
diff --git a/platform/northbound/http-tools/extra-src/test/resources/MANIFEST.MF b/platform/northbound/http-tools/extra-src/test/resources/MANIFEST.MF
index 53d7a376..28b71a3c 100644
--- a/platform/northbound/http-tools/extra-src/test/resources/MANIFEST.MF
+++ b/platform/northbound/http-tools/extra-src/test/resources/MANIFEST.MF
@@ -3,7 +3,7 @@ Import-Package: org.eclipse.sensinact.gateway.nthbnd.http.tools.osgi;versio
n="2.0.0",org.eclipse.sensinact.gateway.nthbnd.http.forward;version="2.
0.0",org.eclipse.sensinact.gateway.common.bundle;version="2.0.0",org.ec
lipse.sensinact.gateway.common.execution;version="2.0.0",org.eclipse.je
- tty.server,org.eclipse.jetty.http
+ tty.server,org.eclipse.jetty.http,javax.servlet.http
Export-Package: org.eclipse.sensinact.gateway.nthbnd.http.forward.test.b
undle1
Tool: Bnd-2.3.0.201405100607
diff --git a/platform/northbound/http-tools/extra-src2/test/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/test/bundle1/CallbackServiceImpl.java b/platform/northbound/http-tools/extra-src2/test/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/test/bundle1/CallbackServiceImpl.java
index 7ddd27a0..79081160 100644
--- a/platform/northbound/http-tools/extra-src2/test/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/test/bundle1/CallbackServiceImpl.java
+++ b/platform/northbound/http-tools/extra-src2/test/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/test/bundle1/CallbackServiceImpl.java
@@ -1,12 +1,11 @@
package org.eclipse.sensinact.gateway.nthbnd.http.callback.test.bundle1;
-import org.eclipse.sensinact.gateway.common.execution.Executable;
-import org.eclipse.sensinact.gateway.nthbnd.http.callback.CallbackContext;
-import org.eclipse.sensinact.gateway.nthbnd.http.callback.CallbackService;
-
import java.util.Dictionary;
import java.util.Hashtable;
+import org.eclipse.sensinact.gateway.nthbnd.http.callback.CallbackContext;
+import org.eclipse.sensinact.gateway.nthbnd.http.callback.CallbackService;
+
/**
*
*/
@@ -22,8 +21,7 @@ public class CallbackServiceImpl implements CallbackService {
*/
@Override
public String getPattern() {
-
- return "/callbackTest1";
+ return "/callbackTest1/*";
}
/* (non-Javadoc)
@@ -32,27 +30,17 @@ public class CallbackServiceImpl implements CallbackService {
@Override
public Dictionary getProperties() {
return new Hashtable() {{
- this.put("pattern", "/callbackTest1");
+ this.put("pattern", "/callbackTest1/*");
}};
}
- /* (non-Javadoc)
- * @see org.eclipse.sensinact.gateway.nthbnd.forward.http.ForwardingService#getUriBuilder()
- */
- @Override
- public Executable<CallbackContext, Void> getCallbackProcessor() {
- return new Executable<CallbackContext, Void>() {
- @Override
- public Void execute(CallbackContext context) throws Exception {
- try {
- context.setResponseContent(("[" + context.getMethod() + "]" + context.getRequest().getRequestURI()).getBytes());
-
- context.setResponseStatus(200);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- };
- }
+ @Override
+ public void process(CallbackContext context) {
+ try {
+ context.setResponseContent(("[" + context.getMethod() + "]" + context.getRequest().getRequestURI()).getBytes());
+ context.setResponseStatus(200);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
}
diff --git a/platform/northbound/http-tools/pom.xml b/platform/northbound/http-tools/pom.xml
index bd3bed4b..70cc346e 100644
--- a/platform/northbound/http-tools/pom.xml
+++ b/platform/northbound/http-tools/pom.xml
@@ -27,53 +27,45 @@
<dependencies>
<dependency>
<groupId>org.eclipse.sensinact.gateway</groupId>
- <artifactId>sensinact-utils</artifactId>
+ <artifactId>sensinact-core</artifactId>
<version>${project.version}</version>
- <scope>provided</scope>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.sensinact.gateway</groupId>
<artifactId>sensinact-common</artifactId>
<version>${project.version}</version>
- <scope>provided</scope>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.sensinact.gateway</groupId>
- <artifactId>sensinact-core</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.eclipse.sensinact.gateway.nthbnd</groupId>
- <artifactId>sensinact-northbound-access</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.eclipse.sensinact.gateway.protocol</groupId>
- <artifactId>http</artifactId>
+ <artifactId>sensinact-utils</artifactId>
<version>${project.version}</version>
- <scope>provided</scope>
+ <scope>provided</scope>
</dependency>
- <!--
<dependency>
- <groupId>org.eclipse.sensinact.gateway.sthbnd.http</groupId>
- <artifactId>http-device</artifactId>
- <version>${project.version}</version>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-server</artifactId>
+ <version>9.4.15.v20190215</version>
<scope>provided</scope>
</dependency>
- -->
<dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- <version>3.1.0</version>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-http</artifactId>
+ <version>9.4.15.v20190215</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.http.jetty</artifactId>
- <version>3.0.0</version>
+ <artifactId>org.apache.felix.http.servlet-api</artifactId>
+ <version>1.1.2</version>
<scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.sensinact.gateway.tools</groupId>
+ <artifactId>sensinact-test</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
@@ -82,11 +74,11 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.eclipse.sensinact.gateway.tools</groupId>
- <artifactId>sensinact-test</artifactId>
- <version>${project.version}</version>
+ <groupId>org.eclipse.sensinact.gateway.protocol</groupId>
+ <artifactId>http</artifactId>
+ <version>${project.version}</version>
<scope>test</scope>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
@@ -166,34 +158,90 @@
<phase>generate-test-resources</phase>
<configuration>
<artifactItems>
+ <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>
@@ -216,6 +264,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>
@@ -231,26 +293,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>
@@ -270,7 +318,21 @@
<version>${project.version}</version>
<outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
<destFileName>rest-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>
@@ -279,25 +341,25 @@
<destFileName>http.jar</destFileName>
</artifactItem>
<artifactItem>
- <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>
<outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
- <destFileName>javax.servlet-api.jar</destFileName>
+ <destFileName>org.apache.felix.http.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.jetty</artifactId>
+ <version>4.0.8</version>
<outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
- <destFileName>org.apache.felix.http.api.jar</destFileName>
+ <destFileName>org.apache.felix.http.jetty.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.http.jetty</artifactId>
+ <artifactId>org.apache.felix.http.api</artifactId>
<version>3.0.0</version>
<outputDirectory>${project.build.directory}/felix/bundle</outputDirectory>
- <destFileName>org.apache.felix.http.jetty.jar</destFileName>
+ <destFileName>org.apache.felix.http.api.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>org.eclipse.sensinact.gateway.simulated.devices</groupId>
@@ -349,7 +411,6 @@
org.eclipse.sensinact.gateway.nthbnd.http.tools.osgi.Activator
</Bundle-Activator>
<Export-Package>
- <!-- org.eclipse.sensinact.gateway.nthbnd.http.tools,-->
org.eclipse.sensinact.gateway.nthbnd.http.tools.osgi,
org.eclipse.sensinact.gateway.nthbnd.http.forward,
org.eclipse.sensinact.gateway.nthbnd.http.callback
diff --git a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/CallbackService.java b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/CallbackService.java
index 3f34b621..7adccad6 100644
--- a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/CallbackService.java
+++ b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/CallbackService.java
@@ -42,5 +42,5 @@ public interface CallbackService {
*
* @return the {@link Executable} processing the callback
*/
- Executable<CallbackContext, Void> getCallbackProcessor();
+ void process(CallbackContext context);
}
diff --git a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackFactory.java b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackFactory.java
index f43448b4..9b21954f 100644
--- a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackFactory.java
+++ b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackFactory.java
@@ -10,18 +10,23 @@
*/
package org.eclipse.sensinact.gateway.nthbnd.http.callback.internal;
-import org.apache.felix.http.api.ExtHttpService;
-import org.eclipse.sensinact.gateway.common.bundle.Mediator;
-import org.eclipse.sensinact.gateway.common.execution.Executable;
-import org.eclipse.sensinact.gateway.nthbnd.http.callback.CallbackService;
-import org.osgi.service.http.HttpContext;
-
+import java.util.Arrays;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
+import javax.servlet.Servlet;
+
+import org.eclipse.sensinact.gateway.common.bundle.Mediator;
+import org.eclipse.sensinact.gateway.common.execution.Executable;
+import org.eclipse.sensinact.gateway.nthbnd.http.callback.CallbackService;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+
/**
* A CallbackFactory is in charge of creating the {@link CallbackServlet}s attached
* to one specific {@link ExtHttpService}, and configured by the {@link CallbackService}s
@@ -34,8 +39,7 @@ public class CallbackFactory {
private String appearingKey;
private String disappearingKey;
- private ExtHttpService extHttpService;
- private Map<String, CallbackServlet> callbacks;
+ private Map<String, ServiceRegistration> registrations;
private final AtomicBoolean running;
@@ -44,14 +48,10 @@ public class CallbackFactory {
*
* @param mediator the {@link Mediator} allowing the CallbackFactory
* to be instantiated to interact with the OSGi host environment
- * @param extHttpService the {@link ExtHttpService} to which the
- * CallbackFactory to be instantiated will register {@link CallbackServlet}s
- * according to the registered {@link CallbackService}
*/
- public CallbackFactory(Mediator mediator, ExtHttpService extHttpService) {
+ public CallbackFactory(Mediator mediator) {
this.mediator = mediator;
- this.extHttpService = extHttpService;
- this.callbacks = Collections.synchronizedMap(new HashMap<String, CallbackServlet>());
+ this.registrations = Collections.synchronizedMap(new HashMap<String, ServiceRegistration>());
this.running = new AtomicBoolean(false);
}
@@ -141,7 +141,8 @@ public class CallbackFactory {
*
* @param callbackService the {@link CallbackService} to be attached
*/
- public final void attach(CallbackService callbackService) {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public final void attach(CallbackService callbackService) {
if (callbackService == null || !this.running.get()) {
return;
}
@@ -153,21 +154,19 @@ public class CallbackFactory {
if (!endpoint.startsWith("/")) {
endpoint = "/".concat(endpoint);
}
- if (callbacks.containsKey(endpoint)) {
+ if (registrations.containsKey(endpoint)) {
mediator.error("A callback service is already registered at '%s'", endpoint);
return;
}
- CallbackServlet CallbackServlet = new CallbackServlet(mediator, callbackService.getCallbackProcessor());
+ CallbackServlet callbackServlet = new CallbackServlet(mediator, callbackService);
Dictionary props = callbackService.getProperties();
- HttpContext context = extHttpService.createDefaultHttpContext();
- try {
- extHttpService.registerServlet(endpoint, CallbackServlet, props, context);
- mediator.info("Callback servlet '%s' registered", endpoint);
- callbacks.put(endpoint, CallbackServlet);
- } catch (Exception e) {
- mediator.error(e);
- }
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, endpoint);
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED,true);
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,"("+HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME+"=org.osgi.service.http)");
+
+ ServiceRegistration registration = mediator.getContext().registerService(Servlet.class, callbackServlet, props);
+ this.registrations.put(endpoint, registration);
}
/**
@@ -180,18 +179,16 @@ public class CallbackFactory {
if (callbackService == null) {
return;
}
- String endpoint = callbackService.getPattern();
- CallbackServlet CallbackServlet = callbacks.remove(endpoint);
- if (CallbackServlet == null) {
- mediator.warn("The specified callback service '%s' was not registered", endpoint);
- return;
- }
- try {
- extHttpService.unregisterServlet(CallbackServlet);
- mediator.info("Callback servlet '%s' unregistered", endpoint);
- } catch (Exception e) {
- mediator.error(e);
- }
- return;
+ String endpoint = callbackService.getPattern();
+ ServiceRegistration registration = this.registrations.get(endpoint);
+ if(registration != null) {
+ try {
+ registration.unregister();
+ mediator.info("Callback servlet '%s' unregistered", endpoint);
+ }catch(IllegalStateException e) {
+ //do nothing
+ }
+ registration = null;
+ }
}
}
diff --git a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackServlet.java b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackServlet.java
index ca0e6e52..056aebca 100644
--- a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackServlet.java
+++ b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackServlet.java
@@ -11,10 +11,13 @@
package org.eclipse.sensinact.gateway.nthbnd.http.callback.internal;
import org.eclipse.sensinact.gateway.common.bundle.Mediator;
-import org.eclipse.sensinact.gateway.common.execution.Executable;
import org.eclipse.sensinact.gateway.nthbnd.http.callback.CallbackContext;
+import org.eclipse.sensinact.gateway.nthbnd.http.callback.CallbackService;
import javax.servlet.AsyncContext;
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
import javax.servlet.WriteListener;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
@@ -29,30 +32,41 @@ import java.io.IOException;
*/
@SuppressWarnings("serial")
@WebServlet(asyncSupported = true)
-public class CallbackServlet extends HttpServlet {
+public class CallbackServlet extends HttpServlet implements Servlet{
+
public static enum CALLBACK_METHOD {
GET, POST, PUT, DELETE;
}
private Mediator mediator;
- private Executable<CallbackContext, Void> callbackProcessor;
+
+ private CallbackService callbackService;
/**
* Constructor
*
- * @param mediator the {@link Mediator} allowing the CallbackServlet
- * to be instantiated to interact with the OSGi host environment
- * @param callbackProcessor the {@link Executable} allowing the
- * CallbackServlet to be instantiated to process the callback request
+ * @param mediator the {@link Mediator} allowing the CallbackServlet
+ * to be instantiated to interact with the OSGi host environment
+ * @param callbackService the {@link CallbackService} allowing the
+ * CallbackServlet to be instantiated to process the callback request
*/
- public CallbackServlet(Mediator mediator, Executable<CallbackContext, Void> callbackProcessor) {
+ public CallbackServlet(Mediator mediator, CallbackService callbackService) {
this.mediator = mediator;
- this.callbackProcessor = callbackProcessor;
+ this.callbackService = callbackService;
+ }
+
+ public void init(ServletConfig config) throws ServletException {
+ try {
+ super.init(config);
+ }catch(Exception e) {
+ e.printStackTrace();
+ throw new ServletException(e);
+ }
}
private final void doCall(final CALLBACK_METHOD method, HttpServletRequest request, HttpServletResponse response) throws IOException {
- if (response.isCommitted()) {
- return;
+ if (response.isCommitted()) {
+ return;
}
final AsyncContext asyncContext;
if (request.isAsyncStarted()) {
@@ -69,8 +83,8 @@ public class CallbackServlet extends HttpServlet {
HttpServletRequest request = (HttpServletRequest) asyncContext.getRequest();
HttpServletResponse response = (HttpServletResponse) asyncContext.getResponse();
try {
- if (CallbackServlet.this.callbackProcessor != null) {
- CallbackServlet.this.callbackProcessor.execute(context);
+ if (CallbackServlet.this.callbackService != null) {
+ CallbackServlet.this.callbackService.process(context);
}
} catch (Exception e) {
e.printStackTrace();
@@ -91,7 +105,6 @@ public class CallbackServlet extends HttpServlet {
public void onError(Throwable t) {
mediator.error(t);
}
-
});
}
diff --git a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/ForwardingService.java b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/ForwardingService.java
index cfff16ec..44b7bddf 100644
--- a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/ForwardingService.java
+++ b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/ForwardingService.java
@@ -15,6 +15,8 @@ import org.eclipse.sensinact.gateway.common.execution.Executable;
import java.util.Dictionary;
+import javax.servlet.http.HttpServletRequest;
+
/**
* A ForwardingService provides the information allowing to create a
* {@link ForwardingFilter}
@@ -22,6 +24,7 @@ import java.util.Dictionary;
* @author <a href="mailto:christophe.munilla@cea.fr">Christophe Munilla</a>
*/
public interface ForwardingService {
+
/**
* Returns the String pattern of a {@link ForwardingFilter}
* based on this ForwardingService
@@ -37,6 +40,15 @@ public interface ForwardingService {
* @return the set of properties of this ForwardingService
*/
Dictionary getProperties();
+
+ /**
+ * Returns the {@link Executable} in charge of building the query to
+ * be forwarded by the {@link ForwardingFilter} based on this ForwardingService,
+ * and according to the {@link Request} parameterizing its execution
+ *
+ * @return the forwarding query of this ForwardingService
+ */
+ String getQuery(HttpServletRequest baseRequest);
/**
* Returns the {@link Executable} in charge of building the forwarding
@@ -45,14 +57,23 @@ public interface ForwardingService {
*
* @return the forwarding URI builder of this ForwardingService
*/
- Executable<Request, String> getUriBuilder();
-
- /**
- * Returns the {@link Executable} in charge of building the query to
- * be forwarded by the {@link ForwardingFilter} based on this ForwardingService,
- * and according to the {@link Request} parameterizing its execution
+ String getUri(HttpServletRequest baseRequest);
+
+ /**
+ * Returns the {@link Executable} in charge of building the forwarding
+ * URI of a {@link ForwardingFilter} based on this ForwardingService,
+ * according to the {@link Request} parameterizing its execution
*
- * @return the forwarding query of this ForwardingService
+ * @return the forwarding URI builder of this ForwardingService
+ */
+ String getParam(HttpServletRequest baseRequest);
+
+ /**
+ * Returns the {@link Executable} in charge of building the forwarding
+ * URI of a {@link ForwardingFilter} based on this ForwardingService,
+ * according to the {@link Request} parameterizing its execution
+ *
+ * @return the forwarding URI builder of this ForwardingService
*/
- Executable<Request, String> getQueryBuilder();
+ String getFragment(HttpServletRequest baseRequest);
}
diff --git a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/internal/ForwardingFactory.java b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/internal/ForwardingFactory.java
index db5f5945..b97540e6 100644
--- a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/internal/ForwardingFactory.java
+++ b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/internal/ForwardingFactory.java
@@ -10,18 +10,22 @@
*/
package org.eclipse.sensinact.gateway.nthbnd.http.forward.internal;
-import org.apache.felix.http.api.ExtHttpService;
-import org.eclipse.sensinact.gateway.common.bundle.Mediator;
-import org.eclipse.sensinact.gateway.common.execution.Executable;
-import org.eclipse.sensinact.gateway.nthbnd.http.forward.ForwardingService;
-import org.osgi.service.http.HttpContext;
-
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
+import javax.servlet.Filter;
+
+import org.eclipse.sensinact.gateway.common.bundle.Mediator;
+import org.eclipse.sensinact.gateway.common.execution.Executable;
+import org.eclipse.sensinact.gateway.nthbnd.http.forward.ForwardingService;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+
/**
* A ForwardingFactory is in charge of creating the {@link ForwardingFilter}s attached
* to one specific {@link ExtHttpService}, and configured by the {@link ForwardingService}s
@@ -34,10 +38,8 @@ public class ForwardingFactory {
private String appearingKey;
private String disappearingKey;
- private ExtHttpService extHttpService;
- private Map<String, ForwardingFilter> filters;
+ private Map<String, ServiceRegistration> registrations;
- private volatile int ranking;
private final AtomicBoolean running;
/**
@@ -45,14 +47,10 @@ public class ForwardingFactory {
*
* @param mediator the {@link Mediator} allowing the ForwardingFactory
* to be instantiated to interact with the OSGi host environment
- * @param extHttpService the {@link ExtHttpService} to which the
- * ForwardingFactory to be instantiated will register {@link ForwardingFilter}s
- * according to the registered {@link ForwardingService}
*/
- public ForwardingFactory(Mediator mediator, ExtHttpService extHttpService) {
+ public ForwardingFactory(Mediator mediator) {
this.mediator = mediator;
- this.extHttpService = extHttpService;
- this.filters = Collections.synchronizedMap(new HashMap<String, ForwardingFilter>());
+ this.registrations = Collections.synchronizedMap(new HashMap<String, ServiceRegistration>());
this.running = new AtomicBoolean(false);
}
@@ -142,7 +140,8 @@ public class ForwardingFactory {
*
* @param forwardingService the {@link ForwardingService} to be attached
*/
- public final void attach(ForwardingService forwardingService) {
+ @SuppressWarnings("unchecked")
+ public final void attach(ForwardingService forwardingService) {
if (forwardingService == null || !this.running.get()) {
return;
}
@@ -154,22 +153,21 @@ public class ForwardingFactory {
if (!endpoint.startsWith("/")) {
endpoint = "/".concat(endpoint);
}
- if (filters.containsKey(endpoint)) {
+ if (registrations.containsKey(endpoint)) {
mediator.error("A forwarding service is already registered at '%s'", endpoint);
return;
}
- ForwardingFilter forwardingFilter = new ForwardingFilter(mediator, forwardingService.getUriBuilder(), forwardingService.getQueryBuilder());
-
+ ForwardingFilter forwardingFilter = new ForwardingFilter(mediator, forwardingService);
+
Dictionary props = forwardingService.getProperties();
- HttpContext context = extHttpService.createDefaultHttpContext();
- try {
- extHttpService.registerFilter(forwardingFilter, endpoint, props, ranking++, context);
- mediator.info("Forwarding filter '%s' registered", endpoint);
- filters.put(endpoint, forwardingFilter);
- } catch (Exception e) {
- mediator.error(e);
- }
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN, endpoint);
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,"("+HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME+"=*)");
+ props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_ASYNC_SUPPORTED, true );
+
+ ServiceRegistration registration = mediator.getContext().registerService(Filter.class, forwardingFilter, props);
+ this.registrations.put(endpoint,registration);
}
+
/**
* Detaches the {@link ForwardingService} passed as parameter by
@@ -182,17 +180,15 @@ public class ForwardingFactory {
return;
}
String endpoint = forwardingService.getPattern();
- ForwardingFilter forwardingFilter = filters.get(endpoint);
- if (forwardingFilter == null) {
- mediator.warn("The specified forwarding service '%s' was not registered", endpoint);
- return;
- }
- try {
- extHttpService.unregisterFilter(forwardingFilter);
- mediator.info("Forwarding filter '%s' unregistered", endpoint);
- } catch (Exception e) {
- mediator.error(e);
- }
- return;
+ ServiceRegistration registration = this.registrations.get(endpoint);
+ if(registration != null) {
+ try {
+ registration.unregister();
+ mediator.info("Forwarding filter '%s' unregistered", endpoint);
+ }catch(IllegalStateException e) {
+ //do nothing
+ }
+ registration = null;
+ }
}
}
diff --git a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/internal/ForwardingFilter.java b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/internal/ForwardingFilter.java
index ac380c30..95ae0ea2 100644
--- a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/internal/ForwardingFilter.java
+++ b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/forward/internal/ForwardingFilter.java
@@ -10,10 +10,10 @@
*/
package org.eclipse.sensinact.gateway.nthbnd.http.forward.internal;
-import org.eclipse.jetty.server.Request;
-import org.eclipse.jetty.util.Attributes;
-import org.eclipse.sensinact.gateway.common.bundle.Mediator;
-import org.eclipse.sensinact.gateway.common.execution.Executable;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
@@ -22,237 +22,261 @@ import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
-import javax.servlet.ServletRequestWrapper;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashSet;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.jetty.http.HttpURI;
+import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Response;
+import org.eclipse.jetty.util.Attributes;
+import org.eclipse.jetty.util.MultiMap;
+import org.eclipse.sensinact.gateway.common.bundle.Mediator;
+import org.eclipse.sensinact.gateway.common.execution.Executable;
+import org.eclipse.sensinact.gateway.nthbnd.http.forward.ForwardingService;
/**
- * {@link Filter} Implementation in charge of forwarding a request
- * in an asynchronous context
+ * {@link Filter} Implementation in charge of forwarding a request in an
+ * asynchronous context
*
* @author <a href="mailto:christophe.munilla@cea.fr">Christophe Munilla</a>
*/
@WebFilter(asyncSupported = true)
public class ForwardingFilter implements Filter {
- public static final java.lang.String __INCLUDE_PREFIX = "javax.servlet.include.";
-
- public static final java.lang.String __FORWARD_PREFIX = "javax.servlet.forward.";
-
- /**
- * Extended {@link Attributes}
- */
- private class ForwardAttributes implements Attributes {
- final Attributes _attr;
-
- String _requestURI;
- String _contextPath;
- String _servletPath;
- String _pathInfo;
- String _query;
-
- ForwardAttributes(Attributes attributes) {
- _attr = attributes;
- }
-
- /**
- * @inheritDoc
- * @see org.eclipse.jetty.util.Attributes#getAttribute(java.lang.String)
- */
- @Override
- public Object getAttribute(String key) {
- if (key.equals(RequestDispatcher.FORWARD_PATH_INFO)) return _pathInfo;
- if (key.equals(RequestDispatcher.FORWARD_REQUEST_URI)) return _requestURI;
- if (key.equals(RequestDispatcher.FORWARD_SERVLET_PATH)) return _servletPath;
- if (key.equals(RequestDispatcher.FORWARD_CONTEXT_PATH)) return _contextPath;
- if (key.equals(RequestDispatcher.FORWARD_QUERY_STRING)) return _query;
- if (key.startsWith(__INCLUDE_PREFIX)) return null;
- return _attr.getAttribute(key);
- }
-
- /**
- * @inheritDoc
- * @see org.eclipse.jetty.util.Attributes#getAttributeNames()
- */
- @Override
- public Enumeration<String> getAttributeNames() {
- HashSet<String> set = new HashSet<>();
- Enumeration<String> e = _attr.getAttributeNames();
- while (e.hasMoreElements()) {
- String name = e.nextElement();
- if (!name.startsWith(__INCLUDE_PREFIX) && !name.startsWith(__FORWARD_PREFIX)) set.add(name);
- }
- if (_pathInfo != null) set.add(RequestDispatcher.FORWARD_PATH_INFO);
- else set.remove(RequestDispatcher.FORWARD_PATH_INFO);
- set.add(RequestDispatcher.FORWARD_REQUEST_URI);
- set.add(RequestDispatcher.FORWARD_SERVLET_PATH);
- set.add(RequestDispatcher.FORWARD_CONTEXT_PATH);
- if (_query != null) set.add(RequestDispatcher.FORWARD_QUERY_STRING);
- else set.remove(RequestDispatcher.FORWARD_QUERY_STRING);
-
- return Collections.enumeration(set);
- }
-
- /**
- * @inheritDoc
- * @see org.eclipse.jetty.util.Attributes#setAttribute(java.lang.String, java.lang.Object)
- */
- @Override
- public void setAttribute(String key, Object value) {
- if (key.startsWith("javax.servlet.")) {
- if (key.equals(RequestDispatcher.FORWARD_PATH_INFO)) _pathInfo = (String) value;
- else if (key.equals(RequestDispatcher.FORWARD_REQUEST_URI)) _requestURI = (String) value;
- else if (key.equals(RequestDispatcher.FORWARD_SERVLET_PATH)) _servletPath = (String) value;
- else if (key.equals(RequestDispatcher.FORWARD_CONTEXT_PATH)) _contextPath = (String) value;
- else if (key.equals(RequestDispatcher.FORWARD_QUERY_STRING)) _query = (String) value;
-
- else if (value == null) _attr.removeAttribute(key);
- else _attr.setAttribute(key, value);
- } else if (value == null) _attr.removeAttribute(key);
- else _attr.setAttribute(key, value);
- }
-
- /**
- * @inheritDoc
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "FORWARD+" + _attr.toString();
- }
-
- /**
- * @inheritDoc
- * @see org.eclipse.jetty.util.Attributes#clearAttributes()
- */
- @Override
- public void clearAttributes() {
- _attr.clearAttributes();
- _requestURI = null;
- _contextPath = null;
- _servletPath = null;
- _pathInfo = null;
- _query = null;
- }
-
- /**
- * @inheritDoc
- * @see org.eclipse.jetty.util.Attributes#removeAttribute(java.lang.String)
- */
- @Override
- public void removeAttribute(String name) {
- setAttribute(name, null);
- }
- }
-
- /**
- * the {@link Mediator} allowing to interact with the OSGi
- * host environment
- */
- private Mediator mediator;
- /**
- * the {@link Executable} allowing to build the target URI
- * of the forwarding process
- */
- private Executable<Request, String> uriBuilder;
-
- /**
- * the {@link Executable} allowing to build the query String
- * to be forwarded
- */
- private Executable<Request, String> queryBuilder;
-
- /**
- * Constructor
- *
- * @param uriBuilder the {@link Executable} allowing the ForwardingFilter to
- * be instantiated to build the forwarding String URI according to the {@link Request}
- * parameterizing its execution
- * @param queryBuilder the {@link Executable} allowing the ForwardingFilter to
- * be instantiated to build the forwarding query according to the {@link Request}
- * parameterizing its execution
- */
- public ForwardingFilter(Mediator mediator, Executable<Request, String> uriBuilder, Executable<Request, String> queryBuilder) {
- this.mediator = mediator;
- this.uriBuilder = uriBuilder;
- this.queryBuilder = queryBuilder;
- }
-
- /**
- * @inheritDoc
- * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
- */
- public void init(FilterConfig config) throws ServletException {
- mediator.debug("Init with config [" + config + "]");
- }
-
- /**
- * @inheritDoc
- * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, * javax.servlet.ServletResponse, javax.servlet.FilterChain)
- */
- public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
- ServletRequest sr = req;
- while (ServletRequestWrapper.class.isAssignableFrom(sr.getClass())) {
- sr = ((ServletRequestWrapper) sr).getRequest();
- }
- final org.eclipse.jetty.server.Request baseRequest = (org.eclipse.jetty.server.Request) sr;
- final String old_uri = baseRequest.getRequestURI();
- final String old_context_path = baseRequest.getContextPath();
- final String old_servlet_path = baseRequest.getServletPath();
- final String old_path_info = baseRequest.getPathInfo();
- final String old_query = baseRequest.getQueryString();
- final Attributes old_attr = baseRequest.getAttributes();
-
- baseRequest.getResponse().resetForForward();
- String uri = null;
- String query = null;
- if (this.uriBuilder != null) {
- try {
- uri = this.uriBuilder.execute(baseRequest);
- } catch (Exception e) {
- throw new IOException(e);
- }
- }
- if (uri == null) {
- uri = old_uri;
- }
- baseRequest.setHandled(false);
- baseRequest.setDispatcherType(DispatcherType.REQUEST);
- ForwardAttributes attr = new ForwardAttributes(old_attr);
- attr._pathInfo = old_path_info;
- attr._query = old_query;
- attr._requestURI = old_uri;
- attr._contextPath = old_context_path;
- attr._servletPath = old_servlet_path;
- baseRequest.setRequestURI(uri);
- baseRequest.setContextPath(baseRequest.getContextPath());
- baseRequest.setServletPath(null);
- baseRequest.setPathInfo(uri);
- if (this.queryBuilder != null) {
- try {
- query = this.queryBuilder.execute(baseRequest);
- } catch (Exception e) {
- throw new IOException(e);
- }
- }
- if (query == null) {
- query = old_query;
- }
- if (query != null) {
- baseRequest.mergeQueryParameters(query, true);
- }
- baseRequest.setAttributes(attr);
- chain.doFilter(req, res);
- }
-
- /**
- * @inheritDoc
- * @see javax.servlet.Filter#destroy()
- */
- public void destroy() {
- mediator.debug("Destroyed filter");
- }
-}
+
+ public static final java.lang.String __INCLUDE_PREFIX = "javax.servlet.include.";
+
+ public static final java.lang.String __FORWARD_PREFIX = "javax.servlet.forward.";
+
+ /**
+ * Extended {@link Attributes}
+ */
+ private class ForwardAttributes implements Attributes {
+ final Attributes _attr;
+
+ String _requestURI;
+ String _contextPath;
+ String _servletPath;
+ String _pathInfo;
+ String _query;
+
+ ForwardAttributes(Attributes attributes) {
+ _attr = attributes;
+ }
+
+ /**
+ * @inheritDoc
+ * @see org.eclipse.jetty.util.Attributes#getAttribute(java.lang.String)
+ */
+ @Override
+ public Object getAttribute(String key) {
+ if (key.equals(RequestDispatcher.FORWARD_PATH_INFO))
+ return _pathInfo;
+ if (key.equals(RequestDispatcher.FORWARD_REQUEST_URI))
+ return _requestURI;
+ if (key.equals(RequestDispatcher.FORWARD_SERVLET_PATH))
+ return _servletPath;
+ if (key.equals(RequestDispatcher.FORWARD_CONTEXT_PATH))
+ return _contextPath;
+ if (key.equals(RequestDispatcher.FORWARD_QUERY_STRING))
+ return _query;
+ if (key.startsWith(__INCLUDE_PREFIX))
+ return null;
+ return _attr.getAttribute(key);
+ }
+
+ /**
+ * @inheritDoc
+ * @see org.eclipse.jetty.util.Attributes#getAttributeNames()
+ */
+ @Override
+ public Enumeration<String> getAttributeNames() {
+ HashSet<String> set = new HashSet<>();
+ Enumeration<String> e = _attr.getAttributeNames();
+ while (e.hasMoreElements()) {
+ String name = e.nextElement();
+ if (!name.startsWith(__INCLUDE_PREFIX) && !name.startsWith(__FORWARD_PREFIX))
+ set.add(name);
+ }
+ if (_pathInfo != null)
+ set.add(RequestDispatcher.FORWARD_PATH_INFO);
+ else
+ set.remove(RequestDispatcher.FORWARD_PATH_INFO);
+ set.add(RequestDispatcher.FORWARD_REQUEST_URI);
+ set.add(RequestDispatcher.FORWARD_SERVLET_PATH);
+ set.add(RequestDispatcher.FORWARD_CONTEXT_PATH);
+ if (_query != null)
+ set.add(RequestDispatcher.FORWARD_QUERY_STRING);
+ else
+ set.remove(RequestDispatcher.FORWARD_QUERY_STRING);
+
+ return Collections.enumeration(set);
+ }
+
+ /**
+ * @inheritDoc
+ * @see org.eclipse.jetty.util.Attributes#setAttribute(java.lang.String,
+ * java.lang.Object)
+ */
+ @Override
+ public void setAttribute(String key, Object value) {
+ if (key.startsWith("javax.servlet.")) {
+ if (key.equals(RequestDispatcher.FORWARD_PATH_INFO))
+ _pathInfo = (String) value;
+ else if (key.equals(RequestDispatcher.FORWARD_REQUEST_URI))
+ _requestURI = (String) value;
+ else if (key.equals(RequestDispatcher.FORWARD_SERVLET_PATH))
+ _servletPath = (String) value;
+ else if (key.equals(RequestDispatcher.FORWARD_CONTEXT_PATH))
+ _contextPath = (String) value;
+ else if (key.equals(RequestDispatcher.FORWARD_QUERY_STRING))
+ _query = (String) value;
+
+ else if (value == null)
+ _attr.removeAttribute(key);
+ else
+ _attr.setAttribute(key, value);
+ } else if (value == null)
+ _attr.removeAttribute(key);
+ else
+ _attr.setAttribute(key, value);
+ }
+
+ /**
+ * @inheritDoc
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "FORWARD+" + _attr.toString();
+ }
+
+ /**
+ * @inheritDoc
+ * @see org.eclipse.jetty.util.Attributes#clearAttributes()
+ */
+ @Override
+ public void clearAttributes() {
+ _attr.clearAttributes();
+ _requestURI = null;
+ _contextPath = null;
+ _servletPath = null;
+ _pathInfo = null;
+ _query = null;
+ }
+
+ /**
+ * @inheritDoc
+ * @see org.eclipse.jetty.util.Attributes#removeAttribute(java.lang.String)
+ */
+ @Override
+ public void removeAttribute(String name) {
+ setAttribute(name, null);
+ }
+ }
+
+ /**
+ * the {@link Executable} allowing to build the target
+ * URI of the forwarding process
+ */
+ private ForwardingService forwardingService;
+
+ private FilterConfig config;
+
+ private Mediator mediator;
+
+ /**
+ * Constructor
+ *
+ * @param mediator
+ * the {@link Mediator} allowing the ForwardingFilter to be
+ * instantiated to interact with the OSGi host environment
+ * @param forwardingService
+ * the {@link ForwardingService} allowing the ForwardingFilter to be
+ * instantiated to build the forwarding String URI according to the
+ * processed {@link HttpServletRequest}
+ */
+ public ForwardingFilter(Mediator mediator, ForwardingService forwardingService) {
+ this.mediator = mediator;
+ this.forwardingService = forwardingService;
+ }
+
+ /**
+ * @inheritDoc
+ * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
+ */
+ public void init(FilterConfig config) throws ServletException {
+ this.config = config;
+ mediator.debug("Init with config [" + config + "]");
+ }
+
+ /**
+ * @inheritDoc
+ * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, *
+ * javax.servlet.ServletResponse, javax.servlet.FilterChain)
+ */
+ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
+ throws IOException, ServletException {
+
+ Request baseRequest = Request.getBaseRequest(req);
+ Response base_response = baseRequest.getResponse();
+ base_response.resetForForward();
+
+ final HttpURI old_uri = baseRequest.getHttpURI();
+ final String old_context_path = baseRequest.getContextPath();
+ final String old_servlet_path = baseRequest.getServletPath();
+ final String old_path_info = baseRequest.getPathInfo();
+
+ final DispatcherType old_type = baseRequest.getDispatcherType();
+ final Attributes old_attr = baseRequest.getAttributes();
+ final MultiMap<String> old_query_params = baseRequest.getQueryParameters();
+
+ baseRequest.setDispatcherType(DispatcherType.FORWARD);
+ ForwardAttributes attr = new ForwardAttributes(old_attr);
+
+ if (old_attr.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI) != null) {
+ attr._pathInfo = (String) old_attr.getAttribute(RequestDispatcher.FORWARD_PATH_INFO);
+ attr._query = (String) old_attr.getAttribute(RequestDispatcher.FORWARD_QUERY_STRING);
+ attr._requestURI = (String) old_attr.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
+ attr._contextPath = (String) old_attr.getAttribute(RequestDispatcher.FORWARD_CONTEXT_PATH);
+ attr._servletPath = (String) old_attr.getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH);
+ } else {
+ attr._pathInfo = old_path_info;
+ attr._query = old_uri.getQuery();
+ attr._requestURI = old_uri.getPath();
+ attr._contextPath = old_context_path;
+ attr._servletPath = old_servlet_path;
+ }
+ String query = forwardingService.getQuery(baseRequest);
+ String path = forwardingService.getUri(baseRequest);
+ String param = forwardingService.getParam(baseRequest);
+ String fragment = forwardingService.getFragment(baseRequest);
+
+ HttpURI uri = new HttpURI(old_uri.getScheme(), old_uri.getHost(), old_uri.getPort(), path, param,
+ query, fragment);
+
+ baseRequest.setHttpURI(uri);
+ baseRequest.setContextPath(this.config.getServletContext().getContextPath());
+ baseRequest.setServletPath(null);
+ baseRequest.setPathInfo(path);
+
+ if (query != null || old_uri.getQuery() != null)
+ baseRequest.mergeQueryParameters(old_uri.getQuery(), query, true);
+
+ baseRequest.setAttributes(attr);
+ if (attr._query != null)
+ baseRequest.mergeQueryParameters(baseRequest.getQueryString(), attr._query, false);
+ baseRequest.setAttributes(attr);
+
+ RequestDispatcher d = this.config.getServletContext().getRequestDispatcher(path);
+ d.forward(req, res);
+ }
+
+ /**
+ * @inheritDoc
+ * @see javax.servlet.Filter#destroy()
+ */
+ public void destroy() {
+ mediator.debug("Destroyed filter");
+ }
+} \ No newline at end of file
diff --git a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/tools/internal/FactoryFactory.java b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/tools/internal/FactoryFactory.java
index c129a3ab..baa9faee 100644
--- a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/tools/internal/FactoryFactory.java
+++ b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/tools/internal/FactoryFactory.java
@@ -10,30 +10,20 @@
*/
package org.eclipse.sensinact.gateway.nthbnd.http.tools.internal;
-import org.apache.felix.http.api.ExtHttpService;
import org.eclipse.sensinact.gateway.common.bundle.Mediator;
-import org.eclipse.sensinact.gateway.common.execution.Executable;
import org.eclipse.sensinact.gateway.nthbnd.http.callback.internal.CallbackFactory;
import org.eclipse.sensinact.gateway.nthbnd.http.forward.internal.ForwardingFactory;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
/**
- * A FactoryFactory is in charge of creating {@link CallbackFactory}s and
- * {@link ForwardingFactory}s to be attached to registered {@link
- * ExtHttpService}s
+ * A FactoryFactory is in charge of creating {@link CallbackFactory} and
+ * {@link ForwardingFactory}
*
* @author <a href="mailto:christophe.munilla@cea.fr">Christophe Munilla</a>
*/
public class FactoryFactory {
private Mediator mediator;
- private String appearingKey;
- private String disappearingKey;
- private Map<ExtHttpService, ForwardingFactory> forwarders;
- private Map<ExtHttpService, CallbackFactory> callbacks;
+ private ForwardingFactory forwarderFactory;
+ private CallbackFactory callbackFactory;
/**
* Constructor
@@ -43,74 +33,26 @@ public class FactoryFactory {
*/
public FactoryFactory(Mediator mediator) {
this.mediator = mediator;
- this.callbacks = Collections.synchronizedMap(new HashMap<ExtHttpService, CallbackFactory>());
- this.forwarders = Collections.synchronizedMap(new HashMap<ExtHttpService, ForwardingFactory>());
}
/**
- * Starts this ForwardingInstallerFActory and starts to observe the registration and
- * the unregistration of the {@link ExtHttpService}s
+ * Starts this FactoryFactory's CallbackFactory and ForwardingFactory
*/
public void start() throws Exception {
- appearingKey = 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) {
- CallbackFactory callback = new CallbackFactory(mediator, service);
- FactoryFactory.this.callbacks.put(service, callback);
- callback.start();
+ callbackFactory = new CallbackFactory(mediator);
+ callbackFactory.start();
- ForwardingFactory forwarder = new ForwardingFactory(mediator, service);
- FactoryFactory.this.forwarders.put(service, forwarder);
- forwarder.start();
- return null;
- }
- });
- disappearingKey = mediator.attachOnServiceDisappearing(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) {
- CallbackFactory callback = FactoryFactory.this.callbacks.remove(service);
- if (callback != null) {
- callback.stop();
- }
- ForwardingFactory forwarder = FactoryFactory.this.forwarders.remove(service);
- if (forwarder != null) {
- forwarder.stop();
- }
- return null;
- }
- });
+ forwarderFactory = new ForwardingFactory(mediator);
+ forwarderFactory.start();
}
/**
- * Stops this ForwardingInstallerFactory and stops to observe the registration and
- * the unregistration of the {@link ExtHttpService}s
+ * Stops this FactoryFactory's CallbackFactory and ForwardingFactory
*/
public void stop() throws Exception {
- mediator.detachOnServiceAppearing(ExtHttpService.class, null, appearingKey);
- mediator.detachOnServiceDisappearing(ExtHttpService.class, null, disappearingKey);
- synchronized (this.callbacks) {
- Iterator<CallbackFactory> it = this.callbacks.values().iterator();
- while (it.hasNext()) {
- it.next().stop();
- it.remove();
- }
- }
- synchronized (this.forwarders) {
- Iterator<ForwardingFactory> it = this.forwarders.values().iterator();
- while (it.hasNext()) {
- it.next().stop();
- it.remove();
- }
- }
+ callbackFactory.stop();
+ callbackFactory = null;
+ forwarderFactory.stop();
+ forwarderFactory = null;
}
}
diff --git a/platform/northbound/http-tools/src/test/java/org/eclipse/sensinact/gateway/nthbnd/forward/test/TestForwardingService.java b/platform/northbound/http-tools/src/test/java/org/eclipse/sensinact/gateway/nthbnd/forward/test/TestForwardingService.java
index b5ec3490..c610bca5 100644
--- a/platform/northbound/http-tools/src/test/java/org/eclipse/sensinact/gateway/nthbnd/forward/test/TestForwardingService.java
+++ b/platform/northbound/http-tools/src/test/java/org/eclipse/sensinact/gateway/nthbnd/forward/test/TestForwardingService.java
@@ -10,21 +10,24 @@
*/
package org.eclipse.sensinact.gateway.nthbnd.forward.test;
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Map;
+
import org.eclipse.sensinact.gateway.common.bundle.Mediator;
import org.eclipse.sensinact.gateway.test.MidOSGiTest;
+import org.eclipse.sensinact.gateway.util.IOUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.skyscreamer.jsonassert.JSONAssert;
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-
@SuppressWarnings({"unchecked", "rawtypes"})
public class TestForwardingService extends MidOSGiTest {
//********************************************************************//
@@ -68,24 +71,72 @@ public class TestForwardingService extends MidOSGiTest {
*/
@Override
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/rest-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.log.level", "4");
+ 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.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/rest-access.jar");
+ configuration.put("felix.auto.start.4",
+ "file:target/felix/bundle/dynamicBundle.jar " +
+ "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.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();
+ }
}
@Test
public void testForwarding() throws Exception {
+ Thread.sleep(5000);
Mediator mediator = new Mediator(context);
this.initializeMoke(new File("./extra-src/test/resources/MANIFEST.MF"), new File("./extra-src/test/resources/meta"), new File("./target/extra-test-classes"));
-
+
String simulated1 = HttpServiceTestClient.newRequest(mediator, HTTP_ROOTURL + "/sensinact/providers", null, "GET");
System.out.println(simulated1);
@@ -105,6 +156,7 @@ public class TestForwardingService extends MidOSGiTest {
@Test
public void testCallback() throws Exception {
+ Thread.sleep(5000);
Mediator mediator = new Mediator(context);
this.initializeMoke(new File("./extra-src2/test/resources/MANIFEST.MF"), new File("./extra-src2/test/resources/meta"), new File("./target/extra-test-classes2"));
try {
@@ -112,8 +164,8 @@ public class TestForwardingService extends MidOSGiTest {
System.out.println(simulated1);
assertEquals("[GET]/callbackTest1", simulated1);
+
String simulated2 = HttpServiceTestClient.newRequest(mediator, HTTP_ROOTURL + "/callbackTest1/withContent", "MyContent", "POST");
-
System.out.println(simulated2);
assertEquals("[POST]/callbackTest1/withContent", simulated2);
} catch (Exception e) {
@@ -123,8 +175,11 @@ public class TestForwardingService extends MidOSGiTest {
private void initializeMoke(File manifestFile, File... sourceDirectories) throws Exception {
File tmpDirectory = new File("./target/felix/tmp");
- new File(tmpDirectory, "dynamicBundle.jar").delete();
-
+ if(!tmpDirectory.exists()) {
+ tmpDirectory.mkdir();
+ } else {
+ new File(tmpDirectory, "dynamicBundle.jar").delete();
+ }
int length = (sourceDirectories == null ? 0 : sourceDirectories.length);
File[] sources = new File[length + 1];
int index = 0;
@@ -140,13 +195,11 @@ public class TestForwardingService extends MidOSGiTest {
ClassLoader current = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(super.classloader);
+ Thread.sleep(5000);
try {
bundle.start();
-
} catch (Exception e) {
-
e.printStackTrace();
-
} finally {
Thread.currentThread().setContextClassLoader(current);
}
diff --git a/platform/northbound/http-tools/src/test/resources/sensinact.config b/platform/northbound/http-tools/src/test/resources/sensinact.config
new file mode 100644
index 00000000..402fa74c
--- /dev/null
+++ b/platform/northbound/http-tools/src/test/resources/sensinact.config
@@ -0,0 +1,3 @@
+namespace=SERVER
+broker=tcp://sensinact-cea.ddns.net:5269
+broker.topic.prefix=/

Back to the top