Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for header value order change on Java 18 client #11

Merged
merged 1 commit into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.eclipse.equinox.http.servlet.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</parent>
<groupId>org.eclipse.equinox</groupId>
<artifactId>org.eclipse.equinox.http.servlet.tests</artifactId>
<version>1.8.300-SNAPSHOT</version>
<version>1.8.400-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1407,14 +1412,16 @@ protected void service(HttpServletRequest request, HttpServletResponse response)

Map<String, List<String>> 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);

Expand All @@ -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<Version> versions = systemWiring.getCapabilities(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE). //
stream().filter(c -> c.getAttributes().get(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE).equals("JavaSE")) //
.findFirst().map(c -> (List<Version>) 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 {
Expand Down