Skip to content

Commit

Permalink
Update TCK project to also use the Servlet Whiteboard
Browse files Browse the repository at this point in the history
The TCK project was only running using the Jetty integration project. This commit adds an additional run for the Servlet Whiteboard, and some fixes to the ServletContextHelper/Servlet registration paths to make the TCK pass with the Servlet Whiteboard

Signed-off-by: Tim Ward <timothyjward@apache.org>
  • Loading branch information
timothyjward committed Jul 11, 2023
1 parent 4676b7c commit 7ee450a
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static org.osgi.service.servlet.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_TARGET;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
Expand Down Expand Up @@ -105,11 +106,35 @@ private String[] getURLs() {
//first look which http whiteboards would fit
String[] endpoints = JerseyHelper.getStringPlusProperty(HTTP_SERVICE_ENDPOINT, asMap(runtimeTarget.getProperties()));

return Arrays.stream(endpoints).map(s -> buildEndPoint(s, basePath))
return Arrays.stream(endpoints)
.sorted(this::preferIPv4)
.map(s -> buildEndPoint(s, basePath))
.toArray(String[]::new);
}


private int preferIPv4(String a, String b) {
if(a == null) {
return b == null ? 0 : 1;
} else if (b == null) {
return -1;
}
int aIdx = a.indexOf("://");
int bIdx = b.indexOf("://");

boolean aIPv6 = a.charAt(aIdx < 0 ? 0 : aIdx + 3) == '[';
boolean bIPv6 = b.charAt(bIdx < 0 ? 0 : bIdx + 3) == '[';

if(aIPv6 && !bIPv6) {
return 1;
} else if (!aIPv6 && bIPv6) {
return -1;
} else {
return a.compareTo(b);
}
}


private String buildEndPoint(String endpoint, String path) {
String rsEndpoint = endpoint;
if(!endpoint.endsWith("/")) {
Expand All @@ -134,16 +159,31 @@ private String buildEndPoint(String endpoint, String path) {
* @see org.eclipse.osgitech.rest.runtime.common.AbstractJerseyServiceRuntime#doRegisterServletContainer(org.eclipse.osgitech.rest.provider.application.JakartarsApplicationProvider, java.lang.String, org.glassfish.jersey.server.ResourceConfig)
*/
private WhiteboardServletContainer registerContainer(String path, ResourceConfig config) {
String applicationPath = config.getApplicationPath() == null ? "" : config.getApplicationPath();

String contextId = String.format("ContextForRestWhiteboard.%s.instance.%s", httpId, counter.incrementAndGet());
Dictionary<String, Object> contextHelperProps = new Hashtable<>();
contextHelperProps.put(HTTP_WHITEBOARD_TARGET, httpWhiteboardTarget);
contextHelperProps.put(HTTP_WHITEBOARD_CONTEXT_NAME, contextId);
String contextPath = basePath.endsWith("/") ? basePath.substring(0, basePath.length() -1) : basePath;
contextPath += path.substring(0, path.length() - applicationPath.length());
if(contextPath.endsWith("/")) {
contextPath = contextPath.substring(0, contextPath.length() - 1);
}
contextHelperProps.put(HTTP_WHITEBOARD_CONTEXT_PATH, contextPath.startsWith("/") ? contextPath : "/" + contextPath);

Dictionary<String, Object> servletProps = new Hashtable<>();

servletProps.put(HTTP_WHITEBOARD_SERVLET_PATTERN, path + (path.endsWith("/") ? "*" : "/*"));
String servletPath = applicationPath;
if(!servletPath.startsWith("/")) {
servletPath = "/" + servletPath;
}
if(servletPath.endsWith("/")) {
servletPath += "*";
} else {
servletPath += "/*";
}
servletProps.put(HTTP_WHITEBOARD_SERVLET_PATTERN, servletPath);
servletProps.put(HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED, Boolean.TRUE);
servletProps.put(HTTP_WHITEBOARD_FILTER_ASYNC_SUPPORTED, Boolean.TRUE);
servletProps.put(HTTP_WHITEBOARD_TARGET, httpWhiteboardTarget);
Expand Down
27 changes: 27 additions & 0 deletions org.eclipse.osgitech.rest.tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<artifactId>org.eclipse.osgitech.rest.jetty</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.osgitech.rest</groupId>
<artifactId>org.eclipse.osgitech.rest.servlet.whiteboard</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.osgitech.rest</groupId>
<artifactId>org.eclipse.osgitech.rest.sse</artifactId>
Expand Down Expand Up @@ -220,10 +225,32 @@
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-resolver-maven-plugin</artifactId>
<executions>
<execution>
<id>resolve-test</id>
<configuration>
<bndruns>
<include>test.bndrun</include>
<include>test2.bndrun</include>
</bndruns>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-testing-maven-plugin</artifactId>
<executions>
<execution>
<id>testing</id>
<configuration>
<bndruns>
<include>test.bndrun</include>
<include>test2.bndrun</include>
</bndruns>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
"jersey.jakartars.whiteboard.name" : "test_wb",
"jersey.context.path" : "test",
"jersey.disable.sessions" : false
},
"JakartarsServletWhiteboardRuntimeComponent":
{
"jersey.jakartars.whiteboard.name" : "test_wb",
"jersey.context.path" : "test"
}
}
89 changes: 89 additions & 0 deletions org.eclipse.osgitech.rest.tck/test2.bndrun
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
-runfw: org.apache.felix.framework
-runee: JavaSE-11

-runsystemcapabilities: ${native_capability}

-tester: biz.aQute.tester.junit-platform

-runrequires: \
osgi.extender;filter:='(osgi.extender=osgi.configurator)',\
bnd.identity;id='org.eclipse.osgitech.rest.tck-tests',\
bnd.identity;id='org.osgi.test.cases.jakartars',\
bnd.identity;id='org.eclipse.osgitech.rest.servlet.whiteboard'

-runblacklist: \
bnd.identity;id='org.osgi.service.cm',\
bnd.identity;id='org.glassfish.jersey.bundles.jaxrs-ri',\
bnd.identity;id='org.eclipse.osgitech.rest.jetty',\
bnd.identity;id='jakarta.json-api'

-runbundles.junit: \
org.opentest4j;version='[1.2.0,1.3)',\
org.osgi.util.function;version='[1.2.0,1.3)',\
assertj-core;version='[3.23.1,3.25)',\
junit-jupiter-api;version='[5.8.2,6)',\
junit-jupiter-engine;version='[5.8.2,6)',\
junit-jupiter-params;version='[5.8.2,6)',\
junit-platform-commons;version='[1.8.2,2)',\
junit-platform-engine;version='[1.8.2,2)',\
junit-platform-launcher;version='[1.8.2,2)',\
net.bytebuddy.byte-buddy;version='[1.12.8,1.13)',\
org.apache.felix.cm.json;version='[2.0.0,2.1)',\
org.apache.felix.configadmin;version='[1.9.24,1.10)',\
org.apache.felix.configurator;version='[1.0.18,1.1)',\
org.eclipse.parsson.jakarta.json;version='[1.1.2,1.2)',\
org.osgi.util.converter;version='[1.0.9,1.1)'


-runbundles: \
jakarta.annotation-api;version='[2.1.1,2.1.2)',\
jakarta.inject.jakarta.inject-api;version='[2.0.1,2.0.2)',\
jakarta.validation.jakarta.validation-api;version='[3.0.2,3.0.3)',\
jakarta.ws.rs-api;version='[3.1.0,3.1.1)',\
jakarta.xml.bind-api;version='[4.0.0,4.0.1)',\
javassist;version='[3.29.2,3.29.3)',\
org.apache.felix.configadmin;version='[1.9.24,1.9.25)',\
org.apache.servicemix.bundles.junit;version='[4.13.2,4.13.3)',\
org.glassfish.hk2.osgi-resource-locator;version='[1.0.3,1.0.4)',\
org.opentest4j;version='[1.2.0,1.2.1)',\
org.osgi.service.jakartars;version='[2.0.0,2.0.1)',\
org.osgi.test.cases.jakartars;version='[8.1.0,8.1.1)',\
org.osgi.util.converter;version='[1.0.9,1.0.10)',\
org.osgi.util.function;version='[1.2.0,1.2.1)',\
org.osgi.util.promise;version='[1.3.0,1.3.1)',\
slf4j.api;version='[1.7.36,1.7.37)',\
slf4j.simple;version='[1.7.36,1.7.37)',\
org.osgi.test.common;version='[1.2.1,1.2.2)',\
org.osgi.test.junit5;version='[1.2.1,1.2.2)',\
jakarta.activation-api;version='[2.1.2,2.1.3)',\
org.apache.felix.http.jetty;version='[5.0.4,5.0.5)',\
org.glassfish.hk2.api;version='[3.0.4,3.0.5)',\
org.glassfish.hk2.external.aopalliance-repackaged;version='[3.0.4,3.0.5)',\
org.glassfish.hk2.locator;version='[3.0.4,3.0.5)',\
org.glassfish.hk2.utils;version='[3.0.4,3.0.5)',\
org.glassfish.jersey.containers.jersey-container-servlet;version='[3.1.2,3.1.3)',\
org.glassfish.jersey.containers.jersey-container-servlet-core;version='[3.1.2,3.1.3)',\
org.glassfish.jersey.core.jersey-client;version='[3.1.2,3.1.3)',\
org.glassfish.jersey.core.jersey-common;version='[3.1.2,3.1.3)',\
org.glassfish.jersey.core.jersey-server;version='[3.1.2,3.1.3)',\
org.glassfish.jersey.inject.jersey-hk2;version='[3.1.2,3.1.3)',\
org.glassfish.jersey.media.jersey-media-jaxb;version='[3.1.2,3.1.3)',\
org.glassfish.jersey.media.jersey-media-sse;version='[3.1.2,3.1.3)',\
org.apache.aries.spifly.dynamic.framework.extension;version='[1.3.6,1.3.7)',\
org.apache.felix.cm.json;version='[2.0.0,2.0.1)',\
org.apache.felix.configurator;version='[1.0.18,1.0.19)',\
org.apache.felix.http.servlet-api;version='[2.1.0,2.1.1)',\
org.eclipse.parsson.jakarta.json;version='[1.1.2,1.1.3)',\
org.objectweb.asm;version='[9.5.0,9.5.1)',\
assertj-core;version='[3.24.2,3.24.3)',\
junit-jupiter-api;version='[5.9.2,5.9.3)',\
junit-jupiter-params;version='[5.9.2,5.9.3)',\
junit-platform-commons;version='[1.9.2,1.9.3)',\
net.bytebuddy.byte-buddy;version='[1.12.21,1.12.22)',\
org.apache.felix.scr;version='[2.2.6,2.2.7)',\
org.osgi.service.component;version='[1.5.1,1.5.2)',\
org.eclipse.osgitech.rest;version='[1.0.0,1.0.1)',\
org.eclipse.osgitech.rest.servlet.whiteboard;version='[1.0.0,1.0.1)',\
org.eclipse.osgitech.rest.sse;version='[1.0.0,1.0.1)',\
org.eclipse.osgitech.rest.tck-tests;version='[1.0.0,1.0.1)',\
org.osgi.service.servlet;version='[2.0.0,2.0.1)'

0 comments on commit 7ee450a

Please sign in to comment.