diff --git a/containers/jetty-http/src/main/java/org/glassfish/jersey/jetty/JettyHttpContainer.java b/containers/jetty-http/src/main/java/org/glassfish/jersey/jetty/JettyHttpContainer.java index 5fa394d23b..e1a04d73ed 100644 --- a/containers/jetty-http/src/main/java/org/glassfish/jersey/jetty/JettyHttpContainer.java +++ b/containers/jetty-http/src/main/java/org/glassfish/jersey/jetty/JettyHttpContainer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -18,6 +18,8 @@ import java.io.IOException; import java.io.OutputStream; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.lang.reflect.Type; import java.net.URI; import java.net.URISyntaxException; @@ -323,7 +325,7 @@ public void setSuspendTimeout(final long timeOut, final TimeUnit timeUnit) throw @Override public void commit() { try { - response.closeOutput(); + closeOutput(response); } catch (final IOException e) { LOGGER.log(Level.WARNING, LocalizationMessages.UNABLE_TO_CLOSE_RESPONSE(), e); } finally { @@ -334,6 +336,22 @@ public void commit() { } } + private void closeOutput(Response response) throws IOException { + try { + response.completeOutput(); + } catch (final IOException e) { + throw e; + } catch (NoSuchMethodError e) { + // try older Jetty Response#closeOutput + try { + Method method = response.getClass().getMethod("closeOutput"); + method.invoke(response); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) { + throw new IOException(ex); + } + } + } + @Override public void failure(final Throwable error) { try { diff --git a/pom.xml b/pom.xml index 16f3fb382e..6fe2eef4eb 100644 --- a/pom.xml +++ b/pom.xml @@ -1960,6 +1960,12 @@ 4.12 test + + org.junit.jupiter + junit-jupiter-engine + ${junit5.version} + test + org.testng testng @@ -2080,7 +2086,6 @@ 8.28 3.3 3.2.5 - 5.1.0-RC2 1.3.3 1.7 3.0.4 @@ -2097,41 +2102,21 @@ org.jvnet.hk2.*;version="[2.5,4)" 5.1.0 4.5.9 - 3.0.8 2.10.1 1.9.13 - 1.2.1 3.25.0-GA - javax.annotation.*;version="[1.2,3)" - 1.3.5 - 3.0.3 - 3.0.2 - 1.2.5 - 2.2.3 - 2.0.2 - 2.3.2 - 2.3.2 - 1.0.2 - 2.1 - 2.1.6 3.3.0.Final 1.19.3 ${jersey1.version} 1.3.7 - 6.1.26 - 9.4.17.v20190418 - 6.1.14 1.10.2 1.44 - 1.1.5 - 1.1.5 2.3.6 1.2.7 1.3.3 + 5.6.0 4.0.1 - 1.9.11 1.10.19 - 2.7.4 0.8.17 4.1.43.Final 1.6.7 @@ -2156,6 +2141,30 @@ 2.2.14.Final 3.0.0.Final 2.11.0 - 1.0.3 + + + 5.1.0 + 3.0.8 + 1.2.2 + 3.0.3 + 3.0.3 + javax.annotation.*;version="[1.2,3)" + 1.3.5 + 1.2.5 + 2.2.3 + 2.0.2 + 2.3.2 + 2.3.2 + 2.1 + 2.1.6 + 6.1.26 + 9.4.27.v20200227 + 6.1.14 + 1.0.2 + 1.1.6 + 1.1.6 + 1.9.13 + 2.7.6 + 1.0.6 diff --git a/tests/e2e-entity/src/test/java/org/glassfish/jersey/tests/e2e/json/entity/ComplexBeanWithAttributes4.java b/tests/e2e-entity/src/test/java/org/glassfish/jersey/tests/e2e/json/entity/ComplexBeanWithAttributes4.java index 6e674d5538..78b118ec34 100644 --- a/tests/e2e-entity/src/test/java/org/glassfish/jersey/tests/e2e/json/entity/ComplexBeanWithAttributes4.java +++ b/tests/e2e-entity/src/test/java/org/glassfish/jersey/tests/e2e/json/entity/ComplexBeanWithAttributes4.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -86,7 +86,7 @@ public boolean equals(Object obj) { public int hashCode() { int hash = 3; hash = 19 * hash + (this.a1 != null ? this.a1.hashCode() : 0); - hash = 19 * hash + this.a2; + hash = 19 * hash + (this.a2 != null ? this.a2.hashCode() : 0); hash = 19 * hash + (this.b != null ? this.b.hashCode() : 0); hash = 19 * hash + (this.filler1 != null ? this.filler1.hashCode() : 0); hash = 19 * hash + (this.filler2 != null ? this.filler2.hashCode() : 0); diff --git a/tests/e2e-entity/src/test/java/org/glassfish/jersey/tests/e2e/json/entity/SimpleBeanWithObjectAttributes.java b/tests/e2e-entity/src/test/java/org/glassfish/jersey/tests/e2e/json/entity/SimpleBeanWithObjectAttributes.java index bc10df1d69..5478ba4f97 100644 --- a/tests/e2e-entity/src/test/java/org/glassfish/jersey/tests/e2e/json/entity/SimpleBeanWithObjectAttributes.java +++ b/tests/e2e-entity/src/test/java/org/glassfish/jersey/tests/e2e/json/entity/SimpleBeanWithObjectAttributes.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -80,7 +80,9 @@ public int hashCode() { if (null != uri) { hash += 17 * uri.hashCode(); } - hash += 13 * i; + if (null != i) { + hash += 13 * i; + } return hash; } diff --git a/tests/integration/jetty-response-close/pom.xml b/tests/integration/jetty-response-close/pom.xml new file mode 100644 index 0000000000..b6e9c3444a --- /dev/null +++ b/tests/integration/jetty-response-close/pom.xml @@ -0,0 +1,62 @@ + + + + + project + org.glassfish.jersey.tests.integration + 2.31-SNAPSHOT + + 4.0.0 + + jetty-response-close + + + + org.glassfish.jersey.containers + jersey-container-jetty-http + ${project.version} + test + + + org.eclipse.jetty + jetty-server + + + + + org.eclipse.jetty + jetty-server + + 9.4.17.v20190418 + + + + org.junit.jupiter + junit-jupiter-engine + test + + + + + -Djava.security.manager -Djava.security.policy=${project.build.directory}/test-classes/surefire.policy + + + \ No newline at end of file diff --git a/tests/integration/jetty-response-close/src/main/java/org/glassfish/jersey/tests/jettyresponseclose/Resource.java b/tests/integration/jetty-response-close/src/main/java/org/glassfish/jersey/tests/jettyresponseclose/Resource.java new file mode 100644 index 0000000000..9ab1e33fc3 --- /dev/null +++ b/tests/integration/jetty-response-close/src/main/java/org/glassfish/jersey/tests/jettyresponseclose/Resource.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.tests.jettyresponseclose; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +@Path("/") +public class Resource { + @GET + public String get() { + return Resource.class.getName(); + } +} diff --git a/tests/integration/jetty-response-close/src/test/java/org/glassfish/jersey/tests/jettyresponseclose/JettyHttpContainerCloseTest.java b/tests/integration/jetty-response-close/src/test/java/org/glassfish/jersey/tests/jettyresponseclose/JettyHttpContainerCloseTest.java new file mode 100644 index 0000000000..eb8a3caef2 --- /dev/null +++ b/tests/integration/jetty-response-close/src/test/java/org/glassfish/jersey/tests/jettyresponseclose/JettyHttpContainerCloseTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.tests.jettyresponseclose; + +import org.eclipse.jetty.server.Server; +import org.glassfish.jersey.jetty.JettyHttpContainer; +import org.glassfish.jersey.jetty.JettyHttpContainerFactory; +import org.glassfish.jersey.server.ResourceConfig; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Response; +import java.net.URI; + +public class JettyHttpContainerCloseTest { + + private static Server server; + private static JettyHttpContainer container; + private static final String URL = "http://localhost:9080"; + + @BeforeAll + public static void setup() { + server = JettyHttpContainerFactory.createServer(URI.create(URL), + new ResourceConfig(Resource.class)); + container = (JettyHttpContainer) server.getHandler(); + } + + @AfterAll + public static void teardown() throws Exception { + container.doStop(); + } + + @Test + public void testResponseClose() { + try (Response response = ClientBuilder.newClient().target(URL).request().get()) { + Assertions.assertEquals(200, response.getStatus()); + Assertions.assertEquals(Resource.class.getName(), response.readEntity(String.class)); + + } + } +} diff --git a/tests/integration/jetty-response-close/src/test/resources/surefire.policy b/tests/integration/jetty-response-close/src/test/resources/surefire.policy new file mode 100644 index 0000000000..f012633e76 --- /dev/null +++ b/tests/integration/jetty-response-close/src/test/resources/surefire.policy @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +// we do not care about java lib itself +grant codebase "file:${java.home}/-" { + permission java.security.AllPermission; +}; + +// we do not care about our dependencies +grant codebase "file:${settings.localRepository}/-" { + permission java.security.AllPermission; +}; + +grant codebase "file:${user.home}/-" { + permission java.io.FilePermission "<>", "read"; +}; + +grant { + permission java.lang.management.ManagementPermission "monitor"; + permission java.util.PropertyPermission "*", "read, write"; + permission java.util.logging.LoggingPermission "control"; + permission java.lang.RuntimePermission "setIO"; + permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; + + permission java.lang.RuntimePermission "accessDeclaredMembers"; + permission java.lang.RuntimePermission "modifyThread"; + permission java.io.FilePermission "<>", "read"; + + permission java.lang.RuntimePermission "getenv.JETTY_AVAILABLE_PROCESSORS"; + permission java.net.SocketPermission "localhost", "accept,connect,listen,resolve"; + permission java.lang.RuntimePermission "setContextClassLoader"; +}; diff --git a/tests/integration/pom.xml b/tests/integration/pom.xml index 8232ae466b..cb2fb63533 100644 --- a/tests/integration/pom.xml +++ b/tests/integration/pom.xml @@ -84,6 +84,7 @@ jersey-3992 jersey-4099 jersey-4321 + jetty-response-close microprofile portability-jersey-1 portability-jersey-2