From 72b2aeb84407b522fe91c4e1344e44474e1b9a6b Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Mon, 11 Apr 2022 12:24:21 -0500 Subject: [PATCH] Account for header value order change on Java 18 client The HttpURLConnection changed the order of multi-value headers in Java 18. This updates the test to account for that --- .../META-INF/MANIFEST.MF | 3 ++- .../pom.xml | 2 +- .../http/servlet/tests/DispatchingTest.java | 24 +++++++++++++++---- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.http.servlet.tests/META-INF/MANIFEST.MF index 9e49a4f165..48d5ba8c96 100644 --- a/bundles/org.eclipse.equinox.http.servlet.tests/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.http.servlet.tests/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: org.eclipse.equinox.http.servlet.tests Bundle-Vendor: Eclipse.org - Equinox Bundle-SymbolicName: org.eclipse.equinox.http.servlet.tests -Bundle-Version: 1.8.300.qualifier +Bundle-Version: 1.8.400.qualifier Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Eclipse-BundleShape: dir Require-Bundle: org.junit;bundle-version="4.0" @@ -19,6 +19,7 @@ Import-Package: javax.servlet;version="2.6.0", org.eclipse.osgi.service.urlconversion;version="1.0.0", org.osgi.framework;version="1.6.0", org.osgi.framework.hooks.service;version="1.1.0", + org.osgi.framework.namespace;version="1.2.0", org.osgi.framework.wiring;version="1.2.0", org.osgi.resource;version="1.0.0", org.osgi.service.component, diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/pom.xml b/bundles/org.eclipse.equinox.http.servlet.tests/pom.xml index 0a345e8655..6cead03ffd 100644 --- a/bundles/org.eclipse.equinox.http.servlet.tests/pom.xml +++ b/bundles/org.eclipse.equinox.http.servlet.tests/pom.xml @@ -19,7 +19,7 @@ org.eclipse.equinox org.eclipse.equinox.http.servlet.tests - 1.8.300-SNAPSHOT + 1.8.400-SNAPSHOT eclipse-test-plugin diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/DispatchingTest.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/DispatchingTest.java index 340c02a9f3..f1fbf29129 100644 --- a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/DispatchingTest.java +++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/DispatchingTest.java @@ -52,6 +52,11 @@ import org.eclipse.equinox.http.servlet.tests.util.EventHandler; import org.junit.Assert; import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.Constants; +import org.osgi.framework.Version; +import org.osgi.framework.namespace.ExecutionEnvironmentNamespace; +import org.osgi.framework.wiring.BundleWiring; import org.osgi.service.http.HttpContext; import org.osgi.service.http.HttpService; import org.osgi.service.http.context.ServletContextHelper; @@ -1407,14 +1412,16 @@ protected void service(HttpServletRequest request, HttpServletResponse response) Map> response = requestAdvisor.request("s1", null); + // On Java 18 the order changed on the client for headers with multiple values. + int multiValueIdx = new Version(18, 0 ,0).compareTo(getJavaVersion()) > 0 ? 0 : 1; Assert.assertNotNull(response.get("Set-Cookie")); - Assert.assertEquals("foo=baz", response.get("Set-Cookie").get(0)); + Assert.assertEquals("foo=baz", response.get("Set-Cookie").get(multiValueIdx)); Assert.assertNotNull(response.get("X-date")); - Assert.assertEquals(format.format(new Date(date2)), response.get("X-date").get(0)); + Assert.assertEquals(format.format(new Date(date2)), response.get("X-date").get(multiValueIdx)); Assert.assertNotNull(response.get("X-colour")); - Assert.assertEquals("green", response.get("X-colour").get(0)); + Assert.assertEquals("green", response.get("X-colour").get(multiValueIdx)); Assert.assertNotNull(response.get("X-size")); - Assert.assertEquals("30", response.get("X-size").get(0)); + Assert.assertEquals("30", response.get("X-size").get(multiValueIdx)); String contentType = response.get("Content-Type").get(0); @@ -1425,6 +1432,15 @@ protected void service(HttpServletRequest request, HttpServletResponse response) Assert.assertEquals("dog", response.get("X-animal").get(0)); } + private Version getJavaVersion() { + Bundle system = getBundleContext().getBundle(Constants.SYSTEM_BUNDLE_LOCATION); + BundleWiring systemWiring = system.adapt(BundleWiring.class); + @SuppressWarnings("unchecked") + List versions = systemWiring.getCapabilities(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE). // + stream().filter(c -> c.getAttributes().get(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE).equals("JavaSE")) // + .findFirst().map(c -> (List) c.getAttributes().get(ExecutionEnvironmentNamespace.CAPABILITY_VERSION_ATTRIBUTE)).get(); + return versions.get(versions.size() - 1); + } // Bug 493583 @Test public void test_streamed_response_outputstream() throws Exception {