Initial Contribution
Signed-off-by: Jan Supol <jan.supol@oracle.com>
diff --git a/tests/integration/JERSEY-2988/pom.xml b/tests/integration/JERSEY-2988/pom.xml
new file mode 100644
index 0000000..82dc34a
--- /dev/null
+++ b/tests/integration/JERSEY-2988/pom.xml
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.23-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2988</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2988</name>
+
+ <description>
+ Reproducer of JERSEY-2988.
+
+ Jersey does not set locator properly for SingleHk2LocatorManager.
+ </description>
+
+ <properties>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ </properties>
+
+ <dependencies>
+ <!-- Jersey -->
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- Weld -->
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <version>2.0-EDR1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.weld.servlet</groupId>
+ <artifactId>weld-servlet-core</artifactId>
+ <version>3.0.0.Alpha13</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/JERSEY-2988/src/main/java/org/glassfish/jersey/tests/integration/jersey2988/ContextAwareBean.java b/tests/integration/JERSEY-2988/src/main/java/org/glassfish/jersey/tests/integration/jersey2988/ContextAwareBean.java
new file mode 100644
index 0000000..11f7e6a
--- /dev/null
+++ b/tests/integration/JERSEY-2988/src/main/java/org/glassfish/jersey/tests/integration/jersey2988/ContextAwareBean.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2988;
+
+import javax.ws.rs.core.Configuration;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+
+import javax.enterprise.context.ApplicationScoped;
+
+@ApplicationScoped
+public class ContextAwareBean {
+
+ @Context
+ private Configuration field;
+
+ private Configuration setter;
+
+ public Response fieldConfig() {
+ return field == null
+ ? Response.serverError().build()
+ : Response.ok().build();
+ }
+
+ public Response setterConfig() {
+ return setter == null
+ ? Response.serverError().build()
+ : Response.ok().build();
+ }
+
+ @Context
+ public void setConfig(Configuration setter) {
+ this.setter = setter;
+ }
+
+}
diff --git a/tests/integration/JERSEY-2988/src/main/java/org/glassfish/jersey/tests/integration/jersey2988/FieldContextExceptionMapper.java b/tests/integration/JERSEY-2988/src/main/java/org/glassfish/jersey/tests/integration/jersey2988/FieldContextExceptionMapper.java
new file mode 100644
index 0000000..38ddd30
--- /dev/null
+++ b/tests/integration/JERSEY-2988/src/main/java/org/glassfish/jersey/tests/integration/jersey2988/FieldContextExceptionMapper.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2988;
+
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class FieldContextExceptionMapper implements ExceptionMapper<IllegalStateException> {
+
+ @Context
+ private HttpHeaders field;
+
+ @Override
+ public Response toResponse(IllegalStateException ex) {
+ return Response.status(520)
+ .header("x-test-header", field.getHeaderString("x-test-header"))
+ .build();
+ }
+}
diff --git a/tests/integration/JERSEY-2988/src/main/java/org/glassfish/jersey/tests/integration/jersey2988/SetterContextExceptionMapper.java b/tests/integration/JERSEY-2988/src/main/java/org/glassfish/jersey/tests/integration/jersey2988/SetterContextExceptionMapper.java
new file mode 100644
index 0000000..c153e9f
--- /dev/null
+++ b/tests/integration/JERSEY-2988/src/main/java/org/glassfish/jersey/tests/integration/jersey2988/SetterContextExceptionMapper.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2988;
+
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class SetterContextExceptionMapper implements ExceptionMapper<NullPointerException> {
+
+ private HttpHeaders setter;
+
+ @Context
+ public void setSetter(HttpHeaders setter) {
+ this.setter = setter;
+ }
+
+ @Override
+ public Response toResponse(NullPointerException ex) {
+ return Response.status(520)
+ .header("x-test-header", setter.getHeaderString("x-test-header"))
+ .build();
+ }
+}
diff --git a/tests/integration/JERSEY-2988/src/main/java/org/glassfish/jersey/tests/integration/jersey2988/TestApplication.java b/tests/integration/JERSEY-2988/src/main/java/org/glassfish/jersey/tests/integration/jersey2988/TestApplication.java
new file mode 100644
index 0000000..3102bfa
--- /dev/null
+++ b/tests/integration/JERSEY-2988/src/main/java/org/glassfish/jersey/tests/integration/jersey2988/TestApplication.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2988;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+@ApplicationPath("/")
+public class TestApplication extends javax.ws.rs.core.Application {
+
+}
diff --git a/tests/integration/JERSEY-2988/src/main/java/org/glassfish/jersey/tests/integration/jersey2988/TestResource.java b/tests/integration/JERSEY-2988/src/main/java/org/glassfish/jersey/tests/integration/jersey2988/TestResource.java
new file mode 100644
index 0000000..8c18fe6
--- /dev/null
+++ b/tests/integration/JERSEY-2988/src/main/java/org/glassfish/jersey/tests/integration/jersey2988/TestResource.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2988;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Configuration;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+
+import javax.inject.Inject;
+
+@Path("/test")
+public class TestResource {
+
+ @Inject
+ private ContextAwareBean contextAwareBean;
+
+ @GET
+ @Path("field")
+ public Response field() {
+ return contextAwareBean.fieldConfig();
+ }
+
+ @GET
+ @Path("setter")
+ public Response setter() {
+ return contextAwareBean.setterConfig();
+ }
+
+ @GET
+ @Path("ex/field")
+ public String fieldExceptionMapper() {
+ throw new IllegalStateException("My handled exception.");
+ }
+
+ @GET
+ @Path("ex/setter")
+ public String setterExceptionMapper() {
+ throw new NullPointerException("My handled exception.");
+ }
+
+}
diff --git a/tests/integration/JERSEY-2988/src/main/webapp/WEB-INF/beans.xml b/tests/integration/JERSEY-2988/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..3dcd6e8
--- /dev/null
+++ b/tests/integration/JERSEY-2988/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
+ version="1.1" bean-discovery-mode="all">
+
+</beans>
diff --git a/tests/integration/JERSEY-2988/src/main/webapp/WEB-INF/jetty-web.xml b/tests/integration/JERSEY-2988/src/main/webapp/WEB-INF/jetty-web.xml
new file mode 100644
index 0000000..eb69254
--- /dev/null
+++ b/tests/integration/JERSEY-2988/src/main/webapp/WEB-INF/jetty-web.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
+<Configure class="org.eclipse.jetty.webapp.WebAppContext">
+ <Set name="serverClasses">
+ <Array type="java.lang.String">
+ <Item>-org.eclipse.jetty.servlet.ServletContextHandler.Decorator</Item>
+ </Array>
+ </Set>
+</Configure>
diff --git a/tests/integration/JERSEY-2988/src/test/java/org/glassfish/jersey/tests/integration/jersey2988/Jersey2988ITCase.java b/tests/integration/JERSEY-2988/src/test/java/org/glassfish/jersey/tests/integration/jersey2988/Jersey2988ITCase.java
new file mode 100644
index 0000000..b5bc49d
--- /dev/null
+++ b/tests/integration/JERSEY-2988/src/test/java/org/glassfish/jersey/tests/integration/jersey2988/Jersey2988ITCase.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2988;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.fail;
+
+/**
+ * JERSEY-2988 reproducer and JERSEY-2990 (duplicate of the previous one)
+ *
+ * @author Petr Bouda
+ */
+public class Jersey2988ITCase extends JerseyTest {
+
+ private static final String HEADER_NAME = "x-test-header";
+ private static final String HEADER_VALUE = "cool-header";
+
+ @Override
+ protected Application configure() {
+ return new TestApplication();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ /**
+ * Reproducer for JERSEY-2988
+ *
+ * @throws Exception
+ */
+ @Test
+ public void contextFieldInjection() throws Exception {
+ testCdiBeanContextInjection("field");
+ }
+
+ @Test
+ public void contextSetterInjection() throws Exception {
+ testCdiBeanContextInjection("setter");
+ }
+
+ private void testCdiBeanContextInjection(String path) {
+ int status = target("test/" + path).request().get().getStatus();
+ if (status != 200) {
+ fail("@Context field is not properly injected into CDI Bean.");
+ }
+ }
+
+ /**
+ * Reproducer for JERSEY-2990
+ *
+ * @throws Exception
+ */
+ @Test
+ public void contextFieldInjectionExceptionMapper() throws Exception {
+ testExceptionMapperContextInjection("field");
+ }
+
+ @Test
+ public void contextSetterExceptionMapper() throws Exception {
+ testExceptionMapperContextInjection("setter");
+ }
+
+ private void testExceptionMapperContextInjection(String path) {
+ Response response = target("test/ex/" + path).request().header(HEADER_NAME, HEADER_VALUE).get();
+ if (response.getStatus() != 520 || !HEADER_VALUE.equals(response.getHeaderString(HEADER_NAME))) {
+ fail("@Context method was not properly injected into ExceptionMapper.");
+ }
+ }
+}
diff --git a/tests/integration/async-jersey-filter/pom.xml b/tests/integration/async-jersey-filter/pom.xml
new file mode 100644
index 0000000..da8cd9b
--- /dev/null
+++ b/tests/integration/async-jersey-filter/pom.xml
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>async-jersey-filter</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-async-filter</name>
+
+ <description>
+ This web project reproduces tickets:
+ JERSEY-2730
+ JERSEY-2812
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>${servlet3.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/async/TestApplication.java b/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/async/TestApplication.java
new file mode 100644
index 0000000..f23fa16
--- /dev/null
+++ b/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/async/TestApplication.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.async;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+import org.glassfish.jersey.tests.integration.jersey2730.TestExceptionResource;
+import org.glassfish.jersey.tests.integration.jersey2730.exception.MappedExceptionMapper;
+import org.glassfish.jersey.tests.integration.jersey2812.TestWaitResource;
+
+/**
+ * Jersey application for JERSEY-2730.
+ *
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+@ApplicationPath("/")
+public class TestApplication extends ResourceConfig {
+
+ public TestApplication() {
+ register(TestExceptionResource.class);
+ register(MappedExceptionMapper.class);
+ register(TestWaitResource.class);
+ }
+}
diff --git a/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2730/TestExceptionResource.java b/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2730/TestExceptionResource.java
new file mode 100644
index 0000000..c531760
--- /dev/null
+++ b/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2730/TestExceptionResource.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2730;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.Suspended;
+
+import javax.inject.Singleton;
+
+import org.glassfish.jersey.servlet.internal.ResponseWriter;
+import org.glassfish.jersey.tests.integration.jersey2730.exception.MappedException;
+import org.glassfish.jersey.tests.integration.jersey2730.exception.UnmappedException;
+import org.glassfish.jersey.tests.integration.jersey2730.exception.UnmappedRuntimeException;
+
+/**
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+@Path("/exception")
+@Singleton
+public class TestExceptionResource {
+
+ /**
+ * An instance of thread that was processing a last request to this resource.
+ */
+ private Thread lastProcessingThread;
+
+ @GET
+ @Path("null")
+ public void get(@Suspended final AsyncResponse asyncResponse) {
+ lastProcessingThread = Thread.currentThread();
+ asyncResponse.resume((Throwable) null);
+ }
+
+ @GET
+ @Path("mapped")
+ public void getMappedException(@Suspended final AsyncResponse asyncResponse) {
+ lastProcessingThread = Thread.currentThread();
+ asyncResponse.resume(new MappedException());
+ }
+
+ @GET
+ @Path("unmapped")
+ public void getUnmappedException(@Suspended final AsyncResponse asyncResponse) {
+ lastProcessingThread = Thread.currentThread();
+ asyncResponse.resume(new UnmappedException());
+ }
+
+ @GET
+ @Path("runtime")
+ public void getUnmappedRuntimeException(@Suspended final AsyncResponse asyncResponse) {
+ lastProcessingThread = Thread.currentThread();
+ asyncResponse.resume(new UnmappedRuntimeException());
+ }
+
+ /**
+ * Returns whether a thread that was processing a last request got stuck in {@link ResponseWriter}.
+ * <p/>
+ * Under normal circumstances, the last processing thread should return back to the servlet container
+ * and its pool.
+ * <p/>
+ * May not work when executed in parallel.
+ *
+ * @return
+ */
+ @GET
+ @Path("rpc/lastthreadstuck")
+ public boolean lastThreadStuckRpc() {
+ if (lastProcessingThread == null || Thread.currentThread() == lastProcessingThread) {
+ return false;
+ }
+
+ switch (lastProcessingThread.getState()) {
+ case BLOCKED:
+ case TIMED_WAITING:
+ case WAITING:
+ for (StackTraceElement stackTraceElement : lastProcessingThread.getStackTrace()) {
+ if (ResponseWriter.class.getName().equals(stackTraceElement.getClassName())) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+}
diff --git a/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2730/exception/MappedException.java b/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2730/exception/MappedException.java
new file mode 100644
index 0000000..cc0ab0f
--- /dev/null
+++ b/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2730/exception/MappedException.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2730.exception;
+
+/**
+ * This exception will get mapped to a 432 response with the application exception mapper
+ * implemented by {@link MappedExceptionMapper} class.
+ *
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+public class MappedException extends Exception {
+
+}
diff --git a/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2730/exception/MappedExceptionMapper.java b/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2730/exception/MappedExceptionMapper.java
new file mode 100644
index 0000000..052dbc3
--- /dev/null
+++ b/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2730/exception/MappedExceptionMapper.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2730.exception;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+
+/**
+ * An exception mapper to return 432 error response when a {@link MappedException} is thrown.
+ *
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+public class MappedExceptionMapper implements ExceptionMapper<MappedException> {
+
+ @Override
+ public Response toResponse(MappedException exception) {
+ return Response.status(432).build();
+ }
+
+}
diff --git a/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2730/exception/UnmappedException.java b/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2730/exception/UnmappedException.java
new file mode 100644
index 0000000..751872c
--- /dev/null
+++ b/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2730/exception/UnmappedException.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2730.exception;
+
+/**
+ * An exception that will be propagated to the servlet container.
+ *
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+public class UnmappedException extends Exception {
+
+}
diff --git a/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2730/exception/UnmappedRuntimeException.java b/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2730/exception/UnmappedRuntimeException.java
new file mode 100644
index 0000000..d84dc6a
--- /dev/null
+++ b/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2730/exception/UnmappedRuntimeException.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2730.exception;
+
+/**
+ * An exception that will be propagated to the servlet container.
+ *
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+public class UnmappedRuntimeException extends RuntimeException {
+
+}
diff --git a/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2812/TestFilter.java b/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2812/TestFilter.java
new file mode 100644
index 0000000..9fd3cd9
--- /dev/null
+++ b/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2812/TestFilter.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2812;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.concurrent.CountDownLatch;
+import java.util.logging.Logger;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+ * This servlet filter class provides a means to detect whether Jersey (in servlet filter based setup) properly freed the
+ * server-side thread processing the http request to an async RESTful resource where {@link javax.ws.rs.container.AsyncResponse}
+ * wasn't resumed.
+ * <p/>
+ * Reported as JERSEY-2812.
+ *
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+public class TestFilter implements Filter {
+
+ private static final Logger LOGGER = Logger.getLogger(TestFilter.class.getName());
+ public static final String CDL_FINISHED = "CDL-finished";
+
+ @Override
+ public void init(final FilterConfig filterConfig) throws ServletException {
+
+ }
+
+ @Override
+ public void doFilter(final ServletRequest servletRequest,
+ final ServletResponse servletResponse,
+ final FilterChain filterChain)
+ throws IOException, ServletException {
+ LOGGER.finest(new Date() + " Thread " + Thread.currentThread().getName() + " is being acquired...");
+
+ final CountDownLatch cdlFinished = new CountDownLatch(1);
+ servletRequest.setAttribute(CDL_FINISHED, cdlFinished);
+
+ filterChain.doFilter(servletRequest, servletResponse);
+
+ // the thread did return from Jersey
+ cdlFinished.countDown();
+
+ LOGGER.finest(new Date() + " Thread " + Thread.currentThread().getName() + " is being released.");
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+}
diff --git a/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2812/TestWaitResource.java b/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2812/TestWaitResource.java
new file mode 100644
index 0000000..b457107
--- /dev/null
+++ b/tests/integration/async-jersey-filter/src/main/java/org/glassfish/jersey/tests/integration/jersey2812/TestWaitResource.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2812;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Logger;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.NotAcceptableException;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.Suspended;
+import javax.ws.rs.core.Context;
+
+import javax.inject.Singleton;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * This resource provides a way to reproduce JERSEY-2818.
+ *
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+@Path("/async")
+@Produces("text/plain")
+@Singleton
+public class TestWaitResource {
+
+ private static final Logger LOGGER = Logger.getLogger(TestWaitResource.class.getName());
+
+ /**
+ * Test context identified by UUID chosen by client.
+ */
+ private final ConcurrentMap<String, TestContext> testContextMap = new ConcurrentHashMap<>();
+
+ private TestContext testContextForUUID(String uuid) {
+ testContextMap.putIfAbsent(uuid, new TestContext());
+ return testContextMap.get(uuid);
+ }
+
+ @GET
+ @Path("wait/{uuid}")
+ public void waitForEvent(@Suspended AsyncResponse asyncResponse,
+ @Context HttpServletRequest request,
+ @PathParam("uuid") String uuid) {
+
+ LOGGER.finer("Adding response: " + asyncResponse);
+
+ final TestContext testContext = testContextForUUID(uuid);
+ final CountDownLatch finishedCdl = (CountDownLatch) request.getAttribute(TestFilter.CDL_FINISHED);
+
+ if (finishedCdl == null) {
+ throw new IllegalStateException("The " + TestFilter.class + " was not properly processed before this request!");
+ }
+
+ testContext.asyncResponse = asyncResponse;
+ testContext.finishedCdl = finishedCdl;
+ testContext.startedCdl.countDown();
+
+ LOGGER.finer("Decreasing started cdl: " + testContext.startedCdl);
+ }
+
+ @POST
+ @Path("release/{uuid}")
+ public String releaseLastSuspendedAsyncRequest(@PathParam("uuid") String uuid) {
+
+ LOGGER.finer("Releasing async response");
+
+ if (!testContextMap.containsKey(uuid)) {
+ throw new NotAcceptableException("UUID not found!" + uuid);
+ }
+
+ // clean it up
+ final TestContext releasedTestContext = testContextMap.remove(uuid);
+ releasedTestContext.finishedCdl.countDown();
+ releasedTestContext.startedCdl.countDown();
+ releasedTestContext.asyncResponse.resume("async-OK-" + uuid);
+
+ return "RELEASED";
+ }
+
+ @GET
+ @Path("await/{uuid}/started")
+ public boolean awaitForTheAsyncRequestThreadToStart(@PathParam("uuid") String uuid, @QueryParam("millis") Long millis) {
+ final CountDownLatch startedCdl = testContextForUUID(uuid).startedCdl;
+ try {
+ LOGGER.finer("Checking started cdl: " + startedCdl);
+ return startedCdl.await(millis, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ throw new IllegalStateException("Interrupted while waiting for the thread to finish!", e);
+ }
+ }
+
+ @GET
+ @Path("await/{uuid}/finished")
+ public boolean awaitForTheAsyncRequestThreadToFinish(@PathParam("uuid") String uuid, @QueryParam("millis") Long millis) {
+ if (!testContextMap.containsKey(uuid)) {
+ throw new NotAcceptableException("UUID not found!" + uuid);
+ }
+ try {
+ LOGGER.finer("Decreasing finished cdl: " + testContextMap.get(uuid).finishedCdl);
+ return testContextMap.get(uuid).finishedCdl.await(millis, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ throw new IllegalStateException("Interrupted while waiting for the thread to finish!", e);
+ }
+ }
+
+ /**
+ * Test context holder class.
+ * <p/>
+ * Holds the information for one test identified by UUID chosen by client.
+ *
+ * @see #testContextMap
+ */
+ private static class TestContext {
+
+ /**
+ * This CDL ensures the server-side thread processing the request to /async/wait/{uuid} has started handling the request.
+ */
+ final CountDownLatch startedCdl = new CountDownLatch(1);
+
+ /**
+ * This CDL ensures the server-side thread processing the request to /async/wait/{uuid} was returned to the thread-pool.
+ */
+ volatile CountDownLatch finishedCdl;
+
+ /**
+ * The async response that does get resumed outside of the request to /async/wait/{uuid}. This reproduces the JERSEY-2812
+ * bug.
+ */
+ volatile AsyncResponse asyncResponse;
+ }
+
+}
diff --git a/tests/integration/async-jersey-filter/src/main/webapp/WEB-INF/web.xml b/tests/integration/async-jersey-filter/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..d1d166c
--- /dev/null
+++ b/tests/integration/async-jersey-filter/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ metadata-complete="true">
+
+ <filter>
+ <filter-name>jersey2812</filter-name>
+ <filter-class>org.glassfish.jersey.tests.integration.jersey2812.TestFilter</filter-class>
+ <async-supported>true</async-supported>
+ </filter>
+
+ <filter>
+ <filter-name>jersey</filter-name>
+ <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
+ <async-supported>true</async-supported>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.async.TestApplication</param-value>
+ </init-param>
+ <!-- let ServletContainer#doFilter(HttpServletRequest, HttpServletResponse, FilterChain, String, String, String)
+ resolve the response status -->
+ <init-param>
+ <param-name>jersey.config.servlet.filter.forwardOn404</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>jersey2812</filter-name>
+ <url-pattern>/asyncTest/async/wait/*</url-pattern>
+ </filter-mapping>
+
+ <filter-mapping>
+ <filter-name>jersey</filter-name>
+ <url-pattern>/exceptionTest/*</url-pattern>
+ </filter-mapping>
+ <filter-mapping>
+ <filter-name>jersey</filter-name>
+ <url-pattern>/asyncTest/*</url-pattern>
+ </filter-mapping>
+
+ <absolute-ordering />
+</web-app>
diff --git a/tests/integration/async-jersey-filter/src/test/java/org/glassfish/jersey/tests/integration/async/AbstractAsyncJerseyTest.java b/tests/integration/async-jersey-filter/src/test/java/org/glassfish/jersey/tests/integration/async/AbstractAsyncJerseyTest.java
new file mode 100644
index 0000000..a2e1927
--- /dev/null
+++ b/tests/integration/async-jersey-filter/src/test/java/org/glassfish/jersey/tests/integration/async/AbstractAsyncJerseyTest.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.async;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+/**
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+public class AbstractAsyncJerseyTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new ResourceConfig(TestApplication.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+}
diff --git a/tests/integration/async-jersey-filter/src/test/java/org/glassfish/jersey/tests/integration/jersey2730/Jersey2730ITCase.java b/tests/integration/async-jersey-filter/src/test/java/org/glassfish/jersey/tests/integration/jersey2730/Jersey2730ITCase.java
new file mode 100644
index 0000000..c3ca725
--- /dev/null
+++ b/tests/integration/async-jersey-filter/src/test/java/org/glassfish/jersey/tests/integration/jersey2730/Jersey2730ITCase.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2730;
+
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.tests.integration.async.AbstractAsyncJerseyTest;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+/**
+ * JERSEY-2730 reproducer.
+ * <p/>
+ * This test must not run in parallel.
+ *
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+public class Jersey2730ITCase extends AbstractAsyncJerseyTest {
+
+ private void assertLastThreadNotStuck() {
+ final boolean lastThreadGotStuck = target("/exceptionTest/exception/rpc/lastthreadstuck").request().get(boolean.class);
+
+ assertFalse("Thread processing last request got stuck while processing the request for "
+ + TestExceptionResource.class.getCanonicalName(),
+ lastThreadGotStuck);
+ }
+
+ @Test
+ public void asyncResourceNullThrowableReturns500AndDoesNotStuck() throws Exception {
+ final Response response = target("/exceptionTest/exception/null").request().get();
+
+ assertEquals(500, response.getStatus());
+ assertLastThreadNotStuck();
+ }
+
+ @Test
+ public void asyncResourceUnmappedExceptionReturns500AndDoesNotStuck() throws Exception {
+ final Response response = target("/exceptionTest/exception/unmapped").request().get();
+
+ assertEquals(500, response.getStatus());
+ assertLastThreadNotStuck();
+ }
+
+ @Test
+ public void asyncResourceUnmappedRuntimeExceptionReturns500AndDoesNotStuck() throws Exception {
+ final Response response = target("/exceptionTest/exception/runtime").request().get();
+
+ assertEquals(500, response.getStatus());
+ assertLastThreadNotStuck();
+ }
+
+ @Test
+ public void asyncResourceMappedExceptionReturns432() throws Exception {
+ final Response response = target("/exceptionTest/exception/mapped").request().get();
+
+ assertEquals(432, response.getStatus());
+ assertLastThreadNotStuck();
+ }
+
+ @Test
+ public void asyncResourceNonExistentReturns404() throws Exception {
+ final Response response = target("/exceptionTest/exception/notfound").request().get();
+
+ assertEquals(404, response.getStatus());
+ }
+
+}
diff --git a/tests/integration/async-jersey-filter/src/test/java/org/glassfish/jersey/tests/integration/jersey2812/Jersey2812ITCase.java b/tests/integration/async-jersey-filter/src/test/java/org/glassfish/jersey/tests/integration/jersey2812/Jersey2812ITCase.java
new file mode 100644
index 0000000..d86a8f4
--- /dev/null
+++ b/tests/integration/async-jersey-filter/src/test/java/org/glassfish/jersey/tests/integration/jersey2812/Jersey2812ITCase.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2812;
+
+import java.util.UUID;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.logging.Logger;
+
+import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.core.Response;
+
+import javax.servlet.FilterChain;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.glassfish.jersey.internal.guava.ThreadFactoryBuilder;
+import org.glassfish.jersey.tests.integration.async.AbstractAsyncJerseyTest;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * JERSEY-2812 reproducer.
+ * <p/>
+ * This test must not run in parallel.
+ *
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+public class Jersey2812ITCase extends AbstractAsyncJerseyTest {
+
+ private static final Logger LOGGER = Logger.getLogger(Jersey2812ITCase.class.getName());
+ private static long WAIT_TIMEOUT = 5000;
+
+ private AtomicReference<String> asyncResult = new AtomicReference<>();
+ private String uuid = UUID.randomUUID().toString();
+ private ExecutorService executorService = Executors
+ .newSingleThreadExecutor(new ThreadFactoryBuilder().setDaemon(true).build());
+
+ @Before
+ public void triggerTheWaitRequestInSeparateThread() throws Exception {
+ executorService.execute(new Runnable() {
+ @Override
+ public void run() {
+ LOGGER.finer("Running a request to /async/wait in a separate thread.");
+ asyncResult.set(target("/asyncTest/async/wait").path(uuid).request().get(String.class));
+ }
+ });
+ }
+
+ /**
+ * Tests whether the server-side thread that is processing a http request to the servlet-filter-based Jersey setup ends up
+ * stuck or returned back to the pool of available threads.
+ * <p/>
+ * This test prevents a regression reported in JERSEY-2812.
+ * <p/>
+ * When the {@link javax.ws.rs.container.AsyncResponse} was left intact in the RESTful resource (as implemented in {@link
+ * TestWaitResource#waitForEvent(AsyncResponse, HttpServletRequest, String)}), the server-side Jersey thread ended up in
+ * {@link org.glassfish.jersey.servlet.internal.ResponseWriter#getResponseContext()} blocked because of the resolution of http
+ * response status from {@link org.glassfish.jersey.servlet.ServletContainer#doFilter(HttpServletRequest, HttpServletResponse,
+ * FilterChain, String, String, String)}
+ * <p/>
+ * This test uses a separate thread to call {@code /async/wait/{uuid}} resource which blocks until the {@code
+ * /async/release/{uuid}} is called. In the meantime the JUnit thread calls {@code /async/await/{uuid}} to discover whether
+ * the server-side thread processing the request to {@code /async/await/{uuid}/started} did start processing of the request.
+ * Consecutively, the JUnit thread calls {@code /async/await/{uuid}/finished} with a timeout {@code #WAIT_TIMEOUT} to discover
+ * whether the server-side thread got stuck (which is what JERSEY-2812 reported) or not.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void asyncSuspendedResourceDoesNotGetStuck() throws Exception {
+ // [1] wait for the /async/wait request to be processed
+ final Response startResponse = target("/asyncTest/async/await").path(uuid).path("started")
+ .queryParam("millis", WAIT_TIMEOUT).request().get();
+ assertTrue("The server-side thread handling the request to /async/wait didn't start in timely fashion. "
+ + "This error indicates this test is not executed / designed properly rather than a regression in "
+ + "JERSEY-2812 fix.",
+ startResponse.readEntity(Boolean.class));
+
+ // [2] wait for the /async/wait request to finish
+ final Response finishResponse = target("/asyncTest/async/await").path(uuid).path("finished")
+ .queryParam("millis", WAIT_TIMEOUT).request().get();
+ assertTrue("The thread processing the /async/wait request did not respond in timely fashion. "
+ + "Memory leak / thread got stuck detected!",
+ finishResponse.readEntity(Boolean.class));
+
+ // [3] release the blocked http call to /async/wait
+ final String releaseResponse = target("/asyncTest/async/release").path(uuid).request().post(null, String.class);
+ assertEquals("RELEASED", releaseResponse);
+
+ // [4] test whether everything ended as expected
+ executorService.shutdown();
+ assertTrue("The test thread did not finish in timely fashion!",
+ executorService.awaitTermination(WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
+ assertEquals("async-OK-" + uuid, asyncResult.get());
+ }
+
+ @After
+ public void releaseResources() {
+ // release the server-side thread regardless of whether left un-attended
+ target("/asyncTest/async/release").path(uuid).request().post(null);
+ }
+
+ @After
+ public void terminateThread() {
+ // forcibly terminate the test client thread
+ executorService.shutdownNow();
+ }
+
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/pom.xml b/tests/integration/cdi-beanvalidation-webapp/pom.xml
new file mode 100644
index 0000000..df201d3
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/pom.xml
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cdi-beanvalidation-webapp</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-cdi-beanvalidation-webapp</name>
+
+ <description>Jersey CDI/Bean Validation test web application</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-bean-validation</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-validator-cdi</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-weld2-se</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x-validation</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>run-external-tests</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${external.container.factory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${external.container.port}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <!-- External test container configuration is done via properties to allow overriding via command line. -->
+ <external.container.factory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</external.container.factory>
+ <external.container.port>8080</external.container.port>
+ <maven.test.skip>false</maven.test.skip>
+ </properties>
+ </profile>
+ </profiles>
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ </build>
+</project>
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiApplication.java b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiApplication.java
new file mode 100644
index 0000000..6adcc12
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiApplication.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * JAX-RS application to configure resources.
+ * This one is configured as a CDI bean.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("/cdi")
+@ApplicationScoped
+public class CdiApplication extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return new HashSet<Class<?>>() {{
+ add(CdiFieldInjectedResource.class);
+ add(CdiParamInjectedResource.class);
+ add(CdiPropertyInjectedResource.class);
+ add(CdiOldFashionedResource.class);
+
+ add(CdiValidationInterceptor.class);
+ }};
+ }
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiFieldInjectedResource.java b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiFieldInjectedResource.java
new file mode 100644
index 0000000..31d05cf
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiFieldInjectedResource.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import javax.enterprise.context.RequestScoped;
+
+import javax.inject.Inject;
+import javax.validation.ConstraintViolationException;
+import javax.validation.constraints.NotNull;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+/**
+ * This CDI backed resource should get validated and validation result field injected.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("validated/field")
+@RequestScoped
+public class CdiFieldInjectedResource {
+
+ @Inject
+ ValidationResult validationResult;
+
+ @Inject
+ NonJaxRsValidatedBean cdiBean;
+
+ @QueryParam("q")
+ @NotNull
+ String q;
+
+ /**
+ * Return number of validation issues.
+ *
+ * @return value from field injected validation bean.
+ */
+ @Path("validate")
+ @GET
+ public int getValidate() {
+
+ return validationResult.getViolationCount();
+ }
+
+ /**
+ * Return number of validation issues for non JAX-RS bean.
+ * This is to make sure the implicit Hibernate validator
+ * is functioning for raw CDI beans, where Jersey
+ * is not involved in method invocation.
+ *
+ * @return number of validation issues revealed when invoking injected CDI bean.
+ */
+ @Path("validate/non-jaxrs")
+ @GET
+ public int getValidateNonJaxRs(@QueryParam("h") String h) {
+
+ try {
+ cdiBean.echo(h);
+ return 0;
+ } catch (ConstraintViolationException ex) {
+ return ex.getConstraintViolations().size();
+ }
+ }
+
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiOldFashionedResource.java b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiOldFashionedResource.java
new file mode 100644
index 0000000..b7a5803
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiOldFashionedResource.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.RequestScoped;
+import javax.validation.constraints.NotNull;
+
+/**
+ * This CDI backed resource should get validated.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("old/fashioned")
+@RequestScoped
+public class CdiOldFashionedResource {
+
+ /**
+ * Query param getter.
+ *
+ * @return query param value.
+ */
+ @Path("validate")
+ @GET
+ public String getQ(@QueryParam("q") @NotNull String q) {
+
+ return q;
+ }
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiParamInjectedResource.java b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiParamInjectedResource.java
new file mode 100644
index 0000000..18f74c7
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiParamInjectedResource.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import javax.enterprise.context.RequestScoped;
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+
+/**
+ * This CDI backed resource should get validated.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("validated/param")
+@RequestScoped
+public class CdiParamInjectedResource {
+
+ /**
+ * Return number of validation issues.
+ *
+ * @return value from param injected validation bean.
+ */
+ @Path("validate")
+ @GET
+ public int getValidate(@QueryParam("q") @NotNull String q, @Context ValidationResult validationResult) {
+
+ return validationResult.getViolationCount();
+ }
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiPropertyInjectedResource.java b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiPropertyInjectedResource.java
new file mode 100644
index 0000000..2af8a87
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiPropertyInjectedResource.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.Interceptors;
+import javax.interceptor.InvocationContext;
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+/**
+ * This CDI backed resource should get validated and validation result property injected.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("validated/property")
+@RequestScoped
+public class CdiPropertyInjectedResource {
+
+ private ValidationResult validationResult;
+
+ @Inject
+ public void setValidationResult(ValidationResult validationResult) {
+ this.validationResult = validationResult;
+ }
+
+ public ValidationResult getValidationResult() {
+ return validationResult;
+ }
+
+ /**
+ * Return number of validation issues.
+ *
+ * @return value from field injected validation bean.
+ */
+ @Path("validate")
+ @GET
+ public int getValidate(@QueryParam("q") @NotNull String q) {
+
+ return getValidationResult().getViolationCount();
+ }
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiValidationInterceptor.java b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiValidationInterceptor.java
new file mode 100644
index 0000000..d3f9d9d
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiValidationInterceptor.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.validation.ConstraintViolationException;
+import javax.validation.ValidationException;
+
+import org.glassfish.jersey.server.spi.ValidationInterceptor;
+import org.glassfish.jersey.server.spi.ValidationInterceptorContext;
+
+import org.jboss.weld.interceptor.util.proxy.TargetInstanceProxy;
+
+/**
+ * CDI backed interceptor to handle validation issues.
+ *
+ * @author Jaku Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationScoped
+public class CdiValidationInterceptor implements ValidationInterceptor {
+
+ private final CdiValidationResult validationResult;
+ private final CdiPropertyInjectedResource pir;
+
+ /**
+ * Empty constructor to make CDI happy.
+ */
+ @SuppressWarnings("UnusedDeclaration")
+ public CdiValidationInterceptor() {
+ this.validationResult = null;
+ this.pir = null;
+ }
+
+ /**
+ * Injection constructor.
+ *
+ * @param validationResult CDI implementation of validation result.
+ * @param resource CDI property-injected JAX-RS resource.
+ */
+ @Inject
+ public CdiValidationInterceptor(CdiValidationResult validationResult, CdiPropertyInjectedResource resource) {
+ this.validationResult = validationResult;
+ this.pir = resource;
+ }
+
+ @Override
+ public void onValidate(ValidationInterceptorContext ctx) throws ValidationException {
+
+ final Object resource = ctx.getResource();
+ if (resource instanceof TargetInstanceProxy) {
+ ctx.setResource(((TargetInstanceProxy) resource).getTargetInstance());
+ }
+
+ try {
+ ctx.proceed();
+ } catch (ConstraintViolationException constraintViolationException) {
+
+ // First check for a property
+ if (ValidationResultUtil.hasValidationResultProperty(resource)) {
+ final Method validationResultGetter = ValidationResultUtil.getValidationResultGetter(resource);
+ ValidationResultUtil.updateValidationResultProperty(resource, validationResultGetter,
+ constraintViolationException.getConstraintViolations());
+ pir.setValidationResult(validationResult);
+ } else {
+ // Then check for a field
+ final Field vr = ValidationResultUtil.getValidationResultField(resource);
+ if (vr != null) {
+ // we have the right guy, no need to use reflection:
+ validationResult.setViolations(constraintViolationException.getConstraintViolations());
+ } else {
+ if (isValidationResultInArgs(ctx.getArgs())) {
+ this.validationResult.setViolations(constraintViolationException.getConstraintViolations());
+ } else {
+ throw constraintViolationException;
+ }
+ }
+ }
+ }
+ }
+
+ private boolean isValidationResultInArgs(Object[] args) {
+ for (Object a : args) {
+ if (a != null) {
+ Class<?> argClass = a.getClass();
+ do {
+ if (ValidationResult.class.isAssignableFrom(argClass)) {
+ return true;
+ }
+ argClass = argClass.getSuperclass();
+ } while (argClass != Object.class);
+ }
+ }
+ return false;
+ }
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiValidationResult.java b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiValidationResult.java
new file mode 100644
index 0000000..0bed3ff
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiValidationResult.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.RequestScoped;
+import javax.validation.ConstraintViolation;
+
+/**
+ * CDI implementation of validation result.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestScoped
+public class CdiValidationResult implements ValidationResult {
+
+ private Set<ConstraintViolation<?>> constraintViolationSet;
+
+ public void setViolations(Set<ConstraintViolation<?>> violations) {
+ this.constraintViolationSet = new HashSet<>(violations);
+ }
+
+ @Override
+ public Set<ConstraintViolation<?>> getAllViolations() {
+ return constraintViolationSet;
+ }
+
+ @Override
+ public boolean isFailed() {
+ return (constraintViolationSet != null) ? !constraintViolationSet.isEmpty() : false;
+ }
+
+ @Override
+ public int getViolationCount() {
+ return (constraintViolationSet != null) ? constraintViolationSet.size() : 0;
+ }
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiValidationResultBinder.java b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiValidationResultBinder.java
new file mode 100644
index 0000000..52bdb79
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/CdiValidationResultBinder.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import java.util.Set;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.Extension;
+import javax.inject.Inject;
+
+import org.glassfish.jersey.ext.cdi1x.internal.CdiUtil;
+import org.glassfish.jersey.ext.cdi1x.internal.GenericCdiBeanSupplier;
+import org.glassfish.jersey.internal.inject.Binding;
+import org.glassfish.jersey.internal.inject.Bindings;
+import org.glassfish.jersey.internal.inject.InjectionManager;
+import org.glassfish.jersey.server.spi.ComponentProvider;
+
+/**
+ * Utility that binds HK2 factory to provide CDI managed validation result bean.
+ * This is to make sure validation result could be injected as a resource method parameter
+ * even when running in CDI environment.
+ */
+public class CdiValidationResultBinder implements Extension, ComponentProvider {
+
+ @Inject
+ BeanManager beanManager;
+
+ InjectionManager injectionManager;
+
+ @Override
+ public void initialize(InjectionManager injectionManager) {
+ this.injectionManager = injectionManager;
+ this.beanManager = CdiUtil.getBeanManager();
+ }
+
+ @Override
+ public boolean bind(Class<?> component, Set<Class<?>> providerContracts) {
+ return false;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void done() {
+ if (beanManager != null) { // in CDI environment
+ Binding binding = Bindings
+ .supplier(new GenericCdiBeanSupplier(
+ CdiValidationResult.class, injectionManager, beanManager, true))
+ .to(CdiValidationResult.class)
+ .to(ValidationResult.class);
+
+ injectionManager.register(binding);
+ }
+ }
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2Application.java b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2Application.java
new file mode 100644
index 0000000..e6efb11
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2Application.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import javax.ws.rs.ApplicationPath;
+
+import javax.enterprise.inject.Vetoed;
+
+import org.glassfish.jersey.internal.inject.AbstractBinder;
+import org.glassfish.jersey.process.internal.RequestScoped;
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * JAX-RS application to configure resources.
+ * This one will get fully managed by HK2.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("/hk2")
+@Vetoed
+public class Hk2Application extends ResourceConfig {
+
+ public Hk2Application() {
+ super(Hk2ParamInjectedResource.class,
+ Hk2FieldInjectedResource.class,
+ Hk2PropertyInjectedResource.class,
+ Hk2OldFashionedResource.class);
+
+ register(new Hk2ValidationInterceptor.Binder());
+ register(new AbstractBinder(){
+
+ @Override
+ protected void configure() {
+ bindAsContract(Hk2ValidationResult.class).to(ValidationResult.class).in(RequestScoped.class);
+ }
+ });
+ }
+
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2FieldInjectedResource.java b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2FieldInjectedResource.java
new file mode 100644
index 0000000..3d3b850
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2FieldInjectedResource.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import javax.enterprise.inject.Vetoed;
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+
+/**
+ * This one should get validated.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("validated/field")
+@Vetoed
+public class Hk2FieldInjectedResource {
+
+ @QueryParam("q")
+ @NotNull
+ String q;
+
+ @Context
+ ValidationResult validationResult;
+
+ /**
+ * Return number of validation issues.
+ *
+ * @return value from field produced bean.
+ */
+ @Path("validate")
+ @GET
+ public int getValidate() {
+ return validationResult.getViolationCount();
+ }
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2OldFashionedResource.java b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2OldFashionedResource.java
new file mode 100644
index 0000000..a1c8596
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2OldFashionedResource.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.inject.Vetoed;
+import javax.validation.constraints.NotNull;
+
+/**
+ * This HK2 managed resource should get validated.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("old/fashioned")
+@Vetoed
+public class Hk2OldFashionedResource {
+
+ /**
+ * Query param getter.
+ *
+ * @return query parameter value.
+ */
+ @Path("validate")
+ @GET
+ public String getQ(@QueryParam("q") @NotNull String q) {
+
+ return q;
+ }
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2ParamInjectedResource.java b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2ParamInjectedResource.java
new file mode 100644
index 0000000..ee9a6fb
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2ParamInjectedResource.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import javax.enterprise.inject.Vetoed;
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+
+/**
+ * This HK2 managed resource should get validated and validation
+ * result injected via resource method parameter.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("validated/param")
+@Vetoed
+public class Hk2ParamInjectedResource {
+
+ /**
+ * Return number of validation issues.
+ *
+ * @return value from field produced bean.
+ */
+ @Path("validate")
+ @GET
+ public int getValidate(@QueryParam("q") @NotNull String q, @Context Hk2ValidationResult validationResult) {
+
+ return validationResult.getViolationCount();
+ }
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2PropertyInjectedResource.java b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2PropertyInjectedResource.java
new file mode 100644
index 0000000..ba02b09
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2PropertyInjectedResource.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import javax.enterprise.inject.Vetoed;
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+
+/**
+ * This one should get validated.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("validated/property")
+@Vetoed
+public class Hk2PropertyInjectedResource {
+
+ @QueryParam("q")
+ @NotNull
+ String q;
+
+ ValidationResult validationResult;
+
+ public ValidationResult getValidationResult() {
+ return validationResult;
+ }
+
+ @Context
+ public void setValidationResult(ValidationResult validationResult) {
+ this.validationResult = validationResult;
+ }
+
+ /**
+ * Return number of validation issues.
+ *
+ * @return value from field produced bean.
+ */
+ @Path("validate")
+ @GET
+ public int getValidate() {
+ return validationResult.getViolationCount();
+ }
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2ValidationInterceptor.java b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2ValidationInterceptor.java
new file mode 100644
index 0000000..985453d
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2ValidationInterceptor.java
@@ -0,0 +1,193 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.function.Supplier;
+
+import javax.ws.rs.core.Context;
+
+import javax.enterprise.inject.Vetoed;
+import javax.inject.Inject;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+import javax.validation.ConstraintViolationException;
+import javax.validation.ValidationException;
+
+import org.glassfish.jersey.internal.inject.AbstractBinder;
+import org.glassfish.jersey.server.spi.ValidationInterceptor;
+import org.glassfish.jersey.server.spi.ValidationInterceptorContext;
+
+/**
+ * HK2 managed validation interceptor.
+ */
+@Vetoed
+public class Hk2ValidationInterceptor implements ValidationInterceptor {
+
+
+ private final Provider<Hk2ValidationResult> validationResult;
+
+ public Hk2ValidationInterceptor(Provider<Hk2ValidationResult> validationResult) {
+ this.validationResult = validationResult;
+ }
+
+ public static class Binder extends AbstractBinder {
+
+ @Override
+ protected void configure() {
+ bindFactory(ValidationInterceptorFactory.class, Singleton.class)
+ .to(ValidationInterceptor.class);
+ }
+
+ }
+
+ private static class ValidationInterceptorFactory implements Supplier<ValidationInterceptor> {
+
+ @Inject
+ Provider<Hk2ValidationResult> validationResultProvider;
+
+ @Override
+ public ValidationInterceptor get() {
+ return new Hk2ValidationInterceptor(validationResultProvider);
+ }
+ }
+
+ @Override
+ public void onValidate(
+ ValidationInterceptorContext ctx) throws ValidationException {
+ try {
+ ctx.proceed();
+ } catch (ConstraintViolationException ex) {
+ ensureValidationResultInjected(ctx, ex);
+ validationResult.get().setViolations(ex.getConstraintViolations());
+ }
+ }
+
+ private void ensureValidationResultInjected(
+ final ValidationInterceptorContext ctx, final ConstraintViolationException ex) {
+
+ if (!isValidationResultInArgs(ctx.getArgs())
+ && !isValidationResultInResource(ctx)
+ && !hasValidationResultProperty(ctx.getResource())) {
+
+ throw ex;
+ }
+ }
+
+ private boolean isValidationResultInResource(ValidationInterceptorContext ctx) {
+ Class<?> clazz = ctx.getResource().getClass();
+ do {
+ for (Field f : clazz.getDeclaredFields()) {
+ // Of ValidationResult and JAX-RS injectable
+ if (ValidationResult.class.isAssignableFrom(f.getType())
+ && f.getAnnotation(Context.class) != null) {
+ return true;
+ }
+ }
+ clazz = clazz.getSuperclass();
+ } while (clazz != Object.class);
+ return false;
+ }
+
+ private boolean isValidationResultInArgs(Object[] args) {
+ for (Object a : args) {
+ if (a != null && ValidationResult.class.isAssignableFrom(a.getClass())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Determines if a resource has a property of type {@code javax.mvc.validation.ValidationResult}.
+ *
+ * @param resource resource instance.
+ * @return outcome of test.
+ */
+ public static boolean hasValidationResultProperty(final Object resource) {
+ return getValidationResultGetter(resource) != null && getValidationResultSetter(resource) != null;
+ }
+
+ /**
+ * Returns a getter for {@code javax.mvc.validation.ValidationResult} or {@code null}
+ * if one cannot be found.
+ *
+ * @param resource resource instance.
+ * @return getter or {@code null} if not available.
+ */
+ public static Method getValidationResultGetter(final Object resource) {
+ Class<?> clazz = resource.getClass();
+ do {
+ for (Method m : clazz.getDeclaredMethods()) {
+ if (isValidationResultGetter(m)) {
+ return m;
+ }
+ }
+ clazz = clazz.getSuperclass();
+ } while (clazz != Object.class);
+ return null;
+ }
+
+ /**
+ * Determines if a method is a getter for {@code javax.mvc.validation.ValidationResult}.
+ *
+ * @param m method to test.
+ * @return outcome of test.
+ */
+ private static boolean isValidationResultGetter(Method m) {
+ return m.getName().startsWith("get")
+ && ValidationResult.class.isAssignableFrom(m.getReturnType())
+ && Modifier.isPublic(m.getModifiers()) && m.getParameterTypes().length == 0;
+ }
+
+ /**
+ * Returns a setter for {@code javax.mvc.validation.ValidationResult} or {@code null}
+ * if one cannot be found.
+ *
+ * @param resource resource instance.
+ * @return setter or {@code null} if not available.
+ */
+ public static Method getValidationResultSetter(final Object resource) {
+ Class<?> clazz = resource.getClass();
+ do {
+ for (Method m : clazz.getDeclaredMethods()) {
+ if (isValidationResultSetter(m)) {
+ return m;
+ }
+ }
+ clazz = clazz.getSuperclass();
+ } while (clazz != Object.class);
+ return null;
+ }
+
+ /**
+ * Determines if a method is a setter for {@code javax.mvc.validation.ValidationResult}.
+ * As a CDI initializer method, it must be annotated with {@link javax.inject.Inject}.
+ *
+ * @param m method to test.
+ * @return outcome of test.
+ */
+ private static boolean isValidationResultSetter(Method m) {
+ return m.getName().startsWith("set") && m.getParameterTypes().length == 1
+ && ValidationResult.class.isAssignableFrom(m.getParameterTypes()[0])
+ && m.getReturnType() == Void.TYPE && Modifier.isPublic(m.getModifiers())
+ && m.getAnnotation(Context.class) != null;
+ }
+
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2ValidationResult.java b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2ValidationResult.java
new file mode 100644
index 0000000..f286105
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/Hk2ValidationResult.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.Vetoed;
+import javax.validation.ConstraintViolation;
+
+/**
+ * HK2 managed validation result bean.
+ */
+@Vetoed
+public class Hk2ValidationResult implements ValidationResult {
+
+ Set<ConstraintViolation<?>> constraintViolationSet;
+
+ public void setViolations(Set<ConstraintViolation<?>> violations) {
+ this.constraintViolationSet = new HashSet<>(violations);
+ }
+
+ @Override
+ public Set<ConstraintViolation<?>> getAllViolations() {
+ return constraintViolationSet;
+ }
+
+ @Override
+ public boolean isFailed() {
+ return (constraintViolationSet != null) ? !constraintViolationSet.isEmpty() : false;
+ }
+
+ @Override
+ public int getViolationCount() {
+ return (constraintViolationSet != null) ? constraintViolationSet.size() : 0;
+ }
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/NonJaxRsValidatedBean.java b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/NonJaxRsValidatedBean.java
new file mode 100644
index 0000000..110aca3
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/NonJaxRsValidatedBean.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import javax.enterprise.context.RequestScoped;
+import javax.validation.constraints.NotNull;
+
+/**
+ * CDI bean that gets validated by Hibernate validator directly.
+ * This is to ensure Jersey interceptor wrapper
+ * does not block the original validator from functioning
+ * on raw CDI beans.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestScoped
+public class NonJaxRsValidatedBean {
+
+ public String echo(@NotNull String value) {
+ return value;
+ }
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/ValidationResult.java b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/ValidationResult.java
new file mode 100644
index 0000000..b723793
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/ValidationResult.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import java.util.Set;
+
+import javax.validation.ConstraintViolation;
+
+/**
+ * An interface to be utilized when resource method validation issues
+ * are to be handled within actual resource method.
+ */
+public interface ValidationResult {
+
+ /**
+ * Returns an immutable set of all constraint violations detected.
+ *
+ * @return All constraint violations detected
+ */
+ public Set<ConstraintViolation<?>> getAllViolations();
+
+ /**
+ * Returns <code>true</code> if there is at least one constraint violation.
+ * Same as checking whether {@link #getViolationCount()} is greater than zero.
+ *
+ * @return <code>true</code> if there is at least one constraint violation.
+ */
+ public boolean isFailed();
+
+ /**
+ * Returns the total number of constraint violations detected. Same as calling
+ * <code>getAllViolations().size()</code>.
+ *
+ * @return The number of constraint violations
+ */
+ int getViolationCount();
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/ValidationResultUtil.java b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/ValidationResultUtil.java
new file mode 100644
index 0000000..906da13
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/java/org/glassfish/jersey/tests/cdi/bv/ValidationResultUtil.java
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.bv;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Set;
+
+import javax.enterprise.inject.Vetoed;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.validation.ConstraintViolation;
+
+/**
+ * Helper class to implement support for {@code javax.mvc.validation.ValidationResult}.
+ *
+ * @author Santiago Pericas-Geertsen
+ */
+@Vetoed
+public final class ValidationResultUtil {
+
+ private static final String VALIDATION_RESULT = ValidationResult.class.getName();
+
+ private ValidationResultUtil() {
+ throw new AssertionError("Instantiation not allowed.");
+ }
+
+ /**
+ * Search for a {@code javax.mvc.validation.ValidationResult} field in the resource's
+ * class hierarchy. Field must be annotated with {@link javax.inject.Inject}.
+ *
+ * @param resource resource instance.
+ * @return field or {@code null} if none is found.
+ */
+ public static Field getValidationResultField(final Object resource) {
+ Class<?> clazz = resource.getClass();
+ do {
+ for (Field f : clazz.getDeclaredFields()) {
+ // Of ValidationResult and CDI injectable
+ if (f.getType().getName().equals(VALIDATION_RESULT)
+ && f.getAnnotation(Inject.class) != null) {
+ return f;
+ }
+ }
+ clazz = clazz.getSuperclass();
+ } while (clazz != Object.class);
+ return null;
+ }
+
+ /**
+ * Updates a {@code javax.mvc.validation.ValidationResult} field. In pseudo-code:
+ * <p/>
+ * resource.field.setViolations(constraints)
+ *
+ * @param resource resource instance.
+ * @param field field to be updated.
+ * @param constraints new set of constraints.
+ */
+ public static void updateValidationResultField(Object resource, Field field,
+ Set<ConstraintViolation<?>> constraints) {
+ try {
+ field.setAccessible(true);
+ final Object obj = field.get(resource);
+ Method setter;
+ try {
+ setter = obj.getClass().getMethod("setViolations", Set.class);
+ } catch (NoSuchMethodException e) {
+ setter = obj.getClass().getSuperclass().getMethod("setViolations", Set.class);
+ }
+ setter.invoke(obj, constraints);
+ } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
+ // ignore for now
+ System.out.println("Damn it...");
+ } catch (Throwable t) {
+ System.out.println("What the heck...");
+ }
+ }
+
+ /**
+ * Updates a {@code javax.mvc.validation.ValidationResult} property. In pseudo-code:
+ * <p/>
+ * obj = getter.invoke(resource);
+ * obj.setViolations(constraints);
+ * setter.invoke(resource, obj);
+ *
+ * @param resource resource instance.
+ * @param getter getter to be used.
+ * @param constraints new set of constraints.
+ */
+ public static void updateValidationResultProperty(Object resource, Method getter,
+ Set<ConstraintViolation<?>> constraints) {
+ try {
+ final Object obj = getter.invoke(resource);
+ Method setViolations;
+ try {
+ setViolations = obj.getClass().getMethod("setViolations", Set.class);
+ } catch (NoSuchMethodException e) {
+ setViolations = obj.getClass().getSuperclass().getMethod("setViolations", Set.class);
+ }
+ setViolations.invoke(obj, constraints);
+
+ final Method setter = getValidationResultSetter(resource);
+
+ if (setter != null) {
+ setter.invoke(resource, obj);
+ }
+ } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
+ // ignore for now
+ }
+ }
+
+ /**
+ * Determines if a resource has a property of type {@code javax.mvc.validation.ValidationResult}.
+ *
+ * @param resource resource instance.
+ * @return outcome of test.
+ */
+ public static boolean hasValidationResultProperty(final Object resource) {
+ return getValidationResultGetter(resource) != null && getValidationResultSetter(resource) != null;
+ }
+
+ /**
+ * Returns a getter for {@code javax.mvc.validation.ValidationResult} or {@code null}
+ * if one cannot be found.
+ *
+ * @param resource resource instance.
+ * @return getter or {@code null} if not available.
+ */
+ public static Method getValidationResultGetter(final Object resource) {
+ Class<?> clazz = resource.getClass();
+ do {
+ for (Method m : clazz.getDeclaredMethods()) {
+ if (isValidationResultGetter(m)) {
+ return m;
+ }
+ }
+ clazz = clazz.getSuperclass();
+ } while (clazz != Object.class);
+ return null;
+ }
+
+ /**
+ * Determines if a method is a getter for {@code javax.mvc.validation.ValidationResult}.
+ *
+ * @param m method to test.
+ * @return outcome of test.
+ */
+ private static boolean isValidationResultGetter(Method m) {
+ return m.getName().startsWith("get")
+ && m.getReturnType().getName().equals(VALIDATION_RESULT)
+ && Modifier.isPublic(m.getModifiers()) && m.getParameterTypes().length == 0;
+ }
+
+ /**
+ * Returns a setter for {@code javax.mvc.validation.ValidationResult} or {@code null}
+ * if one cannot be found.
+ *
+ * @param resource resource instance.
+ * @return setter or {@code null} if not available.
+ */
+ public static Method getValidationResultSetter(final Object resource) {
+ return getValidationResultSetter(resource.getClass());
+ }
+
+ private static Method getValidationResultSetter(final Class<?> resourceClass) {
+ Class<?> clazz = resourceClass;
+ do {
+ for (Method m : clazz.getDeclaredMethods()) {
+ if (isValidationResultSetter(m)) {
+ return m;
+ }
+ }
+ clazz = clazz.getSuperclass();
+ } while (clazz != Object.class);
+ return null;
+ }
+
+ /**
+ * Determines if a method is a setter for {@code javax.mvc.validation.ValidationResult}.
+ * As a CDI initializer method, it must be annotated with {@link javax.inject.Inject}.
+ *
+ * @param m method to test.
+ * @return outcome of test.
+ */
+ private static boolean isValidationResultSetter(Method m) {
+ return m.getName().startsWith("set") && m.getParameterTypes().length == 1
+ && m.getParameterTypes()[0].getName().equals(VALIDATION_RESULT)
+ && m.getReturnType() == Void.TYPE && Modifier.isPublic(m.getModifiers())
+ && m.getAnnotation(Inject.class) != null;
+ }
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/resources/META-INF/beans.xml b/tests/integration/cdi-beanvalidation-webapp/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/tests/integration/cdi-beanvalidation-webapp/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
new file mode 100644
index 0000000..d036d62
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
@@ -0,0 +1 @@
+org.glassfish.jersey.tests.cdi.bv.CdiValidationResultBinder
\ No newline at end of file
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/resources/META-INF/services/org.glassfish.jersey.server.spi.ComponentProvider b/tests/integration/cdi-beanvalidation-webapp/src/main/resources/META-INF/services/org.glassfish.jersey.server.spi.ComponentProvider
new file mode 100644
index 0000000..d036d62
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/resources/META-INF/services/org.glassfish.jersey.server.spi.ComponentProvider
@@ -0,0 +1 @@
+org.glassfish.jersey.tests.cdi.bv.CdiValidationResultBinder
\ No newline at end of file
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/main/webapp/WEB-INF/beans.xml b/tests/integration/cdi-beanvalidation-webapp/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..1d9cc6c
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<beans/>
+
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/BaseValidationTest.java b/tests/integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/BaseValidationTest.java
new file mode 100644
index 0000000..f2eb3fb
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/BaseValidationTest.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import java.net.URI;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Common test for resource validation. The same set of tests is used
+ * for the following scenarios: Grizzly based combined deployment with CDI enabled,
+ * WAR based combined deployment with CDI enabled, Grizzly based deployment without CDI enabled.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public abstract class BaseValidationTest extends JerseyTest {
+
+ public abstract String getAppPath();
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-beanvalidation-webapp").path(getAppPath()).build();
+ }
+
+ @Test
+ public void testParamValidatedResourceNoParam() throws Exception {
+ _testParamValidatedResourceNoParam(target());
+ }
+
+ public static void _testParamValidatedResourceNoParam(final WebTarget target) throws Exception {
+
+ Integer errors = target.register(LoggingFeature.class)
+ .path("validated").path("param").path("validate")
+ .request().get(Integer.class);
+
+ assertThat(errors, is(1));
+ }
+
+ @Test
+ public void testParamValidatedResourceParamProvided() throws Exception {
+ _testParamValidatedResourceParamProvided(target());
+ }
+
+ public static void _testParamValidatedResourceParamProvided(WebTarget target) throws Exception {
+ Integer errors = target.register(LoggingFeature.class).path("validated").path("field").path("validate")
+ .queryParam("q", "one").request().get(Integer.class);
+ assertThat(errors, is(0));
+ }
+
+ @Test
+ public void testFieldValidatedResourceNoParam() throws Exception {
+ _testFieldValidatedResourceNoParam(target());
+ }
+
+ public static void _testFieldValidatedResourceNoParam(final WebTarget target) throws Exception {
+
+ Integer errors = target.register(LoggingFeature.class)
+ .path("validated").path("field").path("validate")
+ .request().get(Integer.class);
+
+ assertThat(errors, is(1));
+ }
+
+ @Test
+ public void testFieldValidatedResourceParamProvided() throws Exception {
+ _testFieldValidatedResourceParamProvided(target());
+ }
+
+ public static void _testFieldValidatedResourceParamProvided(final WebTarget target) throws Exception {
+ Integer errors = target.register(LoggingFeature.class).path("validated").path("field").path("validate")
+ .queryParam("q", "one").request().get(Integer.class);
+ assertThat(errors, is(0));
+ }
+
+ @Test
+ public void testPropertyValidatedResourceNoParam() throws Exception {
+ _testPropertyValidatedResourceNoParam(target());
+ }
+
+ public static void _testPropertyValidatedResourceNoParam(final WebTarget target) throws Exception {
+
+ Integer errors = target.register(LoggingFeature.class)
+ .path("validated").path("property").path("validate")
+ .request().get(Integer.class);
+
+ assertThat(errors, is(1));
+ }
+
+ @Test
+ public void testPropertyValidatedResourceParamProvided() throws Exception {
+ _testPropertyValidatedResourceParamProvided(target());
+ }
+
+ public static void _testPropertyValidatedResourceParamProvided(final WebTarget target) throws Exception {
+ Integer errors = target.register(LoggingFeature.class).path("validated").path("property").path("validate")
+ .queryParam("q", "one").request().get(Integer.class);
+ assertThat(errors, is(0));
+ }
+
+ @Test
+ public void testOldFashionedResourceNoParam() {
+ _testOldFashionedResourceNoParam(target());
+ }
+
+ public static void _testOldFashionedResourceNoParam(final WebTarget target) {
+
+ Response response = target.register(LoggingFeature.class)
+ .path("old").path("fashioned").path("validate")
+ .request().get();
+
+ assertThat(response.getStatus(), is(400));
+ }
+
+ @Test
+ public void testOldFashionedResourceParamProvided() throws Exception {
+ _testOldFashionedResourceParamProvided(target());
+ }
+
+ public static void _testOldFashionedResourceParamProvided(final WebTarget target) throws Exception {
+ String response = target.register(LoggingFeature.class).path("old").path("fashioned").path("validate")
+ .queryParam("q", "one").request().get(String.class);
+ assertThat(response, is("one"));
+ }
+
+ public static void _testNonJaxRsValidationFieldValidatedResourceNoParam(final WebTarget target) {
+ Integer errors = target.register(LoggingFeature.class)
+ .path("validated").path("field").path("validate").path("non-jaxrs")
+ .queryParam("q", "not-important-just-to-get-this-through-jax-rs").request().get(Integer.class);
+
+ assertThat(errors, is(1));
+ }
+
+ public static void _testNonJaxRsValidationFieldValidatedResourceParamProvided(final WebTarget target) {
+ Integer errors = target.register(LoggingFeature.class)
+ .path("validated").path("field").path("validate").path("non-jaxrs")
+ .queryParam("q", "not-important-just-to-get-this-through-jax-rs")
+ .queryParam("h", "bummer")
+ .request().get(Integer.class);
+
+ assertThat(errors, is(0));
+ }
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/CombinedTest.java b/tests/integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/CombinedTest.java
new file mode 100644
index 0000000..847b0ef
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/CombinedTest.java
@@ -0,0 +1,197 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Properties;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.WebTarget;
+
+import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer;
+import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainerProvider;
+import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
+import org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.TestProperties;
+
+import org.glassfish.grizzly.http.server.HttpHandler;
+import org.glassfish.grizzly.http.server.HttpServer;
+
+import org.hamcrest.CoreMatchers;
+import org.jboss.weld.environment.se.Weld;
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test both Jersey apps running simultaneously within a single Grizzly HTTP server
+ * to make sure injection managers do not interfere. The test is not executed
+ * if other than the default (Grizzly) test container has been set.
+ * For Servlet based container testing, the other two tests, {@link RawCdiTest} and {@link RawHk2Test},
+ * do the same job, because the WAR application contains both Jersey apps already.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class CombinedTest {
+
+ public static final String CDI_URI = "/cdi";
+ public static final String HK2_URI = "/hk2";
+
+ public static final String PORT_NUMBER = getSystemProperty(TestProperties.CONTAINER_PORT,
+ Integer.toString(TestProperties.DEFAULT_CONTAINER_PORT));
+
+ private static final URI BASE_HK2_URI = URI.create("http://localhost:" + PORT_NUMBER + HK2_URI);
+ private static final URI BASE_CDI_URI = URI.create("http://localhost:" + PORT_NUMBER + CDI_URI);
+
+ private static final boolean isDefaultTestContainerFactorySet = isDefaultTestContainerFactorySet();
+
+ Weld weld;
+ HttpServer cdiServer;
+
+ Client client;
+ WebTarget cdiTarget, hk2Target;
+
+ @Before
+ public void before() throws IOException {
+ if (isDefaultTestContainerFactorySet && Hk2InjectionManagerFactory.isImmediateStrategy()) {
+ initializeWeld();
+ startGrizzlyContainer();
+ initializeClient();
+ }
+ }
+
+ @Before
+ public void beforeIsImmediate() {
+ Assume.assumeTrue(Hk2InjectionManagerFactory.isImmediateStrategy());
+ }
+
+ @After
+ public void after() {
+ if (isDefaultTestContainerFactorySet && Hk2InjectionManagerFactory.isImmediateStrategy()) {
+ cdiServer.shutdownNow();
+ weld.shutdown();
+ client.close();
+ }
+ }
+
+ @Test
+ public void testParamValidatedResourceNoParam() throws Exception {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testParamValidatedResourceNoParam(cdiTarget);
+ BaseValidationTest._testParamValidatedResourceNoParam(hk2Target);
+ }
+
+ @Test
+ public void testParamValidatedResourceParamProvided() throws Exception {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testParamValidatedResourceParamProvided(cdiTarget);
+ BaseValidationTest._testParamValidatedResourceParamProvided(hk2Target);
+ }
+
+ @Test
+ public void testFieldValidatedResourceNoParam() throws Exception {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testFieldValidatedResourceNoParam(cdiTarget);
+ BaseValidationTest._testFieldValidatedResourceNoParam(hk2Target);
+ }
+
+ @Test
+ public void testFieldValidatedResourceParamProvided() throws Exception {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testFieldValidatedResourceParamProvided(cdiTarget);
+ BaseValidationTest._testFieldValidatedResourceParamProvided(hk2Target);
+ }
+
+ @Test
+ public void testPropertyValidatedResourceNoParam() throws Exception {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testPropertyValidatedResourceNoParam(cdiTarget);
+ BaseValidationTest._testPropertyValidatedResourceNoParam(hk2Target);
+ }
+
+ @Test
+ public void testPropertyValidatedResourceParamProvided() throws Exception {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testPropertyValidatedResourceParamProvided(cdiTarget);
+ BaseValidationTest._testPropertyValidatedResourceParamProvided(hk2Target);
+ }
+
+ @Test
+ public void testOldFashionedResourceNoParam() {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testOldFashionedResourceNoParam(cdiTarget);
+ BaseValidationTest._testOldFashionedResourceNoParam(hk2Target);
+ }
+
+ @Test
+ public void testOldFashionedResourceParamProvided() throws Exception {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testOldFashionedResourceParamProvided(cdiTarget);
+ BaseValidationTest._testOldFashionedResourceParamProvided(hk2Target);
+ }
+
+ @Test
+ public void testNonJaxRsValidationFieldValidatedResourceNoParam() {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testNonJaxRsValidationFieldValidatedResourceNoParam(cdiTarget);
+ }
+
+ @Test
+ public void testNonJaxRsValidationFieldValidatedResourceParamProvided() {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ BaseValidationTest._testNonJaxRsValidationFieldValidatedResourceParamProvided(cdiTarget);
+ }
+
+ private void initializeWeld() {
+ weld = new Weld();
+ weld.initialize();
+ }
+
+ private void startGrizzlyContainer() throws IOException {
+ final ResourceConfig cdiConfig = ResourceConfig.forApplicationClass(CdiApplication.class);
+ final ResourceConfig hk2Config = ResourceConfig.forApplicationClass(Hk2Application.class);
+
+ cdiServer = GrizzlyHttpServerFactory.createHttpServer(BASE_CDI_URI, cdiConfig, false);
+ final HttpHandler hk2Handler = createGrizzlyContainer(hk2Config);
+ cdiServer.getServerConfiguration().addHttpHandler(hk2Handler, HK2_URI);
+ cdiServer.start();
+ }
+
+ private void initializeClient() {
+ client = ClientBuilder.newClient();
+ cdiTarget = client.target(BASE_CDI_URI);
+ hk2Target = client.target(BASE_HK2_URI);
+ }
+
+ private GrizzlyHttpContainer createGrizzlyContainer(ResourceConfig resourceConfig) {
+ return (new GrizzlyHttpContainerProvider()).createContainer(GrizzlyHttpContainer.class, resourceConfig);
+ }
+
+ private static boolean isDefaultTestContainerFactorySet() {
+ final String testContainerFactory = getSystemProperty(TestProperties.CONTAINER_FACTORY, null);
+ return testContainerFactory == null || TestProperties.DEFAULT_CONTAINER_FACTORY.equals(testContainerFactory);
+ }
+
+ private static String getSystemProperty(final String propertyName, final String defaultValue) {
+ final Properties systemProperties = System.getProperties();
+ return systemProperties.getProperty(propertyName, defaultValue);
+ }
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/RawCdiTest.java b/tests/integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/RawCdiTest.java
new file mode 100644
index 0000000..d0b996c
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/RawCdiTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+
+import org.jboss.weld.environment.se.Weld;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Validation result test for CDI environment.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class RawCdiTest extends BaseValidationTest {
+
+ Weld weld;
+
+ @Before
+ public void setup() {
+ Assume.assumeTrue(Hk2InjectionManagerFactory.isImmediateStrategy());
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ if (Hk2InjectionManagerFactory.isImmediateStrategy()) {
+ if (!ExternalTestContainerFactory.class.isAssignableFrom(getTestContainerFactory().getClass())) {
+ weld = new Weld();
+ weld.initialize();
+ }
+ super.setUp();
+ }
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ if (Hk2InjectionManagerFactory.isImmediateStrategy()) {
+ if (!ExternalTestContainerFactory.class.isAssignableFrom(getTestContainerFactory().getClass())) {
+ weld.shutdown();
+ }
+ super.tearDown();
+ }
+ }
+
+ @Override
+ protected Application configure() {
+ return ResourceConfig.forApplicationClass(CdiApplication.class);
+ }
+
+ @Override
+ public String getAppPath() {
+ return "cdi";
+ }
+
+ @Test
+ public void testNonJaxRsValidationFieldValidatedResourceNoParam() {
+ BaseValidationTest._testNonJaxRsValidationFieldValidatedResourceNoParam(target());
+ }
+
+ @Test
+ public void testNonJaxRsValidationFieldValidatedResourceParamProvided() {
+ BaseValidationTest._testNonJaxRsValidationFieldValidatedResourceParamProvided(target());
+ }
+}
diff --git a/tests/integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/RawHk2Test.java b/tests/integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/RawHk2Test.java
new file mode 100644
index 0000000..f83ea61
--- /dev/null
+++ b/tests/integration/cdi-beanvalidation-webapp/src/test/java/org/glassfish/jersey/tests/cdi/bv/RawHk2Test.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.bv;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * Validation result test for raw HK2 environment.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class RawHk2Test extends BaseValidationTest {
+
+ @Override
+ protected Application configure() {
+ return ResourceConfig.forApplicationClass(Hk2Application.class);
+ }
+
+ @Override
+ public String getAppPath() {
+ return "hk2";
+ }
+}
diff --git a/tests/integration/cdi-ejb-test-webapp/pom.xml b/tests/integration/cdi-ejb-test-webapp/pom.xml
new file mode 100644
index 0000000..39b0521
--- /dev/null
+++ b/tests/integration/cdi-ejb-test-webapp/pom.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cdi-ejb-test-webapp</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-cdi-ejb-webapp</name>
+
+ <description>Jersey CDI/EJB test web application</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.ejb</groupId>
+ <artifactId>javax.ejb-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/BasicTimer.java b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/BasicTimer.java
new file mode 100644
index 0000000..775fae0
--- /dev/null
+++ b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/BasicTimer.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import javax.annotation.PostConstruct;
+
+/**
+ * Basic timer implementation to be reused for various types of beans.
+ *
+ * @author Jakub Podlesak
+ */
+public abstract class BasicTimer {
+
+ long ms;
+
+ /**
+ * Provide information on internal timer millisecond value.
+ *
+ * @return milliseconds when the current bean has been post-constructed.
+ */
+ public long getMiliseconds() {
+ return ms;
+ }
+
+ /**
+ * Initialize this timer with the current time.
+ */
+ @PostConstruct
+ public void init() {
+ this.ms = System.currentTimeMillis();
+ }
+}
diff --git a/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiAppScopedTimer.java b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiAppScopedTimer.java
new file mode 100644
index 0000000..259e669
--- /dev/null
+++ b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiAppScopedTimer.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ * Application scoped CDI bean to be injected into EJB resources.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationScoped
+public class CdiAppScopedTimer extends BasicTimer {
+}
diff --git a/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiRequestScopedResource.java b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiRequestScopedResource.java
new file mode 100644
index 0000000..a2e6204
--- /dev/null
+++ b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiRequestScopedResource.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import javax.ejb.EJB;
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * Request scoped CDI bean injected with EJB timers.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestScoped
+@Path("request-scoped")
+public class CdiRequestScopedResource {
+
+ @EJB EjbSingletonTimer ejbInjectedTimer;
+ @Inject EjbSingletonTimer jsr330InjectedTimer;
+ @Inject CdiAppScopedTimer cdiTimer;
+
+ @GET
+ @Path("ejb-injected-timer")
+ public String getEjbTime() {
+ return Long.toString(ejbInjectedTimer.getMiliseconds());
+ }
+
+ @GET
+ @Path("jsr330-injected-timer")
+ public String getJsr330Time() {
+ return Long.toString(jsr330InjectedTimer.getMiliseconds());
+ }
+
+ @GET
+ public String getMyself() {
+ return this.toString();
+ }
+}
diff --git a/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiRequestScopedTimer.java b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiRequestScopedTimer.java
new file mode 100644
index 0000000..f48e1f4
--- /dev/null
+++ b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiRequestScopedTimer.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import javax.enterprise.context.RequestScoped;
+
+/**
+ * Request scoped CDI timer.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestScoped
+public class CdiRequestScopedTimer extends BasicTimer {
+}
diff --git a/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbSingletonResource.java b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbSingletonResource.java
new file mode 100644
index 0000000..b3472d9
--- /dev/null
+++ b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbSingletonResource.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import javax.ejb.Singleton;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * EJB singleton session bean injected with CDI timers.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Singleton
+@Path("singleton")
+public class EjbSingletonResource {
+
+ @Inject CdiRequestScopedTimer requestScopedTimer;
+ @Inject CdiAppScopedTimer appScopedTimer;
+
+ @GET
+ @Path("request-scoped-timer")
+ public String getReqTime() {
+ return Long.toString(requestScopedTimer.getMiliseconds());
+ }
+
+ @GET
+ @Path("app-scoped-timer")
+ public String getAppTime() {
+ return Long.toString(appScopedTimer.getMiliseconds());
+ }
+}
diff --git a/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbSingletonTimer.java b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbSingletonTimer.java
new file mode 100644
index 0000000..3bec04d
--- /dev/null
+++ b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbSingletonTimer.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import javax.ejb.Singleton;
+
+/**
+ * EJB singleton timer.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Singleton
+public class EjbSingletonTimer extends BasicTimer {
+}
diff --git a/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbStatefulResource.java b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbStatefulResource.java
new file mode 100644
index 0000000..25fbc9f
--- /dev/null
+++ b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbStatefulResource.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import javax.ejb.Stateful;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * EJB backed JAX-RS resource injected with CDI service providers.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Stateful
+@Path("stateful")
+public class EjbStatefulResource {
+
+ @Inject CdiRequestScopedTimer requestScopedTimer;
+ @Inject CdiAppScopedTimer appScopedTimer;
+
+ @GET
+ @Path("request-scoped-timer")
+ public String getReqTime() {
+ return Long.toString(requestScopedTimer.getMiliseconds());
+ }
+
+ @GET
+ @Path("app-scoped-timer")
+ public String getAppTime() {
+ return Long.toString(appScopedTimer.getMiliseconds());
+ }
+}
diff --git a/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbStatelessResource.java b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbStatelessResource.java
new file mode 100644
index 0000000..71da1ce
--- /dev/null
+++ b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbStatelessResource.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import javax.ejb.Stateless;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * EJB session bean injected with CDI service providers.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Stateless
+@Path("stateless")
+public class EjbStatelessResource {
+
+ @Inject CdiRequestScopedTimer requestScopedTimer;
+ @Inject CdiAppScopedTimer appScopedTimer;
+
+ @GET
+ @Path("request-scoped-timer")
+ public String getReqTime() {
+ return Long.toString(requestScopedTimer.getMiliseconds());
+ }
+
+ @GET
+ @Path("app-scoped-timer")
+ public String getAppTime() {
+ return Long.toString(appScopedTimer.getMiliseconds());
+ }
+}
diff --git a/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbStatelessTimer.java b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbStatelessTimer.java
new file mode 100644
index 0000000..721aa18
--- /dev/null
+++ b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EjbStatelessTimer.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import javax.ejb.Stateless;
+
+/**
+ * EJB session timer bean.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Stateless
+public class EjbStatelessTimer extends BasicTimer {
+}
diff --git a/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
new file mode 100644
index 0000000..69e395d
--- /dev/null
+++ b/tests/integration/cdi-ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2010, 2018 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.cdi.resources;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * JAX-RS application to configure resources.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("/*")
+public class MyApplication extends Application {
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> classes = new HashSet<Class<?>>();
+ classes.add(CdiRequestScopedResource.class);
+ classes.add(CdiRequestScopedTimer.class);
+ classes.add(CdiAppScopedTimer.class);
+ classes.add(EjbStatelessResource.class);
+ classes.add(EjbStatefulResource.class);
+ classes.add(EjbSingletonResource.class);
+ return classes;
+ }
+}
diff --git a/tests/integration/cdi-ejb-test-webapp/src/main/webapp/WEB-INF/beans.xml b/tests/integration/cdi-ejb-test-webapp/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/cdi-ejb-test-webapp/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-ejb-test-webapp/src/main/webapp/WEB-INF/web.xml b/tests/integration/cdi-ejb-test-webapp/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..71e6b6e
--- /dev/null
+++ b/tests/integration/cdi-ejb-test-webapp/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 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
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+</web-app>
diff --git a/tests/integration/cdi-ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiIntoEjbTest.java b/tests/integration/cdi-ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiIntoEjbTest.java
new file mode 100644
index 0000000..d0e8226
--- /dev/null
+++ b/tests/integration/cdi-ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiIntoEjbTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import javax.ws.rs.client.WebTarget;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test CDI timers injected into EJB beans.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class CdiIntoEjbTest extends TestBase {
+
+ @Test
+ public void testStateless() {
+ _testRequestScoped("stateless");
+ _testAppScoped("stateless");
+ }
+
+ @Test
+ public void testStateful() {
+ _testRequestScoped("stateful");
+ _testAppScoped("stateful");
+ }
+
+ @Test
+ public void testSingleton() {
+ _testRequestScoped("singleton");
+ _testAppScoped("singleton");
+ }
+
+ private void _testRequestScoped(final String ejbType) {
+
+ final WebTarget target = target().path(ejbType).path("request-scoped-timer");
+ long firstMillis = _getMillis(target);
+ sleep(2);
+ long secondMillis = _getMillis(target);
+
+ assertTrue("Second request should have greater millis!", secondMillis > firstMillis);
+ }
+
+ private void _testAppScoped(final String ejbType) {
+
+ final WebTarget target = target().path(ejbType).path("app-scoped-timer");
+ long firstMillis = _getMillis(target);
+ sleep(2);
+ long secondMillis = _getMillis(target);
+
+ assertTrue("Second request should have the same millis!", secondMillis == firstMillis);
+ }
+}
diff --git a/tests/integration/cdi-ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/EjbIntoCdiTest.java b/tests/integration/cdi-ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/EjbIntoCdiTest.java
new file mode 100644
index 0000000..231836c
--- /dev/null
+++ b/tests/integration/cdi-ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/EjbIntoCdiTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import javax.ws.rs.client.WebTarget;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.equalTo;
+
+/**
+ * Test EJB timers injected into CDI beans.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class EjbIntoCdiTest extends TestBase {
+
+ @Test
+ public void testInjection() {
+
+ final WebTarget cdiResource = target().path("request-scoped");
+ final WebTarget ejbInjectedTimer = cdiResource.path("ejb-injected-timer");
+ final WebTarget jsr330InjectedTimer = cdiResource.path("jsr330-injected-timer");
+
+ String firstResource = cdiResource.request().get(String.class);
+ long firstMillis = _getMillis(ejbInjectedTimer);
+ sleep(2);
+ String secondResource = cdiResource.request().get(String.class);
+ long secondMillis = _getMillis(jsr330InjectedTimer);
+
+ assertThat(firstMillis, equalTo(secondMillis));
+ assertThat(firstResource, not(equalTo(secondResource)));
+ }
+}
diff --git a/tests/integration/cdi-ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/TestBase.java b/tests/integration/cdi-ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/TestBase.java
new file mode 100644
index 0000000..d11189d
--- /dev/null
+++ b/tests/integration/cdi-ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/TestBase.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import java.net.URI;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.test.JerseyTest;
+
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.is;
+
+/**
+ * Test for CDI web application resources.
+ * Run with:
+ * <pre>
+ * mvn clean package
+ * $AS_HOME/bin/asadmin deploy target/cdi-test-webapp
+ * mvn -DskipTests=false test</pre>
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class TestBase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new MyApplication();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-ejb-test-webapp").build();
+ }
+
+ protected long _getMillis(final WebTarget target) throws NumberFormatException {
+ final Response response = target.request().get();
+ assertThat(response.getStatus(), is(200));
+ return Long.decode(response.readEntity(String.class));
+ }
+
+ protected void sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ } catch (InterruptedException ex) {
+ Logger.getLogger(CdiIntoEjbTest.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+}
+
diff --git a/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/pom.xml b/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/pom.xml
new file mode 100644
index 0000000..d0cf29f
--- /dev/null
+++ b/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/pom.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cdi-iface-with-non-jaxrs-impl-test-webapp</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-cdi-iface-with-non-jaxrs-impl-test-webapp</name>
+
+ <description>Jersey CDI using non JAX-RS implementation for CDI injection</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiEcho.java b/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiEcho.java
new file mode 100644
index 0000000..217a999
--- /dev/null
+++ b/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiEcho.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+/**
+ * Raw CDI implementation of {@link Echo} service.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class CdiEcho implements Echo {
+
+ @Override
+ public String echo(String s) {
+ return String.format("CDI ECHOED %s", s);
+ }
+}
diff --git a/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Echo.java b/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Echo.java
new file mode 100644
index 0000000..0173d6c
--- /dev/null
+++ b/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Echo.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+/**
+ * Echo service interface.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public interface Echo {
+
+ /**
+ * Echo service method;
+ *
+ * @param s input
+ * @return echoed input
+ */
+ public String echo(String s);
+}
diff --git a/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoResource.java b/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoResource.java
new file mode 100644
index 0000000..5ca0c7c
--- /dev/null
+++ b/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoResource.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+/**
+ * JAX-RS resource class backed by CDI bean.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("echo")
+public class EchoResource {
+
+ // CDI injection, HK2 should back off
+ // even if EchoImpl is not directly used here
+ // and could appear as HK2 custom bound type
+ // to Jersey CDI extension
+ @Inject Echo echoService;
+
+ @GET
+ public String cdiEcho(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+
+}
diff --git a/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java b/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
new file mode 100644
index 0000000..a5506a8
--- /dev/null
+++ b/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2010, 2018 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.cdi.resources;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * JAX-RS application to configure resources.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("/*")
+public class MyApplication extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> classes = new HashSet<>();
+ classes.add(EchoResource.class);
+ return classes;
+ }
+}
diff --git a/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/webapp/WEB-INF/beans.xml b/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/webapp/WEB-INF/web.xml b/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..71e6b6e
--- /dev/null
+++ b/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 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
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+</web-app>
diff --git a/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/EchoResourceTest.java b/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/EchoResourceTest.java
new file mode 100644
index 0000000..dfe58b0
--- /dev/null
+++ b/tests/integration/cdi-iface-with-non-jaxrs-impl-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/EchoResourceTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.net.URI;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.junit.Test;
+
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.startsWith;
+
+/**
+ * Test for CDI web application resources.
+ * Run with:
+ * <pre>
+ * mvn clean package
+ * $AS_HOME/bin/asadmin deploy target/cdi-test-webapp
+ * mvn -DskipTests=false test</pre>
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class EchoResourceTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new MyApplication();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-iface-with-non-jaxrs-impl-test-webapp").build();
+ }
+
+ @Test
+ public void testCdiInjection() throws Exception {
+ final Response response = target().path("echo").queryParam("s", "I").request().get();
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), startsWith("CDI ECHOED"));
+ }
+
+ protected void sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ } catch (InterruptedException ex) {
+ Logger.getLogger(EchoResourceTest.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+}
diff --git a/tests/integration/cdi-multimodule/ear/pom.xml b/tests/integration/cdi-multimodule/ear/pom.xml
new file mode 100644
index 0000000..5b01d1e
--- /dev/null
+++ b/tests/integration/cdi-multimodule/ear/pom.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>cdi-multimodule-ear</artifactId>
+ <packaging>ear</packaging>
+ <name>jersey-tests-integration-cdi-multimodule-ear</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-ear-plugin</artifactId>
+ <configuration>
+ <version>6</version>
+ <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
+ <modules>
+ <webModule>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>cdi-multimodule-war1</artifactId>
+ </webModule>
+ <webModule>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>cdi-multimodule-war2</artifactId>
+ </webModule>
+ <jarModule>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>cdi-multimodule-lib</artifactId>
+ </jarModule>
+ </modules>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>cdi-multimodule-war1</artifactId>
+ <type>war</type>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>cdi-multimodule-war2</artifactId>
+ <type>war</type>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>cdi-multimodule-lib</artifactId>
+ <type>jar</type>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/tests/integration/cdi-multimodule/lib/pom.xml b/tests/integration/cdi-multimodule/lib/pom.xml
new file mode 100644
index 0000000..4e38c98
--- /dev/null
+++ b/tests/integration/cdi-multimodule/lib/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>cdi-multimodule-lib</artifactId>
+ <packaging>jar</packaging>
+ <name>jersey-tests-integration-cdi-multimodule-lib</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.ejb</groupId>
+ <artifactId>javax.ejb-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/cdi-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/lib/JaxRsInjectedDependentBean.java b/tests/integration/cdi-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/lib/JaxRsInjectedDependentBean.java
new file mode 100644
index 0000000..44eca4a
--- /dev/null
+++ b/tests/integration/cdi-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/lib/JaxRsInjectedDependentBean.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.multimodule.cdi.lib;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * CDI managed bean, that gets JAX-RS injected. This bean is being consumed
+ * by all web apps within an EAR packaged enterprise application.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class JaxRsInjectedDependentBean {
+
+ @Context
+ UriInfo uriInfo;
+
+ @HeaderParam("x-test")
+ String testHeader;
+
+ /**
+ * Get me URI info.
+ *
+ * @return URI info from the JAX-RS layer.
+ */
+ public UriInfo getUriInfo() {
+ return uriInfo;
+ }
+
+ /**
+ * Get me the actual request test header.
+ *
+ * @return actual request URI info.
+ */
+ public String getTestHeader() {
+ return testHeader;
+ }
+
+}
diff --git a/tests/integration/cdi-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/lib/JaxRsInjectedRequestScopedBean.java b/tests/integration/cdi-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/lib/JaxRsInjectedRequestScopedBean.java
new file mode 100644
index 0000000..5664ed8
--- /dev/null
+++ b/tests/integration/cdi-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/lib/JaxRsInjectedRequestScopedBean.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.multimodule.cdi.lib;
+
+import javax.enterprise.context.RequestScoped;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * CDI managed bean, that gets JAX-RS injected. This bean is being consumed
+ * by all web apps within an EAR packaged enterprise application.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestScoped
+public class JaxRsInjectedRequestScopedBean {
+
+ @Context
+ UriInfo uriInfo;
+
+ @HeaderParam("x-test")
+ String testHeader;
+
+ /**
+ * Get me the actual JAX-RS request URI info.
+ *
+ * @return actual request URI info.
+ */
+ public UriInfo getUriInfo() {
+ return uriInfo;
+ }
+
+ /**
+ * Get me the actual request test header.
+ *
+ * @return actual request URI info.
+ */
+ public String getTestHeader() {
+ return testHeader;
+ }
+}
diff --git a/tests/integration/cdi-multimodule/lib/src/main/resources/META-INF/beans.xml b/tests/integration/cdi-multimodule/lib/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..3b46d69
--- /dev/null
+++ b/tests/integration/cdi-multimodule/lib/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-multimodule/pom.xml b/tests/integration/cdi-multimodule/pom.xml
new file mode 100644
index 0000000..803f972
--- /dev/null
+++ b/tests/integration/cdi-multimodule/pom.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cdi-multimodule</artifactId>
+ <packaging>pom</packaging>
+ <name>jersey-tests-integration-cdi-multimodule</name>
+
+ <description>
+ CDI Multi-Module
+ </description>
+
+ <modules>
+ <module>ear</module>
+ <module>lib</module>
+ <module>war1</module>
+ <module>war2</module>
+ </modules>
+</project>
diff --git a/tests/integration/cdi-multimodule/war1/pom.xml b/tests/integration/cdi-multimodule/war1/pom.xml
new file mode 100644
index 0000000..6c9cea8
--- /dev/null
+++ b/tests/integration/cdi-multimodule/war1/pom.xml
@@ -0,0 +1,111 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>cdi-multimodule-war1</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-cdi-multimodule-war</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>cdi-multimodule-lib</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/cdi-multimodule/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/AppScopedJaxRsResource.java b/tests/integration/cdi-multimodule/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/AppScopedJaxRsResource.java
new file mode 100644
index 0000000..3a1a69c
--- /dev/null
+++ b/tests/integration/cdi-multimodule/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/AppScopedJaxRsResource.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.multimodule.cdi.web1;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+import org.glassfish.jersey.tests.integration.multimodule.cdi.lib.JaxRsInjectedDependentBean;
+import org.glassfish.jersey.tests.integration.multimodule.cdi.lib.JaxRsInjectedRequestScopedBean;
+
+/**
+ * JAX-RS resource backed by an application scoped CDI bean.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("app-scoped")
+@ApplicationScoped
+public class AppScopedJaxRsResource {
+
+ @Inject
+ JaxRsInjectedRequestScopedBean reqScopedBean;
+
+ @Path("req/header")
+ @GET
+ public String getReqHeader() {
+ return reqScopedBean.getTestHeader();
+ }
+
+ @Path("req/uri/{p}")
+ @GET
+ public String getReqUri() {
+ return reqScopedBean.getUriInfo().getRequestUri().toString();
+ }
+
+}
diff --git a/tests/integration/cdi-multimodule/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/JaxRsApp.java b/tests/integration/cdi-multimodule/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/JaxRsApp.java
new file mode 100644
index 0000000..f8b64da
--- /dev/null
+++ b/tests/integration/cdi-multimodule/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/JaxRsApp.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.multimodule.cdi.web1;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * JAX-RS application resource configuration.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("/")
+public class JaxRsApp extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return new HashSet<Class<?>>() {{
+ add(RequestScopedJaxRsResource.class);
+ add(AppScopedJaxRsResource.class);
+ }};
+ }
+}
diff --git a/tests/integration/cdi-multimodule/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/RequestScopedJaxRsResource.java b/tests/integration/cdi-multimodule/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/RequestScopedJaxRsResource.java
new file mode 100644
index 0000000..5f0ff3e
--- /dev/null
+++ b/tests/integration/cdi-multimodule/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/RequestScopedJaxRsResource.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.multimodule.cdi.web1;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+import org.glassfish.jersey.tests.integration.multimodule.cdi.lib.JaxRsInjectedDependentBean;
+import org.glassfish.jersey.tests.integration.multimodule.cdi.lib.JaxRsInjectedRequestScopedBean;
+
+/**
+ * JAX-RS resource backed by a request scoped CDI bean.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("request-scoped")
+@RequestScoped
+public class RequestScopedJaxRsResource {
+
+ @Inject
+ JaxRsInjectedDependentBean dependentBean;
+
+ @Inject
+ JaxRsInjectedRequestScopedBean reqScopedBean;
+
+ @Path("req/header")
+ @GET
+ public String getReqHeader() {
+ return reqScopedBean.getTestHeader();
+ }
+
+ @Path("dependent/header")
+ @GET
+ public String getDependentHeader() {
+ return dependentBean.getTestHeader();
+ }
+
+ @Path("req/uri/{p}")
+ @GET
+ public String getReqUri() {
+ return reqScopedBean.getUriInfo().getRequestUri().toString();
+ }
+
+ @Path("dependent/uri/{p}")
+ @GET
+ public String getAppUri() {
+ return dependentBean.getUriInfo().getRequestUri().toString();
+ }
+}
diff --git a/tests/integration/cdi-multimodule/war1/src/main/webapp/index.jsp b/tests/integration/cdi-multimodule/war1/src/main/webapp/index.jsp
new file mode 100644
index 0000000..d9c02e5
--- /dev/null
+++ b/tests/integration/cdi-multimodule/war1/src/main/webapp/index.jsp
@@ -0,0 +1,31 @@
+<%--
+
+ Copyright (c) 2015, 2018 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
+
+--%>
+
+<%@page contentType="text/html" pageEncoding="UTF-8"%>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>JSP Page</title>
+ </head>
+ <body>
+ <h1>Hello World!</h1>
+ </body>
+</html>
diff --git a/tests/integration/cdi-multimodule/war1/src/test/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/JaxRsCdiIntegrationTest.java b/tests/integration/cdi-multimodule/war1/src/test/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/JaxRsCdiIntegrationTest.java
new file mode 100644
index 0000000..62cf293
--- /dev/null
+++ b/tests/integration/cdi-multimodule/war1/src/test/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web1/JaxRsCdiIntegrationTest.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.multimodule.cdi.web1;
+
+import java.net.URI;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Test for CDI web application resources. The JAX-RS resources use CDI components from a library jar.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class JaxRsCdiIntegrationTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new JaxRsApp();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-multimodule-war1").build();
+ }
+
+ @Override
+ protected void configureClient(final ClientConfig config) {
+ config.register(LoggingFeature.class);
+ }
+
+ @Test
+ public void testUriInfoInjectionReqScopedResourceDependentBean() {
+ _testResource("request-scoped/dependent");
+ }
+
+ @Test
+ public void testUriInfoInjectionReqScopedResourceRequestScopedBean() {
+ _testResource("request-scoped/req");
+ }
+
+ @Test
+ public void testUriInfoInjectionAppScopedResourceRequestScopedBean() {
+ _testResource("app-scoped/req");
+ }
+
+ private void _testResource(String resourcePath) {
+ _testUriInfo(resourcePath);
+ _testHeader(resourcePath);
+ }
+
+ private void _testUriInfo(String resourcePath) {
+
+ _testSinglePathUriUnfo(resourcePath, "one");
+ _testSinglePathUriUnfo(resourcePath, "two");
+ _testSinglePathUriUnfo(resourcePath, "three");
+ }
+
+ private void _testSinglePathUriUnfo(final String resourcePath, final String pathParam) {
+
+ final URI baseUri = getBaseUri();
+ final String expectedResult = baseUri.resolve(resourcePath + "/uri/" + pathParam).toString();
+
+ final Response response = target().path(resourcePath).path("uri").path(pathParam).request().get();
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), equalTo(expectedResult));
+ }
+
+ private void _testHeader(final String resourcePath) {
+
+ _testSingleHeader(resourcePath, "one");
+ _testSingleHeader(resourcePath, "two");
+ _testSingleHeader(resourcePath, "three");
+ }
+
+ private void _testSingleHeader(final String resourcePath, final String headerValue) {
+
+ final String expectedResult = headerValue;
+
+ final Response response = target().path(resourcePath).path("header").request().header("x-test", headerValue).get();
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), equalTo(expectedResult));
+ }
+}
diff --git a/tests/integration/cdi-multimodule/war2/pom.xml b/tests/integration/cdi-multimodule/war2/pom.xml
new file mode 100644
index 0000000..0c4352b
--- /dev/null
+++ b/tests/integration/cdi-multimodule/war2/pom.xml
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>cdi-multimodule-war2</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-cdi-multimodule-war2</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>cdi-multimodule-lib</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/JaxRsAppOne.java b/tests/integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/JaxRsAppOne.java
new file mode 100644
index 0000000..11d5cb3
--- /dev/null
+++ b/tests/integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/JaxRsAppOne.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.multimodule.cdi.web2;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * First JAX-RS application resource configuration.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("one")
+public class JaxRsAppOne extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return new HashSet<Class<?>>() {{
+ add(SharedRequestScopedJaxRsResource.class);
+ add(SharedAppScopedJaxRsResource.class);
+ }};
+ }
+}
+
diff --git a/tests/integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/JaxRsAppTwo.java b/tests/integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/JaxRsAppTwo.java
new file mode 100644
index 0000000..0dbe770
--- /dev/null
+++ b/tests/integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/JaxRsAppTwo.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.multimodule.cdi.web2;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * Second JAX-RS application resource configuration.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("two")
+public class JaxRsAppTwo extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return new HashSet<Class<?>>() {{
+ add(SharedRequestScopedJaxRsResource.class);
+ add(SharedAppScopedJaxRsResource.class);
+ }};
+ }
+}
+
diff --git a/tests/integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/SharedAppScopedJaxRsResource.java b/tests/integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/SharedAppScopedJaxRsResource.java
new file mode 100644
index 0000000..ba722b7
--- /dev/null
+++ b/tests/integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/SharedAppScopedJaxRsResource.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.multimodule.cdi.web2;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+import org.glassfish.jersey.tests.integration.multimodule.cdi.lib.JaxRsInjectedDependentBean;
+import org.glassfish.jersey.tests.integration.multimodule.cdi.lib.JaxRsInjectedRequestScopedBean;
+
+/**
+ * JAX-RS resource backed by an application scoped CDI bean.
+ * This one is being shared between the two JAX-RS apps
+ * {@link JaxRsAppOne} and {@link JaxRsAppTwo}.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("app-scoped")
+@ApplicationScoped
+public class SharedAppScopedJaxRsResource {
+
+ @Inject
+ JaxRsInjectedDependentBean dependentBean;
+
+ @Inject
+ JaxRsInjectedRequestScopedBean reqScopedBean;
+
+ @Path("req/header")
+ @GET
+ public String getReqHeader() {
+ return reqScopedBean.getTestHeader();
+ }
+
+ @Path("dependent/header")
+ @GET
+ public String getDependentHeader() {
+ return dependentBean.getTestHeader();
+ }
+
+ @Path("req/uri/{p}")
+ @GET
+ public String getReqUri() {
+ return reqScopedBean.getUriInfo().getRequestUri().toString();
+ }
+
+ @Path("dependent/uri/{p}")
+ @GET
+ public String getAppUri() {
+ return dependentBean.getUriInfo().getRequestUri().toString();
+ }
+}
diff --git a/tests/integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/SharedRequestScopedJaxRsResource.java b/tests/integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/SharedRequestScopedJaxRsResource.java
new file mode 100644
index 0000000..876ee7f
--- /dev/null
+++ b/tests/integration/cdi-multimodule/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/SharedRequestScopedJaxRsResource.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.multimodule.cdi.web2;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+import org.glassfish.jersey.tests.integration.multimodule.cdi.lib.JaxRsInjectedDependentBean;
+import org.glassfish.jersey.tests.integration.multimodule.cdi.lib.JaxRsInjectedRequestScopedBean;
+
+/**
+ * JAX-RS resource backed by a request scoped CDI bean.
+ * This one is being shared between the two JAX-RS apps
+ * {@link JaxRsAppOne} and {@link JaxRsAppTwo}.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("request-scoped")
+@RequestScoped
+public class SharedRequestScopedJaxRsResource {
+
+ @Inject
+ JaxRsInjectedDependentBean dependentBean;
+
+ @Inject
+ JaxRsInjectedRequestScopedBean reqScopedBean;
+
+ @Path("req/header")
+ @GET
+ public String getReqHeader() {
+ return reqScopedBean.getTestHeader();
+ }
+
+ @Path("dependent/header")
+ @GET
+ public String getDependentHeader() {
+ return dependentBean.getTestHeader();
+ }
+
+ @Path("req/uri/{p}")
+ @GET
+ public String getReqUri() {
+ return reqScopedBean.getUriInfo().getRequestUri().toString();
+ }
+
+ @Path("dependent/uri/{p}")
+ @GET
+ public String getAppUri() {
+ return dependentBean.getUriInfo().getRequestUri().toString();
+ }
+}
diff --git a/tests/integration/cdi-multimodule/war2/src/main/webapp/index.jsp b/tests/integration/cdi-multimodule/war2/src/main/webapp/index.jsp
new file mode 100644
index 0000000..d9c02e5
--- /dev/null
+++ b/tests/integration/cdi-multimodule/war2/src/main/webapp/index.jsp
@@ -0,0 +1,31 @@
+<%--
+
+ Copyright (c) 2015, 2018 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
+
+--%>
+
+<%@page contentType="text/html" pageEncoding="UTF-8"%>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>JSP Page</title>
+ </head>
+ <body>
+ <h1>Hello World!</h1>
+ </body>
+</html>
diff --git a/tests/integration/cdi-multimodule/war2/src/test/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/JaxRsCdiIntegrationTest.java b/tests/integration/cdi-multimodule/war2/src/test/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/JaxRsCdiIntegrationTest.java
new file mode 100644
index 0000000..033f953
--- /dev/null
+++ b/tests/integration/cdi-multimodule/war2/src/test/java/org/glassfish/jersey/tests/integration/multimodule/cdi/web2/JaxRsCdiIntegrationTest.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.multimodule.cdi.web2;
+
+import java.net.URI;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Test for CDI web application resources. The JAX-RS resources use CDI components from a library jar.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class JaxRsCdiIntegrationTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new JaxRsAppOne();
+ }
+
+// @Override
+// protected URI getBaseUri() {
+// return UriBuilder.fromUri(super.getBaseUri()).path("cdi-multimodule-war1").build();
+// }
+
+ @Override
+ protected void configureClient(final ClientConfig config) {
+ config.register(LoggingFeature.class);
+ }
+
+ @Test
+ public void testUriInfoInjectionReqScopedResourceDependentBean() {
+
+ _testResource("cdi-multimodule-war2/one/request-scoped/dependent");
+ _testResource("cdi-multimodule-war2/two/request-scoped/dependent");
+ }
+
+ @Test
+ public void testUriInfoInjectionReqScopedResourceRequestScopedBean() {
+
+ _testResource("cdi-multimodule-war2/one/request-scoped/req");
+ _testResource("cdi-multimodule-war2/two/request-scoped/req");
+ }
+
+ @Test
+ public void testUriInfoInjectionAppScopedResourceRequestScopedBean() {
+
+ _testResource("cdi-multimodule-war2/one/app-scoped/req");
+ _testResource("cdi-multimodule-war2/two/app-scoped/req");
+ }
+
+ @Ignore("until JERSEY-2914 gets resolved")
+ @Test
+ public void testUriInfoInjectionAppScopedResourceDependentBean() {
+
+ _testResource("cdi-multimodule-war2/one/app-scoped/dependent");
+ _testResource("cdi-multimodule-war2/two/app-scoped/dependent");
+ }
+
+ private void _testResource(String resourcePath) {
+ _testUriInfo(resourcePath);
+ _testHeader(resourcePath);
+ }
+
+ private void _testUriInfo(String resourcePath) {
+
+ _testSinglePathUriUnfo(resourcePath, "one");
+ _testSinglePathUriUnfo(resourcePath, "two");
+ _testSinglePathUriUnfo(resourcePath, "three");
+ }
+
+ private void _testSinglePathUriUnfo(final String resourcePath, final String pathParam) {
+
+ final URI baseUri = getBaseUri();
+ final String expectedResult = baseUri.resolve(resourcePath + "/uri/" + pathParam).toString();
+
+ final Response response = target().path(resourcePath).path("uri").path(pathParam).request().get();
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), equalTo(expectedResult));
+ }
+
+ private void _testHeader(final String resourcePath) {
+
+ _testSingleHeader(resourcePath, "one");
+ _testSingleHeader(resourcePath, "two");
+ _testSingleHeader(resourcePath, "three");
+ }
+
+ private void _testSingleHeader(final String resourcePath, final String headerValue) {
+
+ final String expectedResult = headerValue;
+
+ final Response response = target().path(resourcePath).path("header").request().header("x-test", headerValue).get();
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), equalTo(expectedResult));
+ }
+}
diff --git a/tests/integration/cdi-multipart-webapp/pom.xml b/tests/integration/cdi-multipart-webapp/pom.xml
new file mode 100644
index 0000000..79f0bf4
--- /dev/null
+++ b/tests/integration/cdi-multipart-webapp/pom.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cdi-multipart-webapp</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-cdi-multipart-webapp</name>
+
+ <description>Jersey CDI test web application that uses multipart feature</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-multipart</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/cdi-multipart-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoResource.java b/tests/integration/cdi-multipart-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoResource.java
new file mode 100644
index 0000000..d64a263
--- /dev/null
+++ b/tests/integration/cdi-multipart-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoResource.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.enterprise.context.RequestScoped;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+import org.glassfish.jersey.media.multipart.FormDataParam;
+
+
+/**
+ * GF-21033 reproducer. Just a resource using multi-part support.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("/echo")
+@RequestScoped
+public class EchoResource {
+
+ /**
+ * We want to consume form data using multi-part provider.
+ *
+ * @param input form data
+ * @return input data
+ */
+ @POST
+ public Response echoMultipart(@FormDataParam ("input") String input) {
+ return Response.ok(input).build();
+ }
+}
diff --git a/tests/integration/cdi-multipart-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java b/tests/integration/cdi-multipart-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
new file mode 100644
index 0000000..e730754
--- /dev/null
+++ b/tests/integration/cdi-multipart-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
+
+/**
+ * GF-21033 reproducer. This is to make sure Jersey's multipart
+ * feature could work in GF with CDI.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("/*")
+public class MyApplication extends Application {
+
+ static final Set<Class<?>> classes = new HashSet<Class<?>>();
+
+ static {
+ classes.add(EchoResource.class);
+ classes.add(MultiPartFeature.class);
+ }
+ @Override
+ public Set<Class<?>> getClasses() {
+ return classes;
+ }
+}
diff --git a/tests/integration/cdi-multipart-webapp/src/main/webapp/WEB-INF/beans.xml b/tests/integration/cdi-multipart-webapp/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..aaf0547
--- /dev/null
+++ b/tests/integration/cdi-multipart-webapp/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-multipart-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MultipartFeatureTest.java b/tests/integration/cdi-multipart-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MultipartFeatureTest.java
new file mode 100644
index 0000000..5fb1185
--- /dev/null
+++ b/tests/integration/cdi-multipart-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MultipartFeatureTest.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.net.URI;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.media.multipart.FormDataMultiPart;
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Part of GF-21033 reproducer. Make sure form data processed by the Jersey multi-part
+ * feature make it forth and back all right.
+ *
+ * <p/>Run with:
+ * <pre>
+ * mvn clean package
+ * $AS_HOME/bin/asadmin deploy target/cdi-test-webapp
+ * mvn -DskipTests=false test</pre>
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class MultipartFeatureTest extends JerseyTest {
+
+ final String TestFormDATA;
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"No matter what"},
+ {"You should never"},
+ {"ever"},
+ {"just give up"}
+ });
+ }
+
+ public MultipartFeatureTest(String TestFormDATA) {
+ this.TestFormDATA = TestFormDATA;
+ }
+
+ @Override
+ protected Application configure() {
+ return new MyApplication();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-multipart-webapp").build();
+ }
+
+ @Override
+ protected void configureClient(ClientConfig config) {
+ config.register(MultiPartFeature.class);
+ }
+
+ @Test
+ public void testPostFormData() {
+
+ final WebTarget target = target().path("echo");
+
+ FormDataMultiPart formData = new FormDataMultiPart().field("input", TestFormDATA);
+
+ final Response response = target.request().post(Entity.entity(formData, MediaType.MULTIPART_FORM_DATA_TYPE));
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), is(TestFormDATA));
+ }
+}
+
diff --git a/tests/integration/cdi-test-webapp/pom.xml b/tests/integration/cdi-test-webapp/pom.xml
new file mode 100644
index 0000000..bfddb0f
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/pom.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cdi-test-webapp</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-cdi-webapp</name>
+
+ <description>Jersey CDI test web application</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-weld2-se</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>run-external-tests</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${external.container.factory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${external.container.port}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <!-- External test container configuration is done via properties to allow overriding via command line. -->
+ <external.container.factory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</external.container.factory>
+ <external.container.port>8080</external.container.port>
+ <maven.test.skip>false</maven.test.skip>
+ </properties>
+ </profile>
+ </profiles>
+</project>
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ConstructorInjectedResource.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ConstructorInjectedResource.java
new file mode 100644
index 0000000..736dfb9
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ConstructorInjectedResource.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.MatrixParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+/**
+ * JERSEY-2526 reproducer. CDI managed JAX-RS root resource
+ * that is constructor injected with JAX-RS parameters provided by Jersey
+ * and a single String parameter coming from application provided CDI producer,
+ * {@link CustomCdiProducer}.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("ctor-injected/{p}")
+@RequestScoped
+public class ConstructorInjectedResource {
+
+ String pathParam;
+ String queryParam;
+ String matrixParam;
+ String headerParam;
+ String cdiParam;
+
+ /**
+ * WLS requires this.
+ */
+ public ConstructorInjectedResource() {
+ }
+
+ /**
+ * This will get CDI injected with JAX-RS provided parameters.
+ *
+ * @param pathParam path parameter from the actual request.
+ * @param queryParam query parameter q from the actual request.
+ * @param matrixParam matrix parameter m from the actual request.
+ * @param headerParam Accept header parameter from the actual request.
+ * @param cdiParam custom CDI produced string.
+ */
+ @Inject
+ public ConstructorInjectedResource(
+ @PathParam("p") String pathParam,
+ @QueryParam("q") String queryParam,
+ @MatrixParam("m") String matrixParam,
+ @HeaderParam("Custom-Header") String headerParam,
+ @CustomCdiProducer.Qualifier String cdiParam) {
+
+ this.pathParam = pathParam;
+ this.queryParam = queryParam;
+ this.matrixParam = matrixParam;
+ this.headerParam = headerParam;
+ this.cdiParam = cdiParam;
+ }
+
+ /**
+ * Provide string representation of a single injected parameter
+ * given by the actual path parameter (that is also injected).
+ *
+ * @return a single parameter value.
+ */
+ @GET
+ public String getParameter() {
+
+ switch (pathParam) {
+
+ case "pathParam": return pathParam;
+ case "queryParam": return queryParam;
+ case "matrixParam": return matrixParam;
+ case "headerParam": return headerParam;
+ case "cdiParam": return cdiParam;
+
+ default: throw new WebApplicationException(Response.Status.BAD_REQUEST);
+ }
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CounterResource.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CounterResource.java
new file mode 100644
index 0000000..8342a0c
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CounterResource.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * Part of JERSEY-2461 reproducer. This one will get injected with a CDI extension.
+ * HK2 should not mess up with this.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestScoped
+@Path("counter")
+public class CounterResource {
+
+ final CustomExtension e;
+
+ /**
+ * To make CDI happy... namely to make the bean proxy-able.
+ */
+ public CounterResource() {
+ this.e = null;
+ }
+
+ /**
+ * This one will get used at runtime actually.
+ *
+ * @param extension current application CDI custom extension.
+ */
+ @Inject
+ public CounterResource(CustomExtension extension) {
+ this.e = extension;
+ }
+
+ /**
+ * Return custom extension counter state.
+ *
+ * @return next count.
+ */
+ @GET
+ public int getCount() {
+ return e.getCount();
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CustomCdiProducer.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CustomCdiProducer.java
new file mode 100644
index 0000000..9f00838
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CustomCdiProducer.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.enterprise.inject.Produces;
+
+/**
+ * CDI producer to help us make sure HK2 do not mess up with
+ * types backed by CDI producers.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class CustomCdiProducer {
+
+ /**
+ * Custom qualifier to work around https://java.net/jira/browse/GLASSFISH-20285
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE})
+ @javax.inject.Qualifier
+ public static @interface Qualifier {
+ }
+
+ /**
+ * To cover field producer.
+ */
+ @Produces
+ public static FieldProducedBean<String> field = new FieldProducedBean<>("field");
+
+ /**
+ * To cover method producer.
+ *
+ * @return bean instance to inject
+ */
+ @Produces
+ public MethodProducedBean<String> produceBean() {
+ return new MethodProducedBean<>("method");
+ }
+
+ /**
+ * Part of JERSEY-2526 reproducer. This one is used
+ * to inject constructor of {@link ConstructorInjectedResource}.
+ *
+ * @return fixed string value.
+ */
+ @Produces
+ @Qualifier
+ public String produceString() {
+ return "cdi-produced";
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CustomExtension.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CustomExtension.java
new file mode 100644
index 0000000..081bc51
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CustomExtension.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.enterprise.inject.spi.Extension;
+
+/**
+ * Part of JERSEY-2461 reproducer. We need an extension that we could inject,
+ * to make sure HK2 custom binding does not attempt to mess up.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class CustomExtension implements Extension {
+
+ private AtomicInteger counter = new AtomicInteger();
+
+ /**
+ * A made up functionality. Does not really matter. CDI
+ * would refuse to deploy the application if something went wrong.
+ *
+ * @return next count.
+ */
+ public int getCount() {
+ return counter.incrementAndGet();
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java
new file mode 100644
index 0000000..287d734
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import javax.inject.Qualifier;
+
+/**
+ * Simple echo service to test injections using {@link Qualifier}.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public interface EchoService {
+
+ /**
+ * Provide an echoed response.
+ *
+ * @param s String to be echoed.
+ * @return echoed input.
+ */
+ public String echo(String s);
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/FieldProducedBean.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/FieldProducedBean.java
new file mode 100644
index 0000000..2dbb6c4
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/FieldProducedBean.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.enterprise.inject.Vetoed;
+
+/**
+ * A bean that would be produced by a CDI producer field.
+ * This is to make sure we do not mess up with CDI producers with HK2.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Vetoed
+public class FieldProducedBean<T> implements ValueHolder<T> {
+
+ private final T value;
+
+ /**
+ * Make an instance with given value.
+ *
+ * @param value
+ */
+ public FieldProducedBean(T value) {
+ this.value = value;
+ }
+
+ @Override
+ public T getValue() {
+ return value;
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/FirstNonJaxRsBeanInjectedResource.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/FirstNonJaxRsBeanInjectedResource.java
new file mode 100644
index 0000000..60b552e
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/FirstNonJaxRsBeanInjectedResource.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.resources;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * JAX-RS resource that gets injected with a CDI managed bean,
+ * that includes JAX-RS injection points. The very same bean
+ * gets injected also to {@link FirstNonJaxRsBeanInjectedResource}.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("non-jaxrs-bean-injected")
+@RequestScoped
+public class FirstNonJaxRsBeanInjectedResource {
+
+ @Inject
+ JaxRsInjectedBean bean;
+
+ @GET
+ @Path("path/1")
+ public String getPath() {
+ return bean.getUriInfo().getPath();
+ }
+
+ @GET
+ @Path("header/1")
+ public String getAcceptHeader() {
+ return bean.getTestHeader();
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentExceptionMapper.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentExceptionMapper.java
new file mode 100644
index 0000000..390dc97
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentExceptionMapper.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2010, 2018 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.cdi.resources;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+import javax.annotation.ManagedBean;
+import javax.annotation.PostConstruct;
+
+/**
+ * JAX-RS exception mapper registered as a CDI managed bean.
+ *
+ * @author Paul Sandoz
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Provider
+@ManagedBean
+public class JCDIBeanDependentExceptionMapper implements ExceptionMapper<JDCIBeanDependentException> {
+
+ private static final Logger LOGGER = Logger.getLogger(JCDIBeanDependentExceptionMapper.class.getName());
+
+ @Context
+ private UriInfo uiFieldInject;
+
+ @Context
+ private ResourceContext resourceContext;
+
+ private UriInfo uiMethodInject;
+
+ @Context
+ public void set(UriInfo ui) {
+ this.uiMethodInject = ui;
+ }
+
+ @PostConstruct
+ public void postConstruct() {
+ LOGGER.log(Level.INFO, String.format("In post construct of %s", this));
+ ensureInjected();
+ }
+
+ @Override
+ public Response toResponse(JDCIBeanDependentException exception) {
+ ensureInjected();
+ return Response.serverError().entity("JDCIBeanDependentException").build();
+ }
+
+ private void ensureInjected() throws IllegalStateException {
+ if (uiFieldInject == null || uiMethodInject == null || resourceContext == null) {
+ throw new IllegalStateException();
+ }
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentPerRequestResource.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentPerRequestResource.java
new file mode 100644
index 0000000..2a36eff
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentPerRequestResource.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2010, 2018 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.cdi.resources;
+
+import java.util.logging.Logger;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+import javax.annotation.ManagedBean;
+import javax.annotation.Resource;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.enterprise.context.RequestScoped;
+
+
+/**
+ * Request scoped JAX-RS resource registered as a CDI managed bean.
+ *
+ * @author Paul Sandoz
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("/jcdibean/dependent/per-request")
+@ManagedBean
+@RequestScoped
+public class JCDIBeanDependentPerRequestResource {
+
+ private static final Logger LOGGER = Logger.getLogger(JCDIBeanDependentPerRequestResource.class.getName());
+
+ @Resource(name = "injectedResource")
+ private int injectedResource = 0;
+
+ @Context
+ private UriInfo uiFieldInject;
+
+ @Context
+ private ResourceContext rc;
+
+ @QueryParam("x")
+ private String x;
+
+ private UriInfo uiMethodInject;
+
+ @Context
+ public void set(UriInfo ui) {
+ this.uiMethodInject = ui;
+ }
+
+ @PostConstruct
+ public void postConstruct() {
+
+ ensureInjected();
+
+ LOGGER.info(String.format(
+ "In post construct of %s; uiFieldInject: %s; uiMethodInject: %s",
+ this, uiFieldInject, uiMethodInject));
+ }
+
+ @GET
+ @Produces("text/plain")
+ public String getMessage() {
+
+ ensureInjected();
+
+ LOGGER.info(String.format(
+ "In getMessage of %s; uiFieldInject: %s; uiMethodInject: %s",
+ this, uiFieldInject, uiMethodInject));
+
+ return String.format("%s: queryParam=%s %d", uiFieldInject.getRequestUri().toString(), x, injectedResource++);
+ }
+
+ @PreDestroy
+ public void preDestroy() {
+ LOGGER.info(String.format("In pre destroy of %s", this));
+ }
+
+ private void ensureInjected() throws IllegalStateException {
+ if (uiFieldInject == null || uiMethodInject == null || rc == null) {
+ throw new IllegalStateException();
+ }
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentResource.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentResource.java
new file mode 100644
index 0000000..589de49
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentResource.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * Test case for JERSEY-1747.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("/jcdibean/dependent/timer")
+public class JCDIBeanDependentResource {
+
+ @Inject
+ JCDIBeanRequestScopedTimer timer;
+
+ @GET
+ @Produces("text/plain")
+ public String getValue() {
+ return Long.toString(timer.getMiliseconds());
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentSingletonResource.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentSingletonResource.java
new file mode 100644
index 0000000..09ecf81
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanDependentSingletonResource.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2010, 2018 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.cdi.resources;
+
+import java.util.logging.Logger;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+import javax.annotation.ManagedBean;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ * Application scoped JAX-RS resource registered as CDI managed bean.
+ *
+ * @author Paul Sandoz
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("/jcdibean/dependent/singleton/{p}")
+@ApplicationScoped
+@ManagedBean
+public class JCDIBeanDependentSingletonResource {
+
+ private static final Logger LOGGER = Logger.getLogger(JCDIBeanDependentSingletonResource.class.getName());
+
+ @Resource(name = "injectedResource")
+ private int counter = 0;
+
+ @Context
+ private UriInfo uiFieldinject;
+
+ @Context
+ private ResourceContext resourceContext;
+
+ private UriInfo uiMethodInject;
+
+ @Context
+ public void set(UriInfo ui) {
+ this.uiMethodInject = ui;
+ }
+
+ @PostConstruct
+ public void postConstruct() {
+ LOGGER.info(String.format("In post construct of %s", this));
+ ensureInjected();
+ }
+
+ @GET
+ @Produces("text/plain")
+ public String getMessage(@PathParam("p") String p) {
+ LOGGER.info(String.format(
+ "In getMessage in %s; uiFieldInject: %s; uiMethodInject: %s", this, uiFieldinject, uiMethodInject));
+ ensureInjected();
+
+ return String.format("%s: p=%s, queryParam=%s",
+ uiFieldinject.getRequestUri().toString(), p, uiMethodInject.getQueryParameters().getFirst("x"));
+ }
+
+ @Path("exception")
+ public String getException() {
+ throw new JDCIBeanDependentException();
+ }
+
+ @Path("counter")
+ @GET
+ public synchronized String getCounter() {
+ return Integer.toString(counter++);
+ }
+
+ @Path("counter")
+ @PUT
+ public synchronized void setCounter(String counter) {
+ this.counter = Integer.decode(counter);
+ }
+
+ @PreDestroy
+ public void preDestroy() {
+ LOGGER.info(String.format("In pre destroy of %s", this));
+ }
+
+ private void ensureInjected() throws IllegalStateException {
+ if (uiFieldinject == null || uiMethodInject == null || resourceContext == null) {
+ throw new IllegalStateException();
+ }
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanExceptionMapper.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanExceptionMapper.java
new file mode 100644
index 0000000..d6a06ed
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanExceptionMapper.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2010, 2018 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.cdi.resources;
+
+import java.util.logging.Logger;
+
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ * JAX-RS exception mapper registered as CDI managed bean.
+ *
+ * @author Paul Sandoz
+ */
+@Provider
+@ApplicationScoped
+public class JCDIBeanExceptionMapper implements ExceptionMapper<JDCIBeanException> {
+
+ private static final Logger LOGGER = Logger.getLogger(JCDIBeanExceptionMapper.class.getName());
+
+ @Context
+ private UriInfo uiFieldInject;
+
+ @Context
+ private ResourceContext rc;
+
+ private UriInfo uiMethodInject;
+
+ @Context
+ public void set(UriInfo ui) {
+ this.uiMethodInject = ui;
+ }
+
+ @PostConstruct
+ public void postConstruct() {
+ ensureInjected();
+ LOGGER.info(String.format("In post construct of %s", this));
+ }
+
+ @Override
+ public Response toResponse(JDCIBeanException exception) {
+ ensureInjected();
+ return Response.serverError().entity("JDCIBeanException").build();
+ }
+
+ private void ensureInjected() throws IllegalStateException {
+ if (uiFieldInject == null || uiMethodInject == null || rc == null) {
+ throw new IllegalStateException();
+ }
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanPerRequestResource.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanPerRequestResource.java
new file mode 100644
index 0000000..303e9ad
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanPerRequestResource.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2010, 2018 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.cdi.resources;
+
+import java.util.logging.Logger;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.enterprise.context.RequestScoped;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * Request scoped JAX-RS resource registered.
+ *
+ * @author Paul Sandoz
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("/jcdibean/per-request")
+@RequestScoped
+public class JCDIBeanPerRequestResource {
+
+ private static final Logger LOGGER = Logger.getLogger(JCDIBeanPerRequestResource.class.getName());
+
+ @Resource(name = "injectedResource")
+ private int injectedResource = 0;
+
+ @Context
+ private UriInfo uiFieldInject;
+
+ @Context
+ private ResourceContext rc;
+
+ @QueryParam("x")
+ private String x;
+
+ private UriInfo uiMethodInject;
+
+ @Context
+ public void set(UriInfo ui) {
+ this.uiMethodInject = ui;
+ }
+
+ @PostConstruct
+ public void postConstruct() {
+
+ ensureInjected();
+
+ LOGGER.info(String.format(
+ "In post construct of %s; uiFieldInject: %s; uiMethodInject: %s",
+ this, uiFieldInject, uiMethodInject));
+ }
+
+ @GET
+ @Produces("text/plain")
+ public String getMessage() {
+
+ ensureInjected();
+
+ LOGGER.info(String.format(
+ "In getMessage of %s; uiFieldInject: %s; uiMethodInject: %s",
+ this, uiFieldInject, uiMethodInject));
+
+ return String.format("%s: queryParam=%s %d", uiFieldInject.getRequestUri().toString(), x, injectedResource++);
+ }
+
+ @PreDestroy
+ public void preDestroy() {
+ LOGGER.info(String.format("In pre destroy of %s", this));
+ }
+
+ private void ensureInjected() throws IllegalStateException {
+ if (uiFieldInject == null || uiMethodInject == null || rc == null) {
+ throw new IllegalStateException();
+ }
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanRequestScopedTimer.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanRequestScopedTimer.java
new file mode 100644
index 0000000..019f5a5
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanRequestScopedTimer.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.RequestScoped;
+
+/**
+ * Request scoped CDI bean to be injected into {@link JCDIBeanDependentResource}.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestScoped
+public class JCDIBeanRequestScopedTimer {
+
+ private long ms;
+
+ /**
+ * Provide information on actual request time.
+ *
+ * @return milliseconds when the current bean was post-constructed.
+ */
+ public long getMiliseconds() {
+ return ms;
+ }
+
+ @PostConstruct
+ public void init() {
+ this.ms = System.currentTimeMillis();
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanSingletonResource.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanSingletonResource.java
new file mode 100644
index 0000000..a181f4f
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JCDIBeanSingletonResource.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2010, 2018 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.cdi.resources;
+
+import java.util.logging.Logger;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+/**
+ * Application scoped JAX-RS resource.
+ *
+ * @author Paul Sandoz
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("/jcdibean/singleton/{p}")
+@ApplicationScoped
+public class JCDIBeanSingletonResource {
+
+ private static final Logger LOGGER = Logger.getLogger(JCDIBeanSingletonResource.class.getName());
+
+ @Resource(name = "injectedResource")
+ private int counter = 0;
+
+ @Context
+ private UriInfo uiFieldinject;
+
+ @Context
+ private
+ ResourceContext resourceContext;
+
+ private UriInfo uiMethodInject;
+
+ @Inject
+ Provider<JCDIBeanExceptionMapper> mapperProvider;
+
+ @Context
+ public void set(UriInfo ui) {
+ this.uiMethodInject = ui;
+ }
+
+ @PostConstruct
+ public void postConstruct() {
+ LOGGER.info(String.format("In post construct of %s", this));
+ ensureInjected();
+ }
+
+ @GET
+ @Produces("text/plain")
+ public String getMessage(@PathParam("p") String p) {
+ LOGGER.info(String.format(
+ "In getMessage in %s; uiFieldInject: %s; uiMethodInject: %s; provider: %s; provider.get(): %s", this,
+ uiFieldinject, uiMethodInject, mapperProvider, mapperProvider.get()));
+ ensureInjected();
+
+ return String.format("%s: p=%s, queryParam=%s",
+ uiFieldinject.getRequestUri().toString(), p, uiMethodInject.getQueryParameters().getFirst("x"));
+ }
+
+ @Path("exception")
+ public String getException() {
+ throw new JDCIBeanException();
+ }
+
+ @Path("counter")
+ @GET
+ public synchronized String getCounter() {
+ return Integer.toString(counter++);
+ }
+
+ @Path("counter")
+ @PUT
+ public synchronized void setCounter(String counter) {
+ this.counter = Integer.decode(counter);
+ }
+
+ @PreDestroy
+ public void preDestroy() {
+ LOGGER.info(String.format("In pre destroy of %s", this));
+ }
+
+ private void ensureInjected() throws IllegalStateException {
+ if (uiFieldinject == null || uiMethodInject == null
+ || resourceContext == null || mapperProvider.get() == null) {
+ throw new IllegalStateException();
+ }
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JDCIBeanDependentException.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JDCIBeanDependentException.java
new file mode 100644
index 0000000..73e837a
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JDCIBeanDependentException.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2010, 2018 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.cdi.resources;
+
+/**
+ * Exception to be treated by {@link JCDIBeanDependentExceptionMapper}.
+ *
+ * @author Paul Sandoz
+ */
+public class JDCIBeanDependentException extends RuntimeException {
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JDCIBeanException.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JDCIBeanException.java
new file mode 100644
index 0000000..2b80a0c
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JDCIBeanException.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2010, 2018 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.cdi.resources;
+
+/**
+ * Exception to be treated by {@link JCDIBeanExceptionMapper}.
+ *
+ * @author Paul Sandoz
+ */
+public class JDCIBeanException extends RuntimeException {
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JaxRsInjectedBean.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JaxRsInjectedBean.java
new file mode 100644
index 0000000..fd7a884
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/JaxRsInjectedBean.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.resources;
+
+import javax.enterprise.context.RequestScoped;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * This is to be JAX-RS injected at runtime.
+ * The bean is fully CDI managed, contains JAX-RS injection points and is getting injected into JAX-RS
+ * resources included in two distinct JAX-RS applications running in parallel.
+ */
+@RequestScoped
+public class JaxRsInjectedBean {
+
+ @HeaderParam("x-test")
+ String testHeader;
+
+ @Context
+ UriInfo uriInfo;
+
+ public UriInfo getUriInfo() {
+ return uriInfo;
+ }
+
+ public String getTestHeader() {
+ return testHeader;
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MainApplication.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MainApplication.java
new file mode 100644
index 0000000..b6ec0e6
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MainApplication.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2010, 2018 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.cdi.resources;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Logger;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.spi.BeanManager;
+
+import javax.inject.Inject;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * JAX-RS application to configure resources.
+ *
+ * @author Jonathan Benoit (jonathan.benoit at oracle.com)
+ */
+@ApplicationPath("main")
+@ApplicationScoped
+public class MainApplication extends Application {
+
+ static AtomicInteger postConstructCounter = new AtomicInteger();
+
+ @Inject BeanManager bm;
+
+ private static final Logger LOGGER = Logger.getLogger(MainApplication.class.getName());
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> classes = new HashSet<Class<?>>();
+ classes.add(JCDIBeanDependentResource.class);
+ classes.add(JDCIBeanException.class);
+ classes.add(JDCIBeanDependentException.class);
+ classes.add(JCDIBeanSingletonResource.class);
+ classes.add(JCDIBeanPerRequestResource.class);
+ classes.add(JCDIBeanExceptionMapper.class);
+ classes.add(JCDIBeanDependentSingletonResource.class);
+ classes.add(JCDIBeanDependentPerRequestResource.class);
+ classes.add(JCDIBeanDependentExceptionMapper.class);
+ classes.add(StutteringEchoResource.class);
+ classes.add(StutteringEcho.class);
+ classes.add(ReversingEchoResource.class);
+ classes.add(CounterResource.class);
+ classes.add(ConstructorInjectedResource.class);
+ classes.add(ProducerResource.class);
+ classes.add(FirstNonJaxRsBeanInjectedResource.class);
+ return classes;
+ }
+
+ // JERSEY-2531: make sure this type gets managed by CDI
+ @PostConstruct
+ public void postConstruct() {
+ LOGGER.info(String.format("%s: POST CONSTRUCT.", this.getClass().getName()));
+ postConstructCounter.incrementAndGet();
+ if (bm == null) {
+ throw new IllegalStateException("BeanManager should have been injected into a CDI managed bean.");
+ }
+ if (postConstructCounter.intValue() > 1) {
+ throw new IllegalStateException("postConstruct should have been invoked only once on app scoped bean.");
+ }
+ }
+
+ @PreDestroy
+ public void preDestroy() {
+ LOGGER.info(String.format("%s: PRE DESTROY.", this.getClass().getName()));
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MethodProducedBean.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MethodProducedBean.java
new file mode 100644
index 0000000..94f842f
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MethodProducedBean.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.enterprise.inject.Vetoed;
+
+/**
+ * A bean that would be produced by a CDI producer method.
+ * This is to make sure we do not mess up with CDI producers with HK2.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Vetoed
+public class MethodProducedBean<T> implements ValueHolder<T> {
+
+ private final T value;
+
+ /**
+ * Make an instance with given value.
+ *
+ * @param value
+ */
+ public MethodProducedBean(T value) {
+ this.value = value;
+ }
+
+ /**
+ * Value getter.
+ *
+ * @return value.
+ */
+ @Override
+ public T getValue() {
+ return value;
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ProducerResource.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ProducerResource.java
new file mode 100644
index 0000000..4588692
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ProducerResource.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * This one will get injected with a CDI producer.
+ * HK2 should not mess up with this.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestScoped
+@Path("producer")
+public class ProducerResource {
+
+ @Inject
+ MethodProducedBean<String> m;
+
+ @Inject
+ FieldProducedBean<String> f;
+
+ /**
+ * Return field produced bean value.
+ *
+ * @return value from field produced bean.
+ */
+ @Path("f")
+ @GET
+ public String getFieldValue() {
+ return f.getValue();
+ }
+
+ /**
+ * Return method produced bean value.
+ *
+ * @return value from method produced bean.
+ */
+ @Path("m")
+ @GET
+ public String getMethodValue() {
+ return m.getValue();
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ReverseEcho.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ReverseEcho.java
new file mode 100644
index 0000000..b385655
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ReverseEcho.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+/**
+ * Echo implementation to reverse given input.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Reversing
+public class ReverseEcho implements EchoService {
+
+ @Override
+ public String echo(String s) {
+ return reverseString(s);
+ }
+
+ private String reverseString(final String s) {
+ final int len = s.length();
+
+ char[] chars = new char[len];
+ for (int i = 0; i < len; i++) {
+ chars[i] = s.charAt(len - i - 1);
+ }
+ return new String(chars);
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Reversing.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Reversing.java
new file mode 100644
index 0000000..afe0ff5
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Reversing.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.inject.Qualifier;
+
+/**
+ * Qualifier for reversing echo service.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface Reversing {
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ReversingEchoResource.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ReversingEchoResource.java
new file mode 100644
index 0000000..c1eef59
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ReversingEchoResource.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+
+/**
+ * CDI backed JAX-RS resource to reverse input query parameter using
+ * qualified injection to get a CDI backed service provider.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestScoped
+@Path("reverse")
+public class ReversingEchoResource {
+
+ @Inject @Reversing EchoService echoService;
+
+ @GET
+ public String echo(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/SecondNonJaxRsBeanInjectedResource.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/SecondNonJaxRsBeanInjectedResource.java
new file mode 100644
index 0000000..eb4650a
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/SecondNonJaxRsBeanInjectedResource.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.resources;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * JAX-RS resource that gets injected with a CDI managed bean,
+ * that includes JAX-RS injection points. The very same bean
+ * gets injected also to {@link FirstNonJaxRsBeanInjectedResource}.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("non-jaxrs-bean-injected")
+@RequestScoped
+public class SecondNonJaxRsBeanInjectedResource {
+
+ @Inject
+ JaxRsInjectedBean bean;
+
+ @GET
+ @Path("path/2")
+ public String getPath() {
+ return bean.getUriInfo().getPath();
+ }
+
+ @GET
+ @Path("header/2")
+ public String getAcceptHeader() {
+ return bean.getTestHeader();
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/SecondaryApplication.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/SecondaryApplication.java
new file mode 100644
index 0000000..fccc031
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/SecondaryApplication.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2010, 2018 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.cdi.resources;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Logger;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * Secondary JAX-RS application to configure resources.
+ * This one is to make sure two Jersey apps could co-exist
+ * in CDI managed environment and JAX-RS injection keeps
+ * functioning as expected.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("secondary")
+@ApplicationScoped
+public class SecondaryApplication extends Application {
+
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> classes = new HashSet<Class<?>>();
+ classes.add(SecondNonJaxRsBeanInjectedResource.class);
+ return classes;
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Stuttering.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Stuttering.java
new file mode 100644
index 0000000..a1cc1a8
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Stuttering.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.inject.Qualifier;
+
+/**
+ * Qualifier for stuttering echo service.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface Stuttering {
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/StutteringEcho.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/StutteringEcho.java
new file mode 100644
index 0000000..0579f8c
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/StutteringEcho.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ * Echo implementation to stutter given input n-times.
+ * The stutter factor could be set via JAX-RS interface.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Stuttering
+@ApplicationScoped
+@Path("stutter-service-factor")
+public class StutteringEcho implements EchoService {
+
+ private static final int MIN_FACTOR = 2;
+ private int factor = MIN_FACTOR;
+
+ @Override
+ public String echo(String s) {
+ StringBuilder result = new StringBuilder();
+ for (int i = 0; i < factor; i++) {
+ result.append(s);
+ }
+ return result.toString();
+ }
+
+ @PUT
+ public void setFactor(String factor) {
+ this.factor = ensureValidInput(factor);
+ }
+
+ @GET
+ public String getFactor() {
+ return Integer.toString(factor);
+ }
+
+ private int ensureValidInput(String factor) throws WebApplicationException {
+ try {
+ final int newValue = Integer.parseInt(factor);
+ if (newValue < MIN_FACTOR) {
+ throw createWebAppException(String.format("New factor can not be lesser then %d!", MIN_FACTOR));
+ }
+ return newValue;
+ } catch (NumberFormatException nfe) {
+ throw createWebAppException(String.format("Error parsing %s as an integer!", factor));
+ }
+ }
+
+ private WebApplicationException createWebAppException(String message) {
+
+ return new WebApplicationException(
+
+ Response.status(Response.Status.BAD_REQUEST)
+ .type(MediaType.TEXT_PLAIN)
+ .entity(Entity.text(message)).build());
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/StutteringEchoResource.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/StutteringEchoResource.java
new file mode 100644
index 0000000..c3d5a56
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/StutteringEchoResource.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+/**
+ * CDI backed JAX-RS resource to stutter input query parameter.
+ * Uses qualified injection to get a CDI backed service provider.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationScoped
+@Path("stutter")
+public class StutteringEchoResource {
+
+ @Inject @Stuttering EchoService echoService;
+
+ @GET
+ public String echo(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ValueHolder.java b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ValueHolder.java
new file mode 100644
index 0000000..11046fc
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/ValueHolder.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+/**
+ * Helper type to check CDI producer mechanism is not broken
+ * by automatic HK2/CDI bindings.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public interface ValueHolder<T> {
+
+ /**
+ * Value getter.
+ *
+ * @return value.
+ */
+ T getValue();
+}
diff --git a/tests/integration/cdi-test-webapp/src/main/resources/META-INF/beans.xml b/tests/integration/cdi-test-webapp/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-test-webapp/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/tests/integration/cdi-test-webapp/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
new file mode 100644
index 0000000..7331615
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
@@ -0,0 +1 @@
+org.glassfish.jersey.tests.cdi.resources.CustomExtension
diff --git a/tests/integration/cdi-test-webapp/src/main/webapp/WEB-INF/beans.xml b/tests/integration/cdi-test-webapp/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-test-webapp/src/main/webapp/WEB-INF/web.xml b/tests/integration/cdi-test-webapp/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..ff67ca5
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 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
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <env-entry>
+ <env-entry-name>injectedResource</env-entry-name>
+ <env-entry-type>java.lang.Integer</env-entry-type>
+ <env-entry-value>10</env-entry-value>
+ </env-entry>
+</web-app>
diff --git a/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java
new file mode 100644
index 0000000..a3137a9
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import java.net.URI;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.jboss.weld.environment.se.Weld;
+
+/**
+ * Test for CDI web application resources.
+ * Run with:
+ * <pre>
+ * mvn clean package
+ * $AS_HOME/bin/asadmin deploy target/cdi-test-webapp
+ * mvn -DskipTests=false test</pre>
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class CdiTest extends JerseyTest {
+
+ Weld weld;
+
+ @Override
+ public void setUp() throws Exception {
+ weld = new Weld();
+ weld.initialize();
+ super.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ weld.shutdown();
+ super.tearDown();
+ }
+
+ @Override
+ protected Application configure() {
+ return new MainApplication();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-test-webapp/main").build();
+ }
+}
+
diff --git a/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ConstructorInjectionTest.java b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ConstructorInjectionTest.java
new file mode 100644
index 0000000..0263084
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ConstructorInjectionTest.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import org.junit.Test;
+
+/**
+ * Part of JERSEY-2526 reproducer. Without the fix, the application would
+ * not deploy at all. This is just to make sure the JAX-RS parameter producer
+ * keeps working as expected without regressions.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oralc.com)
+ */
+public class ConstructorInjectionTest extends CdiTest {
+
+ @Test
+ public void testConstructorInjectedResource() {
+
+ final WebTarget target = target().path("ctor-injected");
+
+ final Response pathParamResponse = target.path("pathParam").request().get();
+ assertThat(pathParamResponse.getStatus(), is(200));
+ assertThat(pathParamResponse.readEntity(String.class), is("pathParam"));
+
+ final Response queryParamResponse = target.path("queryParam").queryParam("q", "123").request().get();
+ assertThat(queryParamResponse.getStatus(), is(200));
+ assertThat(queryParamResponse.readEntity(String.class), is("123"));
+
+ final Response matrixParamResponse = target.path("matrixParam").matrixParam("m", "456").request().get();
+ assertThat(matrixParamResponse.getStatus(), is(200));
+ assertThat(matrixParamResponse.readEntity(String.class), is("456"));
+
+ final Response headerParamResponse = target.path("headerParam").request().header("Custom-Header", "789").get();
+ assertThat(headerParamResponse.getStatus(), is(200));
+ assertThat(headerParamResponse.readEntity(String.class), is("789"));
+
+ final Response cdiParamResponse = target.path("cdiParam").request().get();
+ assertThat(cdiParamResponse.getStatus(), is(200));
+ assertThat(cdiParamResponse.readEntity(String.class), is("cdi-produced"));
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CounterTest.java b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CounterTest.java
new file mode 100644
index 0000000..62f4f5d
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CounterTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+import org.junit.Test;
+
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.is;
+
+/**
+ * Part of JERSEY-2641 reproducer. Accessing CDI bean that has custom CDI
+ * extension injected.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class CounterTest extends CdiTest {
+
+ @Test
+ public void testGet() {
+
+ final WebTarget target = target().path("counter");
+
+ final Response firstResponse = target.request().get();
+ assertThat(firstResponse.getStatus(), is(200));
+ int firstNumber = Integer.decode(firstResponse.readEntity(String.class));
+
+ final Response secondResponse = target.request().get();
+ assertThat(secondResponse.getStatus(), is(200));
+ int secondNumber = Integer.decode(secondResponse.readEntity(String.class));
+
+ assertTrue("Second request should have greater number!", secondNumber > firstNumber);
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/JaxRsInjectedCdiBeanTest.java b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/JaxRsInjectedCdiBeanTest.java
new file mode 100644
index 0000000..56cc87b
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/JaxRsInjectedCdiBeanTest.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.resources;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test that a raw CDI managed bean gets JAX-RS injected.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class JaxRsInjectedCdiBeanTest extends CdiTest {
+
+ @Test
+ public void testPathAndHeader() {
+ _testPathAndHeader(target());
+ }
+
+ public static void _testPathAndHeader(final WebTarget webTarget) {
+ final WebTarget target = webTarget.path("non-jaxrs-bean-injected");
+
+ final Response pathResponse = target.path("path/1").request().get();
+ assertThat(pathResponse.getStatus(), is(200));
+ final String path = pathResponse.readEntity(String.class);
+
+ assertThat(path, is("non-jaxrs-bean-injected/path/1"));
+
+ final Response headerResponse = target.path("header/1").request().header("x-test", "bummer").get();
+ assertThat(headerResponse.getStatus(), is(200));
+ final String header = headerResponse.readEntity(String.class);
+
+ assertThat(header, is("bummer"));
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/NonJaxRsBeanJaxRsInjectionTest.java b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/NonJaxRsBeanJaxRsInjectionTest.java
new file mode 100644
index 0000000..2775ebf
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/NonJaxRsBeanJaxRsInjectionTest.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.resources;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Properties;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.WebTarget;
+
+import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer;
+import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainerProvider;
+import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
+import org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.TestProperties;
+
+import org.glassfish.grizzly.http.server.HttpHandler;
+import org.glassfish.grizzly.http.server.HttpServer;
+
+import org.hamcrest.CoreMatchers;
+import org.jboss.weld.environment.se.Weld;
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test two Jersey apps running simultaneously within a single Grizzly HTTP server
+ * to make sure two injection managers do not interfere. The test is not executed
+ * if other than the default (Grizzly) test container has been set.
+ * For Servlet based container testing, the other two tests, {@link JaxRsInjectedCdiBeanTest}
+ * and {@link SecondJaxRsInjectedCdiBeanTest},
+ * do the same job, because the WAR application contains both Jersey apps already.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class NonJaxRsBeanJaxRsInjectionTest {
+
+ public static final String MAIN_URI = "/main";
+ public static final String SECONDARY_URI = "/secondary";
+
+ public static final String PORT_NUMBER = getSystemProperty(TestProperties.CONTAINER_PORT,
+ Integer.toString(TestProperties.DEFAULT_CONTAINER_PORT));
+
+ private static final URI MAIN_APP_URI = URI.create("http://localhost:" + PORT_NUMBER + MAIN_URI);
+ private static final URI SECONDARY_APP_URI = URI.create("http://localhost:" + PORT_NUMBER + SECONDARY_URI);
+
+ private static final boolean isDefaultTestContainerFactorySet = isDefaultTestContainerFactorySet();
+
+ Weld weld;
+ HttpServer httpServer;
+
+ Client client;
+ WebTarget mainTarget, secondaryTarget;
+
+ @Before
+ public void before() throws IOException {
+ Assume.assumeTrue(Hk2InjectionManagerFactory.isImmediateStrategy());
+
+ if (isDefaultTestContainerFactorySet) {
+ initializeWeld();
+ startGrizzlyContainer();
+ initializeClient();
+ }
+ }
+
+ @After
+ public void after() {
+ if (Hk2InjectionManagerFactory.isImmediateStrategy()) {
+ if (isDefaultTestContainerFactorySet) {
+ httpServer.shutdownNow();
+ weld.shutdown();
+ client.close();
+ }
+ }
+ }
+
+ @Test
+ public void testPathAndHeader() throws Exception {
+ Assume.assumeThat(isDefaultTestContainerFactorySet, CoreMatchers.is(true));
+ JaxRsInjectedCdiBeanTest._testPathAndHeader(mainTarget);
+ SecondJaxRsInjectedCdiBeanTest._testPathAndHeader(secondaryTarget);
+ }
+
+ private void initializeWeld() {
+ weld = new Weld();
+ weld.initialize();
+ }
+
+ private void startGrizzlyContainer() throws IOException {
+ final ResourceConfig firstConfig = ResourceConfig.forApplicationClass(MainApplication.class);
+ final ResourceConfig secondConfig = ResourceConfig.forApplicationClass(SecondaryApplication.class);
+
+ httpServer = GrizzlyHttpServerFactory.createHttpServer(MAIN_APP_URI, firstConfig, false);
+ final HttpHandler secondHandler = createGrizzlyContainer(secondConfig);
+ httpServer.getServerConfiguration().addHttpHandler(secondHandler, SECONDARY_URI);
+ httpServer.start();
+ }
+
+ private GrizzlyHttpContainer createGrizzlyContainer(final ResourceConfig resourceConfig) {
+ return (new GrizzlyHttpContainerProvider()).createContainer(GrizzlyHttpContainer.class, resourceConfig);
+ }
+
+ private void initializeClient() {
+ client = ClientBuilder.newClient();
+ mainTarget = client.target(MAIN_APP_URI);
+ secondaryTarget = client.target(SECONDARY_APP_URI);
+ }
+
+ private static boolean isDefaultTestContainerFactorySet() {
+ final String testContainerFactory = getSystemProperty(TestProperties.CONTAINER_FACTORY, null);
+ return testContainerFactory == null || TestProperties.DEFAULT_CONTAINER_FACTORY.equals(testContainerFactory);
+ }
+
+ private static String getSystemProperty(final String propertyName, final String defaultValue) {
+ final Properties systemProperties = System.getProperties();
+ return systemProperties.getProperty(propertyName, defaultValue);
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/PerRequestBeanTest.java b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/PerRequestBeanTest.java
new file mode 100644
index 0000000..19d3984
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/PerRequestBeanTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for the request scoped resource.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class PerRequestBeanTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"alpha"},
+ {"AAA"},
+ {"$%^"},
+ {"a b"}
+ });
+ }
+
+ final String x;
+
+ /**
+ * Create x new test case based on the above defined parameters.
+ *
+ * @param x query parameter value
+ */
+ public PerRequestBeanTest(String x) {
+ this.x = x;
+ }
+
+ @Test
+ public void testGet() {
+
+ final WebTarget target = target().path("jcdibean/per-request").queryParam("x", x);
+
+ String s = target.request().get(String.class);
+
+ assertThat(s, containsString(target.getUri().toString()));
+ assertThat(s, containsString(String.format("queryParam=%s", x)));
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/PerRequestDependentBeanTest.java b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/PerRequestDependentBeanTest.java
new file mode 100644
index 0000000..dd2e879
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/PerRequestDependentBeanTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for the request scoped managed bean resource.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class PerRequestDependentBeanTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"alpha"},
+ {"AAA"},
+ {"$%^"},
+ {"a b"}
+ });
+ }
+
+ final String x;
+
+ /**
+ * Create x new test case based on the above defined parameters.
+ *
+ * @param x query parameter value
+ */
+ public PerRequestDependentBeanTest(String x) {
+ this.x = x;
+ }
+
+ @Test
+ public void testGet() {
+
+ final WebTarget target = target().path("jcdibean/dependent/per-request").queryParam("x", x);
+
+ String s = target.request().get(String.class);
+
+ assertThat(s, containsString(target.getUri().toString()));
+ assertThat(s, containsString(String.format("queryParam=%s", x)));
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ProducerTest.java b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ProducerTest.java
new file mode 100644
index 0000000..1ecf8cd
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ProducerTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+import org.junit.Test;
+
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.is;
+
+/**
+ * Check that automatic HK2 bindings do not break CDI producer mechanism.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class ProducerTest extends CdiTest {
+
+ @Test
+ public void testGet() {
+
+ final WebTarget target = target().path("producer");
+
+ final Response fieldResponse = target.path("f").request().get();
+ assertThat(fieldResponse.getStatus(), is(200));
+ assertThat(fieldResponse.readEntity(String.class), is("field"));
+
+ final Response methodResponse = target.path("m").request().get();
+ assertThat(methodResponse.getStatus(), is(200));
+ assertThat(methodResponse.readEntity(String.class), is("method"));
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/QualifiedInjectionSetGetTest.java b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/QualifiedInjectionSetGetTest.java
new file mode 100644
index 0000000..9a01764
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/QualifiedInjectionSetGetTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import javax.inject.Qualifier;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import org.junit.Test;
+
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.is;
+
+/**
+ * Test CDI bean injected using a {@link Qualifier}
+ * is setup via JAX-RS interface first.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class QualifiedInjectionSetGetTest extends CdiTest {
+
+ @Test
+ public void testSetGet() {
+
+ final WebTarget factorTarget = target().path("stutter-service-factor");
+ final WebTarget stutterTarget = target().path("stutter");
+
+ factorTarget.request().put(Entity.text("3"));
+ final String shouldBeTrippled = stutterTarget.queryParam("s", "lincoln").request().get(String.class);
+
+ assertThat(shouldBeTrippled, is("lincolnlincolnlincoln"));
+
+ factorTarget.request().put(Entity.text("2"));
+ final String shouldBeDoubled = stutterTarget.queryParam("s", "lincoln").request().get(String.class);
+
+ assertThat(shouldBeDoubled, is("lincolnlincoln"));
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ReverseEchoTest.java b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ReverseEchoTest.java
new file mode 100644
index 0000000..0c3c5ca
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ReverseEchoTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for qualified injection.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class ReverseEchoTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"alpha", "ahpla"},
+ {"gogol", "logog"},
+ {"elcaro", "oracle"}
+ });
+ }
+
+ final String in, out;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param in query parameter.
+ * @param out expected output.
+ */
+ public ReverseEchoTest(String in, String out) {
+ this.in = in;
+ this.out = out;
+ }
+
+ @Test
+ public void testGet() {
+ WebTarget reverseService = target().path("reverse").queryParam("s", in);
+ String s = reverseService.request().get(String.class);
+ assertThat(s, equalTo(out));
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/SecondJaxRsInjectedCdiBeanTest.java b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/SecondJaxRsInjectedCdiBeanTest.java
new file mode 100644
index 0000000..a273de4
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/SecondJaxRsInjectedCdiBeanTest.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2015, 2018 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.cdi.resources;
+
+import java.net.URI;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.jboss.weld.environment.se.Weld;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test that a raw CDI managed bean gets JAX-RS injected.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class SecondJaxRsInjectedCdiBeanTest extends JerseyTest {
+ Weld weld;
+
+ @Override
+ public void setUp() throws Exception {
+ weld = new Weld();
+ weld.initialize();
+ super.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ weld.shutdown();
+ super.tearDown();
+ }
+
+ @Override
+ protected Application configure() {
+ return new SecondaryApplication();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-test-webapp/secondary").build();
+ }
+
+ @Test
+ public void testPathAndHeader() {
+ _testPathAndHeader(target());
+ }
+
+ public static void _testPathAndHeader(final WebTarget webTarget) {
+ final WebTarget target = webTarget.path("non-jaxrs-bean-injected");
+
+ final Response pathResponse = target.path("path/2").request().get();
+ assertThat(pathResponse.getStatus(), is(200));
+ final String path = pathResponse.readEntity(String.class);
+
+ assertThat(path, is("non-jaxrs-bean-injected/path/2"));
+
+ final Response headerResponse = target.path("header/2").request().header("x-test", "bummer2").get();
+ assertThat(headerResponse.getStatus(), is(200));
+ final String header = headerResponse.readEntity(String.class);
+
+ assertThat(header, is("bummer2"));
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/SingletonBeanTest.java b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/SingletonBeanTest.java
new file mode 100644
index 0000000..0b35e30
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/SingletonBeanTest.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for the application scoped resource.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class SingletonBeanTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"alpha", "beta"},
+ {"1", "2"}
+ });
+ }
+
+ final String p, x;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param p path parameter.
+ * @param x query parameter.
+ */
+ public SingletonBeanTest(String p, String x) {
+ this.p = p;
+ this.x = x;
+ }
+
+ @Test
+ public void testGet() {
+ final WebTarget singleton = target().path("jcdibean/singleton").path(p).queryParam("x", x);
+ String s = singleton.request().get(String.class);
+ assertThat(s, containsString(singleton.getUri().toString()));
+ assertThat(s, containsString(String.format("p=%s", p)));
+ assertThat(s, containsString(String.format("queryParam=%s", x)));
+ }
+
+ @Test
+ public void testCounter() {
+
+ final WebTarget counter = target().path("jcdibean/singleton").path(p).queryParam("x", x).path("counter");
+
+ if (!ExternalTestContainerFactory.class.isAssignableFrom(getTestContainerFactory().getClass())) {
+ // TODO: remove this workaround once JERSEY-2744 is resolved
+ counter.request().put(Entity.text("10"));
+ }
+
+ String c10 = counter.request().get(String.class);
+ assertThat(c10, containsString("10"));
+
+ String c11 = counter.request().get(String.class);
+ assertThat(c11, containsString("11"));
+
+ counter.request().put(Entity.text("32"));
+
+ String c32 = counter.request().get(String.class);
+ assertThat(c32, containsString("32"));
+
+ counter.request().put(Entity.text("10"));
+ }
+
+ @Test
+ public void testException() {
+ final WebTarget exception = target().path("jcdibean/singleton").path(p).queryParam("x", x).path("exception");
+ assertThat(exception.request().get().readEntity(String.class), containsString("JDCIBeanException"));
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/SingletonDependentBeanTest.java b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/SingletonDependentBeanTest.java
new file mode 100644
index 0000000..5a21ae8
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/SingletonDependentBeanTest.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for the application scoped managed bean resource.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class SingletonDependentBeanTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"alpha", "beta"},
+ {"1", "2"}
+ });
+ }
+
+ final String p, x;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param p path parameter.
+ * @param x query parameter.
+ */
+ public SingletonDependentBeanTest(String p, String x) {
+ this.p = p;
+ this.x = x;
+ }
+
+ @Test
+ public void testGet() {
+ final WebTarget singleton = target().path("jcdibean/dependent/singleton").path(p).queryParam("x", x);
+ String s = singleton.request().get(String.class);
+ assertThat(s, containsString(singleton.getUri().toString()));
+ assertThat(s, containsString(String.format("p=%s", p)));
+ assertThat(s, containsString(String.format("queryParam=%s", x)));
+ }
+
+ @Test
+ public void testCounter() {
+
+ final WebTarget counter = target().path("jcdibean/dependent/singleton").path(p).queryParam("x", x).path("counter");
+
+ if (!ExternalTestContainerFactory.class.isAssignableFrom(getTestContainerFactory().getClass())) {
+ // TODO: remove this workaround once JERSEY-2744 is resolved
+ counter.request().put(Entity.text("10"));
+ }
+
+ String c10 = counter.request().get(String.class);
+ assertThat(c10, containsString("10"));
+
+ String c11 = counter.request().get(String.class);
+ assertThat(c11, containsString("11"));
+
+ counter.request().put(Entity.text("32"));
+
+ String c32 = counter.request().get(String.class);
+ assertThat(c32, containsString("32"));
+
+ counter.request().put(Entity.text("10"));
+ }
+
+ @Test
+ public void testException() {
+ final WebTarget exception = target().path("jcdibean/dependent/singleton").path(p).queryParam("x", x).path("exception");
+ assertThat(exception.request().get().readEntity(String.class), containsString("JDCIBeanDependentException"));
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/StutterEchoTest.java b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/StutterEchoTest.java
new file mode 100644
index 0000000..bc0dc27
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/StutterEchoTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for qualified injection.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class StutterEchoTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][]{
+ {"alpha", "alphaalpha"},
+ {"gogol", "gogolgogol"},
+ {"elcaro", "elcaroelcaro"}
+ });
+ };
+
+ final String in, out;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param in query parameter.
+ * @param out expected output.
+ */
+ public StutterEchoTest(String in, String out) {
+ this.in = in;
+ this.out = out;
+ }
+
+ @Test
+ public void testGet() {
+ String s = target().path("stutter").queryParam("s", in).request().get(String.class);
+ assertThat(s, equalTo(out));
+ }
+}
diff --git a/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/TimerTest.java b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/TimerTest.java
new file mode 100644
index 0000000..ba4ba33
--- /dev/null
+++ b/tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/TimerTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2013, 2018 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.cdi.resources;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+import org.junit.Test;
+
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.is;
+
+/**
+ * Reproducer for JERSEY-1747.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class TimerTest extends CdiTest {
+
+ @Test
+ public void testGet() {
+
+ final WebTarget target = target().path("jcdibean/dependent/timer");
+
+ final Response firstResponse = target.request().get();
+ assertThat(firstResponse.getStatus(), is(200));
+ long firstMillis = Long.decode(firstResponse.readEntity(String.class));
+ sleep(2);
+
+ final Response secondResponse = target.request().get();
+ assertThat(secondResponse.getStatus(), is(200));
+ long secondMillis = Long.decode(secondResponse.readEntity(String.class));
+
+ assertTrue("Second request should have greater millis!", secondMillis > firstMillis);
+ }
+
+ private void sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ } catch (InterruptedException ex) {
+ Logger.getLogger(TimerTest.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/pom.xml b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/pom.xml
new file mode 100644
index 0000000..a491ec4
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/pom.xml
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cdi-with-jersey-injection-custom-cfg-webapp</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-cdi-with-jersey-injection-custom-cfg-webapp</name>
+
+ <description>
+ Jersey CDI test web application, this one uses Jersey (non JAX-RS) component injection and Jersey/CDI SPI to config
+ HK2 custom bindings.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x-transaction</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-server</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.transaction</groupId>
+ <artifactId>javax.transaction-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppEcho.java b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppEcho.java
new file mode 100644
index 0000000..16f3efb
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppEcho.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.enterprise.context.ApplicationScoped;
+
+
+/**
+ * Application specific echo implementation.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@AppSpecific
+@ApplicationScoped
+public class AppEcho implements EchoService {
+
+ @Override
+ public String echo(String s) {
+ return "App: " + s;
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedCtorInjectedResource.java b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedCtorInjectedResource.java
new file mode 100644
index 0000000..f153c02
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedCtorInjectedResource.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+
+/**
+ * CDI backed, application scoped, JAX-RS resource to be injected
+ * via it's constructor from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationScoped
+@Path("app-ctor-injected")
+public class AppScopedCtorInjectedResource {
+
+ // CDI injected
+ EchoService echoService;
+
+ // Jersey injected
+ Provider<ContainerRequest> request;
+ ExceptionMappers mappers;
+ Provider<MonitoringStatistics> stats;
+
+ // Jersey/HK2 custom injected
+ MyApplication.MyInjection customInjected;
+ // Jersey/HK2 custom injected
+ @Inject
+ Hk2InjectedType hk2Injected;
+
+ // to make weld happy
+ public AppScopedCtorInjectedResource() {
+ }
+
+ @Inject
+ public AppScopedCtorInjectedResource(@AppSpecific final EchoService echoService,
+ final Provider<ContainerRequest> request,
+ final ExceptionMappers mappers,
+ final Provider<MonitoringStatistics> stats,
+ final MyApplication.MyInjection customInjected,
+ final Hk2InjectedType hk2Injected) {
+ this.echoService = echoService;
+ this.request = request;
+ this.mappers = mappers;
+ this.stats = stats;
+ this.customInjected = customInjected;
+ this.hk2Injected = hk2Injected;
+ }
+
+ @GET
+ public String echo(@QueryParam("s") final String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.get().getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+
+ @GET
+ @Path("custom2")
+ public String getCustom2() {
+ return hk2Injected.getName();
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedFieldInjectedResource.java b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedFieldInjectedResource.java
new file mode 100644
index 0000000..8999f6a
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedFieldInjectedResource.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+import org.glassfish.jersey.tests.cdi.resources.MyApplication.MyInjection;
+
+/**
+ * CDI backed, application scoped, JAX-RS resource.
+ * It's fields are injected from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationScoped
+@Path("app-field-injected")
+public class AppScopedFieldInjectedResource {
+
+ // CDI injected
+ @Inject
+ @AppSpecific
+ EchoService echoService;
+
+ // Jersey injected
+ @Inject
+ Provider<ContainerRequest> request;
+ @Inject
+ ExceptionMappers mappers;
+ @Inject
+ Provider<MonitoringStatistics> stats;
+
+ // Jersey/HK2 custom injection
+ @Inject
+ MyInjection customInjected;
+ // Jersey/HK2 custom injection
+ @Inject
+ Hk2InjectedType hk2Injected;
+
+ @GET
+ public String echo(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.get().getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+
+ @GET
+ @Path("custom2")
+ public String getCustom2() {
+ return hk2Injected.getName();
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppSpecific.java b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppSpecific.java
new file mode 100644
index 0000000..000fc6d
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppSpecific.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.inject.Qualifier;
+
+/**
+ * Qualifier for application specific echo service.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface AppSpecific {
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java
new file mode 100644
index 0000000..8745b22
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.inject.Qualifier;
+
+/**
+ * Simple echo service to test injections using {@link Qualifier}.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public interface EchoService {
+
+ /**
+ * Provide an echoed response.
+ *
+ * @param s String to be echoed.
+ * @return echoed input.
+ */
+ public String echo(String s);
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Hk2InjectedType.java b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Hk2InjectedType.java
new file mode 100644
index 0000000..d7d73ed
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/Hk2InjectedType.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+/**
+ * CDI compliant bean. Injection will be delegated to HK2 anyway.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class Hk2InjectedType {
+
+ private final String name;
+
+ /**
+ * No-arg constructor makes this bean suitable for CDI injection.
+ */
+ public Hk2InjectedType() {
+ name = "CDI would love this";
+ }
+
+ /**
+ * Hk2 custom binder is going to use this one.
+ *
+ * @param name
+ */
+ public Hk2InjectedType(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Simple getter to prove where this bean was initialized.
+ *
+ * @return name as defined at bean initialization.
+ */
+ public String getName() {
+ return name;
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
new file mode 100644
index 0000000..a5fc240
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.internal.inject.AbstractBinder;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.internal.monitoring.MonitoringFeature;
+
+/**
+ * JAX-RS application to configure resources.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("/*")
+public class MyApplication extends ResourceConfig {
+
+ public static class MyInjection {
+
+ private final String name;
+
+ public MyInjection(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+ }
+
+ public MyApplication() {
+
+ // JAX-RS resource classes
+ register(AppScopedFieldInjectedResource.class);
+ register(AppScopedCtorInjectedResource.class);
+ register(RequestScopedFieldInjectedResource.class);
+ register(RequestScopedCtorInjectedResource.class);
+
+ register(new AbstractBinder() {
+ @Override
+ protected void configure() {
+ bind(new MyInjection("1st: no way CDI would chime in")).to(MyInjection.class);
+ bind(new Hk2InjectedType("2nd: no way CDI would chime in")).to(Hk2InjectedType.class);
+ }
+ });
+
+ // Jersey monitoring
+ register(MonitoringFeature.class);
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyHk2TypesProvider.java b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyHk2TypesProvider.java
new file mode 100644
index 0000000..365e41b
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyHk2TypesProvider.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.glassfish.jersey.ext.cdi1x.spi.Hk2CustomBoundTypesProvider;
+
+/**
+ * Tell Jersey CDI extension what types should be bridged from HK2 to CDI.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class MyHk2TypesProvider implements Hk2CustomBoundTypesProvider {
+
+ @Override
+ public Set<Type> getHk2Types() {
+ return new HashSet<Type>() {{
+ add(Hk2InjectedType.class);
+ add(MyApplication.MyInjection.class);
+ }};
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestEcho.java b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestEcho.java
new file mode 100644
index 0000000..e0c26bc
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestEcho.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+/**
+ * Request specific echo implementation.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestSpecific
+public class RequestEcho implements EchoService {
+
+ @Override
+ public String echo(String s) {
+ return "Request: " + s;
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedCtorInjectedResource.java b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedCtorInjectedResource.java
new file mode 100644
index 0000000..881895d
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedCtorInjectedResource.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+
+/**
+ * CDI backed, request scoped, JAX-RS resource to be injected
+ * via it's constructor from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestScoped
+@Path("request-ctor-injected")
+public class RequestScopedCtorInjectedResource {
+
+ // CDI injected
+ EchoService echoService;
+
+ // Jersey injected
+ ContainerRequest request;
+ ExceptionMappers mappers;
+ Provider<MonitoringStatistics> stats;
+
+ // Jersey/HK2 custom injected
+ MyApplication.MyInjection customInjected;
+ // Jersey/HK2 custom injected
+ Hk2InjectedType hk2Injected;
+
+ // to make weld happy
+ public RequestScopedCtorInjectedResource() {
+ }
+
+ @Inject
+ public RequestScopedCtorInjectedResource(@RequestSpecific final EchoService echoService,
+ final ContainerRequest request,
+ final ExceptionMappers mappers,
+ final Provider<MonitoringStatistics> stats,
+ final MyApplication.MyInjection customInjected,
+ final Hk2InjectedType hk2Injected) {
+
+ this.echoService = echoService;
+ this.mappers = mappers;
+ this.request = request;
+ this.stats = stats;
+ this.customInjected = customInjected;
+ this.hk2Injected = hk2Injected;
+ }
+
+ @GET
+ public String echo(@QueryParam("s") final String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+
+ @GET
+ @Path("custom2")
+ public String getCustom2() {
+ return hk2Injected.getName();
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedFieldInjectedResource.java b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedFieldInjectedResource.java
new file mode 100644
index 0000000..a24f88f
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedFieldInjectedResource.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+
+/**
+ * CDI backed, request scoped, JAX-RS resource.
+ * It's fields are injected from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestScoped
+@Path("request-field-injected")
+public class RequestScopedFieldInjectedResource {
+
+ // built-in CDI bean
+ @Inject
+ BeanManager beanManager;
+
+ // CDI injected
+ @Inject
+ @RequestSpecific
+ EchoService echoService;
+
+ // Jersey injected
+ @Inject
+ ContainerRequest request;
+ @Inject
+ ExceptionMappers mappers;
+ @Inject
+ Provider<MonitoringStatistics> stats;
+
+ // Custom Jersey/HK2 injected
+ @Inject
+ MyApplication.MyInjection customInjected;
+ // Custom Jersey/HK2 injected
+ @Inject
+ Hk2InjectedType hk2Injected;
+
+ @GET
+ public String echo(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+
+ @GET
+ @Path("custom2")
+ public String getCustom2() {
+ return hk2Injected.getName();
+ }
+
+ @GET
+ @Path("bm")
+ public String getBm() {
+ return beanManager.toString();
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestSpecific.java b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestSpecific.java
new file mode 100644
index 0000000..05f048d
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestSpecific.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.inject.Qualifier;
+
+/**
+ * Qualifier for request specific echo service.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface RequestSpecific {
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/resources/META-INF/services/org.glassfish.jersey.ext.cdi1x.spi.Hk2CustomBoundTypesProvider b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/resources/META-INF/services/org.glassfish.jersey.ext.cdi1x.spi.Hk2CustomBoundTypesProvider
new file mode 100644
index 0000000..8ad35f8
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/resources/META-INF/services/org.glassfish.jersey.ext.cdi1x.spi.Hk2CustomBoundTypesProvider
@@ -0,0 +1 @@
+org.glassfish.jersey.tests.cdi.resources.MyHk2TypesProvider
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/webapp/WEB-INF/beans.xml b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/webapp/WEB-INF/web.xml b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..ff67ca5
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 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
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <env-entry>
+ <env-entry-name>injectedResource</env-entry-name>
+ <env-entry-type>java.lang.Integer</env-entry-type>
+ <env-entry-value>10</env-entry-value>
+ </env-entry>
+</web-app>
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java
new file mode 100644
index 0000000..bafe964
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.net.URI;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.test.JerseyTest;
+
+/**
+ * Test for CDI web application resources.
+ * Run with:
+ * <pre>
+ * mvn clean package
+ * $AS_HOME/bin/asadmin deploy target/cdi-with-jersey-injection-webapp
+ * mvn -DskipTests=false test</pre>
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class CdiTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new MyApplication();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-with-jersey-injection-custom-cfg-webapp").build();
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CustomInjectionTest.java b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CustomInjectionTest.java
new file mode 100644
index 0000000..0b58f6d
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CustomInjectionTest.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test custom HK2 injection.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class CustomInjectionTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected"},
+ {"app-ctor-injected"},
+ {"request-field-injected"},
+ {"request-ctor-injected"},
+ });
+ }
+
+ final String resource;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource query parameter.
+ */
+ public CustomInjectionTest(final String resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Check that for one no NPE happens on the server side,
+ * and the custom bound instance of {@link Hk2InjectedType} gets injected.
+ */
+ @Test
+ public void testCustomHk2Injection1() {
+ final WebTarget target = target().path(resource).path("custom");
+ final Response response = target.request().get();
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(String.class), equalTo("1st: no way CDI would chime in"));
+ }
+
+ /**
+ * Check that for one no NPE happens on the server side,
+ * and the custom bound instance of {@link MyApplication.MyInjection} gets injected.
+ */
+ @Test
+ public void testCustomHk2Injection2() {
+ final WebTarget target = target().path(resource).path("custom2");
+ final Response response = target.request().get();
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(String.class), equalTo("2nd: no way CDI would chime in"));
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ExceptionMappersTest.java b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ExceptionMappersTest.java
new file mode 100644
index 0000000..5675349
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ExceptionMappersTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for exception mapper injection.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class ExceptionMappersTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected"},
+ {"app-ctor-injected"},
+ {"request-field-injected"},
+ {"request-ctor-injected"},
+ });
+ }
+
+ final String resource;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource query parameter.
+ */
+ public ExceptionMappersTest(final String resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Check that for one no NPE happens on the server side, and for two
+ * the injected mappers remains the same across requests.
+ */
+ @Test
+ public void testMappersNotNull() {
+ final WebTarget target = target().path(resource).path("mappers");
+ final Response firstResponse = target.request().get();
+ assertThat(firstResponse.getStatus(), equalTo(200));
+ final String firstValue = firstResponse.readEntity(String.class);
+ assertThat(target.request().get(String.class), equalTo(firstValue));
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MonitoringTest.java b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MonitoringTest.java
new file mode 100644
index 0000000..25aed86
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MonitoringTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for monitoring statistics injection.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class MonitoringTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected"},
+ {"app-ctor-injected"},
+ {"request-field-injected"},
+ {"request-ctor-injected"}
+ });
+ }
+
+ final String resource;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource uri of resource to be tested.
+ */
+ public MonitoringTest(final String resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Make several requests and check the counter keeps incrementing.
+ *
+ * @throws Exception in case of unexpected test failure.
+ */
+ @Test
+ public void testRequestCount() throws Exception {
+ final WebTarget target = target().path(resource).path("requestCount");
+ Thread.sleep(1000); // this is to allow statistics on the server side to get updated
+ final int start = Integer.decode(target.request().get(String.class));
+ for (int i = 1; i < 4; i++) {
+ Thread.sleep(1000); // this is to allow statistics on the server side to get updated
+ final int next = Integer.decode(target.request().get(String.class));
+ assertThat(String.format("testing %s", resource), next, equalTo(start + i));
+ }
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/RequestSensitiveTest.java b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/RequestSensitiveTest.java
new file mode 100644
index 0000000..a31befa
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-cfg-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/RequestSensitiveTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test injection of request depending instances works as expected.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class RequestSensitiveTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected", "alpha", "App: alpha"},
+ {"app-field-injected", "gogol", "App: gogol"},
+ {"app-field-injected", "elcaro", "App: elcaro"},
+ {"app-ctor-injected", "alpha", "App: alpha"},
+ {"app-ctor-injected", "gogol", "App: gogol"},
+ {"app-ctor-injected", "elcaro", "App: elcaro"},
+ {"request-field-injected", "alpha", "Request: alpha"},
+ {"request-field-injected", "gogol", "Request: gogol"},
+ {"request-field-injected", "oracle", "Request: oracle"},
+ {"request-ctor-injected", "alpha", "Request: alpha"},
+ {"request-ctor-injected", "gogol", "Request: gogol"},
+ {"request-ctor-injected", "oracle", "Request: oracle"}
+ });
+ }
+
+ final String resource, straight, echoed;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource uri of the resource to be tested.
+ * @param straight request specific input.
+ * @param echoed CDI injected service should produce this out of previous, straight, parameter.
+ */
+ public RequestSensitiveTest(final String resource, final String straight, final String echoed) {
+ this.resource = resource;
+ this.straight = straight;
+ this.echoed = echoed;
+ }
+
+ @Test
+ public void testCdiInjection() {
+ final String s = target().path(resource).queryParam("s", straight).request().get(String.class);
+ assertThat(s, equalTo(echoed));
+ }
+
+ @Test
+ public void testHk2Injection() {
+ final String s = target().path(resource).path("path").path(straight).request().get(String.class);
+ assertThat(s, equalTo(String.format("%s/path/%s", resource, straight)));
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/pom.xml b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/pom.xml
new file mode 100644
index 0000000..5980238
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/pom.xml
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cdi-with-jersey-injection-custom-hk2-banned-webapp</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-cdi-with-jersey-injection-custom-hk2-banned-webapp</name>
+
+ <description>
+ Jersey CDI test web application, this one uses Jersey (non JAX-RS) component injection HK2 custom binding has been banned.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x-transaction</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.transaction</groupId>
+ <artifactId>javax.transaction-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x-ban-custom-hk2-binding</artifactId>
+ <scope>compile</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-common</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-server</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppEcho.java b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppEcho.java
new file mode 100644
index 0000000..16f3efb
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppEcho.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.enterprise.context.ApplicationScoped;
+
+
+/**
+ * Application specific echo implementation.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@AppSpecific
+@ApplicationScoped
+public class AppEcho implements EchoService {
+
+ @Override
+ public String echo(String s) {
+ return "App: " + s;
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedCtorInjectedResource.java b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedCtorInjectedResource.java
new file mode 100644
index 0000000..a50a688
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedCtorInjectedResource.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+
+/**
+ * CDI backed, application scoped, JAX-RS resource to be injected
+ * via it's constructor from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationScoped
+@Path("app-ctor-injected")
+public class AppScopedCtorInjectedResource {
+
+ // CDI injected
+ EchoService echoService;
+
+ // Jersey injected
+ Provider<ContainerRequest> request;
+ ExceptionMappers mappers;
+ Provider<MonitoringStatistics> stats;
+
+ // Jersey/HK2 custom injected
+ MyApplication.MyInjection customInjected;
+ // Jersey/HK2 custom injected
+ @Inject
+ CdiInjectedType hk2Injected;
+
+ // to make weld happy
+ public AppScopedCtorInjectedResource() {
+ }
+
+ @Inject
+ public AppScopedCtorInjectedResource(@AppSpecific final EchoService echoService,
+ final Provider<ContainerRequest> request,
+ final ExceptionMappers mappers,
+ final Provider<MonitoringStatistics> stats,
+ final MyApplication.MyInjection customInjected,
+ final CdiInjectedType hk2Injected) {
+ this.echoService = echoService;
+ this.request = request;
+ this.mappers = mappers;
+ this.stats = stats;
+ this.customInjected = customInjected;
+ this.hk2Injected = hk2Injected;
+ }
+
+ @GET
+ public String echo(@QueryParam("s") final String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.get().getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+
+ @GET
+ @Path("custom2")
+ public String getCustom2() {
+ return hk2Injected.getName();
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedFieldInjectedResource.java b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedFieldInjectedResource.java
new file mode 100644
index 0000000..8c16474
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedFieldInjectedResource.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+import org.glassfish.jersey.tests.cdi.resources.MyApplication.MyInjection;
+
+/**
+ * CDI backed, application scoped, JAX-RS resource.
+ * It's fields are injected from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationScoped
+@Path("app-field-injected")
+public class AppScopedFieldInjectedResource {
+
+ // CDI injected
+ @Inject
+ @AppSpecific
+ EchoService echoService;
+
+ // Jersey injected
+ @Inject
+ Provider<ContainerRequest> request;
+ @Inject
+ ExceptionMappers mappers;
+ @Inject
+ Provider<MonitoringStatistics> stats;
+
+ // Jersey/HK2 custom injection
+ @Inject
+ MyInjection customInjected;
+ // Jersey/HK2 custom injection
+ @Inject
+ CdiInjectedType hk2Injected;
+
+ @GET
+ public String echo(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.get().getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+
+ @GET
+ @Path("custom2")
+ public String getCustom2() {
+ return hk2Injected.getName();
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppSpecific.java b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppSpecific.java
new file mode 100644
index 0000000..000fc6d
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppSpecific.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.inject.Qualifier;
+
+/**
+ * Qualifier for application specific echo service.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface AppSpecific {
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiInjectedType.java b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiInjectedType.java
new file mode 100644
index 0000000..84b1fc2
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/CdiInjectedType.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+/**
+ * CDI compliant bean. Injection will be done by CDI in this application.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class CdiInjectedType {
+
+ private final String name;
+
+ /**
+ * No-arg constructor makes this bean suitable for CDI injection.
+ */
+ public CdiInjectedType() {
+ name = "CDI would love this";
+ }
+
+ /**
+ * Hk2 custom binder is going to use this one.
+ *
+ * @param name
+ */
+ public CdiInjectedType(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Simple getter to prove where this bean was initialized.
+ *
+ * @return name as defined at bean initialization.
+ */
+ public String getName() {
+ return name;
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java
new file mode 100644
index 0000000..8745b22
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.inject.Qualifier;
+
+/**
+ * Simple echo service to test injections using {@link Qualifier}.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public interface EchoService {
+
+ /**
+ * Provide an echoed response.
+ *
+ * @param s String to be echoed.
+ * @return echoed input.
+ */
+ public String echo(String s);
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
new file mode 100644
index 0000000..829f43a
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.internal.inject.AbstractBinder;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.internal.monitoring.MonitoringFeature;
+
+/**
+ * JAX-RS application to configure resources.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("/*")
+public class MyApplication extends ResourceConfig {
+
+ public static class MyInjection {
+
+ private final String name;
+
+ public MyInjection() {
+ name = "CDI injected";
+ }
+
+ public MyInjection(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+ }
+
+ public MyApplication() {
+
+ // JAX-RS resource classes
+ register(AppScopedFieldInjectedResource.class);
+ register(AppScopedCtorInjectedResource.class);
+ register(RequestScopedFieldInjectedResource.class);
+ register(RequestScopedCtorInjectedResource.class);
+
+ register(new AbstractBinder() {
+ @Override
+ protected void configure() {
+ bind(new MyInjection("1st: unused HK2 binding")).to(MyInjection.class);
+ bind(new CdiInjectedType("2nd: unused HK2 binding")).to(CdiInjectedType.class);
+ }
+ });
+
+ // Jersey monitoring
+ register(MonitoringFeature.class);
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestEcho.java b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestEcho.java
new file mode 100644
index 0000000..e0c26bc
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestEcho.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+/**
+ * Request specific echo implementation.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestSpecific
+public class RequestEcho implements EchoService {
+
+ @Override
+ public String echo(String s) {
+ return "Request: " + s;
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedCtorInjectedResource.java b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedCtorInjectedResource.java
new file mode 100644
index 0000000..0080e0d
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedCtorInjectedResource.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+
+/**
+ * CDI backed, request scoped, JAX-RS resource to be injected
+ * via it's constructor from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestScoped
+@Path("request-ctor-injected")
+public class RequestScopedCtorInjectedResource {
+
+ // CDI injected
+ EchoService echoService;
+
+ // Jersey injected
+ ContainerRequest request;
+ ExceptionMappers mappers;
+ Provider<MonitoringStatistics> stats;
+
+ // Jersey/HK2 custom injected
+ MyApplication.MyInjection customInjected;
+ // Jersey/HK2 custom injected
+ CdiInjectedType hk2Injected;
+
+ // to make weld happy
+ public RequestScopedCtorInjectedResource() {
+ }
+
+ @Inject
+ public RequestScopedCtorInjectedResource(@RequestSpecific final EchoService echoService,
+ final ContainerRequest request,
+ final ExceptionMappers mappers,
+ final Provider<MonitoringStatistics> stats,
+ final MyApplication.MyInjection customInjected,
+ final CdiInjectedType hk2Injected) {
+
+ this.echoService = echoService;
+ this.mappers = mappers;
+ this.request = request;
+ this.stats = stats;
+ this.customInjected = customInjected;
+ this.hk2Injected = hk2Injected;
+ }
+
+ @GET
+ public String echo(@QueryParam("s") final String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+
+ @GET
+ @Path("custom2")
+ public String getCustom2() {
+ return hk2Injected.getName();
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedFieldInjectedResource.java b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedFieldInjectedResource.java
new file mode 100644
index 0000000..eecf01e
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedFieldInjectedResource.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+
+/**
+ * CDI backed, request scoped, JAX-RS resource.
+ * It's fields are injected from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestScoped
+@Path("request-field-injected")
+public class RequestScopedFieldInjectedResource {
+
+ // built-in CDI bean
+ @Inject
+ BeanManager beanManager;
+
+ // CDI injected
+ @Inject
+ @RequestSpecific
+ EchoService echoService;
+
+ // Jersey injected
+ @Inject
+ ContainerRequest request;
+ @Inject
+ ExceptionMappers mappers;
+ @Inject
+ Provider<MonitoringStatistics> stats;
+
+ // Custom Jersey/HK2 injected
+ @Inject
+ MyApplication.MyInjection customInjected;
+ // Custom Jersey/HK2 injected
+ @Inject
+ CdiInjectedType hk2Injected;
+
+ @GET
+ public String echo(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+
+ @GET
+ @Path("custom2")
+ public String getCustom2() {
+ return hk2Injected.getName();
+ }
+
+ @GET
+ @Path("bm")
+ public String getBm() {
+ return beanManager.toString();
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestSpecific.java b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestSpecific.java
new file mode 100644
index 0000000..05f048d
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestSpecific.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.inject.Qualifier;
+
+/**
+ * Qualifier for request specific echo service.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface RequestSpecific {
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/webapp/WEB-INF/beans.xml b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/webapp/WEB-INF/web.xml b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..ff67ca5
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 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
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <env-entry>
+ <env-entry-name>injectedResource</env-entry-name>
+ <env-entry-type>java.lang.Integer</env-entry-type>
+ <env-entry-value>10</env-entry-value>
+ </env-entry>
+</web-app>
diff --git a/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java
new file mode 100644
index 0000000..89cf238
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.net.URI;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.test.JerseyTest;
+
+/**
+ * Test for CDI web application resources.
+ * Run with:
+ * <pre>
+ * mvn clean package
+ * $AS_HOME/bin/asadmin deploy target/cdi-with-jersey-injection-webapp
+ * mvn -DskipTests=false test</pre>
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class CdiTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new MyApplication();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-with-jersey-injection-custom-hk2-banned-webapp").build();
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CustomInjectionTest.java b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CustomInjectionTest.java
new file mode 100644
index 0000000..6498726
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CustomInjectionTest.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test custom HK2 injection.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class CustomInjectionTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected"},
+ {"app-ctor-injected"},
+ {"request-field-injected"},
+ {"request-ctor-injected"},
+ });
+ }
+
+ final String resource;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource query parameter.
+ */
+ public CustomInjectionTest(final String resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Check that for one no NPE happens on the server side,
+ * and the custom bound instance of {@link CdiInjectedType} gets CDI injected.
+ */
+ @Test
+ public void testCustomHk2Injection1() {
+ final WebTarget target = target().path(resource).path("custom");
+ final Response response = target.request().get();
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(String.class), equalTo("CDI injected"));
+ }
+
+ /**
+ * Check that for one no NPE happens on the server side,
+ * and the custom bound instance of {@link MyApplication.MyInjection} gets CDI injected.
+ */
+ @Test
+ public void testCustomHk2Injection2() {
+ final WebTarget target = target().path(resource).path("custom2");
+ final Response response = target.request().get();
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(String.class), equalTo("CDI would love this"));
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ExceptionMappersTest.java b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ExceptionMappersTest.java
new file mode 100644
index 0000000..e87369f
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ExceptionMappersTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for exception mapper injection.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class ExceptionMappersTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected"},
+ {"app-ctor-injected"},
+ {"request-field-injected"},
+ {"request-ctor-injected"}
+ });
+ }
+
+ final String resource;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource query parameter.
+ */
+ public ExceptionMappersTest(final String resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Check that for one no NPE happens on the server side, and for two
+ * the injected mappers remains the same across requests.
+ */
+ @Test
+ public void testMappersNotNull() {
+ final WebTarget target = target().path(resource).path("mappers");
+ final Response firstResponse = target.request().get();
+ assertThat(firstResponse.getStatus(), equalTo(200));
+ final String firstValue = firstResponse.readEntity(String.class);
+ assertThat(target.request().get(String.class), equalTo(firstValue));
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MonitoringTest.java b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MonitoringTest.java
new file mode 100644
index 0000000..25aed86
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MonitoringTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for monitoring statistics injection.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class MonitoringTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected"},
+ {"app-ctor-injected"},
+ {"request-field-injected"},
+ {"request-ctor-injected"}
+ });
+ }
+
+ final String resource;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource uri of resource to be tested.
+ */
+ public MonitoringTest(final String resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Make several requests and check the counter keeps incrementing.
+ *
+ * @throws Exception in case of unexpected test failure.
+ */
+ @Test
+ public void testRequestCount() throws Exception {
+ final WebTarget target = target().path(resource).path("requestCount");
+ Thread.sleep(1000); // this is to allow statistics on the server side to get updated
+ final int start = Integer.decode(target.request().get(String.class));
+ for (int i = 1; i < 4; i++) {
+ Thread.sleep(1000); // this is to allow statistics on the server side to get updated
+ final int next = Integer.decode(target.request().get(String.class));
+ assertThat(String.format("testing %s", resource), next, equalTo(start + i));
+ }
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/RequestSensitiveTest.java b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/RequestSensitiveTest.java
new file mode 100644
index 0000000..a31befa
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-custom-hk2-banned-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/RequestSensitiveTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test injection of request depending instances works as expected.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class RequestSensitiveTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected", "alpha", "App: alpha"},
+ {"app-field-injected", "gogol", "App: gogol"},
+ {"app-field-injected", "elcaro", "App: elcaro"},
+ {"app-ctor-injected", "alpha", "App: alpha"},
+ {"app-ctor-injected", "gogol", "App: gogol"},
+ {"app-ctor-injected", "elcaro", "App: elcaro"},
+ {"request-field-injected", "alpha", "Request: alpha"},
+ {"request-field-injected", "gogol", "Request: gogol"},
+ {"request-field-injected", "oracle", "Request: oracle"},
+ {"request-ctor-injected", "alpha", "Request: alpha"},
+ {"request-ctor-injected", "gogol", "Request: gogol"},
+ {"request-ctor-injected", "oracle", "Request: oracle"}
+ });
+ }
+
+ final String resource, straight, echoed;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource uri of the resource to be tested.
+ * @param straight request specific input.
+ * @param echoed CDI injected service should produce this out of previous, straight, parameter.
+ */
+ public RequestSensitiveTest(final String resource, final String straight, final String echoed) {
+ this.resource = resource;
+ this.straight = straight;
+ this.echoed = echoed;
+ }
+
+ @Test
+ public void testCdiInjection() {
+ final String s = target().path(resource).queryParam("s", straight).request().get(String.class);
+ assertThat(s, equalTo(echoed));
+ }
+
+ @Test
+ public void testHk2Injection() {
+ final String s = target().path(resource).path("path").path(straight).request().get(String.class);
+ assertThat(s, equalTo(String.format("%s/path/%s", resource, straight)));
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/pom.xml b/tests/integration/cdi-with-jersey-injection-webapp/pom.xml
new file mode 100644
index 0000000..d0e0c42
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/pom.xml
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cdi-with-jersey-injection-webapp</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-cdi-with-jersey-injection-webapp</name>
+
+ <description>Jersey CDI test web application, this one uses Jersey (non JAX-RS) component injection</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x-transaction</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-server</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppEcho.java b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppEcho.java
new file mode 100644
index 0000000..16f3efb
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppEcho.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.enterprise.context.ApplicationScoped;
+
+
+/**
+ * Application specific echo implementation.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@AppSpecific
+@ApplicationScoped
+public class AppEcho implements EchoService {
+
+ @Override
+ public String echo(String s) {
+ return "App: " + s;
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedCtorInjectedResource.java b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedCtorInjectedResource.java
new file mode 100644
index 0000000..2bffeea
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedCtorInjectedResource.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+
+/**
+ * CDI backed, application scoped, JAX-RS resource to be injected
+ * via it's constructor from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationScoped
+@Path("app-ctor-injected")
+public class AppScopedCtorInjectedResource {
+
+ // CDI injected
+ EchoService echoService;
+
+ // Jersey injected
+ Provider<ContainerRequest> request;
+ ExceptionMappers mappers;
+ Provider<MonitoringStatistics> stats;
+
+ // Jersey/HK2 custom injected
+ MyApplication.MyInjection customInjected;
+
+ // to make weld happy
+ public AppScopedCtorInjectedResource() {
+ }
+
+ @Inject
+ public AppScopedCtorInjectedResource(@AppSpecific final EchoService echoService,
+ final Provider<ContainerRequest> request,
+ final ExceptionMappers mappers,
+ final Provider<MonitoringStatistics> stats,
+ final MyApplication.MyInjection customInjected) {
+ this.echoService = echoService;
+ this.request = request;
+ this.mappers = mappers;
+ this.stats = stats;
+ this.customInjected = customInjected;
+ }
+
+ @GET
+ public String echo(@QueryParam("s") final String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.get().getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedFieldInjectedResource.java b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedFieldInjectedResource.java
new file mode 100644
index 0000000..4c196d3
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppScopedFieldInjectedResource.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+import org.glassfish.jersey.tests.cdi.resources.MyApplication.MyInjection;
+
+/**
+ * CDI backed, application scoped, JAX-RS resource.
+ * It's fields are injected from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationScoped
+@Path("app-field-injected")
+public class AppScopedFieldInjectedResource {
+
+ // CDI injected
+ @Inject
+ @AppSpecific
+ EchoService echoService;
+
+ // Jersey injected
+ @Inject
+ Provider<ContainerRequest> request;
+ @Inject
+ ExceptionMappers mappers;
+ @Inject
+ Provider<MonitoringStatistics> stats;
+
+ // Jersey/HK2 custom injection
+ @Inject
+ MyInjection customInjected;
+
+ @GET
+ public String echo(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.get().getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppSpecific.java b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppSpecific.java
new file mode 100644
index 0000000..000fc6d
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/AppSpecific.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.inject.Qualifier;
+
+/**
+ * Qualifier for application specific echo service.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface AppSpecific {
+}
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java
new file mode 100644
index 0000000..8745b22
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/EchoService.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.inject.Qualifier;
+
+/**
+ * Simple echo service to test injections using {@link Qualifier}.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public interface EchoService {
+
+ /**
+ * Provide an echoed response.
+ *
+ * @param s String to be echoed.
+ * @return echoed input.
+ */
+ public String echo(String s);
+}
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
new file mode 100644
index 0000000..027c907
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyApplication.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.internal.inject.AbstractBinder;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.internal.monitoring.MonitoringFeature;
+
+/**
+ * JAX-RS application to configure resources.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("/*")
+public class MyApplication extends ResourceConfig {
+
+ public static class MyInjection {
+
+ private final String name;
+
+ public MyInjection(final String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+ }
+
+ public MyApplication() {
+ // JAX-RS resource classes
+ register(AppScopedFieldInjectedResource.class);
+ register(AppScopedCtorInjectedResource.class);
+ register(RequestScopedFieldInjectedResource.class);
+ register(RequestScopedCtorInjectedResource.class);
+
+ register(new AbstractBinder() {
+ @Override
+ protected void configure() {
+ bind(new MyInjection("no way CDI would chime in")).to(MyInjection.class);
+ }
+ });
+
+ // Jersey monitoring
+ register(MonitoringFeature.class);
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyHk2TypesProvider.java b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyHk2TypesProvider.java
new file mode 100644
index 0000000..362adf3
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/MyHk2TypesProvider.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.glassfish.jersey.ext.cdi1x.spi.Hk2CustomBoundTypesProvider;
+
+/**
+ * Tell Jersey CDI extension what types should be bridged from HK2 to CDI.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class MyHk2TypesProvider implements Hk2CustomBoundTypesProvider {
+
+ @Override
+ public Set<Type> getHk2Types() {
+ return new HashSet<Type>() {{
+ add(MyApplication.MyInjection.class);
+ }};
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestEcho.java b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestEcho.java
new file mode 100644
index 0000000..e0c26bc
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestEcho.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+/**
+ * Request specific echo implementation.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestSpecific
+public class RequestEcho implements EchoService {
+
+ @Override
+ public String echo(String s) {
+ return "Request: " + s;
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedCtorInjectedResource.java b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedCtorInjectedResource.java
new file mode 100644
index 0000000..250c0d8
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedCtorInjectedResource.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+
+/**
+ * CDI backed, request scoped, JAX-RS resource to be injected
+ * via it's constructor from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestScoped
+@Path("request-ctor-injected")
+public class RequestScopedCtorInjectedResource {
+
+ // CDI injected
+ EchoService echoService;
+
+ // Jersey injected
+ ContainerRequest request;
+ ExceptionMappers mappers;
+ Provider<MonitoringStatistics> stats;
+
+ // Jersey/HK2 custom injected
+ MyApplication.MyInjection customInjected;
+
+ // to make weld happy
+ public RequestScopedCtorInjectedResource() {
+ }
+
+ @Inject
+ public RequestScopedCtorInjectedResource(@RequestSpecific EchoService echoService,
+ ContainerRequest request, ExceptionMappers mappers,
+ Provider<MonitoringStatistics> stats, MyApplication.MyInjection customInjected) {
+
+ this.echoService = echoService;
+ this.mappers = mappers;
+ this.request = request;
+ this.stats = stats;
+ this.customInjected = customInjected;
+ }
+
+ @GET
+ public String echo(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedFieldInjectedResource.java b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedFieldInjectedResource.java
new file mode 100644
index 0000000..e762601
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestScopedFieldInjectedResource.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.monitoring.MonitoringStatistics;
+import org.glassfish.jersey.spi.ExceptionMappers;
+
+/**
+ * CDI backed, request scoped, JAX-RS resource.
+ * It's fields are injected from both CDI and Jersey HK2.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestScoped
+@Path("request-field-injected")
+public class RequestScopedFieldInjectedResource {
+
+ // built-in CDI bean
+ @Inject
+ BeanManager beanManager;
+
+ // CDI injected
+ @Inject
+ @RequestSpecific
+ EchoService echoService;
+
+ // Jersey injected
+ @Inject
+ ContainerRequest request;
+ @Inject
+ ExceptionMappers mappers;
+ @Inject
+ Provider<MonitoringStatistics> stats;
+
+ // Custom Jersey/HK2 injected
+ @Inject
+ MyApplication.MyInjection customInjected;
+
+ @GET
+ public String echo(@QueryParam("s") String s) {
+ return echoService.echo(s);
+ }
+
+ @GET
+ @Path("path/{param}")
+ public String getPath() {
+ return request.getPath(true);
+ }
+
+ @GET
+ @Path("mappers")
+ public String getMappers() {
+ return mappers.toString();
+ }
+
+ @GET
+ @Path("requestCount")
+ public String getStatisticsProperty() {
+ return String.valueOf(stats.get().snapshot().getRequestStatistics().getTimeWindowStatistics().get(0L).getRequestCount());
+ }
+
+ @GET
+ @Path("custom")
+ public String getCustom() {
+ return customInjected.getName();
+ }
+
+ @GET
+ @Path("bm")
+ public String getBm() {
+ return beanManager.toString();
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestSpecific.java b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestSpecific.java
new file mode 100644
index 0000000..05f048d
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/RequestSpecific.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.inject.Qualifier;
+
+/**
+ * Qualifier for request specific echo service.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface RequestSpecific {
+}
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/src/main/resources/META-INF/services/org.glassfish.jersey.ext.cdi1x.spi.Hk2CustomBoundTypesProvider b/tests/integration/cdi-with-jersey-injection-webapp/src/main/resources/META-INF/services/org.glassfish.jersey.ext.cdi1x.spi.Hk2CustomBoundTypesProvider
new file mode 100644
index 0000000..8ad35f8
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/src/main/resources/META-INF/services/org.glassfish.jersey.ext.cdi1x.spi.Hk2CustomBoundTypesProvider
@@ -0,0 +1 @@
+org.glassfish.jersey.tests.cdi.resources.MyHk2TypesProvider
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/src/main/webapp/WEB-INF/beans.xml b/tests/integration/cdi-with-jersey-injection-webapp/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<beans/>
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/src/main/webapp/WEB-INF/web.xml b/tests/integration/cdi-with-jersey-injection-webapp/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..ff67ca5
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 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
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <env-entry>
+ <env-entry-name>injectedResource</env-entry-name>
+ <env-entry-type>java.lang.Integer</env-entry-type>
+ <env-entry-value>10</env-entry-value>
+ </env-entry>
+</web-app>
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java b/tests/integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java
new file mode 100644
index 0000000..1273dd1
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.net.URI;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.test.JerseyTest;
+
+/**
+ * Test for CDI web application resources.
+ * Run with:
+ * <pre>
+ * mvn clean package
+ * $AS_HOME/bin/asadmin deploy target/cdi-with-jersey-injection-webapp
+ * mvn -DskipTests=false test</pre>
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class CdiTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new MyApplication();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("cdi-with-jersey-injection-webapp").build();
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CustomInjectionTest.java b/tests/integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CustomInjectionTest.java
new file mode 100644
index 0000000..4878426
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/CustomInjectionTest.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test custom HK2 injection.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class CustomInjectionTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected"},
+ {"app-ctor-injected"},
+ {"request-field-injected"},
+ {"request-ctor-injected"}
+ });
+ }
+
+ final String resource;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource query parameter.
+ */
+ public CustomInjectionTest(String resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Check that for one no NPE happens on the server side,
+ * and the custom bound instance gets injected.
+ */
+ @Test
+ public void testCustomHk2InjectionNull() {
+ WebTarget target = target().path(resource).path("custom");
+ final Response response = target.request().get();
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(String.class), equalTo("no way CDI would chime in"));
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ExceptionMappersTest.java b/tests/integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ExceptionMappersTest.java
new file mode 100644
index 0000000..4020db3
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/ExceptionMappersTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for exception mapper injection.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class ExceptionMappersTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected"},
+ {"app-ctor-injected"},
+ {"request-field-injected"},
+ {"request-ctor-injected"}
+ });
+ }
+
+ final String resource;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource query parameter.
+ */
+ public ExceptionMappersTest(String resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Check that for one no NPE happens on the server side, and for two
+ * the injected mappers remains the same across requests.
+ */
+ @Test
+ public void testMappersNotNull() {
+ WebTarget target = target().path(resource).path("mappers");
+ final Response firstResponse = target.request().get();
+ assertThat(firstResponse.getStatus(), equalTo(200));
+ String firstValue = firstResponse.readEntity(String.class);
+ assertThat(target.request().get(String.class), equalTo(firstValue));
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MonitoringTest.java b/tests/integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MonitoringTest.java
new file mode 100644
index 0000000..f364be2
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/MonitoringTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test for monitoring statistics injection.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class MonitoringTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected"},
+ {"app-ctor-injected"},
+ {"request-field-injected"},
+ {"request-ctor-injected"}
+ });
+ }
+
+ final String resource;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource uri of resource to be tested.
+ */
+ public MonitoringTest(String resource) {
+ this.resource = resource;
+ }
+
+ /**
+ * Make several requests and check the counter keeps incrementing.
+ *
+ * @throws Exception in case of unexpected test failure.
+ */
+ @Test
+ public void testRequestCount() throws Exception {
+ WebTarget target = target().path(resource).path("requestCount");
+ Thread.sleep(1000); // this is to allow statistics on the server side to get updated
+ int start = Integer.decode(target.request().get(String.class));
+ for (int i = 1; i < 4; i++) {
+ Thread.sleep(1000); // this is to allow statistics on the server side to get updated
+ int next = Integer.decode(target.request().get(String.class));
+ assertThat(String.format("testing %s", resource), next, equalTo(start + i));
+ }
+ }
+}
diff --git a/tests/integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/RequestSensitiveTest.java b/tests/integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/RequestSensitiveTest.java
new file mode 100644
index 0000000..ff41909
--- /dev/null
+++ b/tests/integration/cdi-with-jersey-injection-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/RequestSensitiveTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2014, 2018 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.cdi.resources;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test injection of request depending instances works as expected.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class RequestSensitiveTest extends CdiTest {
+
+ @Parameterized.Parameters
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"app-field-injected", "alpha", "App: alpha"},
+ {"app-field-injected", "gogol", "App: gogol"},
+ {"app-field-injected", "elcaro", "App: elcaro"},
+ {"app-ctor-injected", "alpha", "App: alpha"},
+ {"app-ctor-injected", "gogol", "App: gogol"},
+ {"app-ctor-injected", "elcaro", "App: elcaro"},
+ {"request-field-injected", "alpha", "Request: alpha"},
+ {"request-field-injected", "gogol", "Request: gogol"},
+ {"request-field-injected", "oracle", "Request: oracle"},
+ {"request-ctor-injected", "alpha", "Request: alpha"},
+ {"request-ctor-injected", "gogol", "Request: gogol"},
+ {"request-ctor-injected", "oracle", "Request: oracle"}
+ });
+ }
+
+ final String resource, straight, echoed;
+
+ /**
+ * Construct instance with the above test data injected.
+ *
+ * @param resource uri of the resource to be tested.
+ * @param straight request specific input.
+ * @param echoed CDI injected service should produce this out of previous, straight, parameter.
+ */
+ public RequestSensitiveTest(String resource, String straight, String echoed) {
+ this.resource = resource;
+ this.straight = straight;
+ this.echoed = echoed;
+ }
+
+ @Test
+ public void testCdiInjection() {
+ String s = target().path(resource).queryParam("s", straight).request().get(String.class);
+ assertThat(s, equalTo(echoed));
+ }
+
+ @Test
+ public void testHk2Injection() {
+ String s = target().path(resource).path("path").path(straight).request().get(String.class);
+ assertThat(s, equalTo(String.format("%s/path/%s", resource, straight)));
+ }
+}
diff --git a/tests/integration/client-connector-provider/pom.xml b/tests/integration/client-connector-provider/pom.xml
new file mode 100644
index 0000000..465f8e6
--- /dev/null
+++ b/tests/integration/client-connector-provider/pom.xml
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>client-connector-provider</artifactId>
+ <packaging>jar</packaging>
+ <name>client-connector-provider</name>
+
+ <description>Client Connector provider test</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-client</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ </build>
+</project>
diff --git a/tests/integration/client-connector-provider/src/main/java/org/glassfish/jersey/tests/integration/client/connector/provider/CustomConnectorProvider.java b/tests/integration/client-connector-provider/src/main/java/org/glassfish/jersey/tests/integration/client/connector/provider/CustomConnectorProvider.java
new file mode 100644
index 0000000..5a4e70b
--- /dev/null
+++ b/tests/integration/client-connector-provider/src/main/java/org/glassfish/jersey/tests/integration/client/connector/provider/CustomConnectorProvider.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.client.connector.provider;
+
+import java.net.HttpURLConnection;
+
+import javax.ws.rs.client.Client;
+
+import org.glassfish.jersey.client.HttpUrlConnectorProvider;
+import org.glassfish.jersey.client.JerseyClient;
+import org.glassfish.jersey.client.internal.HttpUrlConnector;
+import org.glassfish.jersey.client.spi.Connector;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+public final class CustomConnectorProvider extends HttpUrlConnectorProvider {
+
+ public static volatile boolean invoked = false;
+
+ @Override
+ protected Connector createHttpUrlConnector(Client client, ConnectionFactory connectionFactory, int chunkSize,
+ boolean fixLengthStreaming, boolean setMethodWorkaround) {
+
+ return new HttpUrlConnector(
+ client,
+ connectionFactory,
+ chunkSize,
+ fixLengthStreaming,
+ setMethodWorkaround) {
+
+ @Override
+ protected void secureConnection(JerseyClient client, HttpURLConnection uc) {
+ invoked = true;
+ }
+ };
+ }
+}
diff --git a/tests/integration/client-connector-provider/src/main/java/org/glassfish/jersey/tests/integration/client/connector/provider/TestResource.java b/tests/integration/client-connector-provider/src/main/java/org/glassfish/jersey/tests/integration/client/connector/provider/TestResource.java
new file mode 100644
index 0000000..f941b89
--- /dev/null
+++ b/tests/integration/client-connector-provider/src/main/java/org/glassfish/jersey/tests/integration/client/connector/provider/TestResource.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.client.connector.provider;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+@Path("test")
+public class TestResource {
+
+ @GET
+ public String get() {
+ return "test";
+ }
+}
diff --git a/tests/integration/client-connector-provider/src/main/resources/META-INF/services/org.glassfish.jersey.client.spi.ConnectorProvider b/tests/integration/client-connector-provider/src/main/resources/META-INF/services/org.glassfish.jersey.client.spi.ConnectorProvider
new file mode 100644
index 0000000..b3bb97e
--- /dev/null
+++ b/tests/integration/client-connector-provider/src/main/resources/META-INF/services/org.glassfish.jersey.client.spi.ConnectorProvider
@@ -0,0 +1 @@
+org.glassfish.jersey.tests.integration.client.connector.provider.CustomConnectorProvider
diff --git a/tests/integration/client-connector-provider/src/test/java/org/glassfish/jersey/tests/integration/client/connector/provider/CustomConnectorProviderTest.java b/tests/integration/client-connector-provider/src/test/java/org/glassfish/jersey/tests/integration/client/connector/provider/CustomConnectorProviderTest.java
new file mode 100644
index 0000000..dc4daf1
--- /dev/null
+++ b/tests/integration/client-connector-provider/src/test/java/org/glassfish/jersey/tests/integration/client/connector/provider/CustomConnectorProviderTest.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.client.connector.provider;
+
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+public class CustomConnectorProviderTest extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig(TestResource.class);
+ }
+
+ @Test
+ public void testInvoked() {
+ assertFalse(CustomConnectorProvider.invoked);
+
+ Response response = target().path("test").request("text/plain").get();
+ assertEquals(200, response.getStatus());
+
+ assertTrue(CustomConnectorProvider.invoked);
+ }
+}
diff --git a/tests/integration/ejb-multimodule-reload/ear/pom.xml b/tests/integration/ejb-multimodule-reload/ear/pom.xml
new file mode 100644
index 0000000..09183cb
--- /dev/null
+++ b/tests/integration/ejb-multimodule-reload/ear/pom.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>ejb-multimodule-reload-ear</artifactId>
+ <packaging>ear</packaging>
+ <name>jersey-tests-integration-ejb-multimodule-reload-ear</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-ear-plugin</artifactId>
+ <configuration>
+ <version>6</version>
+ <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
+ <modules>
+ <webModule>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>ejb-multimodule-reload-war1</artifactId>
+ </webModule>
+ <webModule>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>ejb-multimodule-reload-war2</artifactId>
+ </webModule>
+ <ejbModule>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>ejb-multimodule-reload-lib</artifactId>
+ </ejbModule>
+ </modules>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>ejb-multimodule-reload-war1</artifactId>
+ <type>war</type>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>ejb-multimodule-reload-war2</artifactId>
+ <type>war</type>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>ejb-multimodule-reload-lib</artifactId>
+ <type>ejb</type>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/tests/integration/ejb-multimodule-reload/lib/pom.xml b/tests/integration/ejb-multimodule-reload/lib/pom.xml
new file mode 100644
index 0000000..730d296
--- /dev/null
+++ b/tests/integration/ejb-multimodule-reload/lib/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>ejb-multimodule-reload-lib</artifactId>
+ <packaging>jar</packaging>
+ <name>jersey-tests-integration-ejb-multimodule-reload-lib</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-server</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.ejb</groupId>
+ <artifactId>javax.ejb-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/ejb-multimodule-reload/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/lib/ContainerListener.java b/tests/integration/ejb-multimodule-reload/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/lib/ContainerListener.java
new file mode 100644
index 0000000..11de9c9
--- /dev/null
+++ b/tests/integration/ejb-multimodule-reload/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/lib/ContainerListener.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.multimodule.ejb.reload.lib;
+
+import javax.ejb.EJB;
+import javax.ejb.Singleton;
+import javax.ws.rs.ext.Provider;
+
+import org.glassfish.jersey.server.spi.AbstractContainerLifecycleListener;
+import org.glassfish.jersey.server.spi.Container;
+
+/**
+ * JAX-RS resource that keeps number of reloads.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Provider
+@Singleton
+public class ContainerListener extends AbstractContainerLifecycleListener {
+
+ @EJB EjbReloaderService reloader;
+
+ @Override
+ public void onStartup(final Container container) {
+ reloader.setContainer(container);
+ }
+}
diff --git a/tests/integration/ejb-multimodule-reload/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/lib/EjbReloaderService.java b/tests/integration/ejb-multimodule-reload/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/lib/EjbReloaderService.java
new file mode 100644
index 0000000..fc95ca8
--- /dev/null
+++ b/tests/integration/ejb-multimodule-reload/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/lib/EjbReloaderService.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.multimodule.ejb.reload.lib;
+
+import javax.ejb.Singleton;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.spi.Container;
+
+/**
+ * Singleton EJB bean that is used to reload the first web application.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Singleton
+public class EjbReloaderService {
+
+ Container container;
+
+ public void reload() {
+ container.reload(newApp());
+ }
+
+ /**
+ * Create new resource config that contains {@link ReloadDetectionResource} singleton
+ * with current nano time, so that we can detect when the application has been initialized.
+ *
+ * @return new resource config.
+ */
+ private ResourceConfig newApp() {
+
+ ResourceConfig result = new ResourceConfig();
+ result.register(ReloadDetectionResource.createNewInstance());
+ result.register(ContainerListener.class);
+ return result;
+ }
+
+ /**
+ * Set the container to be reloaded. Invoked from {@link ContainerListener}.
+ *
+ * @param container to be reloaded.
+ */
+ public void setContainer(Container container) {
+ this.container = container;
+ }
+}
diff --git a/tests/integration/ejb-multimodule-reload/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/lib/ReloadDetectionResource.java b/tests/integration/ejb-multimodule-reload/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/lib/ReloadDetectionResource.java
new file mode 100644
index 0000000..95cbf5b
--- /dev/null
+++ b/tests/integration/ejb-multimodule-reload/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/lib/ReloadDetectionResource.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.multimodule.ejb.reload.lib;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+import javax.inject.Singleton;
+
+/**
+ * JAX-RS resource registered as a singleton
+ * allows to detect when application got initiated as the value
+ * returned from its getNano resource method
+ * will get adjusted with each reload.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("last-init-nano-time")
+public class ReloadDetectionResource {
+
+ final long ns = System.nanoTime();
+
+ private ReloadDetectionResource() {
+ // prevent instantiation
+ }
+
+ /**
+ * This is the only mean how to get a new instance of the resource.
+ *
+ * @return new reload detection resource.
+ */
+ public static final ReloadDetectionResource createNewInstance() {
+ return new ReloadDetectionResource();
+ }
+
+
+ @GET
+ public long getNano() {
+ return ns;
+ }
+}
diff --git a/tests/integration/ejb-multimodule-reload/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/lib/ReloaderResource.java b/tests/integration/ejb-multimodule-reload/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/lib/ReloaderResource.java
new file mode 100644
index 0000000..ff2ce6d
--- /dev/null
+++ b/tests/integration/ejb-multimodule-reload/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/lib/ReloaderResource.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.multimodule.ejb.reload.lib;
+
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * JAX-RS resource used to reload the first application.
+ * This resource is only registered inside the second application.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Stateless
+@Path("reload")
+public class ReloaderResource {
+
+ @EJB EjbReloaderService ejbReloaderService;
+
+ @GET
+ public void reloadTheOtherApp() {
+ ejbReloaderService.reload();
+ }
+}
diff --git a/tests/integration/ejb-multimodule-reload/lib/src/main/resources/META-INF/beans.xml b/tests/integration/ejb-multimodule-reload/lib/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..3b46d69
--- /dev/null
+++ b/tests/integration/ejb-multimodule-reload/lib/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<beans/>
diff --git a/tests/integration/ejb-multimodule-reload/pom.xml b/tests/integration/ejb-multimodule-reload/pom.xml
new file mode 100644
index 0000000..35fd46f
--- /dev/null
+++ b/tests/integration/ejb-multimodule-reload/pom.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>ejb-multimodule-reload</artifactId>
+ <packaging>pom</packaging>
+ <name>jersey-tests-integration-ejb-multimodule-reload</name>
+
+ <description>
+ EJB Multi-Module Reload
+ </description>
+
+ <modules>
+ <module>ear</module>
+ <module>lib</module>
+ <module>war1</module>
+ <module>war2</module>
+ </modules>
+</project>
diff --git a/tests/integration/ejb-multimodule-reload/war1/pom.xml b/tests/integration/ejb-multimodule-reload/war1/pom.xml
new file mode 100644
index 0000000..f90e657
--- /dev/null
+++ b/tests/integration/ejb-multimodule-reload/war1/pom.xml
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>ejb-multimodule-reload-war1</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-ejb-multimodule-reload-war1</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-server</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>ejb-multimodule-reload-lib</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.ejb</groupId>
+ <artifactId>javax.ejb-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.hk2.external</groupId>
+ <artifactId>javax.inject</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ </exclusion>
+ </exclusions>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/ejb-multimodule-reload/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/web1/FirstApp.java b/tests/integration/ejb-multimodule-reload/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/web1/FirstApp.java
new file mode 100644
index 0000000..f24d546
--- /dev/null
+++ b/tests/integration/ejb-multimodule-reload/war1/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/web1/FirstApp.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.multimodule.ejb.reload.web1;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.tests.integration.multimodule.ejb.reload.lib.ContainerListener;
+import org.glassfish.jersey.tests.integration.multimodule.ejb.reload.lib.ReloadDetectionResource;
+
+/**
+ * Initial JAX-RS application for the first web application.
+ * This one will get reloaded.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("/")
+public class FirstApp extends Application {
+
+ static final Set<Object> SINGLETONS = new HashSet<Object>() {{
+ add(ReloadDetectionResource.createNewInstance());
+ }};
+
+ static final Set<Class<?>> CLASSES = new HashSet<Class<?>>() {{
+ add(ContainerListener.class);
+ }};
+
+ @Override
+ public Set<Object> getSingletons() {
+ return SINGLETONS;
+ }
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return CLASSES;
+ }
+}
diff --git a/tests/integration/ejb-multimodule-reload/war1/src/main/resources/META-INF/beans.xml b/tests/integration/ejb-multimodule-reload/war1/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/ejb-multimodule-reload/war1/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<beans/>
diff --git a/tests/integration/ejb-multimodule-reload/war1/src/test/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/web1/ReloadTest.java b/tests/integration/ejb-multimodule-reload/war1/src/test/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/web1/ReloadTest.java
new file mode 100644
index 0000000..4d854b0
--- /dev/null
+++ b/tests/integration/ejb-multimodule-reload/war1/src/test/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/web1/ReloadTest.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.multimodule.ejb.reload.web1;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Test reload functionality for two web app test case.
+ * Run with:
+ * <pre>
+ * mvn clean package
+ * $AS_HOME/bin/asadmin deploy ../ear/target/ejb-multimodule-reload-ear-*.ear
+ * mvn -DskipTests=false test</pre>
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class ReloadTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new FirstApp();
+ }
+
+ @Override
+ protected void configureClient(final ClientConfig config) {
+ config.register(LoggingFeature.class);
+ }
+
+ @Test
+ public void testReload() {
+
+ final WebTarget nanosTarget = target().path("ejb-multimodule-reload-war1/last-init-nano-time");
+
+ final long nanos1 = _readInitTimeNanos(nanosTarget);
+ final long nanos2 = _readInitTimeNanos(nanosTarget);
+
+ assertThat(nanos2, is(equalTo(nanos1)));
+
+ // J-592 reproducer:
+
+// reload();
+//
+// final long nanos3 = _readInitTimeNanos(nanosTarget);
+// final long nanos4 = _readInitTimeNanos(nanosTarget);
+//
+// assertThat(nanos4, is(equalTo(nanos3)));
+// assertThat(nanos3, is(greaterThan(nanos2)));
+//
+// reload();
+//
+// final long nanos5 = _readInitTimeNanos(nanosTarget);
+// final long nanos6 = _readInitTimeNanos(nanosTarget);
+//
+// assertThat(nanos6, is(equalTo(nanos5)));
+// assertThat(nanos5, is(greaterThan(nanos4)));
+
+ // END: J-592 reproducer
+ }
+
+ private void reload() {
+ final WebTarget reloadTarget = target().path("ejb-multimodule-reload-war2/reload");
+ assertThat(reloadTarget.request().get().getStatus(), is(204));
+ }
+
+ private long _readInitTimeNanos(final WebTarget target) throws NumberFormatException {
+ final Response response = target.request().get();
+ assertThat(response.getStatus(), is(200));
+ return Long.parseLong(response.readEntity(String.class));
+ }
+}
diff --git a/tests/integration/ejb-multimodule-reload/war2/pom.xml b/tests/integration/ejb-multimodule-reload/war2/pom.xml
new file mode 100644
index 0000000..1a3bf25
--- /dev/null
+++ b/tests/integration/ejb-multimodule-reload/war2/pom.xml
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>ejb-multimodule-reload-war2</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-ejb-multimodule-reload-war2</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>ejb-multimodule-reload-lib</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.ejb</groupId>
+ <artifactId>javax.ejb-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/ejb-multimodule-reload/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/web2/SecondApp.java b/tests/integration/ejb-multimodule-reload/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/web2/SecondApp.java
new file mode 100644
index 0000000..89d2304
--- /dev/null
+++ b/tests/integration/ejb-multimodule-reload/war2/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/web2/SecondApp.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.multimodule.ejb.reload.web2;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.tests.integration.multimodule.ejb.reload.lib.ReloaderResource;
+
+/**
+ * JAX-RS application from which we are going to reload
+ * the other one.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("/")
+public class SecondApp extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return new HashSet<Class<?>>() {{
+ add(ReloaderResource.class);
+ }};
+ }
+}
diff --git a/tests/integration/ejb-multimodule-reload/war2/src/main/resources/META-INF/beans.xml b/tests/integration/ejb-multimodule-reload/war2/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/ejb-multimodule-reload/war2/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<beans/>
diff --git a/tests/integration/ejb-multimodule-reload/war2/src/test/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/web2/JaxRsFromEjbLibraryTest.java b/tests/integration/ejb-multimodule-reload/war2/src/test/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/web2/JaxRsFromEjbLibraryTest.java
new file mode 100644
index 0000000..7dc32da
--- /dev/null
+++ b/tests/integration/ejb-multimodule-reload/war2/src/test/java/org/glassfish/jersey/tests/integration/multimodule/ejb/reload/web2/JaxRsFromEjbLibraryTest.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.multimodule.ejb.reload.web2;
+
+import java.net.URI;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
+
+/**
+ * Test for EJB web application resources. The JAX-RS resources come from bundled EJB library jar.
+ * Run with:
+ * <pre>
+ * mvn clean package
+ * $AS_HOME/bin/asadmin deploy ../ear/target/ejb-multimodule-ear-*.ear
+ * mvn -DskipTests=false test</pre>
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class JaxRsFromEjbLibraryTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new SecondApp();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("ejb-multimodule-war").path("resources").build();
+ }
+
+ @Override
+ protected void configureClient(final ClientConfig config) {
+ config.register(LoggingFeature.class);
+ }
+
+ @Test
+ public void testRequestCountGetsIncremented() {
+ final int requestCount1 = _nextCount(target().path("counter"));
+
+ final int requestCount2 = _nextCount(target().path("counter"));
+ assertThat(requestCount2, is(greaterThan(requestCount1)));
+
+ final int requestCount3 = _nextCount(target().path("stateless"));
+ assertThat(requestCount3, is(greaterThan(requestCount2)));
+
+ final int requestCount4 = _nextCount(target().path("stateless"));
+ assertThat(requestCount4, is(greaterThan(requestCount3)));
+
+ final int requestCount5 = _nextCount(target().path("stateful").path("count"));
+ assertThat(requestCount5, is(greaterThan(requestCount4)));
+
+ final int requestCount6 = _nextCount(target().path("stateful").path("count"));
+ assertThat(requestCount6, is(greaterThan(requestCount5)));
+
+ final int requestCount7 = _nextCount(target().path("war-stateless"));
+ assertThat(requestCount7, is(greaterThan(requestCount6)));
+
+ final int requestCount8 = _nextCount(target().path("war-stateless"));
+ assertThat(requestCount8, is(greaterThan(requestCount7)));
+ }
+
+ private int _nextCount(final WebTarget target) throws NumberFormatException {
+ final Response response = target.request().get();
+ assertThat(response.getStatus(), is(200));
+ return Integer.parseInt(response.readEntity(String.class));
+ }
+
+ @Test
+ public void testUriInfoInjection() {
+ _testPath(target().path("counter").path("one"), "counter/one");
+ _testPath(target().path("counter").path("two"), "counter/two");
+ _testPath(target().path("stateless").path("three"), "stateless/three");
+ _testPath(target().path("stateless").path("four"), "stateless/four");
+ _testPath(target().path("war-stateless").path("five"), "war-stateless/five");
+ _testPath(target().path("war-stateless").path("six"), "war-stateless/six");
+ }
+
+ private void _testPath(final WebTarget target, final String expectedResult) {
+ final Response response = target.request().get();
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), equalTo(expectedResult));
+ }
+}
diff --git a/tests/integration/ejb-multimodule/ear/pom.xml b/tests/integration/ejb-multimodule/ear/pom.xml
new file mode 100644
index 0000000..742f13d
--- /dev/null
+++ b/tests/integration/ejb-multimodule/ear/pom.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>ejb-multimodule-ear</artifactId>
+ <packaging>ear</packaging>
+ <name>jersey-tests-integration-ejb-multimodule-ear</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-ear-plugin</artifactId>
+ <configuration>
+ <version>6</version>
+ <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
+ <modules>
+ <webModule>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>ejb-multimodule-war</artifactId>
+ </webModule>
+ <ejbModule>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>ejb-multimodule-lib</artifactId>
+ </ejbModule>
+ </modules>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>ejb-multimodule-war</artifactId>
+ <type>war</type>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>ejb-multimodule-lib</artifactId>
+ <type>ejb</type>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/tests/integration/ejb-multimodule/ear/src/main/application/META-INF/MANIFEST.MF b/tests/integration/ejb-multimodule/ear/src/main/application/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..59499bc
--- /dev/null
+++ b/tests/integration/ejb-multimodule/ear/src/main/application/META-INF/MANIFEST.MF
@@ -0,0 +1,2 @@
+Manifest-Version: 1.0
+
diff --git a/tests/integration/ejb-multimodule/lib/pom.xml b/tests/integration/ejb-multimodule/lib/pom.xml
new file mode 100644
index 0000000..916ead4
--- /dev/null
+++ b/tests/integration/ejb-multimodule/lib/pom.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>ejb-multimodule-lib</artifactId>
+ <packaging>jar</packaging>
+ <name>jersey-tests-integration-ejb-multimodule-lib</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.ejb</groupId>
+ <artifactId>javax.ejb-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/ejb-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/lib/EjbCounterResource.java b/tests/integration/ejb-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/lib/EjbCounterResource.java
new file mode 100644
index 0000000..b1fcf20
--- /dev/null
+++ b/tests/integration/ejb-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/lib/EjbCounterResource.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.multimodule.ejb.lib;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.ejb.Singleton;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * Singleton EJB counter bean as a JAX-RS resource.
+ * The bean is for one published as a standalone JAX-RS resource
+ * and for two used to inject other EJB based JAX-RS resources.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Singleton
+@Path("counter")
+public class EjbCounterResource {
+
+ final AtomicInteger counter = new AtomicInteger();
+
+ @Context UriInfo ui;
+
+ @GET
+ public int getCount() {
+ return counter.incrementAndGet();
+ }
+
+ @Path("{ui}")
+ @GET
+ public String getUi() {
+ return ui != null ? ui.getPath() : "UriInfo is null";
+ }
+}
diff --git a/tests/integration/ejb-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/lib/StatefulResource.java b/tests/integration/ejb-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/lib/StatefulResource.java
new file mode 100644
index 0000000..6250c2d
--- /dev/null
+++ b/tests/integration/ejb-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/lib/StatefulResource.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.multimodule.ejb.lib;
+
+import javax.ejb.EJB;
+import javax.ejb.Stateful;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * JAX-RS resource backed with a stateful EJB bean.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Stateful
+@Path("stateful")
+public class StatefulResource {
+
+ @EJB EjbCounterResource counter;
+
+ @GET
+ @Path("count")
+ public int getCount() {
+ return counter.getCount();
+ }
+}
diff --git a/tests/integration/ejb-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/lib/StatelessResource.java b/tests/integration/ejb-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/lib/StatelessResource.java
new file mode 100644
index 0000000..b349095
--- /dev/null
+++ b/tests/integration/ejb-multimodule/lib/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/lib/StatelessResource.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.multimodule.ejb.lib;
+
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * JAX-RS resource backed by a stateless EJB bean.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Stateless
+@Path("stateless")
+public class StatelessResource {
+
+ @EJB EjbCounterResource counter;
+ @Context UriInfo uriInfo;
+
+ @GET
+ public int getCount() {
+ return counter.getCount();
+ }
+
+ @GET
+ @Path("{uriInfo}")
+ public String getPath() {
+ return uriInfo != null ? uriInfo.getPath() : "uri info is null";
+ }
+}
diff --git a/tests/integration/ejb-multimodule/pom.xml b/tests/integration/ejb-multimodule/pom.xml
new file mode 100644
index 0000000..78a39c6
--- /dev/null
+++ b/tests/integration/ejb-multimodule/pom.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>ejb-multimodule</artifactId>
+ <packaging>pom</packaging>
+ <name>jersey-tests-integration-ejb-multimodule</name>
+
+ <description>
+ EJB Multi-Module
+ </description>
+
+ <modules>
+ <module>ear</module>
+ <module>lib</module>
+ <module>war</module>
+ </modules>
+</project>
diff --git a/tests/integration/ejb-multimodule/war/pom.xml b/tests/integration/ejb-multimodule/war/pom.xml
new file mode 100644
index 0000000..8c40b68
--- /dev/null
+++ b/tests/integration/ejb-multimodule/war/pom.xml
@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>ejb-multimodule-war</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-ejb-multimodule-war</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>ejb-multimodule-lib</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.ejb</groupId>
+ <artifactId>javax.ejb-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ <!--archive>
+ <manifestEntries>
+ <Class-Path>ejb-lib-${project.version}.jar</Class-Path>
+ </manifestEntries>
+ </archive-->
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/ejb-multimodule/war/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/web1/JaxRsConfiguration.java b/tests/integration/ejb-multimodule/war/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/web1/JaxRsConfiguration.java
new file mode 100644
index 0000000..18ab4ce
--- /dev/null
+++ b/tests/integration/ejb-multimodule/war/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/web1/JaxRsConfiguration.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.multimodule.ejb.web1;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.tests.integration.multimodule.ejb.lib.EjbCounterResource;
+import org.glassfish.jersey.tests.integration.multimodule.ejb.lib.StatefulResource;
+import org.glassfish.jersey.tests.integration.multimodule.ejb.lib.StatelessResource;
+
+/**
+ * JAX-RS application resource configuration that includes only
+ * those JAX-RS components imported from EJB library jar.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("resources")
+public class JaxRsConfiguration extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return new HashSet<Class<?>>() {{
+ add(EjbCounterResource.class);
+ add(StatelessResource.class);
+ add(StatefulResource.class);
+ add(WarStatelessResource.class);
+ }};
+ }
+}
diff --git a/tests/integration/ejb-multimodule/war/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/web1/WarStatelessResource.java b/tests/integration/ejb-multimodule/war/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/web1/WarStatelessResource.java
new file mode 100644
index 0000000..008539d
--- /dev/null
+++ b/tests/integration/ejb-multimodule/war/src/main/java/org/glassfish/jersey/tests/integration/multimodule/ejb/web1/WarStatelessResource.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.multimodule.ejb.web1;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+
+import org.glassfish.jersey.tests.integration.multimodule.ejb.lib.EjbCounterResource;
+
+/**
+ * JAX-RS resource backed by a stateless EJB bean placed in WAR module.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Stateless
+@Path("war-stateless")
+public class WarStatelessResource {
+
+ @EJB EjbCounterResource counter;
+ @Context UriInfo uriInfo;
+
+ @GET
+ public int getCount() {
+ return counter.getCount();
+ }
+
+ @GET
+ @Path("{uriInfo}")
+ public String getPath() {
+ return uriInfo != null ? uriInfo.getPath() : "uri info is null";
+ }
+}
diff --git a/tests/integration/ejb-multimodule/war/src/main/webapp/index.jsp b/tests/integration/ejb-multimodule/war/src/main/webapp/index.jsp
new file mode 100644
index 0000000..d9c02e5
--- /dev/null
+++ b/tests/integration/ejb-multimodule/war/src/main/webapp/index.jsp
@@ -0,0 +1,31 @@
+<%--
+
+ Copyright (c) 2015, 2018 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
+
+--%>
+
+<%@page contentType="text/html" pageEncoding="UTF-8"%>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>JSP Page</title>
+ </head>
+ <body>
+ <h1>Hello World!</h1>
+ </body>
+</html>
diff --git a/tests/integration/ejb-multimodule/war/src/test/java/org/glassfish/jersey/tests/integration/multimodule/ejb/web1/JaxRsFromEjbLibraryTest.java b/tests/integration/ejb-multimodule/war/src/test/java/org/glassfish/jersey/tests/integration/multimodule/ejb/web1/JaxRsFromEjbLibraryTest.java
new file mode 100644
index 0000000..3eb6aa0
--- /dev/null
+++ b/tests/integration/ejb-multimodule/war/src/test/java/org/glassfish/jersey/tests/integration/multimodule/ejb/web1/JaxRsFromEjbLibraryTest.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.multimodule.ejb.web1;
+
+import java.net.URI;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
+
+/**
+ * Test for EJB web application resources. The JAX-RS resources come from bundled EJB library jar.
+ * Run with:
+ * <pre>
+ * mvn clean package
+ * $AS_HOME/bin/asadmin deploy ../ear/target/ejb-multimodule-ear-*.ear
+ * mvn -DskipTests=false test</pre>
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class JaxRsFromEjbLibraryTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new JaxRsConfiguration();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("ejb-multimodule-war").path("resources").build();
+ }
+
+ @Override
+ protected void configureClient(final ClientConfig config) {
+ config.register(LoggingFeature.class);
+ }
+
+ @Test
+ public void testRequestCountGetsIncremented() {
+ final int requestCount1 = _nextCount(target().path("counter"));
+
+ final int requestCount2 = _nextCount(target().path("counter"));
+ assertThat(requestCount2, is(greaterThan(requestCount1)));
+
+ final int requestCount3 = _nextCount(target().path("stateless"));
+ assertThat(requestCount3, is(greaterThan(requestCount2)));
+
+ final int requestCount4 = _nextCount(target().path("stateless"));
+ assertThat(requestCount4, is(greaterThan(requestCount3)));
+
+ final int requestCount5 = _nextCount(target().path("stateful").path("count"));
+ assertThat(requestCount5, is(greaterThan(requestCount4)));
+
+ final int requestCount6 = _nextCount(target().path("stateful").path("count"));
+ assertThat(requestCount6, is(greaterThan(requestCount5)));
+
+ final int requestCount7 = _nextCount(target().path("war-stateless"));
+ assertThat(requestCount7, is(greaterThan(requestCount6)));
+
+ final int requestCount8 = _nextCount(target().path("war-stateless"));
+ assertThat(requestCount8, is(greaterThan(requestCount7)));
+ }
+
+ private int _nextCount(final WebTarget target) throws NumberFormatException {
+ final Response response = target.request().get();
+ assertThat(response.getStatus(), is(200));
+ return Integer.parseInt(response.readEntity(String.class));
+ }
+
+ @Test
+ public void testUriInfoInjection() {
+ _testPath(target().path("counter").path("one"), "counter/one");
+ _testPath(target().path("counter").path("two"), "counter/two");
+ _testPath(target().path("stateless").path("three"), "stateless/three");
+ _testPath(target().path("stateless").path("four"), "stateless/four");
+ _testPath(target().path("war-stateless").path("five"), "war-stateless/five");
+ _testPath(target().path("war-stateless").path("six"), "war-stateless/six");
+ }
+
+ private void _testPath(final WebTarget target, final String expectedResult) {
+ final Response response = target.request().get();
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), equalTo(expectedResult));
+ }
+}
diff --git a/tests/integration/ejb-test-webapp/pom.xml b/tests/integration/ejb-test-webapp/pom.xml
new file mode 100644
index 0000000..6ca69fa
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/pom.xml
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>ejb-test-webapp</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-ejb-webapp</name>
+
+ <description>Jersey EJB test web application</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.1-b07</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.ejb</groupId>
+ <artifactId>javax.ejb-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/AppResource.java b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/AppResource.java
new file mode 100644
index 0000000..ba03d17
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/AppResource.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2015, 2018 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.ejb.resources;
+
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * Test resource that exposes counter from the JAX-RS application subclass.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Stateless
+@Path("app")
+public class AppResource {
+
+ @EJB MyApplication app;
+
+ @Path("count")
+ @GET
+ public int getCount() {
+ return app.incrementAndGetCount();
+ }
+}
diff --git a/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/AsyncResource.java b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/AsyncResource.java
new file mode 100644
index 0000000..e5c67fb
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/AsyncResource.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013, 2018 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.ejb.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.Suspended;
+
+import javax.ejb.EJB;
+
+/**
+ * @author Jan Algermissen
+ * @author Miroslav Fuksa
+ */
+@Path("async-test")
+public class AsyncResource {
+
+ @EJB
+ AsyncService asyncService;
+
+ @GET
+ @Path("sync")
+ public String synchronousGet() {
+ return "sync";
+ }
+
+ @GET
+ @Path("async")
+ public void asynchronousGet(@Suspended AsyncResponse ar) {
+ asyncService.getAsync(ar);
+ }
+}
diff --git a/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/AsyncService.java b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/AsyncService.java
new file mode 100644
index 0000000..8ea1ac4
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/AsyncService.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2013, 2018 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.ejb.resources;
+
+import java.util.logging.Logger;
+
+import javax.ejb.Asynchronous;
+import javax.ejb.Stateless;
+import javax.ws.rs.container.AsyncResponse;
+
+/**
+ * @author Jan Algermissen
+ * @author Miroslav Fuksa
+ */
+@Stateless
+public class AsyncService {
+ private static Logger LOG = Logger.getLogger(AsyncService.class.getName());
+
+ @Asynchronous
+ public void getAsync(AsyncResponse ar) {
+ ar.resume("async");
+ }
+}
+
diff --git a/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/CounterBean.java b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/CounterBean.java
new file mode 100644
index 0000000..3e43e59
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/CounterBean.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2013, 2018 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.ejb.resources;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.ejb.Singleton;
+
+/**
+ * EJB singleton utilized as request counter in this test application.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Singleton
+public class CounterBean {
+
+ AtomicInteger counter = new AtomicInteger();
+
+ public int incrementAndGet() {
+ return counter.incrementAndGet();
+ }
+}
diff --git a/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/CounterFilter.java b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/CounterFilter.java
new file mode 100644
index 0000000..e67edc4
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/CounterFilter.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013, 2018 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.ejb.resources;
+
+import java.io.IOException;
+
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * Response filter implemented as EJB bean. The filter adds Request-Count response header to each response.
+ * Another EJB singleton bean, CounterBean, is injected that holds the actual request count.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Provider
+@Stateless
+public class CounterFilter implements ContainerResponseFilter{
+
+ public static final String RequestCountHEADER = "Request-Count";
+
+ @EJB CounterBean counter;
+
+ @Override
+ public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
+ responseContext.getHeaders().add(RequestCountHEADER, counter.incrementAndGet());
+ }
+}
diff --git a/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/CustomBaseException.java b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/CustomBaseException.java
new file mode 100644
index 0000000..fda6ed4
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/CustomBaseException.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2014, 2018 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.ejb.resources;
+
+/**
+ * Custom exception. Part of JERSEY-2320 reproducer.
+ * This one serves as a base for other exceptions
+ * mapped by {@link EjbExceptionMapperOne} and {@link EjbExceptionMapperTwo}.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class CustomBaseException extends Exception {
+}
diff --git a/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/CustomExceptionOne.java b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/CustomExceptionOne.java
new file mode 100644
index 0000000..8a71b6e
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/CustomExceptionOne.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2014, 2018 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.ejb.resources;
+
+/**
+ * Custom exception. Part of JERSEY-2320 reproducer.
+ * This one gets mapped by {@link EjbExceptionMapperOne}.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class CustomExceptionOne extends CustomBaseException {
+}
diff --git a/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/CustomExceptionTwo.java b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/CustomExceptionTwo.java
new file mode 100644
index 0000000..021dbdc
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/CustomExceptionTwo.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2014, 2018 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.ejb.resources;
+
+/**
+ * Custom exception. Part of JERSEY-2320 reproducer.
+ * This one gets mapped by {@link EjbExceptionMapperTwo}.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class CustomExceptionTwo extends CustomBaseException {
+}
diff --git a/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/Echo.java b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/Echo.java
new file mode 100644
index 0000000..1e544bb
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/Echo.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2013, 2018 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.ejb.resources;
+
+import javax.ejb.Remote;
+
+/**
+ * EJB remote interface. Part of the reproducer for GLASSFISH-16199.
+ * See also the other test case implemented by {@link RawEchoResource}.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Remote
+public interface Echo {
+
+ String echo(String message);
+}
diff --git a/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/EchoBean.java b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/EchoBean.java
new file mode 100644
index 0000000..7763ed8
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/EchoBean.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2013, 2018 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.ejb.resources;
+
+import javax.ejb.Stateful;
+
+/**
+ * Session bean capable of returning an echoed message back.
+ * This is to prove EJB container is used in {@link EchoResource}
+ * and {@link RawEchoResource} resources.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Stateful
+public class EchoBean {
+
+ /**
+ * Prefix, {@value}, to be attached to each message processed by this bean.
+ */
+ public static final String PREFIX = "ECHOED: ";
+
+ /**
+ * Echo message.
+ *
+ * @param message to be echoed.
+ * @return incoming message prefixed with {@link #PREFIX}.
+ */
+ public String echo(final String message) {
+ return String.format("%s%s", PREFIX, message);
+ }
+}
diff --git a/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/EchoResource.java b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/EchoResource.java
new file mode 100644
index 0000000..1414e32
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/EchoResource.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013, 2018 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.ejb.resources;
+
+import javax.ejb.EJB;
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+/**
+ * JAX-RS resource bean backed by an EJB session bean
+ * implementing EJB interface that is annotated with both {@link Local}
+ * and {@link Remote} annotations.
+ * Reproducible test case for GLASSFISH-16199.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Stateless
+@Path("echo")
+public class EchoResource implements Echo {
+
+ @EJB EchoBean echoService;
+
+ @GET
+ @Override
+ public String echo(@QueryParam("message") String message) {
+ return echoService.echo(message);
+ }
+}
diff --git a/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/EjbExceptionMapperBase.java b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/EjbExceptionMapperBase.java
new file mode 100644
index 0000000..715d481
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/EjbExceptionMapperBase.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2014, 2018 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.ejb.resources;
+
+import javax.ws.rs.ext.ExceptionMapper;
+
+/**
+ * JERSEY-2320 reproducer. {@link CustomBaseException} will get mapped
+ * to an ordinary response.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public abstract class EjbExceptionMapperBase<T extends CustomBaseException> implements ExceptionMapper<T> {
+}
diff --git a/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/EjbExceptionMapperOne.java b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/EjbExceptionMapperOne.java
new file mode 100644
index 0000000..0b9a559
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/EjbExceptionMapperOne.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014, 2018 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.ejb.resources;
+
+import javax.ejb.EJB;
+import javax.ejb.Singleton;
+
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * JERSEY-2320 reproducer. {@link CustomExceptionOne} will get mapped
+ * to an ordinary response. We make sure the mapper gets injected properly
+ * by both Jersey runtime and EJB container.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Singleton
+public class EjbExceptionMapperOne extends EjbExceptionMapperBase<CustomExceptionOne> {
+
+ public static final String RESPONSE_BODY = "custom exception one thrown";
+
+ @Context UriInfo uriInfo;
+ @EJB EchoBean echoBean;
+
+ @Override
+ public Response toResponse(final CustomExceptionOne exception) {
+ return Response.ok(RESPONSE_BODY)
+ .header("My-Location", uriInfo.getPath())
+ .header("My-Echo", echoBean.echo("1")).build();
+ }
+
+
+}
diff --git a/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/EjbExceptionMapperTwo.java b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/EjbExceptionMapperTwo.java
new file mode 100644
index 0000000..61227e9
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/EjbExceptionMapperTwo.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2014, 2018 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.ejb.resources;
+
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * JERSEY-2320 reproducer. {@link CustomExceptionTwo} will get mapped
+ * to an ordinary response. We make sure the mapper gets injected properly
+ * by both Jersey runtime and EJB container.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Stateless
+public class EjbExceptionMapperTwo extends EjbExceptionMapperBase<CustomExceptionTwo> {
+
+ @Context UriInfo uriInfo;
+ @EJB EchoBean echoBean;
+
+ public static final String RESPONSE_BODY = "custom exception two thrown";
+
+ @Override
+ public Response toResponse(final CustomExceptionTwo exception) {
+ return Response.ok(RESPONSE_BODY)
+ .header("My-Location", uriInfo.getPath())
+ .header("My-Echo", echoBean.echo("2")).build();
+ }
+}
diff --git a/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/ExceptionEjbResource.java b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/ExceptionEjbResource.java
new file mode 100644
index 0000000..9a12454
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/ExceptionEjbResource.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2013, 2018 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.ejb.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+import javax.ejb.EJBException;
+import javax.ejb.Singleton;
+
+/**
+ * EJB backed JAX-RS resource to test if a custom exception info makes it to the client.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Singleton
+@Path("exception")
+public class ExceptionEjbResource {
+
+ public static class MyCheckedException extends Exception {
+
+ public MyCheckedException(String message) {
+ super(message);
+ }
+ }
+
+ public static class MyRuntimeException extends RuntimeException {
+
+ public MyRuntimeException(String message) {
+ super(message);
+ }
+ }
+
+ public static final String EjbExceptionMESSAGE = "ejb exception thrown directly";
+ public static final String CheckedExceptionMESSAGE = "checked exception thrown directly";
+
+ @GET
+ @Path("ejb")
+ public String throwEjbException() {
+ throw new EJBException(EjbExceptionMESSAGE);
+ }
+
+ @GET
+ @Path("checked")
+ public String throwCheckedException() throws MyCheckedException {
+ throw new MyCheckedException(CheckedExceptionMESSAGE);
+ }
+
+ @GET
+ @Path("custom1/{p}")
+ public String throwCustomExceptionOne() throws CustomBaseException {
+ throw new CustomExceptionOne();
+ }
+
+ @GET
+ @Path("custom2/{p}")
+ public String throwCustomExceptionTwo() throws CustomBaseException {
+ throw new CustomExceptionTwo();
+ }
+}
diff --git a/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/MyApplication.java b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/MyApplication.java
new file mode 100644
index 0000000..c9c84a0
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/MyApplication.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2013, 2018 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.ejb.resources;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.ejb.Singleton;
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * JAX-RS application to configure resources.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("/rest")
+@Singleton
+public class MyApplication extends Application {
+
+ private AtomicInteger counter;
+
+ @Override
+ public Map<String, Object> getProperties() {
+ return new HashMap<String, Object>() {{
+ put("jersey.config.server.response.setStatusOverSendError", true);
+ }};
+ }
+
+ @Override
+ public Set<Class<?>> getClasses() {
+
+ this.counter = new AtomicInteger();
+
+ return new HashSet<Class<?>>() {{
+ add(AppResource.class);
+ add(ExceptionEjbResource.class);
+ add(EchoResource.class);
+ add(RawEchoResource.class);
+ add(CounterFilter.class);
+ add(AsyncResource.class);
+ add(EjbExceptionMapperOne.class);
+ add(EjbExceptionMapperTwo.class);
+ }};
+ }
+
+ public int incrementAndGetCount() {
+ return counter.incrementAndGet();
+ }
+}
diff --git a/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/RawEcho.java b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/RawEcho.java
new file mode 100644
index 0000000..5b53347
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/RawEcho.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2014, 2018 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.ejb.resources;
+
+/**
+ * Part of the reproducer for GLASSFISH-16199. This EJB business interface
+ * is being registered by an annotation on the EJB component class, {@link RawEchoResource}.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public interface RawEcho {
+
+ String echo(String message);
+}
diff --git a/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/RawEchoResource.java b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/RawEchoResource.java
new file mode 100644
index 0000000..bbbe77c
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/RawEchoResource.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2013, 2018 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.ejb.resources;
+
+import javax.ejb.EJB;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+/**
+ * JAX-RS resource bean backed by an EJB session bean
+ * implementing EJB interface, {@link RawEcho}, that is registered using {@link Remote} annotations.
+ * Reproducible test case for GLASSFISH-16199.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Stateless
+@Path("raw-echo")
+@Remote(RawEcho.class)
+public class RawEchoResource {
+
+ @EJB EchoBean echoService;
+
+ @GET
+ public String echo(@QueryParam("message") String message) {
+ return echoService.echo(message);
+ }
+}
diff --git a/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/StandaloneServlet.java b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/StandaloneServlet.java
new file mode 100644
index 0000000..29e9ad5
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/main/java/org/glassfish/jersey/tests/ejb/resources/StandaloneServlet.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2013, 2018 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.ejb.resources;
+
+import java.io.IOException;
+
+import javax.ejb.EJB;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Standalone Servlet instance that has nothing to do with Jersey.
+ * It helps to compare Jersey and non-Jersey specific exception handling
+ * processing.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@WebServlet(name = "StandaloneServlet", urlPatterns = {"/servlet"})
+public class StandaloneServlet extends HttpServlet {
+
+ static final String ThrowCheckedExceptionACTION = "throwCheckedException";
+ static final String ThrowEjbExceptionACTION = "throwEjbException";
+
+ @EJB ExceptionEjbResource ejbResource;
+
+ /**
+ * Handles the HTTP <code>GET</code> method.
+ *
+ * @param request servlet request.
+ * @param response servlet response.
+ * @throws ServletException if a servlet-specific error occurs.
+ * @throws IOException if an I/O error occurs.
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ final String action = request.getParameter("action");
+
+ if (ThrowCheckedExceptionACTION.equals(action)) {
+ try {
+ ejbResource.throwCheckedException();
+ } catch (ExceptionEjbResource.MyCheckedException ex) {
+ throw new ServletException(ex);
+ }
+ }
+
+ if (ThrowEjbExceptionACTION.equals(action)) {
+ ejbResource.throwEjbException();
+ }
+
+ sayHello(response);
+ }
+
+ private void sayHello(HttpServletResponse response) throws IOException {
+ response.setHeader("Content-type", "text/plain");
+ response.getOutputStream().print(
+ String.format("Use action parameter to specify exception."
+ + " \nSupported options: %s, %s.", ThrowCheckedExceptionACTION, ThrowEjbExceptionACTION));
+ }
+}
diff --git a/tests/integration/ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/ejb/resources/EjbTest.java b/tests/integration/ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/ejb/resources/EjbTest.java
new file mode 100644
index 0000000..a588cf6
--- /dev/null
+++ b/tests/integration/ejb-test-webapp/src/test/java/org/glassfish/jersey/tests/ejb/resources/EjbTest.java
@@ -0,0 +1,190 @@
+/*
+ * Copyright (c) 2013, 2018 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.ejb.resources;
+
+import java.net.URI;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.endsWith;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.lessThan;
+
+/**
+ * Test for EJB web application resources.
+ * Run with:
+ * <pre>
+ * mvn clean package
+ * $AS_HOME/bin/asadmin deploy target/ejb-test-webapp
+ * mvn -DskipTests=false test</pre>
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class EjbTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new MyApplication();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("ejb-test-webapp").build();
+ }
+
+ @Override
+ protected void configureClient(ClientConfig config) {
+ config.register(LoggingFeature.class);
+ }
+
+ @Test
+ public void testEjbException() {
+ final Response jerseyResponse = target().path("rest/exception/ejb").request().get();
+ _check500Response(jerseyResponse, ExceptionEjbResource.EjbExceptionMESSAGE);
+
+ final Response servletResponse =
+ target().path("servlet")
+ .queryParam("action", StandaloneServlet.ThrowEjbExceptionACTION).request().get();
+ _check500Response(servletResponse, ExceptionEjbResource.EjbExceptionMESSAGE);
+ }
+
+ @Test
+ public void testCheckedException() {
+ final Response jerseyResponse = target().path("rest/exception/checked").request().get();
+ _check500Response(jerseyResponse, ExceptionEjbResource.CheckedExceptionMESSAGE);
+
+ final Response servletResponse =
+ target().path("servlet")
+ .queryParam("action", StandaloneServlet.ThrowCheckedExceptionACTION).request().get();
+ _check500Response(servletResponse, ExceptionEjbResource.CheckedExceptionMESSAGE);
+ }
+
+ @Test
+ public void testCustomException1() {
+ Response jerseyResponse = target().path("rest/exception/custom1/big").request().get();
+ assertThat(jerseyResponse.getStatus(), is(200));
+ assertThat(jerseyResponse.readEntity(String.class), is(EjbExceptionMapperOne.RESPONSE_BODY));
+ assertThat(jerseyResponse.getHeaderString("My-Location"), is("exception/custom1/big"));
+ assertThat(jerseyResponse.getHeaderString("My-Echo"), is("ECHOED: 1"));
+
+ jerseyResponse = target().path("rest/exception/custom1/one").request().get();
+ assertThat(jerseyResponse.getStatus(), is(200));
+ assertThat(jerseyResponse.readEntity(String.class), is(EjbExceptionMapperOne.RESPONSE_BODY));
+ assertThat(jerseyResponse.getHeaderString("My-Location"), is("exception/custom1/one"));
+ assertThat(jerseyResponse.getHeaderString("My-Echo"), is("ECHOED: 1"));
+ }
+
+ @Test
+ public void testCustomException2() {
+ Response jerseyResponse = target().path("rest/exception/custom2/small").request().get();
+ assertThat(jerseyResponse.getStatus(), is(200));
+ assertThat(jerseyResponse.readEntity(String.class), is(EjbExceptionMapperTwo.RESPONSE_BODY));
+ assertThat(jerseyResponse.getHeaderString("My-Location"), is("exception/custom2/small"));
+ assertThat(jerseyResponse.getHeaderString("My-Echo"), is("ECHOED: 2"));
+
+ jerseyResponse = target().path("rest/exception/custom2/one").request().get();
+ assertThat(jerseyResponse.getStatus(), is(200));
+ assertThat(jerseyResponse.readEntity(String.class), is(EjbExceptionMapperTwo.RESPONSE_BODY));
+ assertThat(jerseyResponse.getHeaderString("My-Location"), is("exception/custom2/one"));
+ assertThat(jerseyResponse.getHeaderString("My-Echo"), is("ECHOED: 2"));
+ }
+
+ @Test
+ public void testRemoteLocalEJBInterface() {
+
+ final String message = "Hi there";
+ final Response response = target().path("rest/echo").queryParam("message", message).request().get();
+
+ assertThat(response.getStatus(), is(200));
+
+ final String responseMessage = response.readEntity(String.class);
+
+ assertThat(responseMessage, startsWith(EchoBean.PREFIX));
+ assertThat(responseMessage, endsWith(message));
+ }
+
+ @Test
+ public void testRemoteAnnotationRegisteredEJBInterface() {
+
+ final String message = "Hi there";
+ final Response response = target().path("rest/raw-echo").queryParam("message", message).request().get();
+
+ assertThat(response.getStatus(), is(200));
+
+ final String responseMessage = response.readEntity(String.class);
+
+ assertThat(responseMessage, startsWith(EchoBean.PREFIX));
+ assertThat(responseMessage, endsWith(message));
+ }
+
+ @Test
+ public void testRequestCountGetsIncremented() {
+
+ final Response response1 = target().path("rest/echo").queryParam("message", "whatever").request().get();
+ assertThat(response1.getStatus(), is(200));
+ final String counterHeader1 = response1.getHeaderString(CounterFilter.RequestCountHEADER);
+ final int requestCount1 = Integer.parseInt(counterHeader1);
+
+ final Response response2 = target().path("rest/echo").queryParam("message", requestCount1).request().get();
+ assertThat(response2.getStatus(), is(200));
+ final int requestCount2 = Integer.parseInt(response2.getHeaderString(CounterFilter.RequestCountHEADER));
+
+ assertThat(requestCount2, is(greaterThan(requestCount1)));
+ }
+
+
+ @Test
+ public void testSync() {
+ final Response response = target().path("rest/async-test/sync").request().get();
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), is("sync"));
+ }
+
+ @Test
+ public void testAsync() {
+ final Response response = target().path("rest/async-test/async").request().get();
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), is("async"));
+ }
+
+ @Test
+ public void testAppIsEjbSingleton() {
+
+ int c1 = target().path("rest/app/count").request().get(Integer.class);
+ int c2 = target().path("rest/app/count").request().get(Integer.class);
+ int c3 = target().path("rest/app/count").request().get(Integer.class);
+
+ assertThat("the first count should be less than the second one", c1, is(lessThan(c2)));
+ assertThat("the second count should be less than the third one", c2, is(lessThan(c3)));
+ }
+
+ private void _check500Response(final Response response, final String expectedSubstring) {
+ assertThat(response.getStatus(), is(500));
+ assertThat(response.readEntity(String.class), containsString(expectedSubstring));
+ }
+}
diff --git a/tests/integration/j-376/pom.xml b/tests/integration/j-376/pom.xml
new file mode 100644
index 0000000..4908e7c
--- /dev/null
+++ b/tests/integration/j-376/pom.xml
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>project</artifactId>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>j-376</artifactId>
+ <packaging>jar</packaging>
+ <name>j-376-reproducer</name>
+
+ <description>Jersey test web application - J-376 reproducer</description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <scope>compile</scope>
+ <version>1.1.0.Final</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-server</artifactId>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-weld2-se</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext.cdi</groupId>
+ <artifactId>jersey-cdi1x</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.grizzly</groupId>
+ <artifactId>grizzly-http-server</artifactId>
+ <version>2.3.16</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-grizzly2-http</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <configuration>
+ <mainClass>org.glassfish.jersey.tests.integration.j376.GrizzlyApp</mainClass>
+ <classpathScope>test</classpathScope>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/ApplicationScopedBean.java b/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/ApplicationScopedBean.java
new file mode 100644
index 0000000..1f5e78e
--- /dev/null
+++ b/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/ApplicationScopedBean.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.j376;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+
+/**
+ * Test {@code ApplicationScoped} bean to be injected to the test resource, while another {@code RequestScoped}
+ * bean being injected into this class.
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+@ApplicationScoped
+public class ApplicationScopedBean {
+
+ /** Request scoped bean injected via CDI */
+ @Inject
+ private SecondBean bean;
+
+ /** JAX-RS {@code Context} injection of request {@code UriInfo} */
+ @Context
+ private UriInfo uri;
+
+ private String name = "ApplicationScopedBean";
+
+ public String getMessage() {
+ return name + ":" + bean.getMessage();
+ }
+
+ public String getUri() {
+ return uri.getPath();
+ }
+}
diff --git a/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/ApplicationScopedResource.java b/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/ApplicationScopedResource.java
new file mode 100644
index 0000000..b0bf055
--- /dev/null
+++ b/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/ApplicationScopedResource.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.j376;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.BeanParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * Resource to test CDI injection into {@code ApplicationScoped} JAX-RS resource.
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+@Path("appScope")
+@ApplicationScoped
+public class ApplicationScopedResource {
+
+ /** Application scoped CDI injected bean */
+ @Inject
+ private ApplicationScopedBean appScoped;
+
+ /** Request scoped CDI injected bean */
+ @Inject
+ private SecondBean reqScoped;
+
+ /** Bean containing form parameters injected by JAX-RS */
+ @Inject
+ @BeanParam
+ private FormDataBean bean;
+
+ @POST
+ @Produces("text/plain")
+ public String get() {
+ return bean.getName() + ":" + bean.getAge() + ":"
+ + bean.getInjectedBean().getMessage() + ":" + bean.getInjectedPath();
+ }
+
+ @GET
+ @Path("msg")
+ @Produces("text/plain")
+ public String testAppScoped() {
+ return appScoped.getMessage();
+ }
+
+ @GET
+ @Path("uri")
+ public String getUri() {
+ return appScoped.getUri();
+ }
+
+ @GET
+ @Path("req")
+ public String getMessage() {
+ return reqScoped.getMessage();
+ }
+}
diff --git a/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/ConstructorInjectionResource.java b/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/ConstructorInjectionResource.java
new file mode 100644
index 0000000..a016733
--- /dev/null
+++ b/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/ConstructorInjectionResource.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.j376;
+
+import javax.ws.rs.BeanParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.validation.Valid;
+
+/**
+ * Resource to test CDI injection into JAX-RS resource via constructor parameter.
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+@Path("constructor")
+@RequestScoped
+public class ConstructorInjectionResource {
+
+ private FormDataBean bean;
+
+ public ConstructorInjectionResource() {
+ }
+
+ @Inject
+ public ConstructorInjectionResource(@Valid @BeanParam final FormDataBean form) {
+ bean = form;
+ }
+
+ @POST
+ @Produces("text/plain")
+ public String get() {
+ return bean.getName() + ":" + bean.getAge() + ":"
+ + bean.getInjectedBean().getMessage() + ":" + bean.getInjectedPath();
+ }
+}
diff --git a/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/FieldInjectionResource.java b/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/FieldInjectionResource.java
new file mode 100644
index 0000000..84c6ec5
--- /dev/null
+++ b/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/FieldInjectionResource.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.j376;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.validation.Valid;
+import javax.ws.rs.BeanParam;
+
+/**
+ * Resource to test CDI injection into JAX-RS resource via field.
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+@Path("field")
+@RequestScoped
+public class FieldInjectionResource {
+
+ /** CDI injected request scoped field */
+ @Inject
+ @Valid
+ @BeanParam
+ private FormDataBean bean;
+
+ /** CDI injected applciation scoped bean */
+ @Inject
+ private ApplicationScopedBean appScoped;
+
+ /**
+ * Return string containing of fields from the injected non JAX-RS request scoped bean,
+ * path injected into it via {@code Context} annotation and another bean injected into it.
+ *
+ * Shows, that {@code Inject} and {@code Context} annotations can be used on one particular non JAX-RS class.
+ **/
+ @POST
+ @Produces("text/plain")
+ public String get() {
+ return bean.getName() + ":" + bean.getAge() + ":"
+ + bean.getInjectedBean().getMessage() + ":" + bean.getInjectedPath();
+ }
+
+ /** Return string from the {@code ApplicationScoped} non JAX_RS bean injected into this JAX-RS resource. */
+ @GET
+ @Path("appScoped")
+ @Produces("text/plain")
+ public String getMessage() {
+ return appScoped.getMessage();
+ }
+
+ /**
+ * Return path injected via {@code Context} annotation into {@code ApplicationScoped} non JAX-RS bean, that is
+ * further injected into this JAX-RS resource via CDI.
+ */
+ @GET
+ @Path("appScopedUri")
+ public String getUri() {
+ return appScoped.getUri();
+ }
+}
diff --git a/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/FormDataBean.java b/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/FormDataBean.java
new file mode 100644
index 0000000..819c498
--- /dev/null
+++ b/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/FormDataBean.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.j376;
+
+import javax.ws.rs.FormParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * Test bean containingboth JAX-RS and CDI injection points.
+ */
+@RequestScoped
+public class FormDataBean {
+
+ private String injectedPath = null;
+
+ @NotNull
+ @Size(min = 4)
+ @FormParam("name")
+ private String name;
+
+ @Min(18)
+ @FormParam("age")
+ private int age;
+
+ @Inject
+ private SecondBean injectedBean;
+
+ @Context
+ private UriInfo uri;
+
+ public String getName() {
+ return name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ /**
+ * Exposes the state of injected {@code UriInfo} in the time of the call of {@link javax.annotation.PostConstruct}
+ * annotated method. The returned value will be used in test to ensure, that {@code UriInfo} is injected in time
+ *
+ * @return path injected via {@code UriInfo} at the time-point of the {@link #postConstruct()} method call.
+
+ */
+ public String getInjectedPath() {
+ return injectedPath;
+ }
+
+ public SecondBean getInjectedBean() {
+ return injectedBean;
+ }
+
+ @PostConstruct
+ public void postConstruct() {
+ this.injectedPath = uri.getPath();
+ }
+
+}
diff --git a/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/GrizzlyApp.java b/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/GrizzlyApp.java
new file mode 100644
index 0000000..3de6d9c
--- /dev/null
+++ b/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/GrizzlyApp.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.j376;
+
+import org.glassfish.grizzly.http.server.HttpServer;
+import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.jboss.weld.environment.se.Weld;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * CDI Test App launcher. Starts the Grizzly server and initializes weld.
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+public class GrizzlyApp {
+
+ private static Weld weld;
+ private static HttpServer server;
+
+ private static final URI BASE_URI = URI.create("http://localhost:8080/j376/");
+
+ public static void main(String[] args) {
+ try {
+ System.out.println("Jersey CDI Test App");
+
+ start();
+
+ System.out.println(String.format("Application started.\nTry out %s%s\nHit enter to stop it...",
+ BASE_URI, "application.wadl"));
+ System.in.read();
+ stop();
+ } catch (IOException ex) {
+ Logger.getLogger(GrizzlyApp.class.getName()).log(Level.SEVERE, null, ex);
+ }
+
+ }
+
+ protected static void stop() {
+ server.shutdownNow();
+ weld.shutdown();
+ }
+
+ protected static void start() {
+ weld = new Weld();
+ weld.initialize();
+
+ server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, createJaxRsApp(), true);
+ }
+
+ public static URI getBaseUri() {
+ return BASE_URI;
+ }
+
+ public static ResourceConfig createJaxRsApp() {
+ return new ResourceConfig(new MyApplication().getClasses());
+ }
+}
diff --git a/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/MethodInjectionResource.java b/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/MethodInjectionResource.java
new file mode 100644
index 0000000..3f19676
--- /dev/null
+++ b/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/MethodInjectionResource.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.j376;
+
+
+import javax.ws.rs.BeanParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.validation.Valid;
+
+/**
+ * Resource to test CDI injection into JAX-RS resource via setter.
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+@Path("method")
+@RequestScoped
+public class MethodInjectionResource {
+
+ private FormDataBean bean;
+
+ @Inject
+ public void setFormDataBean(@Valid @BeanParam final FormDataBean form) {
+ bean = form;
+ }
+
+ @POST
+ @Produces("text/plain")
+ public String get() {
+ return bean.getName() + ":" + bean.getAge() + ":"
+ + bean.getInjectedBean().getMessage() + ":" + bean.getInjectedPath();
+ }
+}
diff --git a/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/MyApplication.java b/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/MyApplication.java
new file mode 100644
index 0000000..4ec0beb
--- /dev/null
+++ b/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/MyApplication.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.j376;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * JAX-RS Application subclass, defines the test application resources.
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+@ApplicationPath("/*")
+public class MyApplication extends Application {
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> classes = new HashSet<>();
+ classes.add(MethodInjectionResource.class);
+ classes.add(ConstructorInjectionResource.class);
+ classes.add(FieldInjectionResource.class);
+ classes.add(ApplicationScopedResource.class);
+ return classes;
+ }
+}
diff --git a/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/SecondBean.java b/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/SecondBean.java
new file mode 100644
index 0000000..2e5ead4
--- /dev/null
+++ b/tests/integration/j-376/src/main/java/org/glassfish/jersey/tests/integration/j376/SecondBean.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.j376;
+
+import javax.enterprise.context.RequestScoped;
+
+/**
+ * Bean to be injected into another bean by CDI.
+ *
+ * The purpose is to test, that CDI and hk2 injections are working together so that one class be injected by
+ * both CDI and Jersey/hk2.
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+@RequestScoped
+public class SecondBean {
+ private String message = "Hello";
+
+ public String getMessage() {
+ return message;
+ }
+
+}
diff --git a/tests/integration/j-376/src/main/resources/META-INF/beans.xml b/tests/integration/j-376/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..3b46d69
--- /dev/null
+++ b/tests/integration/j-376/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<beans/>
diff --git a/tests/integration/j-376/src/test/java/org/glassfish/jersey/tests/integration/j376/J376Test.java b/tests/integration/j-376/src/test/java/org/glassfish/jersey/tests/integration/j376/J376Test.java
new file mode 100644
index 0000000..fa39021
--- /dev/null
+++ b/tests/integration/j-376/src/test/java/org/glassfish/jersey/tests/integration/j376/J376Test.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.j376;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+public class J376Test {
+ final Client client = ClientBuilder.newClient();
+ final WebTarget target = client.target(GrizzlyApp.getBaseUri());
+
+ @BeforeClass
+ public static void setUpTest() {
+ GrizzlyApp.start();
+ }
+
+ @AfterClass
+ public static void tearDownTest() {
+ GrizzlyApp.stop();
+ }
+
+ @Test
+ public void testConstructorInjection() {
+ final String response = target.path("constructor").request().post(Entity.entity("name=John&age=32",
+ MediaType.APPLICATION_FORM_URLENCODED_TYPE), String.class);
+
+ assertEquals("John:32:Hello:constructor", response);
+ }
+
+ @Test
+ public void testFieldInjection() {
+ final String response = target.path("field").request().post(Entity.entity("name=Bill&age=21",
+ MediaType.APPLICATION_FORM_URLENCODED_TYPE), String.class);
+
+ assertEquals("Bill:21:Hello:field", response);
+ }
+
+ @Test
+ public void testMethodInjection() {
+ final String response = target.path("method").request().post(Entity.entity("name=Mike&age=42",
+ MediaType.APPLICATION_FORM_URLENCODED_TYPE), String.class);
+
+ assertEquals("Mike:42:Hello:method", response);
+ }
+
+ @Test
+ public void testAppScopedBeanInReqScopedResource() {
+ final String response = target.path("field/appScoped").request().get(String.class);
+ assertEquals("ApplicationScopedBean:Hello", response);
+ }
+
+ @Test
+ public void testAppScopedResource() {
+ String response = target.path("appScope/msg").request().get(String.class);
+ assertEquals("ApplicationScopedBean:Hello", response);
+ response = target.path("appScope/uri").request().get(String.class);
+ assertEquals("appScope/uri", response);
+ response = target.path("appScope/req").request().get(String.class);
+ assertEquals("Hello", response);
+ }
+
+ @Test
+ public void testBeanParamInAppScoped() {
+ final String response = target.path("appScope").request().post(Entity.entity("name=John&age=35",
+ MediaType.APPLICATION_FORM_URLENCODED_TYPE), String.class);
+
+ assertEquals("John:35:Hello:appScope", response);
+ }
+
+ @Test
+ public void testContextInjectionInAppScopedBean() {
+ final String response = target.path("field/appScopedUri").request().get(String.class);
+ assertEquals("field/appScopedUri", response);
+
+ }
+}
diff --git a/tests/integration/j-441/ear/pom.xml b/tests/integration/j-441/ear/pom.xml
new file mode 100644
index 0000000..ffeb59f
--- /dev/null
+++ b/tests/integration/j-441/ear/pom.xml
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+ <artifactId>j-441-ear</artifactId>
+ <packaging>ear</packaging>
+
+ <name>jersey-tests-integration-j-441-ear</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-ear-plugin</artifactId>
+ <configuration>
+ <version>6</version>
+ <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
+ <modules>
+ <webModule>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>j-441-war1</artifactId>
+ <contextRoot>/one</contextRoot>
+ </webModule>
+ <webModule>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>j-441-war2</artifactId>
+ <contextRoot>/two</contextRoot>
+ </webModule>
+ </modules>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>j-441-war1</artifactId>
+ <type>war</type>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>j-441-war2</artifactId>
+ <type>war</type>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/tests/integration/j-441/pom.xml b/tests/integration/j-441/pom.xml
new file mode 100644
index 0000000..e8109bf
--- /dev/null
+++ b/tests/integration/j-441/pom.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>j-441</artifactId>
+ <packaging>pom</packaging>
+ <name>jersey-tests-integration-j-441</name>
+
+ <description>
+ J-441 Reproducer: Two WARs with enabled CDI in an EAR.
+ </description>
+
+ <modules>
+ <module>ear</module>
+ <module>war1</module>
+ <module>war2</module>
+ </modules>
+</project>
diff --git a/tests/integration/j-441/war1/pom.xml b/tests/integration/j-441/war1/pom.xml
new file mode 100644
index 0000000..067ef5e
--- /dev/null
+++ b/tests/integration/j-441/war1/pom.xml
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>j-441-war1</artifactId>
+ <packaging>war</packaging>
+
+ <name>jersey-tests-integration-j-441-war1</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>${servlet3.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/j-441/war1/src/main/java/org/glassfish/jersey/tests/integration/j441/one/CdiResource.java b/tests/integration/j-441/war1/src/main/java/org/glassfish/jersey/tests/integration/j441/one/CdiResource.java
new file mode 100644
index 0000000..33ce8da
--- /dev/null
+++ b/tests/integration/j-441/war1/src/main/java/org/glassfish/jersey/tests/integration/j441/one/CdiResource.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.j441.one;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+
+/**
+ * CDI backed JAX-RS resource.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("/test")
+@RequestScoped
+public class CdiResource {
+
+ @Context
+ private ServletContext scField;
+
+ private ServletContext scCtorParam;
+
+ /* to make CDI happy */
+ public CdiResource() {
+ }
+
+ @Inject
+ public CdiResource(@Context final ServletContext sc) {
+ this.scCtorParam = sc;
+ }
+
+ @GET
+ @Path("ctor-param")
+ public String getCtorParam() {
+ return scCtorParam.getContextPath();
+ }
+
+ @GET
+ @Path("method-param")
+ public String getMethodParam(@Context final ServletContext sc) {
+ return sc.getContextPath();
+ }
+
+ @GET
+ @Path("field")
+ public String getField() {
+ return scField.getContextPath();
+ }
+
+ @GET
+ @Path("exception")
+ public String getException() throws Exception {
+ throw new Exception() {};
+ }
+}
diff --git a/tests/integration/j-441/war1/src/main/java/org/glassfish/jersey/tests/integration/j441/one/CustomExceptionMapper.java b/tests/integration/j-441/war1/src/main/java/org/glassfish/jersey/tests/integration/j441/one/CustomExceptionMapper.java
new file mode 100644
index 0000000..d5aa71c
--- /dev/null
+++ b/tests/integration/j-441/war1/src/main/java/org/glassfish/jersey/tests/integration/j441/one/CustomExceptionMapper.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.j441.one;
+
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+
+import javax.servlet.ServletContext;
+
+/**
+ * JAX-RS provider added just to make sure the application
+ * deploys fine. Since JAX-RS providers get initialized
+ * at Jersey bootstrapping phase, we would get a deploy
+ * error if something went wrong.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class CustomExceptionMapper implements ExceptionMapper<Exception> {
+
+ @Context
+ private ServletContext sc;
+
+ public Response toResponse(final Exception ex) {
+ return Response.status(200).entity(sc.getContextPath()).build();
+ }
+}
diff --git a/tests/integration/j-441/war1/src/main/java/org/glassfish/jersey/tests/integration/j441/one/MyApplication.java b/tests/integration/j-441/war1/src/main/java/org/glassfish/jersey/tests/integration/j441/one/MyApplication.java
new file mode 100644
index 0000000..073b84c
--- /dev/null
+++ b/tests/integration/j-441/war1/src/main/java/org/glassfish/jersey/tests/integration/j441/one/MyApplication.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.j441.one;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * Test case to ensure proper WAR isolation on Jersey level.
+ * Define JAX-RS application containing a simple CDI backed JAX-RS resource.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("/")
+public class MyApplication extends ResourceConfig {
+
+ public MyApplication() {
+ super(CdiResource.class, CustomExceptionMapper.class);
+ }
+}
diff --git a/tests/integration/j-441/war1/src/main/webapp/WEB-INF/beans.xml b/tests/integration/j-441/war1/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..93cfed7
--- /dev/null
+++ b/tests/integration/j-441/war1/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+</beans>
diff --git a/tests/integration/j-441/war1/src/test/java/org/glassfish/jersey/tests/integration/j441/one/ContextPathTest.java b/tests/integration/j-441/war1/src/test/java/org/glassfish/jersey/tests/integration/j441/one/ContextPathTest.java
new file mode 100644
index 0000000..285859e
--- /dev/null
+++ b/tests/integration/j-441/war1/src/test/java/org/glassfish/jersey/tests/integration/j441/one/ContextPathTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.j441.one;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * This is to make sure two Jersey wars are separated well in a single ear.
+ *
+ * @author Michal Gajdos
+ */
+public class ContextPathTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Application();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testFieldInjection() {
+ assertThat(target("one/test/field").request().get(String.class), is("/one"));
+ }
+
+ @Test
+ public void testConstructorInjection() {
+ assertThat(target("one/test/ctor-param").request().get(String.class), is("/one"));
+ }
+
+ @Test
+ public void testMethodInjection() {
+ assertThat(target("one/test/method-param").request().get(String.class), is("/one"));
+ }
+
+ @Test
+ public void testExceptionMapperInjection() {
+ assertThat(target("one/test/exception").request().get(String.class), is("/one"));
+ }
+}
diff --git a/tests/integration/j-441/war2/pom.xml b/tests/integration/j-441/war2/pom.xml
new file mode 100644
index 0000000..cd385ad
--- /dev/null
+++ b/tests/integration/j-441/war2/pom.xml
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>j-441-war2</artifactId>
+ <packaging>war</packaging>
+
+ <name>jersey-tests-integration-j-441-war2</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>${servlet3.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/j-441/war2/src/main/java/org/glassfish/jersey/tests/integration/j441/two/CdiResource.java b/tests/integration/j-441/war2/src/main/java/org/glassfish/jersey/tests/integration/j441/two/CdiResource.java
new file mode 100644
index 0000000..0629273
--- /dev/null
+++ b/tests/integration/j-441/war2/src/main/java/org/glassfish/jersey/tests/integration/j441/two/CdiResource.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.j441.two;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+
+/**
+ * CDI backed JAX-RS resource.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("/test")
+@RequestScoped
+public class CdiResource {
+
+ @Context
+ private ServletContext scField;
+
+ private ServletContext scCtorParam;
+
+ /* to make CDI happy */
+ public CdiResource() {
+ }
+
+ @Inject
+ public CdiResource(@Context final ServletContext sc) {
+ this.scCtorParam = sc;
+ }
+
+ @GET
+ @Path("ctor-param")
+ public String getCtorParam() {
+ return scCtorParam.getContextPath();
+ }
+
+ @GET
+ @Path("method-param")
+ public String getMethodParam(@Context final ServletContext sc) {
+ return sc.getContextPath();
+ }
+
+ @GET
+ @Path("field")
+ public String getField() {
+ return scField.getContextPath();
+ }
+
+ @GET
+ @Path("exception")
+ public String getException() throws Exception {
+ throw new Exception() {};
+ }
+}
diff --git a/tests/integration/j-441/war2/src/main/java/org/glassfish/jersey/tests/integration/j441/two/CustomExceptionMapper.java b/tests/integration/j-441/war2/src/main/java/org/glassfish/jersey/tests/integration/j441/two/CustomExceptionMapper.java
new file mode 100644
index 0000000..0544100
--- /dev/null
+++ b/tests/integration/j-441/war2/src/main/java/org/glassfish/jersey/tests/integration/j441/two/CustomExceptionMapper.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.j441.two;
+
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+
+import javax.servlet.ServletContext;
+
+/**
+ * JAX-RS provider added just to make sure the application
+ * deploys fine. Since JAX-RS providers get initialized
+ * at Jersey bootstrapping phase, we would get a deploy
+ * error if something went wrong.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class CustomExceptionMapper implements ExceptionMapper<Exception> {
+
+ @Context
+ private ServletContext sc;
+
+ public Response toResponse(final Exception ex) {
+ return Response.status(200).entity(sc.getContextPath()).build();
+ }
+}
diff --git a/tests/integration/j-441/war2/src/main/java/org/glassfish/jersey/tests/integration/j441/two/MyApplication.java b/tests/integration/j-441/war2/src/main/java/org/glassfish/jersey/tests/integration/j441/two/MyApplication.java
new file mode 100644
index 0000000..df6d3e3
--- /dev/null
+++ b/tests/integration/j-441/war2/src/main/java/org/glassfish/jersey/tests/integration/j441/two/MyApplication.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.j441.two;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * Test case to ensure proper WAR isolation on Jersey level.
+ * Define JAX-RS application containing a simple CDI backed JAX-RS resource.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("/")
+public class MyApplication extends ResourceConfig {
+
+ public MyApplication() {
+ super(CdiResource.class, CustomExceptionMapper.class);
+ }
+}
diff --git a/tests/integration/j-441/war2/src/main/webapp/WEB-INF/beans.xml b/tests/integration/j-441/war2/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..93cfed7
--- /dev/null
+++ b/tests/integration/j-441/war2/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+</beans>
diff --git a/tests/integration/j-441/war2/src/test/java/org/glassfish/jersey/tests/integration/j441/two/ContextPathTest.java b/tests/integration/j-441/war2/src/test/java/org/glassfish/jersey/tests/integration/j441/two/ContextPathTest.java
new file mode 100644
index 0000000..bb4f68b
--- /dev/null
+++ b/tests/integration/j-441/war2/src/test/java/org/glassfish/jersey/tests/integration/j441/two/ContextPathTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.j441.two;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * This is to make sure two Jersey wars are separated well in a single ear.
+ *
+ * @author Michal Gajdos
+ */
+public class ContextPathTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Application();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testFieldInjection() {
+ assertThat(target("two/test/field").request().get(String.class), is("/two"));
+ }
+
+ @Test
+ public void testConstructorInjection() {
+ assertThat(target("two/test/ctor-param").request().get(String.class), is("/two"));
+ }
+
+ @Test
+ public void testMethodInjection() {
+ assertThat(target("two/test/method-param").request().get(String.class), is("/two"));
+ }
+
+ @Test
+ public void testExceptionMapperInjection() {
+ assertThat(target("two/test/exception").request().get(String.class), is("/two"));
+ }
+}
diff --git a/tests/integration/j-59/ear/pom.xml b/tests/integration/j-59/ear/pom.xml
new file mode 100644
index 0000000..fdce31a
--- /dev/null
+++ b/tests/integration/j-59/ear/pom.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>j-59-ear</artifactId>
+ <packaging>ear</packaging>
+ <name>jersey-tests-integration-j-59-ear</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-ear-plugin</artifactId>
+ <configuration>
+ <version>6</version>
+ <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
+ <modules>
+ <webModule>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>j-59-cdi-war</artifactId>
+ </webModule>
+ <ejbModule>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>j-59-ejb-lib</artifactId>
+ </ejbModule>
+ </modules>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>j-59-cdi-war</artifactId>
+ <type>war</type>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>j-59-ejb-lib</artifactId>
+ <type>ejb</type>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/tests/integration/j-59/lib/pom.xml b/tests/integration/j-59/lib/pom.xml
new file mode 100644
index 0000000..e90e520
--- /dev/null
+++ b/tests/integration/j-59/lib/pom.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>j-59-ejb-lib</artifactId>
+ <packaging>jar</packaging>
+ <name>jersey-tests-integration-j-59-ejb-lib</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.ejb</groupId>
+ <artifactId>javax.ejb-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/j-59/lib/src/main/java/org/glassfish/jersey/tests/integration/j59/ejb/lib/LocalBeanWithRemoteInterface.java b/tests/integration/j-59/lib/src/main/java/org/glassfish/jersey/tests/integration/j59/ejb/lib/LocalBeanWithRemoteInterface.java
new file mode 100644
index 0000000..086976a
--- /dev/null
+++ b/tests/integration/j-59/lib/src/main/java/org/glassfish/jersey/tests/integration/j59/ejb/lib/LocalBeanWithRemoteInterface.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.j59.ejb.lib;
+
+import javax.ejb.LocalBean;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+/**
+ * Local stateless session bean implementing a remote interface.
+ * Part of CDI extension lookup issue reproducer.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Stateless
+@LocalBean
+@Remote(MyRemoteInterface.class)
+public class LocalBeanWithRemoteInterface {
+
+ /**
+ * Simple getter to be invoked from a CDI backed JAX-RS resource.
+ *
+ * @return Josh string literal.
+ */
+ public String getName() {
+ return "Josh";
+ }
+}
diff --git a/tests/integration/j-59/lib/src/main/java/org/glassfish/jersey/tests/integration/j59/ejb/lib/MyRemoteInterface.java b/tests/integration/j-59/lib/src/main/java/org/glassfish/jersey/tests/integration/j59/ejb/lib/MyRemoteInterface.java
new file mode 100644
index 0000000..ff53484
--- /dev/null
+++ b/tests/integration/j-59/lib/src/main/java/org/glassfish/jersey/tests/integration/j59/ejb/lib/MyRemoteInterface.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.j59.ejb.lib;
+
+/**
+ * Marker interface for remote beans. Part of CDI extension lookup issue reproducer.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public interface MyRemoteInterface {
+}
diff --git a/tests/integration/j-59/pom.xml b/tests/integration/j-59/pom.xml
new file mode 100644
index 0000000..2512403
--- /dev/null
+++ b/tests/integration/j-59/pom.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>j-59</artifactId>
+ <packaging>pom</packaging>
+ <name>jersey-tests-integration-j-59</name>
+
+ <description>
+ J-59 Reproducer: CDI extension lookup in multi-module app to Jersey 2.
+ </description>
+
+ <modules>
+ <module>ear</module>
+ <module>lib</module>
+ <module>war</module>
+ </modules>
+</project>
diff --git a/tests/integration/j-59/war/pom.xml b/tests/integration/j-59/war/pom.xml
new file mode 100644
index 0000000..1783544
--- /dev/null
+++ b/tests/integration/j-59/war/pom.xml
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>j-59-cdi-war</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-j-59-cdi-war</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>j-59-ejb-lib</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/j-59/war/src/main/java/org/glassfish/jersey/tests/integration/j59/cdi/web/CdiBackedResource.java b/tests/integration/j-59/war/src/main/java/org/glassfish/jersey/tests/integration/j59/cdi/web/CdiBackedResource.java
new file mode 100644
index 0000000..f3483dd
--- /dev/null
+++ b/tests/integration/j-59/war/src/main/java/org/glassfish/jersey/tests/integration/j59/cdi/web/CdiBackedResource.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.j59.cdi.web;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+
+import javax.jws.WebResult;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.glassfish.jersey.tests.integration.j59.ejb.lib.LocalBeanWithRemoteInterface;
+
+/**
+ * Part of CDI extension lookup issue reproducer.
+ * This bean will CDI-inject a local EJB bean.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("name")
+@RequestScoped
+public class CdiBackedResource implements ResourceMarkerInterface {
+
+ @Inject
+ private LocalBeanWithRemoteInterface localBean;
+
+ @GET
+ @Path("hello")
+ @Produces(MediaType.TEXT_PLAIN)
+ @WebResult(name = "hello")
+ public String sayHello() {
+ return "Hello " + localBean.getName();
+ }
+}
diff --git a/tests/integration/j-59/war/src/main/java/org/glassfish/jersey/tests/integration/j59/cdi/web/JaxRsConfiguration.java b/tests/integration/j-59/war/src/main/java/org/glassfish/jersey/tests/integration/j59/cdi/web/JaxRsConfiguration.java
new file mode 100644
index 0000000..976125a
--- /dev/null
+++ b/tests/integration/j-59/war/src/main/java/org/glassfish/jersey/tests/integration/j59/cdi/web/JaxRsConfiguration.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.j59.cdi.web;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * CDI extension lookup issue reproducer application configuration.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("resources")
+public class JaxRsConfiguration extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return new HashSet<Class<?>>() {{
+ add(CdiBackedResource.class);
+ }};
+ }
+}
diff --git a/tests/integration/j-59/war/src/main/java/org/glassfish/jersey/tests/integration/j59/cdi/web/ResourceMarkerInterface.java b/tests/integration/j-59/war/src/main/java/org/glassfish/jersey/tests/integration/j59/cdi/web/ResourceMarkerInterface.java
new file mode 100644
index 0000000..f1548c6
--- /dev/null
+++ b/tests/integration/j-59/war/src/main/java/org/glassfish/jersey/tests/integration/j59/cdi/web/ResourceMarkerInterface.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.j59.cdi.web;
+
+/**
+ * Marker interface for CDI backed JAX-RS bean.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public interface ResourceMarkerInterface {
+}
diff --git a/tests/integration/j-59/war/src/main/webapp/WEB-INF/beans.xml b/tests/integration/j-59/war/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..6d5c2c1
--- /dev/null
+++ b/tests/integration/j-59/war/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+</beans>
diff --git a/tests/integration/j-59/war/src/main/webapp/index.jsp b/tests/integration/j-59/war/src/main/webapp/index.jsp
new file mode 100644
index 0000000..a59a2a4
--- /dev/null
+++ b/tests/integration/j-59/war/src/main/webapp/index.jsp
@@ -0,0 +1,29 @@
+<%@page contentType="text/html" pageEncoding="UTF-8"%>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+
+ Copyright (c) 2018 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
+
+-->
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>CDI Extension Lookup Issue Reproducer</title>
+ </head>
+ <body>
+ Visit <a href="resources/name/hello">resources/name/hello</a>
+ </body>
+</html>
diff --git a/tests/integration/j-59/war/src/test/java/org/glassfish/jersey/tests/integration/j59/cdi/web/NameBeanTest.java b/tests/integration/j-59/war/src/test/java/org/glassfish/jersey/tests/integration/j59/cdi/web/NameBeanTest.java
new file mode 100644
index 0000000..26870a9
--- /dev/null
+++ b/tests/integration/j-59/war/src/test/java/org/glassfish/jersey/tests/integration/j59/cdi/web/NameBeanTest.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.j59.cdi.web;
+
+import java.net.URI;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Test for CDI extension lookup issue. Should the extension lookup have failed,
+ * we would not get the correct response here.
+ * <p/>
+ * Run with:
+ * <pre>
+ * mvn clean package
+ * $AS_HOME/bin/asadmin deploy ../ejb-jax-rs-ear1/target/ejb-jax-rs-ear1
+ * mvn -DskipTests=false test</pre>
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class NameBeanTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new JaxRsConfiguration();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("j-59-cdi-war").path("resources").build();
+ }
+
+ @Test
+ public void testCdiResource() {
+ final Response r = target().path("name").path("hello").request().get();
+ final String content = r.readEntity(String.class);
+ assertThat(r.getStatus(), is(200));
+ assertThat(content, equalTo("Hello Josh"));
+ }
+}
diff --git a/tests/integration/jaxrs-component-inject/pom.xml b/tests/integration/jaxrs-component-inject/pom.xml
new file mode 100644
index 0000000..9a392ab
--- /dev/null
+++ b/tests/integration/jaxrs-component-inject/pom.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2017, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jaxrs-component-inject</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-component-inject</name>
+
+ <description>Jersey Jaxrs Component Inject</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/PrintingErrorHandler.java b/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/PrintingErrorHandler.java
new file mode 100644
index 0000000..a8769f3
--- /dev/null
+++ b/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/PrintingErrorHandler.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2017, 2018 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.jaxrs.inject;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * Exception mapper printing the {@link Status#NOT_ACCEPTABLE} error.
+ */
+@Provider
+public class PrintingErrorHandler implements ExceptionMapper<Throwable> {
+
+ @Override
+ public Response toResponse(Throwable throwable) {
+ throwable.printStackTrace();
+
+ Writer result = new StringWriter();
+ PrintWriter printWriter = new PrintWriter(result);
+ throwable.printStackTrace(printWriter);
+ return Response.status(Status.NOT_ACCEPTABLE).entity(result.toString())
+ .build();
+ }
+}
diff --git a/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/Resource.java b/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/Resource.java
new file mode 100644
index 0000000..6c2a965
--- /dev/null
+++ b/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/Resource.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2017, 2018 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.jaxrs.inject;
+
+import java.util.Set;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Configuration;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.ext.Providers;
+
+/**
+ * Resource with {@link Context} injection points.
+ */
+@Path("resource")
+public class Resource {
+
+ @Context
+ Application application;
+ @Context
+ UriInfo info;
+ @Context
+ Request request;
+ @Context
+ HttpHeaders headers;
+ @Context
+ SecurityContext security;
+ @Context
+ Providers providers;
+ @Context
+ ResourceContext resources;
+ @Context
+ Configuration configration;
+
+ @POST
+ @Path("echo")
+ public String returnGivenString(String string) {
+ return string;
+ }
+
+ @POST
+ @Path("reader")
+ public String reader(StringBean bean) {
+ return bean.get();
+ }
+
+ @POST
+ @Path("writer")
+ public StringBean writer(String entity) {
+ return new StringBean(entity);
+ }
+
+ @GET
+ @Path("instance")
+ public String instance() {
+ return StringBeanEntityProviderWithInjectables.computeMask(application,
+ info, request, headers, security, providers, resources,
+ configration);
+ }
+
+ @GET
+ @Path("method")
+ public String method(@Context Application application,
+ @Context UriInfo info, @Context Request request,
+ @Context HttpHeaders headers, @Context SecurityContext security,
+ @Context Providers providers, @Context ResourceContext resources) {
+ return StringBeanEntityProviderWithInjectables.computeMask(application,
+ info, request, headers, security, providers, resources,
+ configration);
+ }
+
+ @GET
+ @Path("application")
+ public String application(@Context Application application) {
+ Set<Object> singletons = application.getSingletons();
+ SingletonWithInjectables singleton = (SingletonWithInjectables) singletons
+ .iterator().next();
+ return singleton.getInjectedContextValues();
+ }
+
+}
diff --git a/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/SingletonWithInjectables.java b/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/SingletonWithInjectables.java
new file mode 100644
index 0000000..22ca84a
--- /dev/null
+++ b/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/SingletonWithInjectables.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2017, 2018 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.jaxrs.inject;
+
+/**
+ * Holder for application configuration.
+ */
+public class SingletonWithInjectables {
+
+ private TSAppConfig config;
+
+ public SingletonWithInjectables(TSAppConfig config) {
+ this.config = config;
+ }
+
+ public String getInjectedContextValues() {
+ return config.getInjectedContextValues();
+ }
+}
diff --git a/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/StringBean.java b/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/StringBean.java
new file mode 100644
index 0000000..40bd98d
--- /dev/null
+++ b/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/StringBean.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2017, 2018 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.jaxrs.inject;
+
+/**
+ * This is the object which standard implementation does not have a provider
+ * for, even though its some simple String holder. It can also be used as mutable
+ * string.
+ */
+public class StringBean {
+ private String header;
+
+ public StringBean(String header) {
+ this.header = header;
+ }
+
+ public String get() {
+ return header;
+ }
+
+ public void set(String header) {
+ this.header = header;
+ }
+
+ @Override
+ public String toString() {
+ return "StringBean. To get a value, use rather #get() method.";
+ }
+}
diff --git a/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/StringBeanEntityProvider.java b/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/StringBeanEntityProvider.java
new file mode 100644
index 0000000..b8520ab
--- /dev/null
+++ b/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/StringBeanEntityProvider.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2017, 2018 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.jaxrs.inject;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * Provider for JAX-RS types {@link MessageBodyReader} and {@link MessageBodyWriter}.
+ */
+@Provider
+public class StringBeanEntityProvider implements MessageBodyReader<StringBean>, MessageBodyWriter<StringBean> {
+
+ @Override
+ public boolean isWriteable(Class<?> type, Type genericType,
+ Annotation[] annotations, MediaType mediaType) {
+ return StringBean.class.isAssignableFrom(type);
+ }
+
+ @Override
+ public long getSize(StringBean t, Class<?> type, Type genericType,
+ Annotation[] annotations, MediaType mediaType) {
+ return t.get().length();
+ }
+
+ @Override
+ public void writeTo(StringBean t, Class<?> type, Type genericType,
+ Annotation[] annotations, MediaType mediaType,
+ MultivaluedMap<String, Object> httpHeaders,
+ OutputStream entityStream) throws IOException,
+ WebApplicationException {
+ entityStream.write(t.get().getBytes());
+ }
+
+ @Override
+ public boolean isReadable(Class<?> type, Type genericType,
+ Annotation[] annotations, MediaType mediaType) {
+ return isWriteable(type, genericType, annotations, mediaType);
+ }
+
+ @Override
+ public StringBean readFrom(Class<StringBean> type, Type genericType,
+ Annotation[] annotations, MediaType mediaType,
+ MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
+ throws IOException, WebApplicationException {
+ return null;
+ }
+}
diff --git a/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/StringBeanEntityProviderWithInjectables.java b/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/StringBeanEntityProviderWithInjectables.java
new file mode 100644
index 0000000..9b8506f
--- /dev/null
+++ b/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/StringBeanEntityProviderWithInjectables.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2017, 2018 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.jaxrs.inject;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Configuration;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.Providers;
+
+/**
+ * Provider with {@link Context} injection points.
+ */
+@Provider
+public class StringBeanEntityProviderWithInjectables extends StringBeanEntityProvider {
+
+ @Context
+ Application application;
+ @Context
+ UriInfo info;
+ @Context
+ Request request;
+ @Context
+ HttpHeaders headers;
+ @Context
+ SecurityContext security;
+ @Context
+ Providers providers;
+ @Context
+ ResourceContext resources;
+ @Context
+ Configuration configuration;
+
+ /**
+ * Chosen decimal as a representation to be more human readable
+ */
+ public static String computeMask(Application application, UriInfo info,
+ Request request, HttpHeaders headers, SecurityContext security,
+ Providers providers, ResourceContext resources,
+ Configuration configuration) {
+ int mask = 1;
+ mask = 10 * mask + (application == null ? 0 : 1);
+ mask = 10 * mask + (info == null ? 0 : 1);
+ mask = 10 * mask + (request == null ? 0 : 1);
+ mask = 10 * mask + (headers == null ? 0 : 1);
+ mask = 10 * mask + (security == null ? 0 : 1);
+ mask = 10 * mask + (providers == null ? 0 : 1);
+ mask = 10 * mask + (resources == null ? 0 : 1);
+ mask = 10 * mask + (configuration == null ? 0 : 1);
+ return String.valueOf(mask);
+ }
+
+ /**
+ * Here, the bitwise operation with mask variable would be more efficient,
+ * but less human readable when sending over the link as a binary number.
+ * Hence, sMask is supposed to be decimal number created by writeTo method.
+ * <p>
+ * If something has not been injected, and thus not written by writeTo, this
+ * static method parses what it was not injected.
+ */
+ public static String notInjected(String sMask) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 1; i != sMask.length(); i++) {
+ sb.append(notInjected(sMask, i));
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Here, the bitwise operation with mask variable would be more efficient,
+ * but less human readable when sending over the link as a binary number.
+ * Hence, sMask is supposed to be decimal number created by writeTo method.
+ * <p>
+ * If something has not been injected, and thus not written by writeTo, this
+ * static method parses what it was not injected.
+ */
+ public static final String notInjected(String sMask, int index) {
+ String[] labels = {
+ "Application,", "UriInfo,", "Request,",
+ "HttpHeaders,", "SecurityContext,", "Providers,",
+ "ResourceContext", "Configuration"
+ };
+ String label = "";
+ if (sMask.charAt(index) == '0') {
+ label = labels[index - 1];
+ }
+ return label;
+ }
+
+ @Override
+ public long getSize(StringBean t, Class<?> type, Type genericType,
+ Annotation[] annotations, MediaType mediaType) {
+ return 9;
+ }
+
+ @Override
+ public void writeTo(StringBean t, Class<?> type, Type genericType,
+ Annotation[] annotations, MediaType mediaType,
+ MultivaluedMap<String, Object> httpHeaders,
+ OutputStream entityStream) throws IOException,
+ WebApplicationException {
+ entityStream.write(computeMask(application, info, request, headers,
+ security, providers, resources, configuration).getBytes());
+ }
+
+ @Override
+ public StringBean readFrom(Class<StringBean> type, Type genericType,
+ Annotation[] annotations, MediaType mediaType,
+ MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
+ throws IOException, WebApplicationException {
+ return new StringBean(computeMask(application, info, request, headers,
+ security, providers, resources, configuration));
+ }
+
+}
diff --git a/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/TSAppConfig.java b/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/TSAppConfig.java
new file mode 100644
index 0000000..04101c2
--- /dev/null
+++ b/tests/integration/jaxrs-component-inject/src/main/java/org/glassfish/jersey/tests/jaxrs/inject/TSAppConfig.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2017, 2018 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.jaxrs.inject;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.ext.Providers;
+
+/**
+ * Application Configuration with {@link Context} injection points.
+ */
+public class TSAppConfig extends Application {
+
+ @Context
+ UriInfo info;
+ @Context
+ Request request;
+ @Context
+ HttpHeaders headers;
+ @Context
+ SecurityContext security;
+ @Context
+ Providers providers;
+ @Context
+ ResourceContext resources;
+
+ public java.util.Set<java.lang.Class<?>> getClasses() {
+ Set<Class<?>> resources = new HashSet<>();
+ resources.add(Resource.class);
+ resources.add(StringBeanEntityProviderWithInjectables.class);
+ resources.add(PrintingErrorHandler.class);
+ return resources;
+ }
+
+ @Override
+ public Set<Object> getSingletons() {
+ Object single = new SingletonWithInjectables(this);
+ return Collections.singleton(single);
+ }
+
+ public String getInjectedContextValues() {
+ return StringBeanEntityProviderWithInjectables.computeMask(
+ /*
+ * Spec: 9.2.1 Application Note that this cannot be injected into the Application subclass itself since this would
+ * create a circular dependency.
+ * */
+ this, info, request, headers, security, providers, resources,
+ // Configuration injection N/A on Application
+ ClientBuilder.newClient().getConfiguration());
+ }
+}
diff --git a/tests/integration/jaxrs-component-inject/src/main/webapp/WEB-INF/web.xml b/tests/integration/jaxrs-component-inject/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..5c07843
--- /dev/null
+++ b/tests/integration/jaxrs-component-inject/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2017, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>CTSJAXRSContextServer</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.jaxrs.inject.TSAppConfig</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>CTSJAXRSContextServer</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+ <session-config>
+ <session-timeout>30</session-timeout>
+ </session-config>
+</web-app>
diff --git a/tests/integration/jaxrs-component-inject/src/test/java/org/glassfish/jersey/tests/jaxrs/inject/ApplicationInjectITCase.java b/tests/integration/jaxrs-component-inject/src/test/java/org/glassfish/jersey/tests/jaxrs/inject/ApplicationInjectITCase.java
new file mode 100644
index 0000000..50c1ff8
--- /dev/null
+++ b/tests/integration/jaxrs-component-inject/src/test/java/org/glassfish/jersey/tests/jaxrs/inject/ApplicationInjectITCase.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2017, 2018 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.jaxrs.inject;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests {@link javax.ws.rs.core.Context} injection into JAX-RS components Provider, Resource, Application.
+ *
+ * @author Petr Bouda
+ */
+public class ApplicationInjectITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Application();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testInstance() throws Exception {
+ WebTarget t = target();
+ t.register(LoggingFeature.class);
+ Response r = t.path("/resource/instance").request().get();
+ assertEquals(200, r.getStatus());
+ assertEquals("111111111", r.readEntity(String.class));
+ }
+
+ @Test
+ public void testMethod() throws Exception {
+ WebTarget t = target();
+ t.register(LoggingFeature.class);
+ Response r = t.path("/resource/method").request().get();
+ assertEquals(200, r.getStatus());
+ assertEquals("111111111", r.readEntity(String.class));
+ }
+ @Test
+ public void testApplication() throws Exception {
+ WebTarget t = target();
+ t.register(LoggingFeature.class);
+ Response r = t.path("/resource/application").request().get();
+ assertEquals(200, r.getStatus());
+ assertEquals("111111111", r.readEntity(String.class));
+ }
+}
diff --git a/tests/integration/jersey-1107/pom.xml b/tests/integration/jersey-1107/pom.xml
new file mode 100644
index 0000000..d2ea930
--- /dev/null
+++ b/tests/integration/jersey-1107/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2012, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-1107</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-1107</name>
+
+ <description>Servlet integration test - JERSEY-1107 - Thread gets stucked if no MessageBodyWriter is found in ApplicationHandler#writeResponse</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-1107/src/main/java/org/glassfish/jersey/tests/integration/jersey1107/Jersey1107.java b/tests/integration/jersey-1107/src/main/java/org/glassfish/jersey/tests/integration/jersey1107/Jersey1107.java
new file mode 100644
index 0000000..7073d75
--- /dev/null
+++ b/tests/integration/jersey-1107/src/main/java/org/glassfish/jersey/tests/integration/jersey1107/Jersey1107.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.jersey1107;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * @author Michal Gajdos
+ */
+public class Jersey1107 extends Application {
+
+ /**
+ * This MessageBodyWriter does not support the "exception/nullpointerexception" media type required by the
+ * {@code Resource#getNpe()} method which should result in an empty {@code MessageBodyWriter} and therefore
+ * an NPE in {@code ApplicationHandler}.
+ *
+ * @see org.glassfish.jersey.tests.integration.jersey1107.Jersey1107.Resource#getNpe()
+ */
+ @Provider
+ @Produces({"exception/ioexception", "exception/webapplicationexception"})
+ public static class ExceptionThrower implements MessageBodyWriter<Exception> {
+
+ @Override
+ public boolean isWriteable(
+ Class<?> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType) {
+ return IOException.class.isAssignableFrom(type) || RuntimeException.class.isAssignableFrom(type);
+ }
+
+ @Override
+ public long getSize(
+ Exception t,
+ Class<?> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType) {
+ return -1;
+ }
+
+ @Override
+ public void writeTo(
+ Exception e,
+ Class<?> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType,
+ MultivaluedMap<String, Object> httpHeaders,
+ OutputStream entityStream) throws IOException, WebApplicationException {
+ // Cannot write anything into the entityStream to ensure the ContainerResponseWriter#writeResponseStatusAndHeaders
+ // in ApplicationHandler#writeResponse is not invoked.
+
+ // Simply throw the given exception.
+ if (e instanceof IOException) {
+ throw (IOException) e;
+ } else {
+ throw (RuntimeException) e;
+ }
+ }
+
+ }
+
+ @Path("/")
+ public static class Resource {
+
+ @GET
+ @Path("/ioe")
+ @Produces("exception/ioexception")
+ public IOException getIoe() {
+ return new IOException();
+ }
+
+ @GET
+ @Path("/wae")
+ @Produces("exception/webapplicationexception")
+ public WebApplicationException getWae() {
+ return new WebApplicationException();
+ }
+
+ @GET
+ @Path("/npe")
+ @Produces("exception/nullpointerexception")
+ public NullPointerException getNpe() {
+ return new NullPointerException("This message should never get to the client!");
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Set<Class<?>> getClasses() {
+ return new HashSet<Class<?>>() {{
+ add(Resource.class);
+ add(ExceptionThrower.class);
+ }};
+ }
+
+}
diff --git a/tests/integration/jersey-1107/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-1107/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..5c144f8
--- /dev/null
+++ b/tests/integration/jersey-1107/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2012, 2018 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
+
+-->
+
+<web-app version="2.5"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <servlet>
+ <servlet-name>testServlet1</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey1107.Jersey1107</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>testServlet1</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
diff --git a/tests/integration/jersey-1107/src/test/java/org/glassfish/jersey/tests/integration/jersey1107/ApplicationHandlerITCase.java b/tests/integration/jersey-1107/src/test/java/org/glassfish/jersey/tests/integration/jersey1107/ApplicationHandlerITCase.java
new file mode 100644
index 0000000..11cb216
--- /dev/null
+++ b/tests/integration/jersey-1107/src/test/java/org/glassfish/jersey/tests/integration/jersey1107/ApplicationHandlerITCase.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.jersey1107;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests for JERSEY-1107: Thread gets stuck if no MessageBodyWriter is found in ApplicationHandler#writeResponse.
+ * <p/>
+ * If an exception (e.g. NPE caused by non-existent MessageBodyWriter) is thrown in ApplicationHandler#writeResponse before
+ * headers and response status are written by ContainerResponseWriter#writeResponseStatusAndHeaders then the
+ * ContainerResponseWriter#commit in the finally clause will stuck the thread.
+ * <p/>
+ * The purpose of the tests below is to show that a response is returned from the server and none of the threads gets stuck.
+ *
+ * @author Michal Gajdos
+ */
+public class ApplicationHandlerITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig().registerInstances(new Jersey1107());
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ /**
+ * Checks if a thread gets stuck when an {@code IOException} is thrown from the {@code
+ * MessageBodyWriter#writeTo}.
+ */
+ @Test
+ public void testIOExceptionInWriteResponseMethod() throws Exception {
+ _testExceptionInWriteResponseMethod("ioe", "exception/ioexception", Response.Status.INTERNAL_SERVER_ERROR);
+ }
+
+ /**
+ * Checks if a thread gets stuck when an {@code WebApplicationException} is thrown from the {@code
+ * MessageBodyWriter#writeTo}.
+ */
+ @Test
+ public void testWebApplicationExceptionInWriteResponseMethod() throws Exception {
+ _testExceptionInWriteResponseMethod("wae", "exception/webapplicationexception", Response.Status.INTERNAL_SERVER_ERROR);
+ }
+
+ /**
+ * Checks if a thread gets stuck when no {@code MessageBodyWriter} is found and therefore an {@code NPE} is thrown
+ * when trying to invoke {@code MessageBodyWriter#writeTo} on an empty object.
+ */
+ @Test
+ public void testNullPointerExceptionInWriteResponseMethod() throws Exception {
+ _testExceptionInWriteResponseMethod("npe", "exception/nullpointerexception", Response.Status.INTERNAL_SERVER_ERROR);
+ }
+
+ /**
+ * Creates a request to the server (with the whole process time set to the maximum of 5 seconds) for the given {@code path}
+ * and {@code mediaType} that should result in the {@code expectedResponse}.
+ */
+ private void _testExceptionInWriteResponseMethod(final String path, final String mediaType,
+ final Response.Status expectedResponse) throws Exception {
+ // Executor.
+ final ExecutorService executor = Executors.newSingleThreadExecutor();
+
+ final Future<Response> responseFuture = executor.submit(new Callable<Response>() {
+
+ @Override
+ public Response call() throws Exception {
+ return target().path(path).request(mediaType).get();
+ }
+
+ });
+
+ executor.shutdown();
+ final boolean inTime = executor.awaitTermination(5000, TimeUnit.MILLISECONDS);
+
+ // Asserts.
+ assertTrue(inTime);
+
+ // Response.
+ final Response response = responseFuture.get();
+ assertEquals(expectedResponse.getStatusCode(), response.getStatusInfo().getStatusCode());
+ }
+
+}
diff --git a/tests/integration/jersey-1223/pom.xml b/tests/integration/jersey-1223/pom.xml
new file mode 100644
index 0000000..4bc9d10
--- /dev/null
+++ b/tests/integration/jersey-1223/pom.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>project</artifactId>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>jersey-1223</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-1223</name>
+ <url>http://maven.apache.org</url>
+
+ <description>
+ Servlet integration test - JERSEY-1223 - "500 Internal Server Error" for POST request with garbage instead of
+ "Content-Type"
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/jersey-1223/src/main/java/org/glassfish/jersey/tests/integration/jersey1223/Jersey1223.java b/tests/integration/jersey-1223/src/main/java/org/glassfish/jersey/tests/integration/jersey1223/Jersey1223.java
new file mode 100644
index 0000000..60fcd3c
--- /dev/null
+++ b/tests/integration/jersey-1223/src/main/java/org/glassfish/jersey/tests/integration/jersey1223/Jersey1223.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey1223;
+
+import java.util.Collections;
+import java.util.Set;
+
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Application;
+
+/**
+ * @author Michal Gajdos
+ */
+public class Jersey1223 extends Application {
+
+ @Path(value = "/ContentType")
+ public static class ContentTypeResource {
+
+ @POST
+ @Produces(value = "text/plain")
+ @SuppressWarnings({"UnusedParameters", "JavaDoc"})
+ public void postTest(final String str) {
+ // Ignore to generate response 204 - NoContent.
+ }
+ }
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return Collections.<Class<?>>singleton(ContentTypeResource.class);
+ }
+}
diff --git a/tests/integration/jersey-1223/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-1223/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..1634824
--- /dev/null
+++ b/tests/integration/jersey-1223/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+
+<web-app version="2.5"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <servlet>
+ <servlet-name>testServlet1</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey1223.Jersey1223</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>testServlet1</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
+
+
diff --git a/tests/integration/jersey-1223/src/test/java/org/glassfish/jersey/tests/integration/jersey1223/ApplicationHandlerITCase.java b/tests/integration/jersey-1223/src/test/java/org/glassfish/jersey/tests/integration/jersey1223/ApplicationHandlerITCase.java
new file mode 100644
index 0000000..6ea3471
--- /dev/null
+++ b/tests/integration/jersey-1223/src/test/java/org/glassfish/jersey/tests/integration/jersey1223/ApplicationHandlerITCase.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey1223;
+
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests JERSEY issue 1223.
+ *
+ * @author Michal Gajdos
+ */
+public class ApplicationHandlerITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig(Jersey1223.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testInvalidContentTypeHeader() throws Exception {
+ final URL url = new URL(getBaseUri().toString() + "ContentType");
+ final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+
+ connection.setRequestMethod("POST");
+ connection.setRequestProperty("Accept", "text/plain");
+ connection.setRequestProperty("Content-Type", "application/json, app/json");
+
+ connection.setDoOutput(true);
+ connection.connect();
+
+ final OutputStream outputStream = connection.getOutputStream();
+ outputStream.write("HelloWorld!".getBytes());
+ outputStream.write('\n');
+ outputStream.flush();
+
+ assertEquals(400, connection.getResponseCode());
+ }
+}
diff --git a/tests/integration/jersey-1604/pom.xml b/tests/integration/jersey-1604/pom.xml
new file mode 100644
index 0000000..c7ec7b2
--- /dev/null
+++ b/tests/integration/jersey-1604/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>project</artifactId>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>jersey-1604</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-1604</name>
+ <url>http://maven.apache.org</url>
+
+ <description>Servlet integration test - JERSEY-1604 - IOException "connection closed" happens on calling delete without parameters</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.connectors</groupId>
+ <artifactId>jersey-apache-connector</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/jersey-1604/src/main/java/org/glassfish/jersey/tests/integration/jersey1604/Jersey1604.java b/tests/integration/jersey-1604/src/main/java/org/glassfish/jersey/tests/integration/jersey1604/Jersey1604.java
new file mode 100644
index 0000000..d4a2bbd
--- /dev/null
+++ b/tests/integration/jersey-1604/src/main/java/org/glassfish/jersey/tests/integration/jersey1604/Jersey1604.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey1604;
+
+import java.util.Collections;
+import java.util.Set;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+/**
+ * Application class with test resource that sets {@code Connection} header to {@code close}.
+ *
+ * @author Michal Gajdos
+ */
+public class Jersey1604 extends Application {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Set<Class<?>> getClasses() {
+ return Collections.<Class<?>>singleton(TestResource.class);
+ }
+
+ @Path("/")
+ public static class TestResource {
+
+ @DELETE
+ public Response delete() {
+ return Response
+ .ok()
+ .type(MediaType.TEXT_PLAIN_TYPE)
+ .header("Connection", "close")
+ .build();
+ }
+ }
+}
diff --git a/tests/integration/jersey-1604/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-1604/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..91aaa79
--- /dev/null
+++ b/tests/integration/jersey-1604/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+
+<web-app version="2.5"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <servlet>
+ <servlet-name>testServlet1</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey1604.Jersey1604</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>testServlet1</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
+
+
diff --git a/tests/integration/jersey-1604/src/test/java/org/glassfish/jersey/tests/integration/jersey1604/ConnectionCloseITCase.java b/tests/integration/jersey-1604/src/test/java/org/glassfish/jersey/tests/integration/jersey1604/ConnectionCloseITCase.java
new file mode 100644
index 0000000..067cbff
--- /dev/null
+++ b/tests/integration/jersey-1604/src/test/java/org/glassfish/jersey/tests/integration/jersey1604/ConnectionCloseITCase.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey1604;
+
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.apache.connector.ApacheConnectorProvider;
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Tests JERSEY issue 1604.
+ *
+ * @author Michal Gajdos
+ */
+public class ConnectionCloseITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig(Jersey1604.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Override
+ protected void configureClient(ClientConfig config) {
+ config.connectorProvider(new ApacheConnectorProvider());
+ }
+
+ @Test
+ public void testConnectionClose() throws Exception {
+ final Response response = target().request().header("Connection", "close").delete();
+
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.hasEntity(), is(false));
+ }
+}
diff --git a/tests/integration/jersey-1667/pom.xml b/tests/integration/jersey-1667/pom.xml
new file mode 100644
index 0000000..1e0243f
--- /dev/null
+++ b/tests/integration/jersey-1667/pom.xml
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-1667</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-1667</name>
+
+ <description>Servlet integration test - JERSEY-1667 - Incorrect handling of file upload errors when temp files cannot be written</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${servlet2.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-multipart</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-1667/src/main/java/org/glassfish/jersey/tests/integration/jersey1667/Issue1667Resource.java b/tests/integration/jersey-1667/src/main/java/org/glassfish/jersey/tests/integration/jersey1667/Issue1667Resource.java
new file mode 100644
index 0000000..46ba64c
--- /dev/null
+++ b/tests/integration/jersey-1667/src/main/java/org/glassfish/jersey/tests/integration/jersey1667/Issue1667Resource.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey1667;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.MediaType;
+
+import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+import org.glassfish.jersey.media.multipart.FormDataParam;
+
+/**
+ * Test resource.
+ *
+ * @author Michal Gajdos
+ */
+@Path("/")
+public class Issue1667Resource {
+
+ @POST
+ @Path("part-file-name")
+ @Consumes(MediaType.MULTIPART_FORM_DATA)
+ public String post(
+ @FormDataParam("part") String s,
+ @FormDataParam("part") FormDataContentDisposition d) {
+ return s + ":" + d.getFileName();
+ }
+}
diff --git a/tests/integration/jersey-1667/src/main/java/org/glassfish/jersey/tests/integration/jersey1667/Jersey1667.java b/tests/integration/jersey-1667/src/main/java/org/glassfish/jersey/tests/integration/jersey1667/Jersey1667.java
new file mode 100644
index 0000000..026623c
--- /dev/null
+++ b/tests/integration/jersey-1667/src/main/java/org/glassfish/jersey/tests/integration/jersey1667/Jersey1667.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey1667;
+
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
+import org.glassfish.jersey.media.multipart.MultiPartProperties;
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * JAX-RS application for the JERSEY-1667 reproducer test.
+ *
+ * @author Michal Gajdos
+ */
+public class Jersey1667 extends ResourceConfig {
+
+ public Jersey1667() {
+ register(Issue1667Resource.class);
+ register(MultiPartFeature.class);
+
+ register(new MultiPartProperties().bufferThreshold(8192).tempDir("/non-existent-directory").resolver());
+ }
+}
diff --git a/tests/integration/jersey-1667/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-1667/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..5897705
--- /dev/null
+++ b/tests/integration/jersey-1667/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>jersey1667Servlet</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey1667.Jersey1667</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>jersey1667Servlet</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/jersey-1667/src/test/java/org/glassfish/jersey/tests/integration/jersey1667/Jersey1667ITCase.java b/tests/integration/jersey-1667/src/test/java/org/glassfish/jersey/tests/integration/jersey1667/Jersey1667ITCase.java
new file mode 100644
index 0000000..4e9523e
--- /dev/null
+++ b/tests/integration/jersey-1667/src/test/java/org/glassfish/jersey/tests/integration/jersey1667/Jersey1667ITCase.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey1667;
+
+import java.util.Arrays;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.media.multipart.FormDataBodyPart;
+import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+import org.glassfish.jersey.media.multipart.FormDataMultiPart;
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Reproducer tests for JERSEY-2160.
+ *
+ * @author Michal Gajdos
+ */
+public class Jersey1667ITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new ResourceConfig();
+ }
+
+ @Override
+ protected void configureClient(final ClientConfig config) {
+ config.register(MultiPartFeature.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ /**
+ * Reproducer method for JERSEY-1667.
+ */
+ @Test
+ public void testJersey1667Fix() {
+ final WebTarget target = target().path("part-file-name");
+
+ char[] chars = new char[10 * 1024];
+ Arrays.fill(chars, 'a');
+ final String body = new String(chars);
+
+ final FormDataMultiPart multiPart = new FormDataMultiPart();
+ final FormDataBodyPart bodyPart = new FormDataBodyPart(FormDataContentDisposition.name("part").fileName("file").build(),
+ body);
+ multiPart.bodyPart(bodyPart);
+
+ final Response response = target.request().post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE));
+
+ assertThat(response.getStatus(), equalTo(500));
+ }
+}
diff --git a/tests/integration/jersey-1829/pom.xml b/tests/integration/jersey-1829/pom.xml
new file mode 100644
index 0000000..c4f1599
--- /dev/null
+++ b/tests/integration/jersey-1829/pom.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>project</artifactId>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>jersey-1829</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-1829</name>
+ <url>http://maven.apache.org</url>
+
+
+ <description>Servlet integration test - JERSEY-1829 - Custom reason phrase in response status does not work</description>
+
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/jersey-1829/src/main/java/org/glassfish/jersey/tests/integration/jersey1829/Jersey1829.java b/tests/integration/jersey-1829/src/main/java/org/glassfish/jersey/tests/integration/jersey1829/Jersey1829.java
new file mode 100644
index 0000000..e2398f2
--- /dev/null
+++ b/tests/integration/jersey-1829/src/main/java/org/glassfish/jersey/tests/integration/jersey1829/Jersey1829.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey1829;
+
+import java.util.Collections;
+import java.util.Set;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+/**
+ * Application class with test resource that returns custom status reason phrase.
+ *
+ * @author Miroslav Fuksa
+ */
+public class Jersey1829 extends Application {
+
+ public static final String REASON_PHRASE = "my-phrase";
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Set<Class<?>> getClasses() {
+ return Collections.<Class<?>>singleton(TestResource.class);
+ }
+
+ @Path("resource")
+ public static class TestResource {
+
+ @GET
+ @Path("428")
+ public Response get() {
+ return Response.status(new Custom428Type()).build();
+ }
+
+ @GET
+ @Path("428-entity")
+ public Response getWithEntity() {
+ return Response.status(new Custom428Type()).entity("entity").build();
+ }
+ }
+
+ public static class Custom428Type implements Response.StatusType {
+
+ @Override
+ public int getStatusCode() {
+ return 428;
+ }
+
+ @Override
+ public String getReasonPhrase() {
+ return REASON_PHRASE;
+ }
+
+ @Override
+ public Response.Status.Family getFamily() {
+ return Response.Status.Family.CLIENT_ERROR;
+ }
+ }
+
+}
diff --git a/tests/integration/jersey-1829/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-1829/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..5e51210
--- /dev/null
+++ b/tests/integration/jersey-1829/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+
+<web-app version="2.5"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <servlet>
+ <servlet-name>testServlet1</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey1829.Jersey1829</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>testServlet1</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
+
+
diff --git a/tests/integration/jersey-1829/src/test/java/org/glassfish/jersey/tests/integration/jersey1829/ApplicationHandlerITCase.java b/tests/integration/jersey-1829/src/test/java/org/glassfish/jersey/tests/integration/jersey1829/ApplicationHandlerITCase.java
new file mode 100644
index 0000000..11f81af
--- /dev/null
+++ b/tests/integration/jersey-1829/src/test/java/org/glassfish/jersey/tests/integration/jersey1829/ApplicationHandlerITCase.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey1829;
+
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests JERSEY issue 1744. Custom status reason phrase returned from the resource method was not propagated out of the
+ * servlet container.
+ *
+ * @author Miroslav Fuksa
+ */
+public class ApplicationHandlerITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig(Jersey1829.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testCustomResponse428() {
+ final Response response = target().path("resource/428").request().get();
+ Assert.assertEquals(428, response.getStatusInfo().getStatusCode());
+ Assert.assertEquals("my-phrase", response.getStatusInfo().getReasonPhrase());
+ }
+
+ @Test
+ public void testCustomResponse428WithEntity() {
+ final Response response = target().path("resource/428-entity").request().get();
+ Assert.assertEquals(428, response.getStatusInfo().getStatusCode());
+ Assert.assertEquals("my-phrase", response.getStatusInfo().getReasonPhrase());
+
+ }
+}
diff --git a/tests/integration/jersey-1883/pom.xml b/tests/integration/jersey-1883/pom.xml
new file mode 100644
index 0000000..c9c8fc0
--- /dev/null
+++ b/tests/integration/jersey-1883/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-1883</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-1883</name>
+
+ <description>Servlet integration test - JERSEY-1883 - @PostConstruct method called twice on @Singleton</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-1883/src/main/java/org/glassfish/jersey/tests/integration/jersey1883/Life.java b/tests/integration/jersey-1883/src/main/java/org/glassfish/jersey/tests/integration/jersey1883/Life.java
new file mode 100644
index 0000000..37effa2
--- /dev/null
+++ b/tests/integration/jersey-1883/src/main/java/org/glassfish/jersey/tests/integration/jersey1883/Life.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey1883;
+
+import javax.annotation.PostConstruct;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Application;
+
+/**
+ * JAX-RS application mixed with resource.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@ApplicationPath("/rest3")
+@Path("/life")
+public class Life extends Application {
+
+ private static int postConstructCount = 0;
+
+ @PostConstruct
+ public void post_construct() {
+ postConstructCount++;
+ }
+
+ @GET
+ public String greet() {
+ return "hi #" + postConstructCount;
+ }
+}
diff --git a/tests/integration/jersey-1883/src/main/java/org/glassfish/jersey/tests/integration/jersey1883/MyApplication.java b/tests/integration/jersey-1883/src/main/java/org/glassfish/jersey/tests/integration/jersey1883/MyApplication.java
new file mode 100644
index 0000000..764a7b6
--- /dev/null
+++ b/tests/integration/jersey-1883/src/main/java/org/glassfish/jersey/tests/integration/jersey1883/MyApplication.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey1883;
+
+import java.util.Collections;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * Explicitly register {@code @Singleton} resource.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@ApplicationPath("/rest1")
+public class MyApplication extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return Collections.singleton(NoLife.class);
+ }
+}
diff --git a/tests/integration/jersey-1883/src/main/java/org/glassfish/jersey/tests/integration/jersey1883/NoLife.java b/tests/integration/jersey-1883/src/main/java/org/glassfish/jersey/tests/integration/jersey1883/NoLife.java
new file mode 100644
index 0000000..9a82223
--- /dev/null
+++ b/tests/integration/jersey-1883/src/main/java/org/glassfish/jersey/tests/integration/jersey1883/NoLife.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey1883;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Singleton;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Application;
+
+/**
+ * Explicitly registered singleton resource by {@link MyApplication}.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Singleton
+@Path("/no-life")
+public class NoLife extends Application {
+
+ private static int postConstructCount = 0;
+
+ @PostConstruct
+ public void post_construct() {
+ postConstructCount++;
+ }
+
+ @GET
+ public String greet() {
+ return "ciao #" + postConstructCount;
+ }
+}
diff --git a/tests/integration/jersey-1883/src/main/java/org/glassfish/jersey/tests/integration/jersey1883/SingletonLife.java b/tests/integration/jersey-1883/src/main/java/org/glassfish/jersey/tests/integration/jersey1883/SingletonLife.java
new file mode 100644
index 0000000..26ae80b
--- /dev/null
+++ b/tests/integration/jersey-1883/src/main/java/org/glassfish/jersey/tests/integration/jersey1883/SingletonLife.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey1883;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Singleton;
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Application;
+
+/**
+ * JAX-RS application mixed with resource - singleton class.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Singleton
+@ApplicationPath("/rest2")
+@Path("/singleton-life")
+public class SingletonLife extends Application {
+
+ private static int postConstructCount = 0;
+
+ @PostConstruct
+ public void post_construct() {
+ postConstructCount++;
+ }
+
+ @GET
+ public String greet() {
+ return "hello #" + postConstructCount;
+ }
+}
diff --git a/tests/integration/jersey-1883/src/test/java/org/glassfish/jersey/tests/integration/jersey1883/Jersey1883ITCase.java b/tests/integration/jersey-1883/src/test/java/org/glassfish/jersey/tests/integration/jersey1883/Jersey1883ITCase.java
new file mode 100644
index 0000000..b2fb307
--- /dev/null
+++ b/tests/integration/jersey-1883/src/test/java/org/glassfish/jersey/tests/integration/jersey1883/Jersey1883ITCase.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey1883;
+
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.TestProperties;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class Jersey1883ITCase extends JerseyTest {
+
+ @Before
+ public void setup() {
+ Assume.assumeTrue(Hk2InjectionManagerFactory.isImmediateStrategy());
+ }
+
+ @Override
+ protected ResourceConfig configure() {
+ enable(TestProperties.LOG_TRAFFIC);
+ enable(TestProperties.DUMP_ENTITY);
+ return new ResourceConfig();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testGetRestNoLife() throws Exception {
+ Response response = target("rest1").path("no-life").request().get();
+ assertThat(response.readEntity(String.class), equalTo("ciao #1"));
+
+ response = target("rest1").path("no-life").request().get();
+ assertThat(response.readEntity(String.class), equalTo("ciao #1"));
+
+ response = target("rest1").path("no-life").request().get();
+ assertThat(response.readEntity(String.class), equalTo("ciao #1"));
+
+ response = target("rest1").path("no-life").request().get();
+ assertThat(response.readEntity(String.class), equalTo("ciao #1"));
+ }
+
+ @Test
+ public void testGetRestSingletonLife() throws Exception {
+ Response response = target("rest2").path("singleton-life").request().get();
+ assertThat(response.readEntity(String.class), equalTo("hello #1"));
+
+ response = target("rest2").path("singleton-life").request().get();
+ assertThat(response.readEntity(String.class), equalTo("hello #1"));
+
+ response = target("rest2").path("singleton-life").request().get();
+ assertThat(response.readEntity(String.class), equalTo("hello #1"));
+
+ response = target("rest2").path("singleton-life").request().get();
+ assertThat(response.readEntity(String.class), equalTo("hello #1"));
+ }
+
+ @Test
+ public void testGetRestLife() throws Exception {
+ Response response = target("rest3").path("life").request().get();
+ assertThat(response.readEntity(String.class), equalTo("hi #2"));
+
+ response = target("rest3").path("life").request().get();
+ assertThat(response.readEntity(String.class), equalTo("hi #3"));
+
+ response = target("rest3").path("life").request().get();
+ assertThat(response.readEntity(String.class), equalTo("hi #4"));
+
+ response = target("rest3").path("life").request().get();
+ assertThat(response.readEntity(String.class), equalTo("hi #5"));
+ }
+
+}
diff --git a/tests/integration/jersey-1928/pom.xml b/tests/integration/jersey-1928/pom.xml
new file mode 100644
index 0000000..5bbc778
--- /dev/null
+++ b/tests/integration/jersey-1928/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>project</artifactId>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>jersey-1928</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-1928</name>
+ <url>http://maven.apache.org</url>
+
+
+ <description>Servlet integration test - JERSEY-1928 - Odd behaviour with empty "path info"</description>
+
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/jersey-1928/src/main/java/org/glassfish/jersey/tests/integration/jersey1928/Jersey1928.java b/tests/integration/jersey-1928/src/main/java/org/glassfish/jersey/tests/integration/jersey1928/Jersey1928.java
new file mode 100644
index 0000000..dde2159
--- /dev/null
+++ b/tests/integration/jersey-1928/src/main/java/org/glassfish/jersey/tests/integration/jersey1928/Jersey1928.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey1928;
+
+import java.util.Collections;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Application;
+
+/**
+ * @author Michal Gajdos
+ */
+@ApplicationPath("/jersey1928")
+public class Jersey1928 extends Application {
+
+ @Path("/")
+ public static class Resource {
+
+ @GET
+ public String list() {
+ return "list";
+ }
+
+ @GET
+ @Path("{id}")
+ public String get(@PathParam("id") final String id) {
+ return id;
+ }
+ }
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return Collections.<Class<?>>singleton(Resource.class);
+ }
+}
diff --git a/tests/integration/jersey-1928/src/test/java/org/glassfish/jersey/tests/integration/jersey1928/Jersey1928ITCase.java b/tests/integration/jersey-1928/src/test/java/org/glassfish/jersey/tests/integration/jersey1928/Jersey1928ITCase.java
new file mode 100644
index 0000000..8fa797b
--- /dev/null
+++ b/tests/integration/jersey-1928/src/test/java/org/glassfish/jersey/tests/integration/jersey1928/Jersey1928ITCase.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey1928;
+
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Tests JERSEY issue 1928.
+ *
+ * @author Michal Gajdos
+ */
+public class Jersey1928ITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testJersey1928List() throws Exception {
+ final Response response = target("jersey1928").request().get();
+
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(String.class), equalTo("list"));
+ }
+
+ @Test
+ public void testJersey1928Id() throws Exception {
+ final Response response = target("jersey1928").path("id").request().get();
+
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(String.class), equalTo("id"));
+ }
+}
diff --git a/tests/integration/jersey-1960/pom.xml b/tests/integration/jersey-1960/pom.xml
new file mode 100644
index 0000000..4de96cb
--- /dev/null
+++ b/tests/integration/jersey-1960/pom.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-1960</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-1960</name>
+
+ <description>Servlet integration test - JERSEY-1960 - Servlet artifact injection into singleton providers.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${servlet2.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-1960/src/main/java/org/glassfish/jersey/tests/integration/jersey1960/EchoResource.java b/tests/integration/jersey-1960/src/main/java/org/glassfish/jersey/tests/integration/jersey1960/EchoResource.java
new file mode 100644
index 0000000..ca3b1a9
--- /dev/null
+++ b/tests/integration/jersey-1960/src/main/java/org/glassfish/jersey/tests/integration/jersey1960/EchoResource.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey1960;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * Test resource.
+ *
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+@Path("echo")
+public class EchoResource {
+
+ @POST
+ @Consumes("text/plain")
+ @Produces("text/plain")
+ public String echo(String message) {
+ return message + "." + this.getClass().getPackage().getName();
+ }
+}
diff --git a/tests/integration/jersey-1960/src/main/java/org/glassfish/jersey/tests/integration/jersey1960/Jersey1960App.java b/tests/integration/jersey-1960/src/main/java/org/glassfish/jersey/tests/integration/jersey1960/Jersey1960App.java
new file mode 100644
index 0000000..8a87f0b
--- /dev/null
+++ b/tests/integration/jersey-1960/src/main/java/org/glassfish/jersey/tests/integration/jersey1960/Jersey1960App.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey1960;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * JAX-RS application for the JERSEY-1960 reproducer test.
+ *
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+@ApplicationPath("application_path")
+public class Jersey1960App extends Application {
+ @SuppressWarnings({"unchecked"})
+ @Override
+ public Set<Class<?>> getClasses() {
+ return Stream.of(EchoResource.class, RequestFilter.class).collect(Collectors.toSet());
+ }
+}
diff --git a/tests/integration/jersey-1960/src/main/java/org/glassfish/jersey/tests/integration/jersey1960/RequestFilter.java b/tests/integration/jersey-1960/src/main/java/org/glassfish/jersey/tests/integration/jersey1960/RequestFilter.java
new file mode 100644
index 0000000..fde6d21
--- /dev/null
+++ b/tests/integration/jersey-1960/src/main/java/org/glassfish/jersey/tests/integration/jersey1960/RequestFilter.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey1960;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.PreMatching;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.glassfish.jersey.message.MessageUtils;
+
+/**
+ * Filter testing injection support for of servlet artifacts.
+ *
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+@PreMatching
+public class RequestFilter implements ContainerRequestFilter {
+ public static final String REQUEST_NUMBER = "request-number";
+ @Context
+ private HttpServletRequest hsReq;
+ @Context
+ private HttpServletResponse hsResp;
+ @Context
+ private ServletContext sCtx;
+ @Context
+ private ServletConfig sCfg;
+
+ @Override
+ public void filter(final ContainerRequestContext ctx) throws IOException {
+ final StringBuilder sb = new StringBuilder();
+
+ // First, make sure there are no null injections.
+ if (hsReq == null) {
+ sb.append("HttpServletRequest is null.\n");
+ }
+ if (hsResp == null) {
+ sb.append("HttpServletResponse is null.\n");
+ }
+ if (sCtx == null) {
+ sb.append("ServletContext is null.\n");
+ }
+ if (sCfg == null) {
+ sb.append("ServletConfig is null.\n");
+ }
+
+ if (sb.length() > 0) {
+ ctx.abortWith(Response.serverError().entity(sb.toString()).build());
+ }
+
+ // let's also test some method calls
+ int flags = 0;
+
+ if ("/jersey-1960".equals(hsReq.getServletPath())) {
+ flags += 1;
+ }
+ if (!hsResp.isCommitted()) {
+ flags += 10;
+ }
+ if (!sCtx.getServerInfo().isEmpty()) {
+ flags += 100;
+ }
+ if (sCfg.getServletContext() == sCtx) {
+ flags += 1000;
+ }
+ final String header = hsReq.getHeader(REQUEST_NUMBER);
+
+ ctx.setEntityStream(new ByteArrayInputStream(("filtered-" + flags + "-" + header).getBytes(
+ MessageUtils.getCharset(ctx.getMediaType()))));
+ }
+}
diff --git a/tests/integration/jersey-1960/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-1960/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..8ba90c2
--- /dev/null
+++ b/tests/integration/jersey-1960/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>jersey1960Servlet</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey1960.Jersey1960App</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>jersey1960Servlet</servlet-name>
+ <url-pattern>/jersey-1960/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/jersey-1960/src/test/java/org/glassfish/jersey/tests/integration/jersey1960/Jersey1960ITCase.java b/tests/integration/jersey-1960/src/test/java/org/glassfish/jersey/tests/integration/jersey1960/Jersey1960ITCase.java
new file mode 100644
index 0000000..da03ead
--- /dev/null
+++ b/tests/integration/jersey-1960/src/test/java/org/glassfish/jersey/tests/integration/jersey1960/Jersey1960ITCase.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey1960;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Reproducer tests for JERSEY-1960.
+ *
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+public class Jersey1960ITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Jersey1960App();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ /**
+ * Reproducer method for JERSEY-1960.
+ */
+ @Test
+ public void testJersey1960Fix() {
+ for (int i = 0; i < 10; i++) {
+ String response = target().path("jersey-1960/echo").request().header(RequestFilter.REQUEST_NUMBER, i)
+ .post(Entity.text("test"), String.class);
+ // Assert that the request has been filtered and processed by the echo method.
+ assertEquals(new EchoResource().echo("filtered-1111-" + i), response);
+ }
+ }
+}
diff --git a/tests/integration/jersey-1964/pom.xml b/tests/integration/jersey-1964/pom.xml
new file mode 100644
index 0000000..b6615c6
--- /dev/null
+++ b/tests/integration/jersey-1964/pom.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-1964</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-1964</name>
+
+ <description>Servlet integration test - JERSEY-1964 - NPE with Jersey 1 + Jackson 2 JAX-RS JSON provider</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-json-jackson</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-metainf-services</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-1964/src/main/java/org/glassfish/jersey/tests/integration/jersey1964/Issue1964Resource.java b/tests/integration/jersey-1964/src/main/java/org/glassfish/jersey/tests/integration/jersey1964/Issue1964Resource.java
new file mode 100644
index 0000000..839fc53
--- /dev/null
+++ b/tests/integration/jersey-1964/src/main/java/org/glassfish/jersey/tests/integration/jersey1964/Issue1964Resource.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey1964;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * Test resource.
+ *
+ * @author Michal Gajdos
+ */
+@Path("/")
+public class Issue1964Resource {
+
+ public static class JsonStringWrapper {
+
+ private String value;
+
+ public JsonStringWrapper() {
+ }
+
+ public JsonStringWrapper(final String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(final String value) {
+ this.value = value;
+ }
+ }
+
+ @PUT
+ @Consumes("application/json")
+ @Produces("application/json")
+ public JsonStringWrapper put(final JsonStringWrapper wrapper) {
+ return wrapper;
+ }
+}
diff --git a/tests/integration/jersey-1964/src/main/java/org/glassfish/jersey/tests/integration/jersey1964/Jersey1964.java b/tests/integration/jersey-1964/src/main/java/org/glassfish/jersey/tests/integration/jersey1964/Jersey1964.java
new file mode 100644
index 0000000..3dd1b6b
--- /dev/null
+++ b/tests/integration/jersey-1964/src/main/java/org/glassfish/jersey/tests/integration/jersey1964/Jersey1964.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey1964;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * JAX-RS application for the JERSEY-1964 reproducer test.
+ *
+ * @author Michal Gajdos
+ */
+public class Jersey1964 extends ResourceConfig {
+
+ public Jersey1964() {
+ register(Issue1964Resource.class);
+ }
+}
diff --git a/tests/integration/jersey-1964/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-1964/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..7736f49
--- /dev/null
+++ b/tests/integration/jersey-1964/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>jersey1964Servlet</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey1964.Jersey1964</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>jersey1964Servlet</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/jersey-1964/src/test/java/org/glassfish/jersey/tests/integration/jersey1964/Jersey1964ITCase.java b/tests/integration/jersey-1964/src/test/java/org/glassfish/jersey/tests/integration/jersey1964/Jersey1964ITCase.java
new file mode 100644
index 0000000..8329fd5
--- /dev/null
+++ b/tests/integration/jersey-1964/src/test/java/org/glassfish/jersey/tests/integration/jersey1964/Jersey1964ITCase.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey1964;
+
+import java.net.ConnectException;
+
+import javax.ws.rs.ProcessingException;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.fail;
+
+/**
+ * Reproducer tests for JERSEY-1964.
+ *
+ * @author Michal Gajdos
+ */
+public class Jersey1964ITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Jersey1964();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testJackson2JsonPut() throws Exception {
+ final Response response = target().request().put(Entity.json(new Issue1964Resource.JsonStringWrapper("foo")));
+
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(Issue1964Resource.JsonStringWrapper.class).getValue(), equalTo("foo"));
+ }
+
+ @Test(expected = ConnectException.class)
+ public void testJackson2JsonGetInvalidEndpoint() throws Throwable {
+ try {
+ ClientBuilder.newClient()
+ .target("http://localhost:1234")
+ .request()
+ .get();
+
+ fail("End-point shouldn't exist.");
+ } catch (final ProcessingException pe) {
+ throw pe.getCause();
+ }
+ }
+
+ @Test(expected = ConnectException.class)
+ public void testJackson2JsonPutInvalidEndpoint() throws Throwable {
+ try {
+ ClientBuilder.newClient()
+ .target("http://localhost:1234")
+ .request()
+ .put(Entity.json(new Issue1964Resource.JsonStringWrapper("foo")));
+
+ fail("End-point shouldn't exist.");
+ } catch (final ProcessingException pe) {
+ throw pe.getCause();
+ }
+ }
+}
diff --git a/tests/integration/jersey-2031/pom.xml b/tests/integration/jersey-2031/pom.xml
new file mode 100644
index 0000000..7b0eea3
--- /dev/null
+++ b/tests/integration/jersey-2031/pom.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2031</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2031</name>
+
+ <description>Servlet integration test - JERSEY-2031 - jersey 2.1 explicit viewable resolvingClass missed when do a jsp tag</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-mvc-jsp</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${servlet2.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2031/src/main/java/org/glassfish/jersey/tests/integration/jersey2031/Issue2031Resource.java b/tests/integration/jersey-2031/src/main/java/org/glassfish/jersey/tests/integration/jersey2031/Issue2031Resource.java
new file mode 100644
index 0000000..1e9fa59
--- /dev/null
+++ b/tests/integration/jersey-2031/src/main/java/org/glassfish/jersey/tests/integration/jersey2031/Issue2031Resource.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2031;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.glassfish.jersey.server.mvc.Template;
+import org.glassfish.jersey.server.mvc.Viewable;
+
+/**
+ * Test resource.
+ *
+ * @author Michal Gajdos
+ */
+@Path("/")
+public class Issue2031Resource {
+
+ private static final Model model;
+ private static final String absolutePath;
+
+ static {
+ absolutePath = "/" + Issue2031Resource.class.getName().replaceAll("\\.", "/").replace('$', '/') + "/index.jsp";
+ model = new Model();
+ }
+
+ @GET
+ @Path("viewable-relative")
+ @Produces("text/html")
+ public Viewable viewableRelative() {
+ return new Viewable("index", model);
+ }
+
+ @GET
+ @Path("viewable-absolute")
+ @Produces("text/html")
+ public Viewable viewableAbsolute() {
+ return new Viewable(absolutePath, model);
+ }
+
+ @GET
+ @Path("template-relative")
+ @Produces("text/html")
+ @Template(name = "index")
+ public Model templateRelative() {
+ return model;
+ }
+
+ @GET
+ @Path("template-absolute")
+ @Produces("text/html")
+ @Template(
+ name = "/org/glassfish/jersey/tests/integration/jersey2031/Issue2031Resource/index.jsp")
+ public Model templateAbsolute() {
+ return model;
+ }
+
+ public static class Model {
+
+ private String index = "index";
+ private String include = "include";
+
+ public String getIndex() {
+ return index;
+ }
+
+ public String getInclude() {
+ return include;
+ }
+ }
+}
diff --git a/tests/integration/jersey-2031/src/main/java/org/glassfish/jersey/tests/integration/jersey2031/Jersey2031.java b/tests/integration/jersey-2031/src/main/java/org/glassfish/jersey/tests/integration/jersey2031/Jersey2031.java
new file mode 100644
index 0000000..3c673eb
--- /dev/null
+++ b/tests/integration/jersey-2031/src/main/java/org/glassfish/jersey/tests/integration/jersey2031/Jersey2031.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2031;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.mvc.jsp.JspMvcFeature;
+
+/**
+ * JAX-RS application for the JERSEY-2031 reproducer test.
+ *
+ * @author Michal Gajdos
+ */
+public class Jersey2031 extends ResourceConfig {
+
+ public Jersey2031() {
+ register(Issue2031Resource.class);
+ register(JspMvcFeature.class);
+ }
+}
diff --git a/tests/integration/jersey-2031/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2031/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..18fc4e3
--- /dev/null
+++ b/tests/integration/jersey-2031/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <filter>
+ <filter-name>jersey2031</filter-name>
+ <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2031.Jersey2031</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>jersey2031</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+</web-app>
diff --git a/tests/integration/jersey-2031/src/main/webapp/org/glassfish/jersey/tests/integration/jersey2031/Issue2031Resource/include.jsp b/tests/integration/jersey-2031/src/main/webapp/org/glassfish/jersey/tests/integration/jersey2031/Issue2031Resource/include.jsp
new file mode 100644
index 0000000..6c914c2
--- /dev/null
+++ b/tests/integration/jersey-2031/src/main/webapp/org/glassfish/jersey/tests/integration/jersey2031/Issue2031Resource/include.jsp
@@ -0,0 +1,22 @@
+<%--
+
+ Copyright (c) 2013, 2018 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
+
+--%>
+
+<%@page contentType="text/html"%>
+<%@page pageEncoding="UTF-8"%>
+
+${model.include}
diff --git a/tests/integration/jersey-2031/src/main/webapp/org/glassfish/jersey/tests/integration/jersey2031/Issue2031Resource/index.jsp b/tests/integration/jersey-2031/src/main/webapp/org/glassfish/jersey/tests/integration/jersey2031/Issue2031Resource/index.jsp
new file mode 100644
index 0000000..cbebedb
--- /dev/null
+++ b/tests/integration/jersey-2031/src/main/webapp/org/glassfish/jersey/tests/integration/jersey2031/Issue2031Resource/index.jsp
@@ -0,0 +1,39 @@
+<%--
+
+ Copyright (c) 2013, 2018 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
+
+--%>
+
+<%@page contentType="text/html"%>
+<%@page pageEncoding="UTF-8"%>
+
+<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
+<%@taglib prefix="rbt" uri="urn:org:glassfish:jersey:servlet:mvc" %>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Book</title>
+ </head>
+ <body>
+
+ ${model.index}
+
+ <rbt:include page="include.jsp"/>
+
+ </body>
+</html>
diff --git a/tests/integration/jersey-2031/src/test/java/org/glassfish/jersey/tests/integration/jersey2031/Jersey2031ITCase.java b/tests/integration/jersey-2031/src/test/java/org/glassfish/jersey/tests/integration/jersey2031/Jersey2031ITCase.java
new file mode 100644
index 0000000..594129b
--- /dev/null
+++ b/tests/integration/jersey-2031/src/test/java/org/glassfish/jersey/tests/integration/jersey2031/Jersey2031ITCase.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2031;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Reproducer tests for JERSEY-2164.
+ *
+ * @author Michal Gajdos
+ */
+public class Jersey2031ITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Jersey2031();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testTemplateRelative() throws Exception {
+ _test("template-relative");
+ }
+
+ @Test
+ public void testTemplateAbsolute() throws Exception {
+ _test("template-absolute");
+ }
+
+ @Test
+ public void testViewableRelative() throws Exception {
+ _test("viewable-relative");
+ }
+
+ @Test
+ public void testViewableAbsolute() throws Exception {
+ _test("viewable-absolute");
+ }
+
+ private void _test(final String path) throws Exception {
+ final Response response = target(path).request("text/html").get();
+ final String page = response.readEntity(String.class);
+
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(page, containsString("index"));
+ assertThat(page, containsString("include"));
+ }
+}
diff --git a/tests/integration/jersey-2136/pom.xml b/tests/integration/jersey-2136/pom.xml
new file mode 100644
index 0000000..5e797da
--- /dev/null
+++ b/tests/integration/jersey-2136/pom.xml
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2136</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2136</name>
+
+ <description>Servlet integration test - JERSEY-2136 - Jersey 2 doesn't work with Google Application Engine</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.appengine</groupId>
+ <artifactId>appengine-api-1.0-sdk</artifactId>
+ <version>${gae.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+
+ <!-- TODO: The test was skipped, including the hooked app-engine start && stop. The app-engine process was sometimes
+ left hanging after the end of the build and kept blocking the port. -->
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <!--<plugin>-->
+ <!--<groupId>com.google.appengine</groupId>-->
+ <!--<artifactId>appengine-maven-plugin</artifactId>-->
+ <!--<version>${gae.version}</version>-->
+ <!--<configuration>-->
+
+ <!--<port>${jersey.config.test.container.port}</port>-->
+ <!--<offline>true</offline>-->
+ <!--</configuration>-->
+ <!--<executions>-->
+ <!--<execution>-->
+ <!--<id>start-gae</id>-->
+ <!--<phase>pre-integration-test</phase>-->
+ <!--<goals>-->
+ <!--<goal>devserver_start</goal>-->
+ <!--</goals>-->
+ <!--</execution>-->
+ <!--<execution>-->
+ <!--<id>stop-gae</id>-->
+ <!--<phase>post-integration-test</phase>-->
+ <!--<goals>-->
+ <!--<goal>devserver_stop</goal>-->
+ <!--</goals>-->
+ <!--</execution>-->
+ <!--</executions>-->
+ <!--</plugin>-->
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2136/src/main/java/org/glassfish/jersey/tests/integration/jersey2136/Issue2136Resource.java b/tests/integration/jersey-2136/src/main/java/org/glassfish/jersey/tests/integration/jersey2136/Issue2136Resource.java
new file mode 100644
index 0000000..ede5954
--- /dev/null
+++ b/tests/integration/jersey-2136/src/main/java/org/glassfish/jersey/tests/integration/jersey2136/Issue2136Resource.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2136;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * Test resource.
+ *
+ * @author Michal Gajdos
+ */
+@Path("/")
+public class Issue2136Resource {
+
+ @GET
+ public String get() {
+ return "Hello, GAE!";
+ }
+}
diff --git a/tests/integration/jersey-2136/src/main/java/org/glassfish/jersey/tests/integration/jersey2136/Jersey2136.java b/tests/integration/jersey-2136/src/main/java/org/glassfish/jersey/tests/integration/jersey2136/Jersey2136.java
new file mode 100644
index 0000000..b7f604e
--- /dev/null
+++ b/tests/integration/jersey-2136/src/main/java/org/glassfish/jersey/tests/integration/jersey2136/Jersey2136.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2136;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * JAX-RS application for the JERSEY-2136 reproducer test.
+ *
+ * @author Michal Gajdos
+ */
+public class Jersey2136 extends ResourceConfig {
+
+ public Jersey2136() {
+ register(Issue2136Resource.class);
+ }
+}
diff --git a/tests/integration/jersey-2136/src/main/webapp/WEB-INF/appengine-web.xml b/tests/integration/jersey-2136/src/main/webapp/WEB-INF/appengine-web.xml
new file mode 100644
index 0000000..fc291a1
--- /dev/null
+++ b/tests/integration/jersey-2136/src/main/webapp/WEB-INF/appengine-web.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
+ <application>jersey2136</application>
+ <version>1</version>
+ <threadsafe>true</threadsafe>
+</appengine-web-app>
diff --git a/tests/integration/jersey-2136/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2136/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..2c67157
--- /dev/null
+++ b/tests/integration/jersey-2136/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>jersey2136Servlet</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2136.Jersey2136</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>jersey2136Servlet</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/jersey-2136/src/test/java/org/glassfish/jersey/tests/integration/jersey2136/Jersey2136ITCase.java b/tests/integration/jersey-2136/src/test/java/org/glassfish/jersey/tests/integration/jersey2136/Jersey2136ITCase.java
new file mode 100644
index 0000000..418666a
--- /dev/null
+++ b/tests/integration/jersey-2136/src/test/java/org/glassfish/jersey/tests/integration/jersey2136/Jersey2136ITCase.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2136;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Reproducer tests for JERSEY-2164.
+ *
+ * @author Michal Gajdos
+ */
+public class Jersey2136ITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Jersey2136();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ // This test requires app engine to be launched by a maven plugin,
+ // which was causing intermittent problems with hanging app engine process.
+ // After un-ignoring this test, make sure to uncomment the app engine plugin
+ // execution in the project's pom.xml
+ @Ignore
+ @Test
+ public void testGet() throws Exception {
+ final Response response = target().request().get();
+
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(String.class), equalTo("Hello, GAE!"));
+ }
+}
diff --git a/tests/integration/jersey-2137/pom.xml b/tests/integration/jersey-2137/pom.xml
new file mode 100644
index 0000000..d5b48c5
--- /dev/null
+++ b/tests/integration/jersey-2137/pom.xml
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2137</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2137</name>
+
+ <description>Jersey CDI/JTA test web application, JERSEY-2137 reproducer</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.transaction</groupId>
+ <artifactId>javax.transaction-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.persistence</groupId>
+ <artifactId>persistence-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/jersey-2137/src/main/java/org/glassfish/jersey/tests/integration/jersey2137/Account.java b/tests/integration/jersey-2137/src/main/java/org/glassfish/jersey/tests/integration/jersey2137/Account.java
new file mode 100644
index 0000000..1c414b7
--- /dev/null
+++ b/tests/integration/jersey-2137/src/main/java/org/glassfish/jersey/tests/integration/jersey2137/Account.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2137;
+
+import java.io.Serializable;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * Entity bean that maintains information on account balance.
+ * This is to help determine if rollback happens or not, when
+ * entity bean is accessed from a transactional CDI beans.
+ * Entity beans have implicit JTA support, so this will
+ * save us some lines of code.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Entity
+public class Account implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ private Long id;
+
+ /**
+ * Get the account id.
+ *
+ * @return account id.
+ */
+ public Long getId() {
+ return id;
+ }
+
+ /**
+ * Set the account id.
+ *
+ * @param id account id.
+ */
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ private long balance;
+
+ /**
+ * Get the value of balance
+ *
+ * @return the value of balance
+ */
+ public long getBalance() {
+ return balance;
+ }
+
+ /**
+ * Set the value of balance
+ *
+ * @param balance new value of balance
+ */
+ public void setBalance(long balance) {
+ this.balance = balance;
+ }
+
+
+ @Override
+ public int hashCode() {
+ int hash = 0;
+ hash += (id != null ? id.hashCode() : 0);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if (!(object instanceof Account)) {
+ return false;
+ }
+ Account other = (Account) object;
+ if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "org.glassfish.jersey.tests.integration.jersey2137.Account[ id=" + id + " ]";
+ }
+}
diff --git a/tests/integration/jersey-2137/src/main/java/org/glassfish/jersey/tests/integration/jersey2137/CdiTransactionalNoRollbackResource.java b/tests/integration/jersey-2137/src/main/java/org/glassfish/jersey/tests/integration/jersey2137/CdiTransactionalNoRollbackResource.java
new file mode 100644
index 0000000..3ce59b1
--- /dev/null
+++ b/tests/integration/jersey-2137/src/main/java/org/glassfish/jersey/tests/integration/jersey2137/CdiTransactionalNoRollbackResource.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2137;
+
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+import javax.enterprise.context.RequestScoped;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.transaction.Transactional;
+
+/**
+ * Request scoped transactional CDI bean registered as JAX-RS resource class.
+ * Part of JERSEY-2137 reproducer. {@link javax.ws.rs.WebApplicationException}
+ * thrown in the resource method below should drive the response as specified
+ * in the JAX-RS spec regardless
+ * on the {@link javax.transaction.Transactional#dontRollbackOn()} value.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestScoped
+@Transactional(dontRollbackOn = WebApplicationException.class)
+@Path("cdi-transactional-no-rollback")
+public class CdiTransactionalNoRollbackResource {
+
+ @PersistenceContext(unitName = "Jersey2137PU")
+ private EntityManager entityManager;
+
+ @Path("{a}")
+ @PUT
+ public void putBalance(@PathParam("a") long a, String balance) {
+ final Account account = entityManager.find(Account.class, a);
+ if (account == null) {
+ Account newAccount = new Account();
+ newAccount.setId(a);
+ newAccount.setBalance(Long.decode(balance));
+ entityManager.persist(newAccount);
+ throw new WebApplicationException(Response.ok("New accout created.").build());
+ } else {
+ account.setBalance(Long.decode(balance));
+ entityManager.merge(account);
+ throw new WebApplicationException(Response.ok("Balance updated.").build());
+ }
+ }
+}
diff --git a/tests/integration/jersey-2137/src/main/java/org/glassfish/jersey/tests/integration/jersey2137/CdiTransactionalResource.java b/tests/integration/jersey-2137/src/main/java/org/glassfish/jersey/tests/integration/jersey2137/CdiTransactionalResource.java
new file mode 100644
index 0000000..0132a91
--- /dev/null
+++ b/tests/integration/jersey-2137/src/main/java/org/glassfish/jersey/tests/integration/jersey2137/CdiTransactionalResource.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2137;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+import javax.enterprise.context.RequestScoped;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.transaction.Transactional;
+
+/**
+ * Request scoped transactional CDI bean registered as JAX-RS resource class.
+ * Part of JERSEY-2137 reproducer. {@link javax.ws.rs.WebApplicationException}
+ * thrown in the resource method below should drive the response as specified
+ * in the JAX-RS spec.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestScoped
+@Transactional
+@Path("cdi-transactional")
+public class CdiTransactionalResource {
+
+ @PersistenceContext(unitName = "Jersey2137PU")
+ private EntityManager entityManager;
+
+ @Path("{a}")
+ @GET
+ public String getBalance(@PathParam("a") long a) {
+ final Account account = entityManager.find(Account.class, a);
+ if (account == null) {
+ throw new WebApplicationException(
+ Response.status(Response.Status.BAD_REQUEST).entity(String.format("Account %d not found", a)).build());
+ } else {
+ return String.format("%d", account.getBalance());
+ }
+ }
+
+ @Path("{a}")
+ @PUT
+ public void putBalance(@PathParam("a") long a, String balance) {
+ final Account account = entityManager.find(Account.class, a);
+ if (account == null) {
+ Account newAccount = new Account();
+ newAccount.setId(a);
+ newAccount.setBalance(Long.decode(balance));
+ entityManager.persist(newAccount);
+ } else {
+ account.setBalance(Long.decode(balance));
+ entityManager.merge(account);
+ }
+ }
+
+ @POST
+ public String transferMoney(@QueryParam("from") long from, @QueryParam("to") long to, String amount) {
+
+ final Account toAccount = entityManager.find(Account.class, to);
+
+ if (toAccount != null) {
+ try {
+ toAccount.setBalance(toAccount.getBalance() + Long.decode(amount));
+ entityManager.merge(toAccount);
+ final Account fromAccount = entityManager.find(Account.class, from);
+ fromAccount.setBalance(fromAccount.getBalance() - Long.decode(amount));
+ if (fromAccount.getBalance() < 0) {
+ throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST)
+ .entity("Transaction failed. Not enough money on the funding account.").build());
+ }
+ entityManager.merge(fromAccount);
+ return "Transaction sucessful.";
+ } catch (Exception e) {
+ if (e instanceof WebApplicationException) {
+ throw (WebApplicationException) e;
+ } else {
+ throw new WebApplicationException(
+ Response.status(Response.Status.BAD_REQUEST).entity("Something bad happened.").build());
+ }
+ }
+ } else {
+ throw new WebApplicationException(
+ Response.status(Response.Status.BAD_REQUEST).entity("Target account not found.").build());
+ }
+ }
+}
diff --git a/tests/integration/jersey-2137/src/main/java/org/glassfish/jersey/tests/integration/jersey2137/TestApplication.java b/tests/integration/jersey-2137/src/main/java/org/glassfish/jersey/tests/integration/jersey2137/TestApplication.java
new file mode 100644
index 0000000..8e3f6d0
--- /dev/null
+++ b/tests/integration/jersey-2137/src/main/java/org/glassfish/jersey/tests/integration/jersey2137/TestApplication.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2137;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * JAX-RS application to configure resources for JERSEY-2137 reproducer.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("/*")
+public class TestApplication extends Application {
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> classes = new HashSet<Class<?>>();
+ classes.add(CdiTransactionalResource.class);
+ classes.add(CdiTransactionalNoRollbackResource.class);
+ return classes;
+ }
+}
diff --git a/tests/integration/jersey-2137/src/main/webapp/WEB-INF/beans.xml b/tests/integration/jersey-2137/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/jersey-2137/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<beans/>
diff --git a/tests/integration/jersey-2137/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2137/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..3c18370
--- /dev/null
+++ b/tests/integration/jersey-2137/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+</web-app>
diff --git a/tests/integration/jersey-2137/src/main/webapp/WEB-INF/weblogic.xml b/tests/integration/jersey-2137/src/main/webapp/WEB-INF/weblogic.xml
new file mode 100644
index 0000000..1d2a9ef
--- /dev/null
+++ b/tests/integration/jersey-2137/src/main/webapp/WEB-INF/weblogic.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">
+
+ <wls:library-ref>
+ <wls:library-name>jax-rs</wls:library-name>
+ <wls:specification-version>2.0</wls:specification-version>
+ <wls:exact-match>true</wls:exact-match>
+ </wls:library-ref>
+</wls:weblogic-web-app>
diff --git a/tests/integration/jersey-2137/src/test/java/org/glassfish/jersey/tests/integration/jersey2137/WaeExceptionMappingTest.java b/tests/integration/jersey-2137/src/test/java/org/glassfish/jersey/tests/integration/jersey2137/WaeExceptionMappingTest.java
new file mode 100644
index 0000000..c722b92
--- /dev/null
+++ b/tests/integration/jersey-2137/src/test/java/org/glassfish/jersey/tests/integration/jersey2137/WaeExceptionMappingTest.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2137;
+
+import java.net.URI;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.equalTo;
+
+/**
+ * Reproducer for JERSEY-2137.
+ * Ensure that generated {@link WebApplicationException} is propagated
+ * via transactional CDI call and mapped to response according to JAX-RS spec.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class WaeExceptionMappingTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new TestApplication();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("jersey-2137").build();
+ }
+
+ /**
+ * Test all {@javax.transaction.Transactional}
+ * annotated CDI beans. The test scenario is as follows.
+ * Set two accounts via the CDI bean that avoids rollback.
+ * Should any rollback happen there, we would not be able
+ * to store any data in JPA. Next try to make two transactions,
+ * first of them should be finished without errors,
+ * during the other one, a rollback is expected.
+ * The rollback should avoid partial data to be written
+ * to the first account.
+ */
+ @Test
+ public void testTransactions() {
+
+ final WebTarget cdiResource = target().path("cdi-transactional");
+ final WebTarget cdiResourceNoRollback = target().path("cdi-transactional-no-rollback");
+
+ Response response;
+ String responseBody;
+
+ // account 12 -> insert 1000:
+ response = cdiResourceNoRollback.path("12").request().put(Entity.text("1000"));
+ assertThat(response.getStatus(), equalTo(200));
+
+ // account 13 -> insert 1000:
+ response = cdiResourceNoRollback.path("13").request().put(Entity.text("1000"));
+ assertThat(response.getStatus(), equalTo(200));
+
+ // transfer 1000 from 13 to 12:
+ response = cdiResource.queryParam("from", "13").queryParam("to", "12").request().post(Entity.text("1000"));
+ assertThat(response.getStatus(), equalTo(200));
+
+ // ensure 12 has balance 2000:
+ response = cdiResource.path("12").request().get();
+ assertThat(response.getStatus(), equalTo(200));
+ responseBody = response.readEntity(String.class);
+ assertThat(responseBody, equalTo("2000"));
+
+ // try to transfer 1000 from non-existing 8 to 12, this time the transaction should fail:
+ response = cdiResource.queryParam("from", "8").queryParam("to", "12").request().post(Entity.text("1000"));
+ assertThat(response.getStatus(), equalTo(400));
+
+ // ensure 12 balance has not changed:
+ response = cdiResource.path("12").request().get();
+ assertThat(response.getStatus(), equalTo(200));
+ responseBody = response.readEntity(String.class);
+ assertThat(responseBody, equalTo("2000"));
+ }
+}
diff --git a/tests/integration/jersey-2154/pom.xml b/tests/integration/jersey-2154/pom.xml
new file mode 100644
index 0000000..6dc290f
--- /dev/null
+++ b/tests/integration/jersey-2154/pom.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2154</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2154</name>
+
+ <description>Jersey CDI/EJB test web application, JERSEY-2154 reproducer</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.ejb</groupId>
+ <artifactId>javax.ejb-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-bundle</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/jersey-2154/src/main/java/org/glassfish/jersey/tests/integration/jersey2154/CdiResource.java b/tests/integration/jersey-2154/src/main/java/org/glassfish/jersey/tests/integration/jersey2154/CdiResource.java
new file mode 100644
index 0000000..8539fc7
--- /dev/null
+++ b/tests/integration/jersey-2154/src/main/java/org/glassfish/jersey/tests/integration/jersey2154/CdiResource.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2154;
+
+import javax.ejb.EJB;
+import javax.enterprise.context.RequestScoped;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * Request scoped CDI bean injected with EJB bean.
+ * Part of JERSEY-2154 reproducer. {@link javax.ejb.EJBException}
+ * thrown in the injected EJB bean should get unwrapped
+ * even when no EJB-backed JAX-RS resources have been registered.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@RequestScoped
+@Path("cdi")
+public class CdiResource {
+
+ @EJB EjbBean ejbBean;
+
+ @GET
+ public String get() {
+ return ejbBean.exceptionDrivenResponse();
+ }
+}
diff --git a/tests/integration/jersey-2154/src/main/java/org/glassfish/jersey/tests/integration/jersey2154/EjbBean.java b/tests/integration/jersey-2154/src/main/java/org/glassfish/jersey/tests/integration/jersey2154/EjbBean.java
new file mode 100644
index 0000000..bd19227
--- /dev/null
+++ b/tests/integration/jersey-2154/src/main/java/org/glassfish/jersey/tests/integration/jersey2154/EjbBean.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2154;
+
+import javax.ejb.EJBException;
+import javax.ejb.Stateless;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+/**
+ * EJB bean to reproduce JERSEY-2154. Bellow generated {@link WebApplicationException}
+ * should get mapped to response even when wrapped into an {@link EJBException}
+ * by the underlying EJB container.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Stateless
+public class EjbBean {
+
+ /**
+ * This is to make sure the exception thrown gets wrapped with an {@link EJBException}.
+ *
+ * @return nothing, just throws an exception.
+ */
+ public String exceptionDrivenResponse() {
+ throw new WebApplicationException(Response.ok("If you read this, the exception got mapped successfully!").build());
+ }
+}
diff --git a/tests/integration/jersey-2154/src/main/java/org/glassfish/jersey/tests/integration/jersey2154/TestApplication.java b/tests/integration/jersey-2154/src/main/java/org/glassfish/jersey/tests/integration/jersey2154/TestApplication.java
new file mode 100644
index 0000000..a794af9
--- /dev/null
+++ b/tests/integration/jersey-2154/src/main/java/org/glassfish/jersey/tests/integration/jersey2154/TestApplication.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2154;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * JAX-RS application to configure resources for JERSEY-2154 reproducer.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("/*")
+public class TestApplication extends Application {
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> classes = new HashSet<Class<?>>();
+ classes.add(CdiResource.class);
+ return classes;
+ }
+}
diff --git a/tests/integration/jersey-2154/src/main/webapp/WEB-INF/beans.xml b/tests/integration/jersey-2154/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..07df368
--- /dev/null
+++ b/tests/integration/jersey-2154/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<beans/>
diff --git a/tests/integration/jersey-2154/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2154/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..3c18370
--- /dev/null
+++ b/tests/integration/jersey-2154/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+</web-app>
diff --git a/tests/integration/jersey-2154/src/test/java/org/glassfish/jersey/tests/integration/jersey2154/EjbExceptionMappingTest.java b/tests/integration/jersey-2154/src/test/java/org/glassfish/jersey/tests/integration/jersey2154/EjbExceptionMappingTest.java
new file mode 100644
index 0000000..564fc14
--- /dev/null
+++ b/tests/integration/jersey-2154/src/test/java/org/glassfish/jersey/tests/integration/jersey2154/EjbExceptionMappingTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2154;
+
+import java.net.URI;
+import javax.ejb.EJBException;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.core.StringContains.containsString;
+
+/**
+ * Reproducer for JERSEY-2154.
+ * Test generated {@link WebApplicationException} is propagated
+ * via CDI call and mapped to 200 response, even when wrapped with an {@link EJBException}.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class EjbExceptionMappingTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new TestApplication();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("jersey-2154").build();
+ }
+
+ /**
+ * The only test needed. Should the original {@link WebApplicationException}
+ * not get unwrapped, we would end up with 500 status code.
+ */
+ @Test
+ public void testInjection() {
+
+ final WebTarget cdiResource = target().path("cdi");
+
+ Response response = cdiResource.request().get();
+
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(String.class), containsString("exception got mapped"));
+ }
+}
diff --git a/tests/integration/jersey-2160/pom.xml b/tests/integration/jersey-2160/pom.xml
new file mode 100644
index 0000000..8e32aac
--- /dev/null
+++ b/tests/integration/jersey-2160/pom.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2160</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2160</name>
+
+ <description>Servlet integration test - JERSEY-2160 - HttpServletRequest/HttpServletResponse do not get injected as a proxy into method parameters</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${servlet2.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2160/src/main/java/org/glassfish/jersey/tests/integration/jersey2160/Issue2160ReproducerResource.java b/tests/integration/jersey-2160/src/main/java/org/glassfish/jersey/tests/integration/jersey2160/Issue2160ReproducerResource.java
new file mode 100644
index 0000000..2097ef2
--- /dev/null
+++ b/tests/integration/jersey-2160/src/main/java/org/glassfish/jersey/tests/integration/jersey2160/Issue2160ReproducerResource.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2160;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.glassfish.hk2.api.ProxyCtl;
+
+/**
+ * Test resource.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("servletInjectees")
+public class Issue2160ReproducerResource {
+
+ @Context
+ HttpServletRequest requestField;
+ @Context
+ HttpServletResponse responseField;
+
+ @GET
+ @Produces("text/plain")
+ public String ensureNoProxyInjected(@Context HttpServletRequest requestParam, @Context HttpServletResponse responseParam) {
+
+ // make sure the injectees are same no matter how they got injected
+ if (requestParam != requestField || responseParam != responseField) {
+ throw new IllegalArgumentException("injected field and parameter should refer to the same instance");
+ }
+
+ // make sure we have not got proxies
+ if (requestParam instanceof ProxyCtl || responseParam instanceof ProxyCtl) {
+ throw new IllegalArgumentException("no proxy expected!");
+ }
+
+ return (String) requestParam.getAttribute(RequestFilter.REQUEST_NUMBER_PROPERTY);
+ }
+}
diff --git a/tests/integration/jersey-2160/src/main/java/org/glassfish/jersey/tests/integration/jersey2160/Jersey2160App.java b/tests/integration/jersey-2160/src/main/java/org/glassfish/jersey/tests/integration/jersey2160/Jersey2160App.java
new file mode 100644
index 0000000..29f21c6
--- /dev/null
+++ b/tests/integration/jersey-2160/src/main/java/org/glassfish/jersey/tests/integration/jersey2160/Jersey2160App.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2160;
+
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+import java.util.HashSet;
+
+/**
+ * JAX-RS application for the JERSEY-1960 reproducer test.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class Jersey2160App extends Application {
+
+ @SuppressWarnings({"unchecked"})
+ @Override
+ public Set<Class<?>> getClasses() {
+ return new HashSet<Class<?>>() {
+ {
+ add(RequestFilter.class);
+ add(Issue2160ReproducerResource.class);
+ }
+ };
+ }
+}
diff --git a/tests/integration/jersey-2160/src/main/java/org/glassfish/jersey/tests/integration/jersey2160/RequestFilter.java b/tests/integration/jersey-2160/src/main/java/org/glassfish/jersey/tests/integration/jersey2160/RequestFilter.java
new file mode 100644
index 0000000..8a44f0c
--- /dev/null
+++ b/tests/integration/jersey-2160/src/main/java/org/glassfish/jersey/tests/integration/jersey2160/RequestFilter.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2160;
+
+import java.io.IOException;
+
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.PreMatching;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * Filter that set a property on actual request. The property value
+ * is expected to be propagated to the resource method via injected
+ * {@link HttpServletRequest} parameter.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@PreMatching
+public class RequestFilter implements ContainerRequestFilter {
+
+ public static final String REQUEST_NUMBER_PROPERTY = "request-number";
+ public static final String REQUEST_NUMBER_HEADER = "number";
+
+ @Override
+ public void filter(ContainerRequestContext ctx) throws IOException {
+ final String number = ctx.getHeaderString(REQUEST_NUMBER_HEADER);
+ ctx.setProperty(REQUEST_NUMBER_PROPERTY, number);
+ }
+}
diff --git a/tests/integration/jersey-2160/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2160/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..3b97459
--- /dev/null
+++ b/tests/integration/jersey-2160/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>jersey2160Servlet</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2160.Jersey2160App</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>jersey2160Servlet</servlet-name>
+ <url-pattern>/jersey-2160/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/jersey-2160/src/test/java/org/glassfish/jersey/tests/integration/jersey2160/Jersey2160ITCase.java b/tests/integration/jersey-2160/src/test/java/org/glassfish/jersey/tests/integration/jersey2160/Jersey2160ITCase.java
new file mode 100644
index 0000000..dd7f0b5
--- /dev/null
+++ b/tests/integration/jersey-2160/src/test/java/org/glassfish/jersey/tests/integration/jersey2160/Jersey2160ITCase.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2160;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Reproducer tests for JERSEY-2160.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class Jersey2160ITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Jersey2160App();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ /**
+ * Reproducer method for JERSEY-2160.
+ */
+ @Test
+ public void testJersey2160Fix() {
+ for (int i = 0; i < 10; i++) {
+ String response = target().path("jersey-2160/servletInjectees")
+ .request().header(RequestFilter.REQUEST_NUMBER_HEADER, i)
+ .get(String.class);
+ assertEquals(Integer.parseInt(response), i);
+ }
+ }
+}
diff --git a/tests/integration/jersey-2164/pom.xml b/tests/integration/jersey-2164/pom.xml
new file mode 100644
index 0000000..24f6782
--- /dev/null
+++ b/tests/integration/jersey-2164/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2164</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2164</name>
+
+ <description>Servlet integration test - JERSEY-2164 - Multi value http headers are not correctly read by the server</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-json-jackson</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2164/src/main/java/org/glassfish/jersey/tests/integration/jersey2164/Issue2164Resource.java b/tests/integration/jersey-2164/src/main/java/org/glassfish/jersey/tests/integration/jersey2164/Issue2164Resource.java
new file mode 100644
index 0000000..40b9da4
--- /dev/null
+++ b/tests/integration/jersey-2164/src/main/java/org/glassfish/jersey/tests/integration/jersey2164/Issue2164Resource.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2164;
+
+import java.util.List;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+
+/**
+ * Test resource.
+ *
+ * @author Michal Gajdos
+ */
+@Path("/")
+public class Issue2164Resource {
+
+ @GET
+ public String get(@HeaderParam("hello") final List<String> headers) {
+ return headers.size() + ":" + headers;
+ }
+}
diff --git a/tests/integration/jersey-2164/src/main/java/org/glassfish/jersey/tests/integration/jersey2164/Jersey2164.java b/tests/integration/jersey-2164/src/main/java/org/glassfish/jersey/tests/integration/jersey2164/Jersey2164.java
new file mode 100644
index 0000000..0b4cff4
--- /dev/null
+++ b/tests/integration/jersey-2164/src/main/java/org/glassfish/jersey/tests/integration/jersey2164/Jersey2164.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2164;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * JAX-RS application for the JERSEY-2164 reproducer test.
+ *
+ * @author Michal Gajdos
+ */
+public class Jersey2164 extends ResourceConfig {
+
+ public Jersey2164() {
+ register(Issue2164Resource.class);
+ }
+}
diff --git a/tests/integration/jersey-2164/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2164/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..8b77a93
--- /dev/null
+++ b/tests/integration/jersey-2164/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>jersey2164Servlet</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2164.Jersey2164</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>jersey2164Servlet</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/jersey-2164/src/test/java/org/glassfish/jersey/tests/integration/jersey2164/Jersey2164ITCase.java b/tests/integration/jersey-2164/src/test/java/org/glassfish/jersey/tests/integration/jersey2164/Jersey2164ITCase.java
new file mode 100644
index 0000000..79c24c9
--- /dev/null
+++ b/tests/integration/jersey-2164/src/test/java/org/glassfish/jersey/tests/integration/jersey2164/Jersey2164ITCase.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2164;
+
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.message.internal.ReaderWriter;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Reproducer tests for JERSEY-2164.
+ *
+ * @author Michal Gajdos
+ */
+public class Jersey2164ITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Jersey2164();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testHeaderListSingleHeader() throws Exception {
+ Response response = target().request().header("hello", "world").header("hello", "universe").get();
+
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(String.class), equalTo("1:[world,universe]"));
+ }
+
+ /**
+ * Check that multi value http headers are correctly read by the server.
+ */
+ @Test
+ public void testHeaderListMultipleHeaders() throws Exception {
+ final URL url = new URL(getBaseUri().toString());
+ final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Accept", "text/plain");
+ connection.setRequestProperty("hello", "world");
+ connection.addRequestProperty("hello", "universe");
+
+ connection.setDoOutput(false);
+ connection.connect();
+
+ assertThat(connection.getResponseCode(), equalTo(200));
+ assertThat(ReaderWriter.readFromAsString(new InputStreamReader(connection.getInputStream())),
+ equalTo("2:[world, universe]"));
+ }
+}
diff --git a/tests/integration/jersey-2167/pom.xml b/tests/integration/jersey-2167/pom.xml
new file mode 100644
index 0000000..943e894
--- /dev/null
+++ b/tests/integration/jersey-2167/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2167</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2167</name>
+
+ <description>JERSEY-2167 reproducer - Injecting a custom parameter type causes REST method to run twice</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2167/src/main/java/org/glassfish/jersey/tests/integration/jersey2167/Issue2167Resource.java b/tests/integration/jersey-2167/src/main/java/org/glassfish/jersey/tests/integration/jersey2167/Issue2167Resource.java
new file mode 100644
index 0000000..48ccef8
--- /dev/null
+++ b/tests/integration/jersey-2167/src/main/java/org/glassfish/jersey/tests/integration/jersey2167/Issue2167Resource.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2167;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Test resource for JERSEY-2167 reproducer.
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+
+@Path("/MyResource")
+public class Issue2167Resource {
+ private static final Logger LOGGER = Logger.getLogger(Issue2167Resource.class.getName());
+ public static final String MSG = "Resource method doA() called at ";
+
+ @Path("test")
+ @GET
+ public Response doA(@MyAnnotation String param) {
+ LOGGER.log(Level.INFO, MSG + System.currentTimeMillis() + "; param=" + param);
+ if (param == null) {
+ return Response.serverError().build();
+ }
+ return Response.ok().build();
+ }
+}
diff --git a/tests/integration/jersey-2167/src/main/java/org/glassfish/jersey/tests/integration/jersey2167/Jersey2167App.java b/tests/integration/jersey-2167/src/main/java/org/glassfish/jersey/tests/integration/jersey2167/Jersey2167App.java
new file mode 100644
index 0000000..1adc3cc
--- /dev/null
+++ b/tests/integration/jersey-2167/src/main/java/org/glassfish/jersey/tests/integration/jersey2167/Jersey2167App.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2167;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * JAX-RS application for the JERSEY-2167 reproducer test.
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+public class Jersey2167App extends ResourceConfig {
+
+ public Jersey2167App() {
+ register(Issue2167Resource.class);
+ register(new MyBinder());
+ }
+}
diff --git a/tests/integration/jersey-2167/src/main/java/org/glassfish/jersey/tests/integration/jersey2167/MyAnnotation.java b/tests/integration/jersey-2167/src/main/java/org/glassfish/jersey/tests/integration/jersey2167/MyAnnotation.java
new file mode 100644
index 0000000..edec66e
--- /dev/null
+++ b/tests/integration/jersey-2167/src/main/java/org/glassfish/jersey/tests/integration/jersey2167/MyAnnotation.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2167;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Custom annotation for JERSEY-2167 reproducer test.
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+
+@Target(ElementType.PARAMETER)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface MyAnnotation {
+}
diff --git a/tests/integration/jersey-2167/src/main/java/org/glassfish/jersey/tests/integration/jersey2167/MyBinder.java b/tests/integration/jersey-2167/src/main/java/org/glassfish/jersey/tests/integration/jersey2167/MyBinder.java
new file mode 100644
index 0000000..b6de2c8
--- /dev/null
+++ b/tests/integration/jersey-2167/src/main/java/org/glassfish/jersey/tests/integration/jersey2167/MyBinder.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2167;
+
+import javax.inject.Singleton;
+
+import org.glassfish.jersey.internal.inject.AbstractBinder;
+import org.glassfish.jersey.server.spi.internal.ValueParamProvider;
+
+/**
+ * Custom annotation binder for JERSEY-2167 reproducer.
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+public class MyBinder extends AbstractBinder {
+
+ @Override
+ protected void configure() {
+ bind(MyValueParamProvider.class).to(ValueParamProvider.class).in(Singleton.class);
+ }
+}
diff --git a/tests/integration/jersey-2167/src/main/java/org/glassfish/jersey/tests/integration/jersey2167/MyValueParamProvider.java b/tests/integration/jersey-2167/src/main/java/org/glassfish/jersey/tests/integration/jersey2167/MyValueParamProvider.java
new file mode 100644
index 0000000..5eae5ae
--- /dev/null
+++ b/tests/integration/jersey-2167/src/main/java/org/glassfish/jersey/tests/integration/jersey2167/MyValueParamProvider.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2167;
+
+import java.util.function.Function;
+
+import javax.inject.Inject;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+import org.glassfish.jersey.server.ContainerRequest;
+import org.glassfish.jersey.server.internal.inject.AbstractValueParamProvider;
+import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
+import org.glassfish.jersey.server.model.Parameter;
+
+/**
+ * Custom annotation value supplier provider for JERSEY-2167 reproducer.
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+@Singleton
+public class MyValueParamProvider extends AbstractValueParamProvider {
+
+ @Inject
+ public MyValueParamProvider(Provider<MultivaluedParameterExtractorProvider> mpep) {
+ super(mpep, Parameter.Source.UNKNOWN);
+ }
+
+ @Override
+ protected Function<ContainerRequest, ?> createValueProvider(Parameter parameter) {
+ return new MyValueSupplier();
+ }
+
+ private static final class MyValueSupplier implements Function<ContainerRequest, Object> {
+
+ @Override
+ public Object apply(ContainerRequest request) {
+ // returns some testing value
+ return "injected timestamp=" + System.currentTimeMillis();
+ }
+ }
+}
diff --git a/tests/integration/jersey-2167/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2167/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..be1fb9d
--- /dev/null
+++ b/tests/integration/jersey-2167/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>jersey2167Servlet</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2167.Jersey2167App</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>jersey2167Servlet</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/jersey-2167/src/test/java/org/glassfish/jersey/tests/integration/jersey2167/Jersey2167ITCase.java b/tests/integration/jersey-2167/src/test/java/org/glassfish/jersey/tests/integration/jersey2167/Jersey2167ITCase.java
new file mode 100644
index 0000000..cff58c6
--- /dev/null
+++ b/tests/integration/jersey-2167/src/test/java/org/glassfish/jersey/tests/integration/jersey2167/Jersey2167ITCase.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2167;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.TestProperties;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Reproducer tests for JERSEY-2167.
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+public class Jersey2167ITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ enable(TestProperties.LOG_TRAFFIC);
+ return new Jersey2167App();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testResourceMethodCall() throws Exception {
+ Response response = target().path("MyResource/test").request().get();
+ // if parameter was not injected, resource returns Response.Status.SERVER_ERROR (500). Missing parameter means,
+ // that hk2 injected the parameter and invoked the method preliminary and during Jersey-driven invocation,
+ // there was no parameter injection any more. If parameter was injected and Response.Status.OK (200) returned,
+ // the resource method was called only once (by Jersey).
+ assertEquals("Parameter not injected into resource method. Resource method could have been called twice. ",
+ response.getStatus(), Response.Status.OK.getStatusCode());
+ }
+}
diff --git a/tests/integration/jersey-2176/pom.xml b/tests/integration/jersey-2176/pom.xml
new file mode 100644
index 0000000..c4c3877
--- /dev/null
+++ b/tests/integration/jersey-2176/pom.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2176</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2176</name>
+
+ <description>Servlet integration test - JERSEY-2176 - Problems with calling close() and flush()
+ methods on underlying output stream.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>${servlet3.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/Issue2176ReproducerResource.java b/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/Issue2176ReproducerResource.java
new file mode 100644
index 0000000..6b0d093
--- /dev/null
+++ b/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/Issue2176ReproducerResource.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2176;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+
+/**
+ * Test resource.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Path("/resource")
+public class Issue2176ReproducerResource {
+
+ static final String X_FAIL_HEADER = "X-FAIL";
+ static final String X_RESPONSE_ENTITY_HEADER = "X-RESPONSE-ENTITY";
+
+ @GET
+ @Produces("text/plain")
+ @Path("{status}")
+ public Response getText(@PathParam("status") int uc,
+ @Context HttpHeaders headers) throws MyException {
+ if (uc == -1) {
+ throw new MyException("UC= " + uc);
+ } else if (uc == -2) {
+ throw new IllegalStateException("UC= " + uc);
+ } else if (uc == -3) {
+ throw new WebApplicationException("UC= " + uc, 321);
+ } else if (uc == -4) {
+ throw new WebApplicationException("UC= " + uc, 432);
+ }
+
+ final Response.ResponseBuilder responseBuilder = Response.status(uc);
+ if (headers.getRequestHeaders().containsKey(X_RESPONSE_ENTITY_HEADER)) {
+ responseBuilder.entity("ENTITY");
+ }
+ final Response response = responseBuilder.build();
+ if (headers.getRequestHeaders().containsKey(X_RESPONSE_ENTITY_HEADER)) {
+ response.getHeaders().add(X_RESPONSE_ENTITY_HEADER, "true");
+ }
+ if (headers.getRequestHeaders().containsKey(X_FAIL_HEADER)) {
+ response.getHeaders().add(X_FAIL_HEADER, "true");
+ }
+ return response;
+ }
+
+}
diff --git a/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/Jersey2176App.java b/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/Jersey2176App.java
new file mode 100644
index 0000000..e28cfc2
--- /dev/null
+++ b/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/Jersey2176App.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2176;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.ServerProperties;
+
+/**
+ * JAX-RS application for the JERSEY-2176 reproducer test.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+abstract class Jersey2176App extends ResourceConfig {
+
+ private final boolean setStatusOverSendError;
+
+ public Jersey2176App(boolean setStatusOverSendError) {
+ this.setStatusOverSendError = setStatusOverSendError;
+
+ property(ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, setStatusOverSendError);
+ register(MyWriterInterceptor.class);
+ register(Issue2176ReproducerResource.class);
+ }
+
+ public boolean isSetStatusOverSendError() {
+ return setStatusOverSendError;
+ }
+}
diff --git a/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/Jersey2176SendErrorApp.java b/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/Jersey2176SendErrorApp.java
new file mode 100644
index 0000000..dcdcaed
--- /dev/null
+++ b/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/Jersey2176SendErrorApp.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2176;
+
+import javax.ws.rs.ApplicationPath;
+
+/**
+ * Configure {@link org.glassfish.jersey.server.ServerProperties#RESPONSE_SET_STATUS_OVER_SEND_ERROR} by {@code true} -
+ * method {@link javax.servlet.http.HttpServletResponse#sendError} will be called in case of errors
+ * (status {@code 4xx} or {@code 5xx}).
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@ApplicationPath(Jersey2176SendErrorApp.APP_PATH)
+public class Jersey2176SendErrorApp extends Jersey2176App {
+
+ public static final String APP_PATH = "send-error";
+
+ public Jersey2176SendErrorApp() {
+ super(false);
+ }
+
+}
diff --git a/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/Jersey2176SetStatusApp.java b/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/Jersey2176SetStatusApp.java
new file mode 100644
index 0000000..501df02
--- /dev/null
+++ b/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/Jersey2176SetStatusApp.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2176;
+
+import javax.ws.rs.ApplicationPath;
+
+/**
+ * Configure {@link org.glassfish.jersey.server.ServerProperties#RESPONSE_SET_STATUS_OVER_SEND_ERROR} by {@code true} -
+ * method {@link javax.servlet.http.HttpServletResponse#setStatus} will be called in case of errors
+ * (status {@code 4xx} or {@code 5xx}).
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@ApplicationPath(Jersey2176SetStatusApp.APP_PATH)
+public class Jersey2176SetStatusApp extends Jersey2176App {
+
+ public static final String APP_PATH = "set-status";
+
+ public Jersey2176SetStatusApp() {
+ super(true);
+ }
+
+}
diff --git a/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/MyException.java b/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/MyException.java
new file mode 100644
index 0000000..e7daf21
--- /dev/null
+++ b/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/MyException.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2176;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class MyException extends Exception {
+
+ public MyException(String message) {
+ super(message);
+ }
+}
diff --git a/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/MyWriterInterceptor.java b/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/MyWriterInterceptor.java
new file mode 100644
index 0000000..f4a4fcd
--- /dev/null
+++ b/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/MyWriterInterceptor.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2176;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.charset.Charset;
+
+import javax.ws.rs.ext.WriterInterceptor;
+import javax.ws.rs.ext.WriterInterceptorContext;
+
+import org.glassfish.jersey.message.MessageUtils;
+
+
+/**
+ * This just set new context output stream and test a clone method on set output stream instance is called.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class MyWriterInterceptor implements WriterInterceptor {
+
+ @Override
+ public void aroundWriteTo(final WriterInterceptorContext context) throws IOException {
+ final boolean fail = context.getHeaders().containsKey(Issue2176ReproducerResource.X_FAIL_HEADER);
+ final boolean responseEntity = context.getHeaders().containsKey(Issue2176ReproducerResource.X_RESPONSE_ENTITY_HEADER);
+
+ if (responseEntity) {
+ context.setOutputStream(
+ new MyOutputStream(context.getOutputStream(), MessageUtils.getCharset(context.getMediaType())));
+ }
+ context.proceed();
+ if (fail) {
+ throw new IllegalStateException("From MyWriterInterceptor");
+ }
+ }
+
+ private static class MyOutputStream extends OutputStream {
+ private final OutputStream delegate;
+ final Charset charset;
+ private final ByteArrayOutputStream localStream;
+
+ private MyOutputStream(final OutputStream delegate, final Charset charset) throws IOException {
+ this.delegate = delegate;
+ this.charset = charset;
+
+ this.localStream = new ByteArrayOutputStream();
+ localStream.write("[INTERCEPTOR]".getBytes(charset));
+ }
+
+ @Override
+ public void write(final int b) throws IOException {
+ localStream.write(b);
+ }
+
+ @Override
+ public void flush() throws IOException {
+ delegate.write(localStream.toByteArray());
+ localStream.reset();
+ delegate.flush();
+ }
+
+ @Override
+ public void close() throws IOException {
+ localStream.write("[/INTERCEPTOR]".getBytes(charset));
+
+ delegate.write(localStream.toByteArray());
+
+ delegate.close();
+ localStream.close();
+ }
+ }
+
+}
diff --git a/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/TraceResponseFilter.java b/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/TraceResponseFilter.java
new file mode 100644
index 0000000..c20ecf3
--- /dev/null
+++ b/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/TraceResponseFilter.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2176;
+
+import java.io.IOException;
+
+import javax.ws.rs.core.HttpHeaders;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class TraceResponseFilter implements Filter {
+
+ public static final String X_SERVER_DURATION_HEADER = "X-SERVER-DURATION";
+ public static final String X_STATUS_HEADER = "X-STATUS";
+ public static final String X_NO_FILTER_HEADER = "X-NO-FILTER";
+
+ @Override
+ public void init(final FilterConfig filterConfig) throws ServletException {
+ }
+
+ @Override
+ public void destroy() {
+ }
+
+ @Override
+ public void doFilter(final ServletRequest request, ServletResponse response, final FilterChain chain)
+ throws IOException, ServletException {
+ TraceResponseWrapper wrappedResponse = null;
+ if (((HttpServletRequest) request).getHeader(X_NO_FILTER_HEADER) == null) {
+ response = wrappedResponse = new TraceResponseWrapper((HttpServletResponse) response);
+ }
+ String status = "n/a";
+ final long startTime = System.nanoTime();
+ try {
+ chain.doFilter(request, response);
+ status = "OK";
+ } catch (final Throwable th) {
+ status = "FAIL";
+ } finally {
+ final long duration = System.nanoTime() - startTime;
+ ((HttpServletResponse) response).addHeader(X_SERVER_DURATION_HEADER, String.valueOf(duration));
+ ((HttpServletResponse) response).addHeader(X_STATUS_HEADER, status);
+ if (wrappedResponse != null) {
+ ((HttpServletResponse) response).setHeader(HttpHeaders.CONTENT_LENGTH, wrappedResponse.getContentLength());
+ wrappedResponse.writeBodyAndClose(response.getCharacterEncoding());
+ }
+ }
+ }
+
+}
diff --git a/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/TraceResponseWrapper.java b/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/TraceResponseWrapper.java
new file mode 100644
index 0000000..3e2f672
--- /dev/null
+++ b/tests/integration/jersey-2176/src/main/java/org/glassfish/jersey/tests/integration/jersey2176/TraceResponseWrapper.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2176;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class TraceResponseWrapper extends HttpServletResponseWrapper {
+ private final ByteArrayOutputStream localStream;
+
+ public TraceResponseWrapper(final HttpServletResponse response) throws IOException {
+ super(response);
+
+ localStream = new ByteArrayOutputStream();
+ localStream.write("[FILTER]".getBytes(response.getCharacterEncoding()));
+ }
+
+ @Override
+ public PrintWriter getWriter() throws IOException {
+ throw new IllegalStateException();
+ }
+
+ @Override
+ public ServletOutputStream getOutputStream() throws IOException {
+ return new ServletOutputStream() {
+ @Override
+ public void write(final int b) throws IOException {
+ localStream.write(b);
+ }
+ };
+ }
+
+ public void writeBodyAndClose(final String encoding) throws IOException {
+ localStream.write("[/FILTER]".getBytes(encoding));
+
+ super.getOutputStream().write(localStream.toByteArray());
+ super.getOutputStream().close();
+ localStream.close();
+ }
+
+ public String getContentLength() {
+ return String.valueOf(localStream.size() + "[/FILTER]".length());
+ }
+
+}
diff --git a/tests/integration/jersey-2176/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2176/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..ac9109f
--- /dev/null
+++ b/tests/integration/jersey-2176/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <filter>
+ <filter-name>TraceFilter</filter-name>
+ <filter-class>org.glassfish.jersey.tests.integration.jersey2176.TraceResponseFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>TraceFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+</web-app>
diff --git a/tests/integration/jersey-2176/src/test/java/org/glassfish/jersey/tests/integration/jersey2176/Jersey2176ITCaseBase.java b/tests/integration/jersey-2176/src/test/java/org/glassfish/jersey/tests/integration/jersey2176/Jersey2176ITCaseBase.java
new file mode 100644
index 0000000..ffeec36
--- /dev/null
+++ b/tests/integration/jersey-2176/src/test/java/org/glassfish/jersey/tests/integration/jersey2176/Jersey2176ITCaseBase.java
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2176;
+
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Reproducer tests for JERSEY-2176.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public abstract class Jersey2176ITCaseBase extends JerseyTest {
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testGetContent222() {
+ testGetContent(222, true);
+ }
+
+ @Test
+ public void testGetContent333() {
+ testGetContent(333, true);
+ }
+
+ @Test
+ public void testGetContent444() {
+ testGetContent(444, true);
+ }
+
+ @Test
+ public void testGetContent555() {
+ testGetContent(555, true);
+ }
+
+ @Test
+ public void testGetContent222NoResponseEntity() {
+ testGetContent(222, false);
+ }
+
+ @Test
+ public void testGetContent333NoResponseEntity() {
+ testGetContent(333, false);
+ }
+
+ @Test
+ public void testGetContent444NoResponseEntity() {
+ testGetContent(444, false);
+ }
+
+ @Test
+ public void testGetContent555NoResponseEntity() {
+ testGetContent(555, false);
+ }
+
+ @Test
+ public void testGetException_1() {
+ testGetException(-1, 500, false);
+ }
+
+ @Test
+ public void testGetException_2() {
+ testGetException(-2, 500, false);
+ }
+
+ @Test
+ public void testGetException_3() {
+ testGetException(-3, 321, false);
+ }
+
+ @Test
+ public void testGetException_4() {
+ testGetException(-4, 432, false);
+ }
+
+ @Test
+ public void testGetException222() {
+ testGetException(222, 500, true);
+ }
+
+ private void testGetContent(int uc, boolean responseEntity) {
+ String expectedContent = "ENTITY";
+ expectedContent = "[INTERCEPTOR]" + expectedContent + "[/INTERCEPTOR]";
+ expectedContent = "[FILTER]" + expectedContent + "[/FILTER]";
+
+ Invocation.Builder builder = target().path("/resource/" + uc).request();
+ if (responseEntity) {
+ builder.header(Issue2176ReproducerResource.X_RESPONSE_ENTITY_HEADER, true);
+ } else {
+ builder.header(TraceResponseFilter.X_NO_FILTER_HEADER, true);
+ }
+
+ final Response response = builder.get();
+ final String assertMessage = uc + "|" + responseEntity;
+
+ Assert.assertEquals(assertMessage, uc, response.getStatus());
+ if (!sendErrorExpected(uc, responseEntity)) {
+ Assert.assertEquals(assertMessage, "OK", response.getHeaderString(TraceResponseFilter.X_STATUS_HEADER));
+ Assert.assertNotNull(assertMessage, response.getHeaderString(TraceResponseFilter.X_SERVER_DURATION_HEADER));
+ if (responseEntity) {
+ Assert.assertEquals(assertMessage, expectedContent, response.readEntity(String.class));
+ Assert.assertEquals(assertMessage, String.valueOf(expectedContent.length()),
+ response.getHeaderString(HttpHeaders.CONTENT_LENGTH));
+ }
+ } else {
+ Assert.assertNull(assertMessage, response.getHeaderString(TraceResponseFilter.X_STATUS_HEADER));
+ Assert.assertNull(assertMessage, response.getHeaderString(TraceResponseFilter.X_SERVER_DURATION_HEADER));
+ }
+ }
+
+ private void testGetException(int uc, int expectedStatus, boolean fail) {
+ Invocation.Builder builder = target().path("/resource/" + uc).request();
+ builder = builder.header(Issue2176ReproducerResource.X_RESPONSE_ENTITY_HEADER, true);
+ if (fail) {
+ builder = builder.header(Issue2176ReproducerResource.X_FAIL_HEADER, true);
+ }
+
+ final Response response = builder.get();
+
+ final String expectedContent = "[FILTER][/FILTER]";
+ final String assertMessage = uc + ":" + expectedStatus + "|" + fail;
+
+ Assert.assertEquals(assertMessage, expectedStatus, response.getStatus());
+ if (!sendErrorExpected(expectedStatus, false)) {
+ Assert.assertEquals(assertMessage, expectedStatus == 500 ? "FAIL" : "OK",
+ response.getHeaderString(TraceResponseFilter.X_STATUS_HEADER));
+ Assert.assertNotNull(assertMessage, response.getHeaderString(TraceResponseFilter.X_SERVER_DURATION_HEADER));
+ Assert.assertEquals(assertMessage, String.valueOf(expectedContent.length()),
+ response.getHeaderString(HttpHeaders.CONTENT_LENGTH));
+ } else {
+ Assert.assertNull(assertMessage, response.getHeaderString(TraceResponseFilter.X_STATUS_HEADER));
+ Assert.assertNull(assertMessage, response.getHeaderString(TraceResponseFilter.X_SERVER_DURATION_HEADER));
+ }
+ }
+
+ private boolean sendErrorExpected(final int uc, final boolean responseEntity) {
+ return !((Jersey2176App) configure()).isSetStatusOverSendError() && (uc >= 400) && !responseEntity;
+ }
+
+}
diff --git a/tests/integration/jersey-2176/src/test/java/org/glassfish/jersey/tests/integration/jersey2176/Jersey2176SendErrorITCase.java b/tests/integration/jersey-2176/src/test/java/org/glassfish/jersey/tests/integration/jersey2176/Jersey2176SendErrorITCase.java
new file mode 100644
index 0000000..9eb2648
--- /dev/null
+++ b/tests/integration/jersey-2176/src/test/java/org/glassfish/jersey/tests/integration/jersey2176/Jersey2176SendErrorITCase.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2176;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.UriBuilder;
+import java.net.URI;
+
+/**
+ * Reproducer tests for JERSEY-2176.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class Jersey2176SendErrorITCase extends Jersey2176ITCaseBase {
+
+ @Override
+ protected Application configure() {
+ return new Jersey2176SendErrorApp();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path(Jersey2176SendErrorApp.APP_PATH).build();
+ }
+
+}
diff --git a/tests/integration/jersey-2176/src/test/java/org/glassfish/jersey/tests/integration/jersey2176/Jersey2176SetStatusITCase.java b/tests/integration/jersey-2176/src/test/java/org/glassfish/jersey/tests/integration/jersey2176/Jersey2176SetStatusITCase.java
new file mode 100644
index 0000000..f894ee0
--- /dev/null
+++ b/tests/integration/jersey-2176/src/test/java/org/glassfish/jersey/tests/integration/jersey2176/Jersey2176SetStatusITCase.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2176;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.UriBuilder;
+import java.net.URI;
+
+/**
+ * Reproducer tests for JERSEY-2176.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class Jersey2176SetStatusITCase extends Jersey2176ITCaseBase {
+
+ @Override
+ protected Application configure() {
+ return new Jersey2176SetStatusApp();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path(Jersey2176SetStatusApp.APP_PATH).build();
+ }
+
+}
diff --git a/tests/integration/jersey-2184/pom.xml b/tests/integration/jersey-2184/pom.xml
new file mode 100644
index 0000000..255156d
--- /dev/null
+++ b/tests/integration/jersey-2184/pom.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2184</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2184</name>
+
+ <description>
+ Servlet integration test - JERSEY-2184 - ServletContext injection into Application subclass constructor.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>${servlet3.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2184/src/main/java/org/glassfish/jersey/tests/integration/jersey2184/App.java b/tests/integration/jersey-2184/src/main/java/org/glassfish/jersey/tests/integration/jersey2184/App.java
new file mode 100644
index 0000000..04a279f
--- /dev/null
+++ b/tests/integration/jersey-2184/src/main/java/org/glassfish/jersey/tests/integration/jersey2184/App.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2184;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Context;
+
+import javax.servlet.ServletContext;
+
+/**
+ * Test Application subclass for JERSEY-2184 integration test.
+ *
+ * Tests the ability to inject {@link ServletContext} into application subclass constructor
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+public class App extends Application {
+
+ /** constructor-injected servletContext */
+ private ServletContext ctx;
+
+ public App(@Context ServletContext servletContext) {
+ this.ctx = servletContext;
+ }
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ HashSet<Class<?>> classes = new HashSet<>();
+ String dynamicClassName = ctx.getInitParameter("dynamicClassName");
+ Class<?> clazz = null;
+ if (classes.isEmpty()) {
+ try {
+ clazz = Class.forName(dynamicClassName);
+ } catch (ClassNotFoundException e) {
+ // swallow the exception - if class is not loaded, the integration test will fail
+ }
+
+ if (clazz != null) {
+ classes.add(clazz);
+ }
+ }
+ return classes;
+ }
+}
diff --git a/tests/integration/jersey-2184/src/main/java/org/glassfish/jersey/tests/integration/jersey2184/MonkeyResource.java b/tests/integration/jersey-2184/src/main/java/org/glassfish/jersey/tests/integration/jersey2184/MonkeyResource.java
new file mode 100644
index 0000000..bd9356b
--- /dev/null
+++ b/tests/integration/jersey-2184/src/main/java/org/glassfish/jersey/tests/integration/jersey2184/MonkeyResource.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2184;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * Test resource for the servlet3-webapp example.
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+@Path("monkey")
+public class MonkeyResource {
+ @GET
+ @Produces("text/plain")
+ public String chatter() {
+ return "Oooh!";
+ }
+}
diff --git a/tests/integration/jersey-2184/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2184/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..98b165c
--- /dev/null
+++ b/tests/integration/jersey-2184/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
+ <servlet>
+ <servlet-name>org.glassfish.jersey.tests.integration.jersey2184.App</servlet-name>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>org.glassfish.jersey.tests.integration.jersey2184.App</servlet-name>
+ <url-pattern>/zoo/*</url-pattern>
+ </servlet-mapping>
+ <context-param>
+ <description>Context parameter to test the correct ServletContext injection into Application subclass.</description>
+ <param-name>dynamicClassName</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2184.MonkeyResource</param-value>
+ </context-param>
+</web-app>
+
diff --git a/tests/integration/jersey-2184/src/test/java/org/glassfish/jersey/tests/integration/jersey2184/Jersey2184ITCase.java b/tests/integration/jersey-2184/src/test/java/org/glassfish/jersey/tests/integration/jersey2184/Jersey2184ITCase.java
new file mode 100644
index 0000000..794203d
--- /dev/null
+++ b/tests/integration/jersey-2184/src/test/java/org/glassfish/jersey/tests/integration/jersey2184/Jersey2184ITCase.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.jersey2184;
+
+import java.net.URI;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.TestProperties;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the JERSEY-2184 fix (the ability to inject ServletContext into application subclass constructor).
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+public class Jersey2184ITCase extends JerseyTest {
+
+ @Before
+ public void setup() {
+ Assume.assumeTrue(Hk2InjectionManagerFactory.isImmediateStrategy());
+ }
+
+ @Override
+ protected Application configure() {
+ enable(TestProperties.LOG_TRAFFIC);
+ return new Application(); // dummy Application instance for the test framework - will no be used.
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ return UriBuilder.fromUri(super.getBaseUri()).path("zoo").build();
+ }
+
+ /**
+ * Tests if {@link javax.servlet.ServletContext} has been correctly injected into {@link App} constructor parameter;
+ * The resource under this URL is being loaded dynamically based on a context parameter in the web.xml,
+ * so if injection fails, the resource will not be available.
+ */
+ @Test
+ public void testInjection() {
+ String s = target().path("monkey").request().get(String.class);
+ assertEquals("Oooh!", s);
+ }
+}
diff --git a/tests/integration/jersey-2255/pom.xml b/tests/integration/jersey-2255/pom.xml
new file mode 100644
index 0000000..3b1f2ad
--- /dev/null
+++ b/tests/integration/jersey-2255/pom.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2255</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2255</name>
+
+ <description>Filtering hierarchy test - JERSEY-2255 - Entity Data Filtering should support inherited fields</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-entity-filtering</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-moxy</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2255/src/main/java/org/glassfish/jersey/tests/integration/jersey2255/Issue2255Resource.java b/tests/integration/jersey-2255/src/main/java/org/glassfish/jersey/tests/integration/jersey2255/Issue2255Resource.java
new file mode 100644
index 0000000..0ac2f37
--- /dev/null
+++ b/tests/integration/jersey-2255/src/main/java/org/glassfish/jersey/tests/integration/jersey2255/Issue2255Resource.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2255;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.internal.inject.AnnotationLiteral;
+import org.glassfish.jersey.message.filtering.EntityFiltering;
+
+/**
+ * Test resource.
+ *
+ * @author Eric Miles (emilesvt at gmail.com)
+ */
+@Path("/")
+@Consumes("application/json")
+@Produces("application/json")
+public class Issue2255Resource {
+
+ public static class A {
+
+ public A() {
+ }
+
+ public A(String fieldA1) {
+ this.fieldA1 = fieldA1;
+ }
+
+ private String fieldA1;
+
+ @Detailed
+ public String getFieldA1() {
+ return fieldA1;
+ }
+
+ public void setFieldA1(final String fieldA1) {
+ this.fieldA1 = fieldA1;
+ }
+ }
+
+ public static class B extends A {
+
+ public B() {
+ }
+
+ public B(String fieldA1, String fieldB1) {
+ super(fieldA1);
+ this.fieldB1 = fieldB1;
+ }
+
+ private String fieldB1;
+
+ public String getFieldB1() {
+ return fieldB1;
+ }
+
+ public void setFieldB1(final String fieldB1) {
+ this.fieldB1 = fieldB1;
+ }
+ }
+
+ @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
+ @Retention(RetentionPolicy.RUNTIME)
+ @Documented
+ @EntityFiltering
+ public static @interface Detailed {
+
+ /**
+ * Factory class for creating instances of {@code ProjectDetailedView} annotation.
+ */
+ public static class Factory
+ extends AnnotationLiteral<Detailed>
+ implements Detailed {
+
+ private Factory() {
+ }
+
+ public static Detailed get() {
+ return new Factory();
+ }
+ }
+ }
+
+ @Path("A")
+ @GET
+ public Response getA(@QueryParam("detailed") final boolean isDetailed) {
+ return Response
+ .ok()
+ .entity(new A("fieldA1Value"), isDetailed ? new Annotation[] {Detailed.Factory.get()} : new Annotation[0])
+ .build();
+ }
+
+ @Path("B")
+ @GET
+ public Response getB(@QueryParam("detailed") final boolean isDetailed) {
+ return Response
+ .ok()
+ .entity(new B("fieldA1Value", "fieldB1Value"),
+ isDetailed ? new Annotation[] {Detailed.Factory.get()} : new Annotation[0])
+ .build();
+ }
+
+}
diff --git a/tests/integration/jersey-2255/src/main/java/org/glassfish/jersey/tests/integration/jersey2255/Jersey2255.java b/tests/integration/jersey-2255/src/main/java/org/glassfish/jersey/tests/integration/jersey2255/Jersey2255.java
new file mode 100644
index 0000000..a1dd1b3
--- /dev/null
+++ b/tests/integration/jersey-2255/src/main/java/org/glassfish/jersey/tests/integration/jersey2255/Jersey2255.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2255;
+
+import org.glassfish.jersey.message.filtering.EntityFilteringFeature;
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * JAX-RS application for the JERSEY-2255 reproducer test.
+ *
+ * @author Eric Miles (emilesvt at gmail.com)
+ */
+public class Jersey2255 extends ResourceConfig {
+
+ public Jersey2255() {
+ register(Issue2255Resource.class);
+ register(EntityFilteringFeature.class);
+ }
+}
diff --git a/tests/integration/jersey-2255/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2255/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..b6b050c
--- /dev/null
+++ b/tests/integration/jersey-2255/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>jersey2255Servlet</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2255.Jersey2255</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>jersey2255Servlet</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/jersey-2255/src/test/java/org/glassfish/jersey/tests/integration/jersey2255/Jersey2255ITCase.java b/tests/integration/jersey-2255/src/test/java/org/glassfish/jersey/tests/integration/jersey2255/Jersey2255ITCase.java
new file mode 100644
index 0000000..a996eba
--- /dev/null
+++ b/tests/integration/jersey-2255/src/test/java/org/glassfish/jersey/tests/integration/jersey2255/Jersey2255ITCase.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2255;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.TestProperties;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+import org.glassfish.jersey.tests.integration.jersey2255.Issue2255Resource.A;
+import org.glassfish.jersey.tests.integration.jersey2255.Issue2255Resource.B;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNull;
+
+/**
+ * Reproducer tests for JERSEY-2255.
+ *
+ * @author Eric Miles (emilesvt at gmail.com)
+ */
+public class Jersey2255ITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ enable(TestProperties.LOG_TRAFFIC);
+ enable(TestProperties.DUMP_ENTITY);
+
+ return new Jersey2255();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ /**
+ * Server side response is wrapped, needs to be read to wrapper class.
+ */
+ @Test
+ public void testClassAGet() {
+ final Response response = target("A").request().get();
+ final A entity = response.readEntity(A.class);
+
+ assertThat(response.getStatus(), equalTo(200));
+ assertNull(entity.getFieldA1());
+ }
+
+ @Test
+ public void testDetailedClassAGet() {
+ final Response response = target("A").queryParam("detailed", true).request().get();
+ final A entity = response.readEntity(A.class);
+
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(entity.getFieldA1(), equalTo("fieldA1Value"));
+ }
+
+ /**
+ * Server side response is returned as orig class.
+ */
+ @Test
+ public void testDetailedClassBGet() {
+ final Response response = target("B").queryParam("detailed", true).request().get();
+ final B entity = response.readEntity(B.class);
+
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(entity.getFieldA1(), equalTo("fieldA1Value"));
+ assertThat(entity.getFieldB1(), equalTo("fieldB1Value"));
+ }
+
+ @Test
+ public void testClassBGet() {
+ final Response response = target("B").request().get();
+ final B entity = response.readEntity(B.class);
+
+ assertThat(response.getStatus(), equalTo(200));
+ assertNull(entity.getFieldA1());
+ assertThat(entity.getFieldB1(), equalTo("fieldB1Value"));
+ }
+}
diff --git a/tests/integration/jersey-2322/pom.xml b/tests/integration/jersey-2322/pom.xml
new file mode 100644
index 0000000..a64aa6b
--- /dev/null
+++ b/tests/integration/jersey-2322/pom.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2322</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2322</name>
+
+ <description>Servlet integration test - JERSEY-2322 - No way to configure auto-discovered Jackson 2.x ObjectMapper</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-json-jackson</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-metainf-services</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2322/src/main/java/org/glassfish/jersey/tests/integration/jersey2322/Issue2322Resource.java b/tests/integration/jersey-2322/src/main/java/org/glassfish/jersey/tests/integration/jersey2322/Issue2322Resource.java
new file mode 100644
index 0000000..7e8b05f
--- /dev/null
+++ b/tests/integration/jersey-2322/src/main/java/org/glassfish/jersey/tests/integration/jersey2322/Issue2322Resource.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2322;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * Test resource.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Path("/")
+@Consumes("application/json")
+@Produces("application/json")
+public class Issue2322Resource {
+
+ public static class JsonString1 {
+ private String value;
+
+ public JsonString1() {
+ }
+ public JsonString1(String value) {
+ this.value = value;
+ }
+ public String getValue() {
+ return value;
+ }
+ public void setValue(String value) {
+ this.value = value;
+ }
+ }
+
+ public static class JsonString2 {
+ private String value;
+
+ public JsonString2() {
+ }
+ public JsonString2(String value) {
+ this.value = value;
+ }
+ public String getValue() {
+ return value;
+ }
+ public void setValue(String value) {
+ this.value = value;
+ }
+ }
+
+ @Path("1")
+ @PUT
+ public JsonString1 put(final JsonString1 wrapper) {
+ return new JsonString1("Hello " + wrapper.getValue());
+ }
+
+ @Path("2")
+ @PUT
+ public JsonString2 put(final JsonString2 wrapper) {
+ return new JsonString2("Hi " + wrapper.getValue());
+ }
+
+}
diff --git a/tests/integration/jersey-2322/src/main/java/org/glassfish/jersey/tests/integration/jersey2322/Jersey2322.java b/tests/integration/jersey-2322/src/main/java/org/glassfish/jersey/tests/integration/jersey2322/Jersey2322.java
new file mode 100644
index 0000000..1e79c1e
--- /dev/null
+++ b/tests/integration/jersey-2322/src/main/java/org/glassfish/jersey/tests/integration/jersey2322/Jersey2322.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2322;
+
+import org.glassfish.jersey.jackson.JacksonFeature;
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * JAX-RS application for the JERSEY-2322 reproducer test.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class Jersey2322 extends ResourceConfig {
+
+ public Jersey2322() {
+ register(Issue2322Resource.class);
+ register(JacksonFeature.class);
+ register(MyObjectMapperProvider.class);
+ }
+}
diff --git a/tests/integration/jersey-2322/src/main/java/org/glassfish/jersey/tests/integration/jersey2322/MyObjectMapperProvider.java b/tests/integration/jersey-2322/src/main/java/org/glassfish/jersey/tests/integration/jersey2322/MyObjectMapperProvider.java
new file mode 100644
index 0000000..61fe632
--- /dev/null
+++ b/tests/integration/jersey-2322/src/main/java/org/glassfish/jersey/tests/integration/jersey2322/MyObjectMapperProvider.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2322;
+
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Provider
+public class MyObjectMapperProvider implements ContextResolver<ObjectMapper> {
+
+ @Override
+ public ObjectMapper getContext(Class<?> type) {
+ if (type == Issue2322Resource.JsonString1.class) {
+ ObjectMapper result = new ObjectMapper();
+ result.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
+ result.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false);
+ return result;
+ } else {
+ return new ObjectMapper();
+ }
+ }
+}
diff --git a/tests/integration/jersey-2322/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2322/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..727ad27
--- /dev/null
+++ b/tests/integration/jersey-2322/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>jersey2322Servlet</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2322.Jersey2322</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>jersey2322Servlet</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/jersey-2322/src/test/java/org/glassfish/jersey/tests/integration/jersey2322/Jersey2322ITCase.java b/tests/integration/jersey-2322/src/test/java/org/glassfish/jersey/tests/integration/jersey2322/Jersey2322ITCase.java
new file mode 100644
index 0000000..4f973a9
--- /dev/null
+++ b/tests/integration/jersey-2322/src/test/java/org/glassfish/jersey/tests/integration/jersey2322/Jersey2322ITCase.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2322;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.TestProperties;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Reproducer tests for JERSEY-2322.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class Jersey2322ITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ enable(TestProperties.LOG_TRAFFIC);
+ enable(TestProperties.DUMP_ENTITY);
+ return new Jersey2322();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ /**
+ * Server side response is wrapped, needs to be read to wrapper class.
+ */
+ @Test
+ public void testJackson2JsonPut1() {
+ final Response response = target("1").request().put(Entity.json(new Issue2322Resource.JsonString1("foo")));
+
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(Wrapper1.class).getJsonString1().getValue(), equalTo("Hello foo"));
+ }
+
+ /**
+ * Server side response is returned as orig class.
+ */
+ @Test
+ public void testJackson2JsonPut2() {
+ final Response response = target("2").request().put(Entity.json(new Issue2322Resource.JsonString2("foo")));
+
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(Issue2322Resource.JsonString2.class).getValue(), equalTo("Hi foo"));
+ }
+
+
+ public static class Wrapper1 {
+ @JsonProperty("JsonString1")
+ Issue2322Resource.JsonString1 jsonString1;
+
+ public Issue2322Resource.JsonString1 getJsonString1() {
+ return jsonString1;
+ }
+
+ public void setJsonString1(Issue2322Resource.JsonString1 jsonString1) {
+ this.jsonString1 = jsonString1;
+ }
+ }
+
+}
diff --git a/tests/integration/jersey-2335/pom.xml b/tests/integration/jersey-2335/pom.xml
new file mode 100644
index 0000000..075bed8
--- /dev/null
+++ b/tests/integration/jersey-2335/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2335</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2335</name>
+
+ <description>Servlet integration test - JERSEY-2335 - Providers do not get injected properly</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-metainf-services</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2335/src/main/java/org/glassfish/jersey/tests/integration/jersey2335/ConstructorInjectedProvider.java b/tests/integration/jersey-2335/src/main/java/org/glassfish/jersey/tests/integration/jersey2335/ConstructorInjectedProvider.java
new file mode 100644
index 0000000..7f59d01
--- /dev/null
+++ b/tests/integration/jersey-2335/src/main/java/org/glassfish/jersey/tests/integration/jersey2335/ConstructorInjectedProvider.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2335;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.Providers;
+
+import org.glassfish.jersey.message.MessageUtils;
+
+/**
+ * Constructor injected provider to prove that provider registered via meta-inf/services
+ * mechanism gets constructed via HK2 and so the constructor parameters are properly injected.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Provider
+@Produces("text/ctor-injected")
+public class ConstructorInjectedProvider implements MessageBodyWriter<String> {
+
+ Providers providers;
+
+ public ConstructorInjectedProvider(@Context final Providers providers) {
+ this.providers = providers;
+ }
+
+ @Override
+ public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType) {
+ return type == String.class;
+ }
+
+ @Override
+ public long getSize(final String t, final Class<?> type, final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType) {
+ return -1;
+ }
+
+ @Override
+ public void writeTo(final String t, final Class<?> type, final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders,
+ final OutputStream entityStream) throws IOException, WebApplicationException {
+ final MessageBodyWriter<String> plainTextWriter =
+ providers.getMessageBodyWriter(String.class, genericType, annotations, MediaType.TEXT_PLAIN_TYPE);
+ entityStream.write("via ctor injected provider:".getBytes(MessageUtils.getCharset(mediaType)));
+ plainTextWriter.writeTo(t, type, genericType, annotations, mediaType, httpHeaders, entityStream);
+ }
+}
diff --git a/tests/integration/jersey-2335/src/main/java/org/glassfish/jersey/tests/integration/jersey2335/FieldInjectedProvider.java b/tests/integration/jersey-2335/src/main/java/org/glassfish/jersey/tests/integration/jersey2335/FieldInjectedProvider.java
new file mode 100644
index 0000000..5c6bc08
--- /dev/null
+++ b/tests/integration/jersey-2335/src/main/java/org/glassfish/jersey/tests/integration/jersey2335/FieldInjectedProvider.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2335;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.Providers;
+
+import org.glassfish.jersey.message.MessageUtils;
+
+/**
+ * Field injected provider to prove that provider registered via meta-inf/services
+ * mechanism gets injected via HK2.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Provider
+@Produces("text/field-injected")
+public class FieldInjectedProvider implements MessageBodyWriter<String> {
+
+ @Context Providers providers;
+
+ @Override
+ public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType) {
+ return type == String.class;
+ }
+
+ @Override
+ public long getSize(final String t, final Class<?> type, final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType) {
+ return -1;
+ }
+
+ @Override
+ public void writeTo(final String t, final Class<?> type, final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders,
+ final OutputStream entityStream) throws IOException, WebApplicationException {
+ final MessageBodyWriter<String> plainTextWriter =
+ providers.getMessageBodyWriter(String.class, genericType, annotations, MediaType.TEXT_PLAIN_TYPE);
+ entityStream.write("via field injected provider:".getBytes(MessageUtils.getCharset(mediaType)));
+ plainTextWriter.writeTo(t, type, genericType, annotations, mediaType, httpHeaders, entityStream);
+ }
+}
diff --git a/tests/integration/jersey-2335/src/main/java/org/glassfish/jersey/tests/integration/jersey2335/Issue2335Resource.java b/tests/integration/jersey-2335/src/main/java/org/glassfish/jersey/tests/integration/jersey2335/Issue2335Resource.java
new file mode 100644
index 0000000..c4a44f6
--- /dev/null
+++ b/tests/integration/jersey-2335/src/main/java/org/glassfish/jersey/tests/integration/jersey2335/Issue2335Resource.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2335;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * Test resource that provides a simple text response.
+ * The response text then gets serialized using message body writer
+ * specified by media type.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("/text")
+public class Issue2335Resource {
+
+ @GET
+ @Produces("text/*")
+ public String get() {
+ return "Hey";
+ }
+}
diff --git a/tests/integration/jersey-2335/src/main/java/org/glassfish/jersey/tests/integration/jersey2335/Jersey2335.java b/tests/integration/jersey-2335/src/main/java/org/glassfish/jersey/tests/integration/jersey2335/Jersey2335.java
new file mode 100644
index 0000000..10ff7e2
--- /dev/null
+++ b/tests/integration/jersey-2335/src/main/java/org/glassfish/jersey/tests/integration/jersey2335/Jersey2335.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2335;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * JAX-RS application for the JERSEY-2335 reproducer test.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class Jersey2335 extends ResourceConfig {
+
+ public Jersey2335() {
+ register(Issue2335Resource.class);
+ }
+}
diff --git a/tests/integration/jersey-2335/src/main/resources/META-INF/services/javax.ws.rs.ext.MessageBodyWriter b/tests/integration/jersey-2335/src/main/resources/META-INF/services/javax.ws.rs.ext.MessageBodyWriter
new file mode 100644
index 0000000..f5bca8b
--- /dev/null
+++ b/tests/integration/jersey-2335/src/main/resources/META-INF/services/javax.ws.rs.ext.MessageBodyWriter
@@ -0,0 +1,2 @@
+org.glassfish.jersey.tests.integration.jersey2335.FieldInjectedProvider
+org.glassfish.jersey.tests.integration.jersey2335.ConstructorInjectedProvider
\ No newline at end of file
diff --git a/tests/integration/jersey-2335/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2335/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..26d8b4a
--- /dev/null
+++ b/tests/integration/jersey-2335/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>jersey2335Servlet</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2335.Jersey2335</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>jersey2335Servlet</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/jersey-2335/src/test/java/org/glassfish/jersey/tests/integration/jersey2335/Jersey2335ITCase.java b/tests/integration/jersey-2335/src/test/java/org/glassfish/jersey/tests/integration/jersey2335/Jersey2335ITCase.java
new file mode 100644
index 0000000..dfa5732
--- /dev/null
+++ b/tests/integration/jersey-2335/src/test/java/org/glassfish/jersey/tests/integration/jersey2335/Jersey2335ITCase.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2335;
+
+import java.net.ConnectException;
+
+import javax.ws.rs.ProcessingException;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.fail;
+
+/**
+ * Reproducer tests for JERSEY-2335.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class Jersey2335ITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Jersey2335();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testGetFieldInjected() throws Exception {
+ final Response response = target().path("text").request().accept("text/field-injected").get();
+
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(String.class), equalTo("via field injected provider:Hey"));
+ }
+
+ @Test
+ public void testGetConstructorInjected() throws Exception {
+ final Response response = target().path("text").request().accept("text/ctor-injected").get();
+
+ assertThat(response.getStatus(), equalTo(200));
+ assertThat(response.readEntity(String.class), equalTo("via ctor injected provider:Hey"));
+ }
+}
diff --git a/tests/integration/jersey-2421/pom.xml b/tests/integration/jersey-2421/pom.xml
new file mode 100644
index 0000000..edae017
--- /dev/null
+++ b/tests/integration/jersey-2421/pom.xml
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2421</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2421</name>
+
+ <description>Client integration test - JERSEY-2421 - MultiPartFeature requires jersey-server to be on the class-path</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-multipart</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2421/src/test/java/org/glassfish/jersey/tests/integration/jersey2421/Jersey2421Test.java b/tests/integration/jersey-2421/src/test/java/org/glassfish/jersey/tests/integration/jersey2421/Jersey2421Test.java
new file mode 100644
index 0000000..dc71185
--- /dev/null
+++ b/tests/integration/jersey-2421/src/test/java/org/glassfish/jersey/tests/integration/jersey2421/Jersey2421Test.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2421;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.concurrent.Future;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Configuration;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.client.ClientRequest;
+import org.glassfish.jersey.client.ClientResponse;
+import org.glassfish.jersey.client.spi.AsyncConnectorCallback;
+import org.glassfish.jersey.client.spi.Connector;
+import org.glassfish.jersey.client.spi.ConnectorProvider;
+import org.glassfish.jersey.media.multipart.FormDataBodyPart;
+import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+import org.glassfish.jersey.media.multipart.FormDataMultiPart;
+import org.glassfish.jersey.media.multipart.MultiPart;
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
+import org.glassfish.jersey.message.internal.NullOutputStream;
+import org.glassfish.jersey.message.internal.OutboundMessageContext;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Reproducer tests for JERSEY-2421.
+ *
+ * @author Michal Gajdos
+ */
+public class Jersey2421Test {
+
+ private static class TestConnector implements Connector, ConnectorProvider {
+
+ @Override
+ public ClientResponse apply(final ClientRequest request) {
+ try {
+ request.setStreamProvider(new OutboundMessageContext.StreamProvider() {
+ @Override
+ public OutputStream getOutputStream(final int contentLength) throws IOException {
+ return new NullOutputStream();
+ }
+ });
+ request.writeEntity();
+
+ if (request.getHeaderString("Content-Type").contains("boundary")) {
+ return new ClientResponse(Response.Status.OK, request);
+ }
+ } catch (final IOException ioe) {
+ // NOOP
+ }
+ return new ClientResponse(Response.Status.BAD_REQUEST, request);
+ }
+
+ @Override
+ public Future<?> apply(final ClientRequest request, final AsyncConnectorCallback callback) {
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public void close() {
+ }
+
+ @Override
+ public Connector getConnector(final Client client, final Configuration runtimeConfig) {
+ return this;
+ }
+ }
+
+ /**
+ * Test that multipart feature works on the client-side - custom connector checks presence of {@code boundary} parameter in
+ * the {@code Content-Type} header (the header is added to the request in MBW).
+ */
+ @Test
+ public void testMultiPartFeatureOnClient() throws Exception {
+ final Client client = ClientBuilder.newClient(new ClientConfig().connectorProvider(new TestConnector()))
+ .register(MultiPartFeature.class);
+
+ final MultiPart entity = new FormDataMultiPart()
+ .bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("part").build(), "CONTENT"));
+
+ final Response response = client.target("http://localhost").request()
+ .post(Entity.entity(entity, MediaType.MULTIPART_FORM_DATA_TYPE));
+
+ assertThat(response.getStatus(), is(200));
+ }
+
+ /**
+ * Test that classes from jersey-server module cannot be loaded.
+ */
+ @Test(expected = ClassNotFoundException.class)
+ public void testLoadJerseyServerClass() throws Exception {
+ Class.forName("org.glassfish.jersey.server.ResourceConfig");
+ }
+}
diff --git a/tests/integration/jersey-2551/pom.xml b/tests/integration/jersey-2551/pom.xml
new file mode 100644
index 0000000..c3fd8fa
--- /dev/null
+++ b/tests/integration/jersey-2551/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2551</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2551</name>
+
+ <description>Servlet integration test - JERSEY-2551 - Injections#generator field is hard coded to ServiceLocatorGeneratorImpl</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2551/src/main/java/org/glassfish/jersey/tests/integration/jersey2551/Jersey2551.java b/tests/integration/jersey-2551/src/main/java/org/glassfish/jersey/tests/integration/jersey2551/Jersey2551.java
new file mode 100644
index 0000000..13f3277
--- /dev/null
+++ b/tests/integration/jersey-2551/src/main/java/org/glassfish/jersey/tests/integration/jersey2551/Jersey2551.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2551;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * JAX-RS application for the JERSEY-2551 reproducer test.
+ *
+ * @author Michal Gajdos
+ */
+public class Jersey2551 extends ResourceConfig {
+
+ public Jersey2551() {
+ register(Resource.class);
+ }
+}
diff --git a/tests/integration/jersey-2551/src/main/java/org/glassfish/jersey/tests/integration/jersey2551/Resource.java b/tests/integration/jersey-2551/src/main/java/org/glassfish/jersey/tests/integration/jersey2551/Resource.java
new file mode 100644
index 0000000..04dbe89
--- /dev/null
+++ b/tests/integration/jersey-2551/src/main/java/org/glassfish/jersey/tests/integration/jersey2551/Resource.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2551;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+import javax.inject.Inject;
+
+import org.glassfish.hk2.api.ServiceLocator;
+
+/**
+ * @author Michal Gajdos
+ */
+@Path("/")
+public class Resource {
+
+ @Inject
+ private ServiceLocator locator;
+
+ @GET
+ public Response get() {
+ return locator instanceof ServiceLocatorGenerator.CustomServiceLocator
+ ? Response.ok().build() : Response.serverError().build();
+ }
+}
diff --git a/tests/integration/jersey-2551/src/main/java/org/glassfish/jersey/tests/integration/jersey2551/ServiceLocatorGenerator.java b/tests/integration/jersey-2551/src/main/java/org/glassfish/jersey/tests/integration/jersey2551/ServiceLocatorGenerator.java
new file mode 100644
index 0000000..610ba43
--- /dev/null
+++ b/tests/integration/jersey-2551/src/main/java/org/glassfish/jersey/tests/integration/jersey2551/ServiceLocatorGenerator.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2551;
+
+import javax.inject.Singleton;
+
+import org.glassfish.hk2.api.DynamicConfigurationService;
+import org.glassfish.hk2.api.ServiceLocator;
+import org.glassfish.hk2.utilities.BuilderHelper;
+
+import org.jvnet.hk2.external.generator.ServiceLocatorGeneratorImpl;
+import org.jvnet.hk2.internal.DefaultClassAnalyzer;
+import org.jvnet.hk2.internal.DynamicConfigurationImpl;
+import org.jvnet.hk2.internal.DynamicConfigurationServiceImpl;
+import org.jvnet.hk2.internal.ServiceLocatorImpl;
+import org.jvnet.hk2.internal.Utilities;
+
+/**
+ * @author Michal Gajdos
+ */
+public class ServiceLocatorGenerator extends ServiceLocatorGeneratorImpl {
+
+ @Override
+ public ServiceLocator create(final String name, final ServiceLocator parent) {
+ if (parent != null && !(parent instanceof ServiceLocatorImpl)) {
+ throw new AssertionError("parent must be a " + ServiceLocatorImpl.class.getName()
+ + " instead it is a " + parent.getClass().getName());
+ }
+
+ final ServiceLocatorImpl sli = new CustomServiceLocator(name, (ServiceLocatorImpl) parent);
+
+ final DynamicConfigurationImpl dci = new DynamicConfigurationImpl(sli);
+
+ // The service locator itself
+ dci.bind(Utilities.getLocatorDescriptor(sli));
+
+ // The injection resolver for three thirty
+ dci.addActiveDescriptor(Utilities.getThreeThirtyDescriptor(sli));
+
+ // The dynamic configuration utility
+ dci.bind(BuilderHelper.link(DynamicConfigurationServiceImpl.class, false)
+ .to(DynamicConfigurationService.class)
+ .in(Singleton.class.getName())
+ .localOnly()
+ .build());
+
+ dci.bind(BuilderHelper.createConstantDescriptor(
+ new DefaultClassAnalyzer(sli)));
+
+ dci.commit();
+
+ return sli;
+ }
+
+ class CustomServiceLocator extends ServiceLocatorImpl {
+
+ public CustomServiceLocator(final String name, final ServiceLocatorImpl parent) {
+ super(name, parent);
+ }
+ }
+}
diff --git a/tests/integration/jersey-2551/src/main/resources/META-INF/services/org.glassfish.hk2.extension.ServiceLocatorGenerator b/tests/integration/jersey-2551/src/main/resources/META-INF/services/org.glassfish.hk2.extension.ServiceLocatorGenerator
new file mode 100644
index 0000000..ad70f6f
--- /dev/null
+++ b/tests/integration/jersey-2551/src/main/resources/META-INF/services/org.glassfish.hk2.extension.ServiceLocatorGenerator
@@ -0,0 +1 @@
+org.glassfish.jersey.tests.integration.jersey2551.ServiceLocatorGenerator
\ No newline at end of file
diff --git a/tests/integration/jersey-2551/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2551/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..ea1bd52
--- /dev/null
+++ b/tests/integration/jersey-2551/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>jersey2551Servlet</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2551.Jersey2551</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>jersey2551Servlet</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/jersey-2551/src/test/java/org/glassfish/jersey/tests/integration/jersey2551/Jersey2551ITCase.java b/tests/integration/jersey-2551/src/test/java/org/glassfish/jersey/tests/integration/jersey2551/Jersey2551ITCase.java
new file mode 100644
index 0000000..a45e1b4
--- /dev/null
+++ b/tests/integration/jersey-2551/src/test/java/org/glassfish/jersey/tests/integration/jersey2551/Jersey2551ITCase.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2551;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Reproducer tests for JERSEY-2551.
+ *
+ * @author Michal Gajdos
+ */
+public class Jersey2551ITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Jersey2551();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testServiceLocatorServer() throws Exception {
+ assertThat(target().request().get().getStatus(), is(200));
+ }
+}
diff --git a/tests/integration/jersey-2612/pom.xml b/tests/integration/jersey-2612/pom.xml
new file mode 100644
index 0000000..6fe55ac
--- /dev/null
+++ b/tests/integration/jersey-2612/pom.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2612</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2612</name>
+
+ <description>Servlet integration test - JERSEY-2612 - SingleValueExtractor makes it impossible to support java.util.Optional (or Guava Optional).</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2612/src/main/java/org/glassfish/jersey/tests/integration/jersey2612/Jersey2612.java b/tests/integration/jersey-2612/src/main/java/org/glassfish/jersey/tests/integration/jersey2612/Jersey2612.java
new file mode 100644
index 0000000..edb6796
--- /dev/null
+++ b/tests/integration/jersey-2612/src/main/java/org/glassfish/jersey/tests/integration/jersey2612/Jersey2612.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2612;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * JAX-RS application for the JERSEY-2612 reproducer test.
+ */
+public class Jersey2612 extends ResourceConfig {
+
+ public Jersey2612() {
+ register(Resource.class);
+ register(OptionalParamFeature.class);
+ }
+}
diff --git a/tests/integration/jersey-2612/src/main/java/org/glassfish/jersey/tests/integration/jersey2612/OptionalParamBinder.java b/tests/integration/jersey-2612/src/main/java/org/glassfish/jersey/tests/integration/jersey2612/OptionalParamBinder.java
new file mode 100644
index 0000000..a8808f6
--- /dev/null
+++ b/tests/integration/jersey-2612/src/main/java/org/glassfish/jersey/tests/integration/jersey2612/OptionalParamBinder.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2612;
+
+import javax.ws.rs.ext.ParamConverterProvider;
+
+import javax.inject.Singleton;
+
+import org.glassfish.jersey.internal.inject.AbstractBinder;
+
+final class OptionalParamBinder extends AbstractBinder {
+
+ @Override
+ protected void configure() {
+ // Param converter providers
+ bind(OptionalParamConverterProvider.class).to(ParamConverterProvider.class).in(Singleton.class);
+ }
+}
diff --git a/tests/integration/jersey-2612/src/main/java/org/glassfish/jersey/tests/integration/jersey2612/OptionalParamConverterProvider.java b/tests/integration/jersey-2612/src/main/java/org/glassfish/jersey/tests/integration/jersey2612/OptionalParamConverterProvider.java
new file mode 100644
index 0000000..25b6edf
--- /dev/null
+++ b/tests/integration/jersey-2612/src/main/java/org/glassfish/jersey/tests/integration/jersey2612/OptionalParamConverterProvider.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2612;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.Set;
+
+import javax.ws.rs.ext.ParamConverter;
+import javax.ws.rs.ext.ParamConverterProvider;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.glassfish.jersey.internal.inject.InjectionManager;
+import org.glassfish.jersey.internal.inject.Providers;
+import org.glassfish.jersey.internal.util.ReflectionHelper;
+import org.glassfish.jersey.internal.util.collection.ClassTypePair;
+
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+
+@Singleton
+public class OptionalParamConverterProvider implements ParamConverterProvider {
+
+ private final InjectionManager injectionManager;
+
+ @Inject
+ public OptionalParamConverterProvider(final InjectionManager injectionManager) {
+ this.injectionManager = injectionManager;
+ }
+
+ @Override
+ public <T> ParamConverter<T> getConverter(final Class<T> rawType, final Type genericType, final Annotation[] annotations) {
+ final List<ClassTypePair> ctps = ReflectionHelper.getTypeArgumentAndClass(genericType);
+ final ClassTypePair ctp = (ctps.size() == 1) ? ctps.get(0) : null;
+ if (ctp == null || ctp.rawClass() == String.class) {
+ return new ParamConverter<T>() {
+ @Override
+ public T fromString(final String value) {
+ return rawType.cast(Optional.fromNullable(value));
+ }
+
+ @Override
+ public String toString(final T value) throws IllegalArgumentException {
+ return value.toString();
+ }
+ };
+ }
+ final Set<ParamConverterProvider> converterProviders =
+ Providers.getProviders(injectionManager, ParamConverterProvider.class);
+ for (ParamConverterProvider provider : converterProviders) {
+ @SuppressWarnings("unchecked")
+ final ParamConverter<?> converter = provider.getConverter(ctp.rawClass(), ctp.type(), annotations);
+ if (converter != null) {
+ return new ParamConverter<T>() {
+ @Override
+ public T fromString(final String value) {
+ return rawType.cast(Optional.fromNullable(value)
+ .transform((Function<String, Object>) s -> converter.fromString(value)));
+ }
+
+ @Override
+ public String toString(final T value) throws IllegalArgumentException {
+ return value.toString();
+ }
+ };
+ }
+ }
+ return null;
+ }
+}
diff --git a/tests/integration/jersey-2612/src/main/java/org/glassfish/jersey/tests/integration/jersey2612/OptionalParamFeature.java b/tests/integration/jersey-2612/src/main/java/org/glassfish/jersey/tests/integration/jersey2612/OptionalParamFeature.java
new file mode 100644
index 0000000..d6af4d1
--- /dev/null
+++ b/tests/integration/jersey-2612/src/main/java/org/glassfish/jersey/tests/integration/jersey2612/OptionalParamFeature.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2612;
+
+import javax.ws.rs.core.Feature;
+import javax.ws.rs.core.FeatureContext;
+
+public class OptionalParamFeature implements Feature {
+
+ @Override
+ public boolean configure(final FeatureContext context) {
+ context.register(new OptionalParamBinder());
+ return true;
+ }
+
+}
+
diff --git a/tests/integration/jersey-2612/src/main/java/org/glassfish/jersey/tests/integration/jersey2612/Resource.java b/tests/integration/jersey-2612/src/main/java/org/glassfish/jersey/tests/integration/jersey2612/Resource.java
new file mode 100644
index 0000000..ad1be27
--- /dev/null
+++ b/tests/integration/jersey-2612/src/main/java/org/glassfish/jersey/tests/integration/jersey2612/Resource.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2612;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+
+/**
+ * Test resource.
+ */
+@Path("/")
+public class Resource {
+
+ @Path("hello")
+ @GET
+ @Produces("text/plain")
+ public String hello(@QueryParam("name") final Optional<String> name) {
+ return "Hello " + name.or("World") + "!";
+ }
+
+ @Path("square")
+ @GET
+ @Produces("text/plain")
+ public int echo(@QueryParam("value") final Optional<Integer> value) {
+ return value.transform(new Function<Integer, Integer>() {
+ @Override
+ public Integer apply(final Integer integer) {
+ return integer * integer;
+ }
+ }).or(0);
+ }
+
+}
diff --git a/tests/integration/jersey-2612/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2612/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..f506807
--- /dev/null
+++ b/tests/integration/jersey-2612/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>jersey2612Servlet</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2612.Jersey2612</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>jersey2612Servlet</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/jersey-2612/src/test/java/org/glassfish/jersey/tests/integration/jersey2612/Jersey2612ITCase.java b/tests/integration/jersey-2612/src/test/java/org/glassfish/jersey/tests/integration/jersey2612/Jersey2612ITCase.java
new file mode 100644
index 0000000..0ffbad5
--- /dev/null
+++ b/tests/integration/jersey-2612/src/test/java/org/glassfish/jersey/tests/integration/jersey2612/Jersey2612ITCase.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2612;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Reproducer tests for JERSEY-2612.
+ */
+public class Jersey2612ITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Jersey2612();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testResourceMethodWithOptionalGivenNoQueryParam() throws Exception {
+ final Response response = target("/hello").request().get();
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), is("Hello World!"));
+ }
+
+ @Test
+ public void testResourceMethodWithOptionalGivenQueryParam() throws Exception {
+ final Response response = target("/hello").queryParam("name", "Jersey").request().get();
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), is("Hello Jersey!"));
+ }
+
+ @Test
+ public void testResourceMethodWithOptionalIntGivenNoQueryParam() throws Exception {
+ final Response response = target("/square").request().get();
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), is("0"));
+ }
+
+ @Test
+ public void testResourceMethodWithOptionalIntGivenQueryParam() throws Exception {
+ final Response response = target("/square").queryParam("value", "42").request().get();
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), is("1764"));
+ }
+}
diff --git a/tests/integration/jersey-2637/pom.xml b/tests/integration/jersey-2637/pom.xml
new file mode 100644
index 0000000..8615792
--- /dev/null
+++ b/tests/integration/jersey-2637/pom.xml
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2637</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2637</name>
+
+ <description>
+ Servlet integration test - JERSEY-2637 - sensitive params can be exposed in logs even for POST requests.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${servlet2.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2637/src/main/java/org/glassfish/jersey/tests/integration/jersey2637/Jersey2637.java b/tests/integration/jersey-2637/src/main/java/org/glassfish/jersey/tests/integration/jersey2637/Jersey2637.java
new file mode 100644
index 0000000..5f216ee
--- /dev/null
+++ b/tests/integration/jersey-2637/src/main/java/org/glassfish/jersey/tests/integration/jersey2637/Jersey2637.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2637;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * JAX-RS application for the JERSEY-2637 reproducer test.
+ */
+public class Jersey2637 extends ResourceConfig {
+
+ public Jersey2637() {
+ register(Resource.class);
+ }
+}
diff --git a/tests/integration/jersey-2637/src/main/java/org/glassfish/jersey/tests/integration/jersey2637/ParamEatingFilter.java b/tests/integration/jersey-2637/src/main/java/org/glassfish/jersey/tests/integration/jersey2637/ParamEatingFilter.java
new file mode 100644
index 0000000..d1522c6
--- /dev/null
+++ b/tests/integration/jersey-2637/src/main/java/org/glassfish/jersey/tests/integration/jersey2637/ParamEatingFilter.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2637;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+ * @author Michal Gajdos
+ */
+public class ParamEatingFilter implements Filter {
+
+ @Override
+ public void init(final FilterConfig filterConfig) throws ServletException {
+ // NOOP
+ }
+
+ @Override
+ public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
+ throws IOException, ServletException {
+ // NOM-NOM.
+ request.getParameterMap();
+
+ // Continue.
+ chain.doFilter(request, response);
+ }
+
+ @Override
+ public void destroy() {
+ // NOOP
+ }
+}
diff --git a/tests/integration/jersey-2637/src/main/java/org/glassfish/jersey/tests/integration/jersey2637/Resource.java b/tests/integration/jersey-2637/src/main/java/org/glassfish/jersey/tests/integration/jersey2637/Resource.java
new file mode 100644
index 0000000..39401cf
--- /dev/null
+++ b/tests/integration/jersey-2637/src/main/java/org/glassfish/jersey/tests/integration/jersey2637/Resource.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2637;
+
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+
+/**
+ * Test resource.
+ */
+@Path("/")
+public class Resource {
+
+ @POST
+ public String params(@FormParam("username") @DefaultValue("ko") final String username,
+ @FormParam("password") @DefaultValue("ko") final String password) {
+ return username + "_" + password;
+ }
+}
diff --git a/tests/integration/jersey-2637/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2637/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..051d43b
--- /dev/null
+++ b/tests/integration/jersey-2637/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <filter>
+ <filter-name>jersey2637Filter</filter-name>
+ <filter-class>org.glassfish.jersey.tests.integration.jersey2637.ParamEatingFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>jersey2637Filter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
+ <servlet>
+ <servlet-name>default</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2637.Jersey2637</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>default</servlet-name>
+ <url-pattern>/default/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet>
+ <servlet-name>enabled</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2637.Jersey2637</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.servlet.form.queryParams.disabled</param-name>
+ <param-value>false</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>enabled</servlet-name>
+ <url-pattern>/enabled/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet>
+ <servlet-name>disabled</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2637.Jersey2637</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.servlet.form.queryParams.disabled</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>disabled</servlet-name>
+ <url-pattern>/disabled/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/jersey-2637/src/test/java/org/glassfish/jersey/tests/integration/jersey2637/Jersey2637DisabledITCase.java b/tests/integration/jersey-2637/src/test/java/org/glassfish/jersey/tests/integration/jersey2637/Jersey2637DisabledITCase.java
new file mode 100644
index 0000000..de6b68e
--- /dev/null
+++ b/tests/integration/jersey-2637/src/test/java/org/glassfish/jersey/tests/integration/jersey2637/Jersey2637DisabledITCase.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2637;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Form;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Reproducer tests for JERSEY-2637 - Query params cannot be injected using {@link javax.ws.rs.FormParam}.
+ */
+public class Jersey2637DisabledITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Jersey2637();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testFormParams() throws Exception {
+ final Form form = new Form()
+ .param("username", "user")
+ .param("password", "pass");
+
+ final Response response = target("disabled").request().post(Entity.form(form));
+
+ assertThat(response.readEntity(String.class), is("user_pass"));
+ }
+
+ @Test
+ public void testQueryParams() throws Exception {
+ final Response response = target("disabled")
+ .queryParam("username", "user").queryParam("password", "pass")
+ .request()
+ .post(Entity.form(new Form()));
+
+ assertThat(response.readEntity(String.class), is("ko_ko"));
+ }
+
+ @Test
+ public void testDoubleQueryParams() throws Exception {
+ final Response response = target("disabled")
+ .queryParam("username", "user").queryParam("password", "pass")
+ .queryParam("username", "user").queryParam("password", "pass")
+ .request()
+ .post(Entity.form(new Form()));
+
+ assertThat(response.readEntity(String.class), is("ko_ko"));
+ }
+
+ @Test
+ public void testEncodedQueryParams() throws Exception {
+ final Response response = target("disabled")
+ .queryParam("username", "us%20er").queryParam("password", "pass")
+ .request()
+ .post(Entity.form(new Form()));
+
+ assertThat(response.readEntity(String.class), is("ko_ko"));
+ }
+
+ @Test
+ public void testFormAndQueryParams() throws Exception {
+ final Form form = new Form()
+ .param("username", "user")
+ .param("password", "pass");
+
+ final Response response = target("disabled")
+ .queryParam("username", "user").queryParam("password", "pass")
+ .request()
+ .post(Entity.form(form));
+
+ assertThat(response.readEntity(String.class), is("user_pass"));
+ }
+
+ @Test
+ public void testFormAndDoubleQueryParams() throws Exception {
+ final Form form = new Form()
+ .param("username", "user")
+ .param("password", "pass");
+
+ final Response response = target("disabled")
+ .queryParam("username", "user").queryParam("password", "pass")
+ .queryParam("username", "user").queryParam("password", "pass")
+ .request()
+ .post(Entity.form(form));
+
+ assertThat(response.readEntity(String.class), is("user_pass"));
+ }
+}
diff --git a/tests/integration/jersey-2637/src/test/java/org/glassfish/jersey/tests/integration/jersey2637/Jersey2637EnabledITCase.java b/tests/integration/jersey-2637/src/test/java/org/glassfish/jersey/tests/integration/jersey2637/Jersey2637EnabledITCase.java
new file mode 100644
index 0000000..1240bc1
--- /dev/null
+++ b/tests/integration/jersey-2637/src/test/java/org/glassfish/jersey/tests/integration/jersey2637/Jersey2637EnabledITCase.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2637;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Form;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Reproducer tests for JERSEY-2637 - Query params can be injected using {@link javax.ws.rs.FormParam}.
+ */
+@RunWith(Parameterized.class)
+public class Jersey2637EnabledITCase extends JerseyTest {
+
+ @Parameterized.Parameters(name = "path = {0}")
+ public static Collection<Object[]> paths() {
+ return Arrays.asList(new Object[][]{{"defaut"}, {"enabled"}});
+ }
+
+ @Parameterized.Parameter
+ public String path;
+
+ @Override
+ protected Application configure() {
+ return new Jersey2637();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testFormParams() throws Exception {
+ final Form form = new Form()
+ .param("username", "user")
+ .param("password", "pass");
+
+ final Response response = target(path).request().post(Entity.form(form));
+
+ assertThat(response.readEntity(String.class), is("user_pass"));
+ }
+
+ @Test
+ public void testQueryParams() throws Exception {
+ final Response response = target(path)
+ .queryParam("username", "user").queryParam("password", "pass")
+ .request()
+ .post(Entity.form(new Form()));
+
+ assertThat(response.readEntity(String.class), is("user_pass"));
+ }
+
+ @Test
+ public void testDoubleQueryParams() throws Exception {
+ final Response response = target(path)
+ .queryParam("username", "user").queryParam("password", "pass")
+ .queryParam("username", "user").queryParam("password", "pass")
+ .request()
+ .post(Entity.form(new Form()));
+
+ assertThat(response.readEntity(String.class), is("user_pass"));
+ }
+
+ @Test
+ public void testEncodedQueryParams() throws Exception {
+ final Response response = target(path)
+ .queryParam("username", "us%20er").queryParam("password", "pass")
+ .request()
+ .post(Entity.form(new Form()));
+
+ assertThat(response.readEntity(String.class), is("us er_pass"));
+ }
+
+ @Test
+ public void testFormAndQueryParams() throws Exception {
+ final Form form = new Form()
+ .param("username", "user")
+ .param("password", "pass");
+
+ final Response response = target(path)
+ .queryParam("username", "user").queryParam("password", "pass")
+ .request()
+ .post(Entity.form(form));
+
+ assertThat(response.readEntity(String.class), is("user_pass"));
+ }
+}
diff --git a/tests/integration/jersey-2654/pom.xml b/tests/integration/jersey-2654/pom.xml
new file mode 100644
index 0000000..7ae7658
--- /dev/null
+++ b/tests/integration/jersey-2654/pom.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2654</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2654</name>
+
+ <description>Jersey test web application - servlet/filter, JERSEY-2654 reproducer</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/jersey-2654/src/main/java/org/glassfish/jersey/tests/integration/jersey2654/ServletFilterTestResource.java b/tests/integration/jersey-2654/src/main/java/org/glassfish/jersey/tests/integration/jersey2654/ServletFilterTestResource.java
new file mode 100644
index 0000000..bfc062b
--- /dev/null
+++ b/tests/integration/jersey-2654/src/main/java/org/glassfish/jersey/tests/integration/jersey2654/ServletFilterTestResource.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2654;
+
+
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+
+/**
+ * Test resource to be called within an ServletContainer registered as servlet filter.
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+@Path("filter")
+public class ServletFilterTestResource {
+
+ @GET
+ public Response whatYouSendIsWhatYouGet(@DefaultValue("") @QueryParam("json") final String json) {
+ return Response.ok().entity(json).build();
+ }
+}
diff --git a/tests/integration/jersey-2654/src/main/java/org/glassfish/jersey/tests/integration/jersey2654/TestApplication.java b/tests/integration/jersey-2654/src/main/java/org/glassfish/jersey/tests/integration/jersey2654/TestApplication.java
new file mode 100644
index 0000000..099008f
--- /dev/null
+++ b/tests/integration/jersey-2654/src/main/java/org/glassfish/jersey/tests/integration/jersey2654/TestApplication.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2654;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+/**
+ * JAX-RS application to configure resources for JERSEY-2525 reproducer.
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+public class TestApplication extends Application {
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> classes = new HashSet<>();
+ classes.add(ServletFilterTestResource.class);
+ return classes;
+ }
+}
diff --git a/tests/integration/jersey-2654/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2654/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..a75c20f
--- /dev/null
+++ b/tests/integration/jersey-2654/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <filter>
+ <filter-name>MyApplication</filter-name>
+ <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2654.TestApplication</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>MyApplication</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+</web-app>
+
+
diff --git a/tests/integration/jersey-2654/src/test/java/org/glassfish/jersey/tests/integration/jersey2654/Jersey2654ITCase.java b/tests/integration/jersey-2654/src/test/java/org/glassfish/jersey/tests/integration/jersey2654/Jersey2654ITCase.java
new file mode 100644
index 0000000..0589b64
--- /dev/null
+++ b/tests/integration/jersey-2654/src/test/java/org/glassfish/jersey/tests/integration/jersey2654/Jersey2654ITCase.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2654;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.net.Socket;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Reproducer for JERSEY-2654
+ *
+ * Tests, that unencoded curly brackets (typically used in URI queries containing JSON) do not cause the request to
+ * fail when running in a servlet environment and configured as a filter.
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+public class Jersey2654ITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new TestApplication();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testJsonInUriWithSockets() throws IOException {
+ // Low level approach with sockets is used, because common Java HTTP clients are using java.net.URI,
+ // which fails when unencoded curly bracket is part of the URI
+ final Socket socket = new Socket(getBaseUri().getHost(), getBaseUri().getPort());
+ final PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())));
+
+ // quotes are encoded by browsers, curly brackets are not, so the quotes will be sent pre-encoded
+ // HTTP 1.0 is used for simplicity
+ pw.println("GET /filter?json={%22foo%22:%22bar%22} HTTP/1.0");
+ pw.println(); // http request should end with a blank line
+ pw.flush();
+
+ final BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+
+ String lastLine = null;
+ String line;
+ while ((line = br.readLine()) != null) {
+ // read the response and remember the last line
+ lastLine = line;
+ }
+ assertEquals("{\"foo\":\"bar\"}", lastLine);
+ br.close();
+ }
+}
diff --git a/tests/integration/jersey-2673/pom.xml b/tests/integration/jersey-2673/pom.xml
new file mode 100644
index 0000000..827aa30
--- /dev/null
+++ b/tests/integration/jersey-2673/pom.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2673</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2673</name>
+
+ <description>Jersey test web application - servlet/filter, JERSEY-2673 reproducer</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-bean-validation</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-json-jackson</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/jersey-2673/src/main/java/org/glassfish/jersey/tests/integration/jersey2673/Jersey2673.java b/tests/integration/jersey-2673/src/main/java/org/glassfish/jersey/tests/integration/jersey2673/Jersey2673.java
new file mode 100644
index 0000000..26f6274
--- /dev/null
+++ b/tests/integration/jersey-2673/src/main/java/org/glassfish/jersey/tests/integration/jersey2673/Jersey2673.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2673;
+
+import org.glassfish.jersey.jackson.JacksonFeature;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.ServerProperties;
+
+/**
+ * @author Michal Gajdos
+ */
+public class Jersey2673 extends ResourceConfig {
+
+ public Jersey2673() {
+ // Resources.
+ register(Resource.class);
+
+ // Providers.
+ register(JacksonFeature.class);
+
+ // Make sure validations errors are returned to the client.
+ property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
+ }
+}
diff --git a/tests/integration/jersey-2673/src/main/java/org/glassfish/jersey/tests/integration/jersey2673/Resource.java b/tests/integration/jersey-2673/src/main/java/org/glassfish/jersey/tests/integration/jersey2673/Resource.java
new file mode 100644
index 0000000..326a39e
--- /dev/null
+++ b/tests/integration/jersey-2673/src/main/java/org/glassfish/jersey/tests/integration/jersey2673/Resource.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2673;
+
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+import javax.validation.Valid;
+
+/**
+ * @author Michal Gajdos
+ */
+@Path("/")
+@Produces("application/json")
+public class Resource {
+
+ @POST
+ @Valid
+ public Response processBean(@Valid final SampleBean bean) {
+ return Response.ok(new SampleBean()).build();
+ }
+}
diff --git a/tests/integration/jersey-2673/src/main/java/org/glassfish/jersey/tests/integration/jersey2673/SampleBean.java b/tests/integration/jersey-2673/src/main/java/org/glassfish/jersey/tests/integration/jersey2673/SampleBean.java
new file mode 100644
index 0000000..21ac029
--- /dev/null
+++ b/tests/integration/jersey-2673/src/main/java/org/glassfish/jersey/tests/integration/jersey2673/SampleBean.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2673;
+
+import org.hibernate.validator.constraints.NotEmpty;
+
+/**
+ * @author Michal Gajdos
+ */
+public class SampleBean {
+
+ @NotEmpty
+ private byte[] array;
+
+ public byte[] getArray() {
+ return array;
+ }
+
+ public void setArray(final byte[] array) {
+ this.array = array;
+ }
+}
diff --git a/tests/integration/jersey-2673/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2673/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..712879e
--- /dev/null
+++ b/tests/integration/jersey-2673/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<web-app version="2.5"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <servlet>
+ <servlet-name>jersey</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2673.Jersey2673</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>jersey</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
diff --git a/tests/integration/jersey-2673/src/test/java/org/glassfish/jersey/tests/integration/jersey2673/Jersey2673ITCase.java b/tests/integration/jersey-2673/src/test/java/org/glassfish/jersey/tests/integration/jersey2673/Jersey2673ITCase.java
new file mode 100644
index 0000000..f157001
--- /dev/null
+++ b/tests/integration/jersey-2673/src/test/java/org/glassfish/jersey/tests/integration/jersey2673/Jersey2673ITCase.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2673;
+
+import java.util.List;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.validation.ValidationError;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Reproducer for JERSEY-2673: 400 errors generated by a ValidationException are returning default error page instead of
+ * the Bean Validation's response entity.
+ *
+ * @author Michal Gajdos
+ */
+public class Jersey2673ITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new Jersey2673();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testInputParams() throws Exception {
+ final Response response = target().request("application/json").post(Entity.json(new SampleBean()));
+
+ assertThat(response.getStatusInfo().getStatusCode(), is(Response.Status.BAD_REQUEST.getStatusCode()));
+ assertThat(response.readEntity(new GenericType<List<ValidationError>>() {}).size(), is(1));
+ }
+
+ @Test
+ public void testOutputParams() throws Exception {
+ final SampleBean entity = new SampleBean();
+ entity.setArray(new byte[] {42});
+ final Response response = target().request("application/json").post(Entity.json(entity));
+
+ assertThat(response.getStatusInfo().getStatusCode(), is(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
+ assertThat(response.readEntity(new GenericType<List<ValidationError>>() {}).size(), is(1));
+ }
+
+}
diff --git a/tests/integration/jersey-2689/pom.xml b/tests/integration/jersey-2689/pom.xml
new file mode 100644
index 0000000..c4583c8
--- /dev/null
+++ b/tests/integration/jersey-2689/pom.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2689</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2689</name>
+
+ <description>Servlet integration test - JERSEY-2689 - Problem with validation errors on primitive type arrays</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-bean-validation</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.jaxrs</groupId>
+ <artifactId>jackson-jaxrs-json-provider</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2689/src/main/java/org/glassfish/jersey/tests/integration/jersey2689/Jersey2689.java b/tests/integration/jersey-2689/src/main/java/org/glassfish/jersey/tests/integration/jersey2689/Jersey2689.java
new file mode 100644
index 0000000..fc18355
--- /dev/null
+++ b/tests/integration/jersey-2689/src/main/java/org/glassfish/jersey/tests/integration/jersey2689/Jersey2689.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2689;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.ServerProperties;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
+
+/**
+ * @author Oscar Guindzberg
+ */
+public class Jersey2689 extends ResourceConfig {
+
+ public Jersey2689() {
+ // Set package to look for resources in
+ packages("org.glassfish.jersey.tests.integration.jersey2689");
+
+ this.property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
+
+ // create custom ObjectMapper
+ final ObjectMapper mapper = new ObjectMapper();
+ mapper.enable(SerializationFeature.INDENT_OUTPUT);
+
+ // create JsonProvider to provide custom ObjectMapper
+ final JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
+ provider.setMapper(mapper);
+ this.register(provider);
+
+ }
+
+}
diff --git a/tests/integration/jersey-2689/src/main/java/org/glassfish/jersey/tests/integration/jersey2689/Resource.java b/tests/integration/jersey-2689/src/main/java/org/glassfish/jersey/tests/integration/jersey2689/Resource.java
new file mode 100644
index 0000000..6e97b9e
--- /dev/null
+++ b/tests/integration/jersey-2689/src/main/java/org/glassfish/jersey/tests/integration/jersey2689/Resource.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2689;
+
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+
+import javax.validation.Valid;
+
+@Path("/")
+public class Resource {
+
+ @POST
+ @Path("/post-bean")
+ public void processBean(@Valid final SampleBean bean) {
+ //do-nothing
+ }
+}
diff --git a/tests/integration/jersey-2689/src/main/java/org/glassfish/jersey/tests/integration/jersey2689/SampleBean.java b/tests/integration/jersey-2689/src/main/java/org/glassfish/jersey/tests/integration/jersey2689/SampleBean.java
new file mode 100644
index 0000000..a4e759d
--- /dev/null
+++ b/tests/integration/jersey-2689/src/main/java/org/glassfish/jersey/tests/integration/jersey2689/SampleBean.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2689;
+
+import org.hibernate.validator.constraints.NotEmpty;
+
+public class SampleBean {
+
+ @NotEmpty
+ private byte[] array;
+
+ public byte[] getArray() {
+ return array;
+ }
+
+ public void setArray(byte[] array) {
+ this.array = array;
+ }
+
+}
diff --git a/tests/integration/jersey-2689/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2689/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..3842845
--- /dev/null
+++ b/tests/integration/jersey-2689/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<web-app version="2.5"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <servlet>
+ <servlet-name>testServlet1</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2689.Jersey2689</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>testServlet1</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
diff --git a/tests/integration/jersey-2689/src/test/java/org/glassfish/jersey/tests/integration/jersey2689/Jersey2689ITCase.java b/tests/integration/jersey-2689/src/test/java/org/glassfish/jersey/tests/integration/jersey2689/Jersey2689ITCase.java
new file mode 100644
index 0000000..2db2efa
--- /dev/null
+++ b/tests/integration/jersey-2689/src/test/java/org/glassfish/jersey/tests/integration/jersey2689/Jersey2689ITCase.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.jersey2689;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
+
+/**
+ * Tests for JERSEY-2689: Problem with validation errors on primitive type arrays.
+ * <p/> There is a bug when a validation fails for a primitive data array. Eg a NotNull failed validation on a byte[] causes the code to throw a ClassCastException. The problem is caused by ValidationHelper.getViolationInvalidValue(Object invalidValue) It tries to cast any array to a Object[] A byte[] parameter would generate a ClassCastException.*
+ * @author Oscar Guindzberg (oscar.guindzberg at gmail.com)
+ */
+public class Jersey2689ITCase extends JerseyTest {
+
+
+ @Override
+ protected ResourceConfig configure() {
+ return new Jersey2689();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ /**
+ * Checks if a thread gets stuck when an {@code IOException} is thrown from the {@code
+ * MessageBodyWriter#writeTo}.
+ */
+ @Test
+ public void testByteArray() throws Exception {
+ // Executor.
+ final ExecutorService executor = Executors.newSingleThreadExecutor();
+
+ final Future<Response> responseFuture = executor.submit(new Callable<Response>() {
+
+ @Override
+ public Response call() throws Exception {
+ SampleBean bean = new SampleBean();
+ bean.setArray(new byte[]{});
+
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.enable(SerializationFeature.INDENT_OUTPUT);
+ JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
+ provider.setMapper(mapper);
+ client().register(provider);
+
+ return target().path("post-bean").request().post(Entity.entity(bean, MediaType.APPLICATION_JSON));
+ }
+
+ });
+
+ executor.shutdown();
+ final boolean inTime = executor.awaitTermination(5000, TimeUnit.MILLISECONDS);
+
+ // Asserts.
+ assertTrue(inTime);
+
+ // Response.
+ final Response response = responseFuture.get();
+
+ //Make sure we get a 400 error and not a 500 error
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusInfo().getStatusCode());
+
+ }
+
+
+}
diff --git a/tests/integration/jersey-2704/pom.xml b/tests/integration/jersey-2704/pom.xml
new file mode 100644
index 0000000..5dea360
--- /dev/null
+++ b/tests/integration/jersey-2704/pom.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2704</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2704</name>
+
+ <description>
+ This test is to verify if ServiceLocator can be configured within the server context
+ in such a way that Jersey can use it as a parent ServiceLocator in the WebComponent.
+ More details can be found in JERSEY-2704.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2704/src/main/java/org/glassfish/jersey/tests/integration/jersey2704/ServiceLocatorSetup.java b/tests/integration/jersey-2704/src/main/java/org/glassfish/jersey/tests/integration/jersey2704/ServiceLocatorSetup.java
new file mode 100644
index 0000000..3eb8be8
--- /dev/null
+++ b/tests/integration/jersey-2704/src/main/java/org/glassfish/jersey/tests/integration/jersey2704/ServiceLocatorSetup.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.jersey2704;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.glassfish.hk2.api.ServiceLocator;
+import org.glassfish.hk2.utilities.ServiceLocatorUtilities;
+import org.glassfish.jersey.servlet.ServletProperties;
+import org.glassfish.jersey.tests.integration.jersey2704.services.HappyService;
+
+
+/**
+ * This class is to listen for {@link ServletContextEvent} generated whenever context
+ * is initialized and set {@link ServletProperties#SERVICE_LOCATOR} attribute to point
+ * {@link ServiceLocator} pre-populated with {@link HappyService} instance.
+ *
+ * @author Bartosz Firyn (sarxos)
+ */
+public class ServiceLocatorSetup implements ServletContextListener {
+
+ @Override
+ public void contextInitialized(ServletContextEvent event) {
+ ServiceLocator locator = ServiceLocatorUtilities.createAndPopulateServiceLocator();
+ ServiceLocatorUtilities.addOneConstant(locator, new HappyService());
+ event.getServletContext().setAttribute(ServletProperties.SERVICE_LOCATOR, locator);
+ }
+
+ @Override
+ public void contextDestroyed(ServletContextEvent event) {
+ }
+}
diff --git a/tests/integration/jersey-2704/src/main/java/org/glassfish/jersey/tests/integration/jersey2704/TestApplication.java b/tests/integration/jersey-2704/src/main/java/org/glassfish/jersey/tests/integration/jersey2704/TestApplication.java
new file mode 100644
index 0000000..ac7bc57
--- /dev/null
+++ b/tests/integration/jersey-2704/src/main/java/org/glassfish/jersey/tests/integration/jersey2704/TestApplication.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.jersey2704;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+
+/**
+ * Jersey application.
+ *
+ * @author Bartosz Firyn (bartoszfiryn at gmail.com)
+ */
+public class TestApplication extends ResourceConfig {
+
+ public TestApplication() {
+ register(TestResource.class);
+ }
+}
diff --git a/tests/integration/jersey-2704/src/main/java/org/glassfish/jersey/tests/integration/jersey2704/TestResource.java b/tests/integration/jersey-2704/src/main/java/org/glassfish/jersey/tests/integration/jersey2704/TestResource.java
new file mode 100644
index 0000000..dc07f94
--- /dev/null
+++ b/tests/integration/jersey-2704/src/main/java/org/glassfish/jersey/tests/integration/jersey2704/TestResource.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.jersey2704;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+import javax.inject.Inject;
+
+import org.glassfish.jersey.internal.inject.InjectionManager;
+
+/**
+ * This resource is used to test if specific service class instance is available in the
+ * {@link InjectionManager} that comes from Jersey context.
+ *
+ * @author Bartosz Firyn (bartoszfiryn at gmail.com)
+ */
+@Path("test")
+public class TestResource {
+
+ InjectionManager injectionManager;
+
+ /**
+ * Inject {@link InjectionManager} from Jersey context.
+ *
+ * @param injectionManager the {@link InjectionManager}
+ */
+ @Inject
+ public TestResource(InjectionManager injectionManager) {
+ this.injectionManager = injectionManager;
+ }
+
+ /**
+ * This method will test given class by checking if it is available in {@link InjectionManager}
+ * that has been injected from the Jersey context.
+ *
+ * @param clazz the service class name to check
+ * @return {@link Response} with status code 200 if service is available, 600 otherwise
+ * @throws Exception in case when there are any error (e.g. class not exist)
+ */
+ @GET
+ @Path("{clazz}")
+ @Produces("text/plain")
+ public Response test(@PathParam("clazz") String clazz) throws Exception {
+ return Response
+ .status(injectionManager.getInstance(Class.forName(clazz)) != null ? 200 : 600)
+ .build();
+ }
+}
diff --git a/tests/integration/jersey-2704/src/main/java/org/glassfish/jersey/tests/integration/jersey2704/services/HappyService.java b/tests/integration/jersey-2704/src/main/java/org/glassfish/jersey/tests/integration/jersey2704/services/HappyService.java
new file mode 100644
index 0000000..2c87d94
--- /dev/null
+++ b/tests/integration/jersey-2704/src/main/java/org/glassfish/jersey/tests/integration/jersey2704/services/HappyService.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.jersey2704.services;
+
+import org.jvnet.hk2.annotations.Service;
+
+
+/**
+ * This service is registered in the {@link org.glassfish.jersey.internal.inject.InjectionManager} and therefore
+ * can be used in Jersey resources.
+ *
+ * @author Bartosz Firyn (bartoszfiryn at gmail.com)
+ */
+@Service
+public class HappyService {
+
+}
diff --git a/tests/integration/jersey-2704/src/main/java/org/glassfish/jersey/tests/integration/jersey2704/services/SadService.java b/tests/integration/jersey-2704/src/main/java/org/glassfish/jersey/tests/integration/jersey2704/services/SadService.java
new file mode 100644
index 0000000..1d4df28
--- /dev/null
+++ b/tests/integration/jersey-2704/src/main/java/org/glassfish/jersey/tests/integration/jersey2704/services/SadService.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.jersey2704.services;
+
+import org.jvnet.hk2.annotations.Service;
+
+
+/**
+ * This service is not registered in {@link org.glassfish.jersey.internal.inject.InjectionManager} and therefore cannot
+ * be used in the Jersey resources.
+ *
+ * @author Bartosz Firyn (bartoszfiryn at gmail.com)
+ */
+@Service
+public class SadService {
+
+}
diff --git a/tests/integration/jersey-2704/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2704/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..44a2543
--- /dev/null
+++ b/tests/integration/jersey-2704/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2012, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <listener>
+ <listener-class>org.glassfish.jersey.tests.integration.jersey2704.ServiceLocatorSetup</listener-class>
+ </listener>
+ <servlet>
+ <servlet-name>test</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2704.TestApplication</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>test</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/jersey-2704/src/test/java/org/glassfish/jersey/tests/integration/jersey2704/Jersey2704ITCase.java b/tests/integration/jersey-2704/src/test/java/org/glassfish/jersey/tests/integration/jersey2704/Jersey2704ITCase.java
new file mode 100644
index 0000000..2ed829e
--- /dev/null
+++ b/tests/integration/jersey-2704/src/test/java/org/glassfish/jersey/tests/integration/jersey2704/Jersey2704ITCase.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.jersey2704;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.hk2.api.ServiceLocator;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+import org.glassfish.jersey.tests.integration.jersey2704.services.HappyService;
+import org.glassfish.jersey.tests.integration.jersey2704.services.SadService;
+import org.junit.Assert;
+import org.junit.Test;
+
+
+/**
+ * This test case is to cover enhancement implemented in JERSEY-2704. The goal of this enhancement
+ * is to give users possibility to register main {@link ServiceLocator} in the servlet context, so
+ * it can be later used by Jersey. This creates the opportunity to wire Jersey-specific classes with
+ * the services created outside the Jersey context.
+ *
+ * @author Bartosz Firyn (bartoszfiryn at gmail.com)
+ */
+public class Jersey2704ITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new TestApplication();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ /**
+ * Invokes REST endpoint to check whether specific class service is registered in the
+ * {@link ServiceLocator}.
+ *
+ * @param service the service class
+ * @return HTTP status code, 200 when service is available and 600 otherwise
+ * @throws IOException in case of problems with HTTP communication
+ */
+ private int test(Class<?> service) throws IOException {
+
+ String name = service.getCanonicalName();
+ String path = getBaseUri().toString() + "test/" + name;
+
+ HttpURLConnection connection = (HttpURLConnection) new URL(path).openConnection();
+ connection.setRequestMethod("GET");
+ connection.connect();
+ connection.disconnect();
+
+ return connection.getResponseCode();
+ }
+
+ /**
+ * Test to cover sunny day scenario, i.e. specific service has been registered in the parent
+ * {@link ServiceLocator} so it will be available in the one that is used in Jersey context.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testCorrectInjection() throws IOException {
+ Assert.assertEquals(200, test(HappyService.class));
+ }
+
+ /**
+ * Test to cover rainy day scenario, i.e. specific service has <b>not</b> been registered in the
+ * parent {@link ServiceLocator} so it cannot be used to wire Jersey classes.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testMisingInjection() throws IOException {
+ Assert.assertEquals(600, test(SadService.class));
+ }
+}
diff --git a/tests/integration/jersey-2776/pom.xml b/tests/integration/jersey-2776/pom.xml
new file mode 100644
index 0000000..0b484a9
--- /dev/null
+++ b/tests/integration/jersey-2776/pom.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2776</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2776</name>
+
+ <description>
+ This test is to verify that multipart support (server side) works even if apache CXF's RuntimeDelegateImpl is used instead
+ of the RuntimeDelegateImpl shipped with Jersey.
+ </description>
+
+ <dependencies>
+ <!-- For testing multipart support with another http client -->
+ <!-- The order of these imports are important as it's the first dependency that has a javax.ws.rs.ext.RuntimeDelegate in
+ the services that will be used. -->
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-rs-client</artifactId>
+ <version>3.0.3</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-multipart</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2776/src/main/java/org/glassfish/jersey/tests/integration/jersey2776/TestApplication.java b/tests/integration/jersey-2776/src/main/java/org/glassfish/jersey/tests/integration/jersey2776/TestApplication.java
new file mode 100644
index 0000000..3739ba3
--- /dev/null
+++ b/tests/integration/jersey-2776/src/main/java/org/glassfish/jersey/tests/integration/jersey2776/TestApplication.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2776;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * Jersey application.
+ */
+@ApplicationPath("/")
+public class TestApplication extends ResourceConfig {
+
+ public TestApplication() {
+ register(TestResource.class);
+ register(MultiPartFeature.class);
+ }
+}
diff --git a/tests/integration/jersey-2776/src/main/java/org/glassfish/jersey/tests/integration/jersey2776/TestResource.java b/tests/integration/jersey-2776/src/main/java/org/glassfish/jersey/tests/integration/jersey2776/TestResource.java
new file mode 100644
index 0000000..1f05e91
--- /dev/null
+++ b/tests/integration/jersey-2776/src/main/java/org/glassfish/jersey/tests/integration/jersey2776/TestResource.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2776;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.glassfish.jersey.media.multipart.FormDataBodyPart;
+import org.glassfish.jersey.media.multipart.FormDataParam;
+
+@Path("/files")
+public class TestResource {
+
+ @POST
+ @Consumes(MediaType.MULTIPART_FORM_DATA)
+ @Produces(MediaType.TEXT_PLAIN)
+ public String uploadDocument(@FormDataParam("file_path") final FormDataBodyPart body) {
+ return body.getValueAs(String.class);
+ }
+}
diff --git a/tests/integration/jersey-2776/src/test/java/org/glassfish/jersey/tests/integration/jersey2776/Jersey2776ITCase.java b/tests/integration/jersey-2776/src/test/java/org/glassfish/jersey/tests/integration/jersey2776/Jersey2776ITCase.java
new file mode 100644
index 0000000..7a6d2af
--- /dev/null
+++ b/tests/integration/jersey-2776/src/test/java/org/glassfish/jersey/tests/integration/jersey2776/Jersey2776ITCase.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2776;
+
+import java.nio.charset.StandardCharsets;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+
+import org.glassfish.jersey.media.multipart.internal.MultiPartReaderClientSide;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
+import org.apache.cxf.jaxrs.ext.multipart.Attachment;
+import org.apache.cxf.jaxrs.ext.multipart.AttachmentBuilder;
+import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
+import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
+import org.junit.Ignore;
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Code under test: {@link MultiPartReaderClientSide} (unquoteMediaTypeParameters)
+ *
+ * @author Jonatan Jönsson (jontejj at gmail.com)
+ */
+@Ignore
+public class Jersey2776ITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new TestApplication();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Path("/files")
+ public interface ApacheCxfMultipartClient {
+
+ @POST
+ @Consumes(MediaType.MULTIPART_FORM_DATA)
+ @Produces(MediaType.TEXT_PLAIN)
+ String uploadDocument(MultipartBody content);
+ }
+
+ @Test
+ public void testThatMultipartServerSupportsBoundaryQuotesEvenWithInterferingRuntimeDelegate() {
+ final JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+ bean.setAddress(getBaseUri().toString());
+ bean.setServiceClass(ApacheCxfMultipartClient.class);
+ final ApacheCxfMultipartClient cxfClient = bean.create(ApacheCxfMultipartClient.class);
+
+ final String originalContent = "abc";
+ final byte[] content = originalContent.getBytes(StandardCharsets.US_ASCII);
+ final Attachment fileAttachment = new AttachmentBuilder()
+ .object(content)
+ .contentDisposition(new ContentDisposition("form-data; filename=\"abc-file\"; name=\"file_path\""))
+ .build();
+
+ final String fileContentReturnedFromServer = cxfClient.uploadDocument(new MultipartBody(fileAttachment));
+ assertThat(fileContentReturnedFromServer, equalTo(originalContent));
+ }
+}
diff --git a/tests/integration/jersey-2794/pom.xml b/tests/integration/jersey-2794/pom.xml
new file mode 100644
index 0000000..f009641
--- /dev/null
+++ b/tests/integration/jersey-2794/pom.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2794</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2794</name>
+
+ <description>
+ Reproducer of JERSEY-2794. This test makes sure that temporary files created via mimepull library are deleted right after
+ the request processing failed and not when the JVM is shut down.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-multipart</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2794/src/main/java/org/glassfish/jersey/tests/integration/jersey2794/TestApplication.java b/tests/integration/jersey-2794/src/main/java/org/glassfish/jersey/tests/integration/jersey2794/TestApplication.java
new file mode 100644
index 0000000..615df07
--- /dev/null
+++ b/tests/integration/jersey-2794/src/main/java/org/glassfish/jersey/tests/integration/jersey2794/TestApplication.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2794;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * Jersey application for JERSEY-2794.
+ *
+ * @author Michal Gajdos
+ */
+@ApplicationPath("/")
+public class TestApplication extends ResourceConfig {
+
+ public TestApplication() {
+ register(TestResource.class);
+ register(MultiPartFeature.class);
+ }
+}
diff --git a/tests/integration/jersey-2794/src/main/java/org/glassfish/jersey/tests/integration/jersey2794/TestResource.java b/tests/integration/jersey-2794/src/main/java/org/glassfish/jersey/tests/integration/jersey2794/TestResource.java
new file mode 100644
index 0000000..aa8b89f
--- /dev/null
+++ b/tests/integration/jersey-2794/src/main/java/org/glassfish/jersey/tests/integration/jersey2794/TestResource.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2794;
+
+import java.io.InputStream;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.glassfish.jersey.media.multipart.FormDataParam;
+
+/**
+ * @author Michal Gajdos
+ */
+@Path("/")
+public class TestResource {
+
+ @PUT
+ @Consumes("multipart/form-data")
+ @Produces("text/plain")
+ public String put(@FormDataParam("stream") final InputStream stream) {
+ return "OK";
+ }
+}
diff --git a/tests/integration/jersey-2794/src/test/java/org/glassfish/jersey/tests/integration/jersey2794/Jersey2794ITCase.java b/tests/integration/jersey-2794/src/test/java/org/glassfish/jersey/tests/integration/jersey2794/Jersey2794ITCase.java
new file mode 100644
index 0000000..60a54ca
--- /dev/null
+++ b/tests/integration/jersey-2794/src/test/java/org/glassfish/jersey/tests/integration/jersey2794/Jersey2794ITCase.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2794;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * JERSEY-2794 reproducer.
+ *
+ * @author Michal Gajdos
+ */
+public class Jersey2794ITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Application();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void mimeTempFileRemoved() throws Exception {
+ final String tempDir = System.getProperty("java.io.tmpdir");
+
+ // Get number of matching MIME*tmp files (the number should be the same at the end of the test).
+ final int expectedTempFiles = matchingTempFiles(tempDir);
+
+ final URL url = new URL(getBaseUri().toString());
+ final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+
+ connection.setRequestMethod("PUT");
+ connection.setRequestProperty("Accept", "text/plain");
+ connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=XXXX_YYYY");
+
+ connection.setDoOutput(true);
+ connection.connect();
+
+ final OutputStream outputStream = connection.getOutputStream();
+ outputStream.write("--XXXX_YYYY".getBytes());
+ outputStream.write('\n');
+ outputStream.write("Content-Type: text/plain".getBytes());
+ outputStream.write('\n');
+ outputStream.write("Content-Disposition: form-data; name=\"big-part\"".getBytes());
+ outputStream.write('\n');
+ outputStream.write('\n');
+
+ // Send big chunk of data.
+ for (int i = 0; i < 16 * 4096; i++) {
+ outputStream.write('E');
+ if (i % 1024 == 0) {
+ outputStream.flush();
+ }
+ }
+
+ // Do NOT send end of the MultiPart message to simulate the issue.
+
+ // Get Response ...
+ assertThat("Bad Request expected", connection.getResponseCode(), is(400));
+
+ // Make sure that the Mimepull message and it's parts have been closed and temporary files deleted.
+ assertThat("Temporary mimepull files were not deleted", matchingTempFiles(tempDir), is(expectedTempFiles));
+
+ // ... Disconnect.
+ connection.disconnect();
+ }
+
+ private int matchingTempFiles(final String tempDir) throws IOException {
+ AtomicInteger count = new AtomicInteger(0);
+ Files.walkFileTree(Paths.get(tempDir), new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+ if (file.getFileName().startsWith("MIME") && file.getFileName().endsWith("tmp")) {
+ count.incrementAndGet();
+ }
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
+ });
+ return count.get();
+ }
+}
diff --git a/tests/integration/jersey-2846/pom.xml b/tests/integration/jersey-2846/pom.xml
new file mode 100644
index 0000000..7e54819
--- /dev/null
+++ b/tests/integration/jersey-2846/pom.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2846</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2846</name>
+
+ <description>
+ Reproducer of JERSEY-2846. This test makes sure that temporary files created via mimepull (and moved by Jersey) library
+ are deleted right after the request processing (either successful or unsuccessful) and not when the JVM is shut down.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-multipart</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2846/src/main/java/org/glassfish/jersey/tests/integration/jersey2846/TestApplication.java b/tests/integration/jersey-2846/src/main/java/org/glassfish/jersey/tests/integration/jersey2846/TestApplication.java
new file mode 100644
index 0000000..42dafbe
--- /dev/null
+++ b/tests/integration/jersey-2846/src/main/java/org/glassfish/jersey/tests/integration/jersey2846/TestApplication.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2846;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * Jersey application for JERSEY-2846.
+ *
+ * @author Michal Gajdos
+ */
+@ApplicationPath("/")
+public class TestApplication extends ResourceConfig {
+
+ public TestApplication() {
+ register(TestResource.class);
+ register(MultiPartFeature.class);
+ }
+}
diff --git a/tests/integration/jersey-2846/src/main/java/org/glassfish/jersey/tests/integration/jersey2846/TestResource.java b/tests/integration/jersey-2846/src/main/java/org/glassfish/jersey/tests/integration/jersey2846/TestResource.java
new file mode 100644
index 0000000..7356fcf
--- /dev/null
+++ b/tests/integration/jersey-2846/src/main/java/org/glassfish/jersey/tests/integration/jersey2846/TestResource.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2846;
+
+import java.io.File;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.media.multipart.FormDataParam;
+
+/**
+ * @author Michal Gajdos
+ */
+@Path("/")
+@Consumes("multipart/form-data")
+@Produces("text/plain")
+public class TestResource {
+
+ @POST
+ @Path("ExceptionInMethod")
+ public String exceptionInMethod(@FormDataParam("file") final File file) {
+ throw new WebApplicationException(Response.serverError().entity(file.getAbsolutePath()).build());
+ }
+
+ @POST
+ @Path("SuccessfulMethod")
+ public String successfulMethod(@FormDataParam("file") final File file) {
+ return file.getAbsolutePath();
+ }
+}
diff --git a/tests/integration/jersey-2846/src/test/java/org/glassfish/jersey/tests/integration/jersey2846/Jersey2846ITCase.java b/tests/integration/jersey-2846/src/test/java/org/glassfish/jersey/tests/integration/jersey2846/Jersey2846ITCase.java
new file mode 100644
index 0000000..0aecaa2
--- /dev/null
+++ b/tests/integration/jersey-2846/src/test/java/org/glassfish/jersey/tests/integration/jersey2846/Jersey2846ITCase.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2846;
+
+import java.io.IOException;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.Arrays;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.media.multipart.FormDataBodyPart;
+import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+import org.glassfish.jersey.media.multipart.FormDataMultiPart;
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * JERSEY-2846 reproducer.
+ *
+ * @author Michal Gajdos
+ */
+public class Jersey2846ITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Application();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Override
+ protected void configureClient(final ClientConfig config) {
+ config.register(MultiPartFeature.class);
+ }
+
+ @Test
+ public void tempFileDeletedAfterSuccessfulProcessing() throws Exception {
+ _testSmall("SuccessfulMethod", 200);
+ }
+
+ @Test
+ public void tempFileDeletedAfterExceptionInMethod() throws Exception {
+ _testSmall("ExceptionInMethod", 500);
+ }
+
+ @Test
+ public void tempFileDeletedAfterSuccessfulProcessingBigEntity() throws Exception {
+ _testBig("SuccessfulMethod", 200);
+ }
+
+ @Test
+ public void tempFileDeletedAfterExceptionInMethodBigEntity() throws Exception {
+ _testBig("ExceptionInMethod", 500);
+ }
+
+ public void _testBig(final String path, final int status) throws Exception {
+ final byte[] array = new byte[8196];
+ Arrays.fill(array, (byte) 52);
+
+ _test(path, status, array);
+ }
+
+ public void _testSmall(final String path, final int status) throws Exception {
+ _test(path, status, "CONTENT");
+ }
+
+ public void _test(final String path, final int status, final Object entity) throws Exception {
+ final String tempDir = System.getProperty("java.io.tmpdir");
+
+ // Get number of matching MIME*tmp files (the number should be the same at the end of the test).
+ final int expectedTempFiles = matchingTempFiles(tempDir);
+
+ final FormDataMultiPart multipart = new FormDataMultiPart();
+ final FormDataBodyPart bodypart = new FormDataBodyPart(FormDataContentDisposition.name("file").fileName("file").build(),
+ entity, MediaType.TEXT_PLAIN_TYPE);
+ multipart.bodyPart(bodypart);
+
+ final Response response = target().path(path)
+ .request()
+ .post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA));
+
+ // Get Response ...
+ assertThat(response.getStatus(), is(status));
+ // Wait a second to make sure the files don't exist.
+ Thread.sleep(1000);
+
+ // Make sure that the message and it's parts have been closed and temporary files deleted.
+ assertThat("Temporary files were not deleted", matchingTempFiles(tempDir), is(expectedTempFiles));
+ }
+
+ private int matchingTempFiles(final String tempDir) throws IOException {
+ AtomicInteger count = new AtomicInteger(0);
+ Files.walkFileTree(Paths.get(tempDir), new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+ Path name = file.getFileName();
+ if ((name.startsWith("rep") || name.startsWith("MIME")) && name.endsWith("tmp")) {
+ count.incrementAndGet();
+ }
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
+ });
+ return count.get();
+ }
+}
diff --git a/tests/integration/jersey-2878/pom.xml b/tests/integration/jersey-2878/pom.xml
new file mode 100644
index 0000000..2cf6ae1
--- /dev/null
+++ b/tests/integration/jersey-2878/pom.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2878</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2878</name>
+
+ <description>
+ Reproducer of JERSEY-2878.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.connectors</groupId>
+ <artifactId>jersey-apache-connector</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2878/src/main/java/org/glassfish/jersey/tests/integration/jersey2878/TestApplication.java b/tests/integration/jersey-2878/src/main/java/org/glassfish/jersey/tests/integration/jersey2878/TestApplication.java
new file mode 100644
index 0000000..a7f533e
--- /dev/null
+++ b/tests/integration/jersey-2878/src/main/java/org/glassfish/jersey/tests/integration/jersey2878/TestApplication.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2878;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * Jersey application for JERSEY-2878.
+ *
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+@ApplicationPath("/")
+public class TestApplication extends ResourceConfig {
+
+ public TestApplication() {
+ register(TestResource.class);
+ }
+}
diff --git a/tests/integration/jersey-2878/src/main/java/org/glassfish/jersey/tests/integration/jersey2878/TestResource.java b/tests/integration/jersey-2878/src/main/java/org/glassfish/jersey/tests/integration/jersey2878/TestResource.java
new file mode 100644
index 0000000..eaada6a
--- /dev/null
+++ b/tests/integration/jersey-2878/src/main/java/org/glassfish/jersey/tests/integration/jersey2878/TestResource.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2878;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * A simple resource that returns a string.
+ *
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+@Path("string")
+public class TestResource {
+
+ @GET
+ public String string() {
+ return "Hello, World! "
+ + "In production this response would be large, "
+ + "and unsuitable for buffering in memory";
+ }
+}
diff --git a/tests/integration/jersey-2878/src/test/java/org/glassfish/jersey/tests/integration/jersey2878/Jersey2878ApacheITCase.java b/tests/integration/jersey-2878/src/test/java/org/glassfish/jersey/tests/integration/jersey2878/Jersey2878ApacheITCase.java
new file mode 100644
index 0000000..8786b52
--- /dev/null
+++ b/tests/integration/jersey-2878/src/test/java/org/glassfish/jersey/tests/integration/jersey2878/Jersey2878ApacheITCase.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2878;
+
+import org.glassfish.jersey.apache.connector.ApacheConnectorProvider;
+import org.glassfish.jersey.client.ClientConfig;
+
+/**
+ * Additional test class that tests jersey client configured with the apache http.
+ *
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+public class Jersey2878ApacheITCase extends Jersey2878ITCase {
+
+ @Override
+ protected void configureClient(final ClientConfig config) {
+ config.connectorProvider(new ApacheConnectorProvider());
+
+ super.configureClient(config);
+ }
+}
diff --git a/tests/integration/jersey-2878/src/test/java/org/glassfish/jersey/tests/integration/jersey2878/Jersey2878ITCase.java b/tests/integration/jersey-2878/src/test/java/org/glassfish/jersey/tests/integration/jersey2878/Jersey2878ITCase.java
new file mode 100644
index 0000000..a31f49f
--- /dev/null
+++ b/tests/integration/jersey-2878/src/test/java/org/glassfish/jersey/tests/integration/jersey2878/Jersey2878ITCase.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2878;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.client.ClientResponseContext;
+import javax.ws.rs.client.ClientResponseFilter;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.fail;
+
+public class Jersey2878ITCase extends JerseyTest {
+
+ private List<InputStream> responseInputStreams = new ArrayList<>();
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Override
+ protected Application configure() {
+ return new TestApplication();
+ }
+
+ @Override
+ protected void configureClient(ClientConfig config) {
+ ClientResponseFilter trackInputStreams = new ClientResponseFilter() {
+ @Override
+ public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
+ responseInputStreams.add(responseContext.getEntityStream());
+ }
+ };
+
+ config.register(trackInputStreams);
+ }
+
+ private static void consumeStreamFully(InputStream inputStream) throws IOException {
+ while (inputStream.read() != -1) {
+ //consume the stream fully
+ }
+ }
+
+ @Test
+ public void thisShouldWorkButFails() throws Exception {
+ InputStream stream = target("string").request().get(InputStream.class);
+ try {
+ consumeStreamFully(stream);
+ } finally {
+ stream.close();
+ }
+
+ try {
+ stream.read();
+ fail("Exception was not thrown when read() was called on closed stream! Stream implementation: " + stream.getClass());
+ } catch (IOException e) {
+ // this is desired
+ }
+
+ assertThatAllInputStreamsAreClosed();
+ }
+
+ @Test
+ public void thisWorksButIsReallyUgly() throws Exception {
+ Response response = target("string").request().get();
+ if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
+ throw new RuntimeException("We have to manually check that the response was successful");
+ }
+ InputStream stream = response.readEntity(InputStream.class);
+ try {
+ consumeStreamFully(stream);
+ } finally {
+ response.close();
+ }
+
+ try {
+ stream.read();
+ fail("Exception was not thrown when read() was called on closed stream! Stream implementation: " + stream.getClass());
+ } catch (IOException e) {
+ // this is desired
+ }
+
+ assertThatAllInputStreamsAreClosed();
+ }
+
+ @Test
+ public void thisAlsoFails() throws Exception {
+ Response response = target("string").request().get();
+ if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
+ throw new RuntimeException("We have to manually check that the response was successful");
+ }
+
+ InputStream stream = response.readEntity(InputStream.class);
+ try {
+ consumeStreamFully(stream);
+ } finally {
+ stream.close();
+ }
+
+ try {
+ stream.read();
+ fail("Exception was not thrown when read() was called on closed stream! Stream implementation: " + stream.getClass());
+ } catch (IOException e) {
+ // this is desired
+ }
+
+ assertThatAllInputStreamsAreClosed();
+ }
+
+ @Test
+ public void worksWithACast_ifYouKnowThatYouCanCast() throws Exception {
+ Response response = target("string").request().get();
+ if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
+ throw new RuntimeException("We have to manually check that the response was successful");
+ }
+
+ InputStream stream = (InputStream) response.getEntity();
+ try {
+ consumeStreamFully(stream);
+ } finally {
+ stream.close();
+ }
+
+ try {
+ stream.read();
+ fail("Exception was not thrown when read() was called on closed stream! Stream implementation: " + stream.getClass());
+ } catch (IOException e) {
+ // this is desired
+ }
+
+ assertThatAllInputStreamsAreClosed();
+ }
+
+ private void assertThatAllInputStreamsAreClosed() {
+ if (responseInputStreams.size() == 0) {
+ fail("no input stream to check");
+ }
+ for (InputStream stream : responseInputStreams) {
+ assertClosed(stream);
+ }
+ }
+
+ private void assertClosed(InputStream stream) {
+ try {
+ byte[] buffer = new byte[256];
+ stream.read(buffer); //it's not ignored — we're checking for the exception
+ fail("Stream is not closed! Stream implementation: " + stream.getClass());
+ } catch (IOException e) {
+ // an exception is desired
+ }
+ }
+}
diff --git a/tests/integration/jersey-2892/pom.xml b/tests/integration/jersey-2892/pom.xml
new file mode 100644
index 0000000..1e4647f
--- /dev/null
+++ b/tests/integration/jersey-2892/pom.xml
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-2892</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-2892</name>
+
+ <description>
+ Reproducer of JERSEY-2892.
+
+ Repeating classes in object graph of entity filtering facility should not be always filtered out.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- which jersey media provider to use is determined in web.xml by using 'jersey.config.jsonFeature' init param -->
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-moxy</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-json-jackson</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-2892/src/main/java/org/glassfish/jersey/tests/integration/jersey2892/TestApplication.java b/tests/integration/jersey-2892/src/main/java/org/glassfish/jersey/tests/integration/jersey2892/TestApplication.java
new file mode 100644
index 0000000..f1b5eb0
--- /dev/null
+++ b/tests/integration/jersey-2892/src/main/java/org/glassfish/jersey/tests/integration/jersey2892/TestApplication.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2892;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.message.filtering.EntityFilteringFeature;
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * Jersey application for JERSEY-2878 and also J-605 (which is derived from the former one).
+ *
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+@ApplicationPath("/")
+public class TestApplication extends ResourceConfig {
+
+ public TestApplication() {
+ register(TestResource.class);
+ register(EntityFilteringFeature.class);
+ }
+}
diff --git a/tests/integration/jersey-2892/src/main/java/org/glassfish/jersey/tests/integration/jersey2892/TestResource.java b/tests/integration/jersey-2892/src/main/java/org/glassfish/jersey/tests/integration/jersey2892/TestResource.java
new file mode 100644
index 0000000..c59b252
--- /dev/null
+++ b/tests/integration/jersey-2892/src/main/java/org/glassfish/jersey/tests/integration/jersey2892/TestResource.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2892;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import javax.xml.bind.annotation.XmlTransient;
+
+/**
+ * A resource that provides a means to test whether repeating classes in object graph are correctly filtered out.
+ *
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+@Path("/")
+@Produces(MediaType.APPLICATION_JSON)
+public class TestResource {
+
+ @GET
+ @Path("pointer")
+ public Pointer pointer() {
+ return new Pointer();
+ }
+
+ public static class Pointer {
+
+ public final Persons persons = new Persons();
+ }
+
+ @GET
+ @Path("test")
+ public Persons issue() {
+ return new Persons();
+ }
+
+ public static class Persons {
+
+ public final Person first = new Person("Larry", "Amphitheatre Pkwy", 1600, "Mountain View");
+ public final Person second = new Person("Bill", "Microsoft Way", 1, "Redmond");
+ }
+
+ public static class Person {
+
+ public Person() {
+ }
+
+ public Person(final String name, final String streetName, final int streetNumber, final String city) {
+ this.name = name;
+ address = new Address(streetName, streetNumber, city);
+ }
+
+ public Address address;
+ public String name;
+ }
+
+ public static class Address {
+
+ public Address() {
+ }
+
+ public Address(final String name, final int number, final String city) {
+ this.city = city;
+ street = new Street(name, number);
+ }
+
+ public Street street;
+ public String city;
+ }
+
+ public static class Street {
+
+ public Street() {
+ }
+
+ public Street(final String name, final int number) {
+ this.name = name;
+ this.number = number;
+ }
+
+ public String name;
+ public int number;
+ }
+
+ @GET
+ @Path("recursive")
+ public Recursive recursive() {
+ return new Recursive();
+ }
+
+ public static class Recursive {
+
+ public String idRecursive = "a";
+ public SubField subField = new SubField();
+ }
+
+ public static class SubField {
+
+ public final String idSubField = "b";
+ public final SubSubField subSubField;
+
+ public SubField() {
+ subSubField = new SubSubField(this);
+ }
+ }
+
+ public static class SubSubField {
+
+ public final String idSubSubField = "c";
+
+ @XmlTransient
+ public SubField subField;
+
+ public SubSubField() {
+ }
+
+ public SubSubField(final SubField subField) {
+ this.subField = subField;
+ }
+ }
+}
diff --git a/tests/integration/jersey-2892/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-2892/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..d52a435
--- /dev/null
+++ b/tests/integration/jersey-2892/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <servlet>
+ <servlet-name>jerseyMoxyFilteringFeature</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2892.TestApplication</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.jsonFeature</param-name>
+ <param-value>MoxyJsonFeature</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>jerseyMoxyFilteringFeature</servlet-name>
+ <url-pattern>/moxy/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet>
+ <servlet-name>jerseyJacksonFilteringFeature</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey2892.TestApplication</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.jsonFeature</param-name>
+ <param-value>JacksonFeature</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>jerseyJacksonFilteringFeature</servlet-name>
+ <url-pattern>/jackson/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
diff --git a/tests/integration/jersey-2892/src/test/java/org/glassfish/jersey/tests/integration/jersey2892/AbstractJerseyEntityFilteringITCase.java b/tests/integration/jersey-2892/src/test/java/org/glassfish/jersey/tests/integration/jersey2892/AbstractJerseyEntityFilteringITCase.java
new file mode 100644
index 0000000..ac5a7ab
--- /dev/null
+++ b/tests/integration/jersey-2892/src/test/java/org/glassfish/jersey/tests/integration/jersey2892/AbstractJerseyEntityFilteringITCase.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2892;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests whether classes repeating in the object graph are filtered out correctly.
+ *
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+public abstract class AbstractJerseyEntityFilteringITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new TestApplication();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ /**
+ * Tests whether sub-sub-field, {@link TestResource.Street} in particular,
+ * is not filtered out.
+ * <p/>
+ * This corresponds with the JERSEY-2892 reported case.
+ */
+ @Test
+ public void testWhetherSubSubFiledIsNotFilteredOut() {
+ Response response = target(provider() + "/test").request(MediaType.APPLICATION_JSON_TYPE).get();
+
+ final TestResource.Persons persons = response.readEntity(TestResource.Persons.class);
+
+ Assert.assertEquals("Amphitheatre Pkwy", persons.first.address.street.name);
+ Assert.assertEquals("Microsoft Way", persons.second.address.street.name);
+ }
+
+ /**
+ * Tests whether a de-referenced case of the reported problem is still correctly not filtered out. In particular, a
+ * sub-sub-sub-field of the same class is not filtered out.
+ */
+ @Test
+ public void testWhetherSubSubSubFieldIsNotFilteredOut() {
+ Response response = target(provider() + "/pointer").request(MediaType.APPLICATION_JSON_TYPE).get();
+
+ final TestResource.Pointer pointer = response.readEntity(TestResource.Pointer.class);
+
+ Assert.assertEquals("Amphitheatre Pkwy", pointer.persons.first.address.street.name);
+ Assert.assertEquals("Microsoft Way", pointer.persons.second.address.street.name);
+ }
+
+ /**
+ * Tests whether a reference cycle is detected and infinite recursion is prevented.
+ */
+ @Test
+ public void testWhetherReferenceCycleIsDetected() {
+ Response response = target(provider() + "/recursive").request(MediaType.APPLICATION_JSON_TYPE).get();
+
+ final TestResource.Recursive recursive = response.readEntity(TestResource.Recursive.class);
+
+ Assert.assertEquals("c", recursive.subField.subSubField.idSubSubField);
+ }
+
+ /**
+ * Jersey Entity filtering feature provider.
+ *
+ * @return The provider string to match with appropriate Jersey app configured in web.xml.
+ */
+ protected abstract String provider();
+
+}
diff --git a/tests/integration/jersey-2892/src/test/java/org/glassfish/jersey/tests/integration/jersey2892/J605MoxyITCase.java b/tests/integration/jersey-2892/src/test/java/org/glassfish/jersey/tests/integration/jersey2892/J605MoxyITCase.java
new file mode 100644
index 0000000..501df41
--- /dev/null
+++ b/tests/integration/jersey-2892/src/test/java/org/glassfish/jersey/tests/integration/jersey2892/J605MoxyITCase.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2892;
+
+/**
+ * Tests whether classes repeating in the object graph are filtered out correctly when using MOXY json provider.
+ *
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+public class J605MoxyITCase extends AbstractJerseyEntityFilteringITCase {
+
+ @Override
+ protected String provider() {
+ return "moxy";
+ }
+}
diff --git a/tests/integration/jersey-2892/src/test/java/org/glassfish/jersey/tests/integration/jersey2892/Jersey2892JacksonITCase.java b/tests/integration/jersey-2892/src/test/java/org/glassfish/jersey/tests/integration/jersey2892/Jersey2892JacksonITCase.java
new file mode 100644
index 0000000..1ce858e
--- /dev/null
+++ b/tests/integration/jersey-2892/src/test/java/org/glassfish/jersey/tests/integration/jersey2892/Jersey2892JacksonITCase.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.jersey2892;
+
+/**
+ * Tests whether classes repeating in the object graph are filtered out correctly when using Jackson json provider.
+ *
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+public class Jersey2892JacksonITCase extends AbstractJerseyEntityFilteringITCase {
+
+ @Override
+ protected String provider() {
+ return "jackson";
+ }
+}
diff --git a/tests/integration/jersey-780/pom.xml b/tests/integration/jersey-780/pom.xml
new file mode 100644
index 0000000..2962171
--- /dev/null
+++ b/tests/integration/jersey-780/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-780</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-780</name>
+
+ <description>Servlet integration test - JERSEY-780 - Malformed URL returns a 500 instead of a 400</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/jersey-780/src/main/java/org/glassfish/jersey/tests/integration/jersey780/HelloWorldResource.java b/tests/integration/jersey-780/src/main/java/org/glassfish/jersey/tests/integration/jersey780/HelloWorldResource.java
new file mode 100644
index 0000000..9049c36
--- /dev/null
+++ b/tests/integration/jersey-780/src/main/java/org/glassfish/jersey/tests/integration/jersey780/HelloWorldResource.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.jersey780;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Michal Gajdos
+ */
+@Path("helloworld")
+public class HelloWorldResource {
+
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "Hello World! " + this.getClass().getPackage().getName();
+ }
+}
diff --git a/tests/integration/jersey-780/src/main/java/org/glassfish/jersey/tests/integration/jersey780/Jersey780.java b/tests/integration/jersey-780/src/main/java/org/glassfish/jersey/tests/integration/jersey780/Jersey780.java
new file mode 100644
index 0000000..5ea850a
--- /dev/null
+++ b/tests/integration/jersey-780/src/main/java/org/glassfish/jersey/tests/integration/jersey780/Jersey780.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.jersey780;
+
+import java.util.Collections;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+/**
+ * @author Michal Gajdos
+ */
+public class Jersey780 extends Application {
+ @SuppressWarnings({"unchecked"})
+ @Override
+ public Set<Class<?>> getClasses() {
+ return Collections.<Class<?>>singleton(HelloWorldResource.class);
+ }
+}
diff --git a/tests/integration/jersey-780/src/main/webapp/WEB-INF/web.xml b/tests/integration/jersey-780/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..007d609
--- /dev/null
+++ b/tests/integration/jersey-780/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2012, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>testServlet1</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.jersey780.Jersey780</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>testServlet1</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/jersey-780/src/test/java/org/glassfish/jersey/tests/integration/jersey780/HelloWorldResourceITCase.java b/tests/integration/jersey-780/src/test/java/org/glassfish/jersey/tests/integration/jersey780/HelloWorldResourceITCase.java
new file mode 100644
index 0000000..f54d531
--- /dev/null
+++ b/tests/integration/jersey-780/src/test/java/org/glassfish/jersey/tests/integration/jersey780/HelloWorldResourceITCase.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.jersey780;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Michal Gajdos
+ */
+public class HelloWorldResourceITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig().registerInstances(new Jersey780());
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testInvalidUrl() throws Exception {
+ List<Integer> expectedCodes = Arrays.asList(
+ Response.Status.BAD_REQUEST.getStatusCode(), Response.Status.NOT_FOUND.getStatusCode());
+ List<String> expectedPhrases = Arrays.asList(
+ Response.Status.BAD_REQUEST.getReasonPhrase(), Response.Status.NOT_FOUND.getReasonPhrase());
+
+ final URL url = new URL(getBaseUri().toString() + "^");
+ final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+
+ connection.connect();
+
+ final int statusCode = connection.getResponseCode();
+ final String statusMessage = connection.getResponseMessage();
+
+ connection.disconnect();
+
+ assertTrue("Wrong response status code: " + statusCode,
+ expectedCodes.contains(statusCode));
+ assertTrue("Wrong response status reason: " + statusMessage,
+ expectedPhrases.contains(statusMessage));
+ }
+}
diff --git a/tests/integration/pom.xml b/tests/integration/pom.xml
new file mode 100644
index 0000000..d28865c
--- /dev/null
+++ b/tests/integration/pom.xml
@@ -0,0 +1,242 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <packaging>pom</packaging>
+ <name>jersey-tests-integration</name>
+
+ <modules>
+ <module>async-jersey-filter</module>
+ <module>cdi-beanvalidation-webapp</module>
+ <module>cdi-ejb-test-webapp</module>
+ <module>cdi-iface-with-non-jaxrs-impl-test-webapp</module>
+ <module>cdi-multimodule</module>
+ <module>ejb-multimodule-reload</module>
+ <module>cdi-multipart-webapp</module>
+ <module>cdi-test-webapp</module>
+ <module>cdi-with-jersey-injection-custom-cfg-webapp</module>
+ <module>cdi-with-jersey-injection-custom-hk2-banned-webapp</module>
+ <module>cdi-with-jersey-injection-webapp</module>
+ <module>client-connector-provider</module>
+ <module>ejb-multimodule</module>
+ <module>ejb-test-webapp</module>
+ <module>j-376</module>
+ <module>j-441</module>
+ <module>j-59</module>
+ <module>jaxrs-component-inject</module>
+ <module>jersey-1107</module>
+ <module>jersey-1223</module>
+ <module>jersey-1604</module>
+ <module>jersey-1667</module>
+ <module>jersey-1829</module>
+ <module>jersey-1883</module>
+ <module>jersey-1928</module>
+ <module>jersey-1960</module>
+ <module>jersey-1964</module>
+ <module>jersey-2031</module>
+ <module>jersey-2136</module>
+ <module>jersey-2137</module>
+ <module>jersey-2154</module>
+ <module>jersey-2160</module>
+ <module>jersey-2164</module>
+ <module>jersey-2167</module>
+ <module>jersey-2176</module>
+ <module>jersey-2184</module>
+ <module>jersey-2255</module>
+ <module>jersey-2322</module>
+ <module>jersey-2335</module>
+ <module>jersey-2421</module>
+ <module>jersey-2551</module>
+ <module>jersey-2612</module>
+ <module>jersey-2637</module>
+ <module>jersey-2654</module>
+ <module>jersey-2673</module>
+ <module>jersey-2689</module>
+ <module>jersey-2704</module>
+ <module>jersey-2776</module>
+ <module>jersey-2794</module>
+ <module>jersey-2846</module>
+ <module>jersey-2878</module>
+ <module>jersey-2892</module>
+ <module>jersey-780</module>
+ <module>portability-jersey-1</module>
+ <module>portability-jersey-2</module>
+ <module>property-check</module>
+ <module>security-digest</module>
+ <module>servlet-2.5-autodiscovery-1</module>
+ <module>servlet-2.5-autodiscovery-2</module>
+ <module>servlet-2.5-filter</module>
+ <module>servlet-2.5-inflector-1</module>
+ <module>servlet-2.5-init-1</module>
+ <module>servlet-2.5-init-2</module>
+ <module>servlet-2.5-init-3</module>
+ <module>servlet-2.5-init-4</module>
+ <module>servlet-2.5-init-5</module>
+ <module>servlet-2.5-init-6</module>
+ <module>servlet-2.5-init-7</module>
+ <module>servlet-2.5-init-8</module>
+ <module>servlet-2.5-mvc-1</module>
+ <module>servlet-2.5-mvc-2</module>
+ <module>servlet-2.5-mvc-3</module>
+ <module>servlet-2.5-reload</module>
+ <module>servlet-3-async</module>
+ <module>servlet-3-chunked-io</module>
+ <module>servlet-3-filter</module>
+ <module>servlet-3-gf-async</module>
+ <module>servlet-3-inflector-1</module>
+ <module>servlet-3-init-1</module>
+ <module>servlet-3-init-2</module>
+ <module>servlet-3-init-3</module>
+ <module>servlet-3-init-4</module>
+ <module>servlet-3-init-5</module>
+ <module>servlet-3-init-6</module>
+ <module>servlet-3-init-7</module>
+ <module>servlet-3-init-8</module>
+ <module>servlet-3-init-provider</module>
+ <module>servlet-3-params</module>
+ <module>servlet-3-sse-1</module>
+ <module>servlet-request-wrapper-binding-2</module>
+ <module>servlet-request-wrapper-binding</module>
+ <module>servlet-tests</module>
+ <module>sonar-test</module>
+ <!-- TODO: temporarily removing spring 4 integration test -->
+ <!-- TODO: conflict in ASM version (too old) of jetty plugin -->
+ <!--<module>spring4</module>-->
+ <module>tracing-support</module>
+ </modules>
+
+ <profiles>
+ <profile>
+ <id>default</id>
+ <properties>
+ <env>default</env>
+ <jersey.config.test.container.port>9998</jersey.config.test.container.port>
+ </properties>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ </profile>
+ <profile>
+ <id>sonar</id>
+ <properties>
+ <env>default</env>
+ <jersey.config.test.container.port>9998</jersey.config.test.container.port>
+ <jetty.log.file>${project.build.directory}/jetty-out.log</jetty.log.file>
+ </properties>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <!-- configure Jetty to run in a separated JVM in order to get proper coverage -->
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>start-jetty-forked</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>run-forked</goal>
+ </goals>
+ <configuration>
+ <contextPath>/</contextPath>
+ <scanIntervalSeconds>0</scanIntervalSeconds>
+ <waitForChild>false</waitForChild>
+ <jvmArgs>${server.coverage.argline} -Djetty.port=${jersey.config.test.container.port}
+ -Dorg.slf4j.simpleLogger.logFile=${jetty.log.file}
+ </jvmArgs>
+ </configuration>
+ </execution>
+ <execution>
+ <id>start-jetty</id>
+ <phase>none</phase>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.7.5</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+ </profile>
+
+ </profiles>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ <configuration>
+ <skip>${skip.tests}</skip>
+ <scanIntervalSeconds>10</scanIntervalSeconds>
+ <stopPort>9999</stopPort>
+ <stopKey>STOP</stopKey>
+ <webApp>
+ <contextPath>/</contextPath>
+ <webInfIncludeJarPattern>.*/.*jersey-[^/]\.jar$</webInfIncludeJarPattern>
+ </webApp>
+ <connectors>
+ <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
+ <port>${jersey.config.test.container.port}</port>
+ <maxIdleTime>60000</maxIdleTime>
+ </connector>
+ </connectors>
+ <jvmArgs>${server.coverage.argline}</jvmArgs>
+ </configuration>
+ <executions>
+ <execution>
+ <id>start-jetty</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <scanIntervalSeconds>0</scanIntervalSeconds>
+ <daemon>true</daemon>
+ </configuration>
+ </execution>
+ <execution>
+ <id>stop-jetty</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>stop</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
diff --git a/tests/integration/portability-jersey-1/pom.xml b/tests/integration/portability-jersey-1/pom.xml
new file mode 100644
index 0000000..c8499d7
--- /dev/null
+++ b/tests/integration/portability-jersey-1/pom.xml
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2012, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>portability-jersey-1</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-portability-jersey-1</name>
+
+ <description>Servlet portability test - testing co-bundling with Jersey 1</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-servlet-portability</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey.jersey-test-framework</groupId>
+ <artifactId>jersey-test-framework-external</artifactId>
+ <version>${jersey1.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey.jersey-test-framework</groupId>
+ <artifactId>jersey-test-framework-core</artifactId>
+ <version>${jersey1.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-server</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-servlet</artifactId>
+ <version>${jersey1.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <configuration>
+ <classpathDependencyExcludes> <!-- this is to ensure only one Jersey version is present in the classpath -->
+ <classpathDependencyExclude>org.glassfish.jersey.core:jersey-common</classpathDependencyExclude>
+ <classpathDependencyExclude>org.glassfish.jersey.core:jersey-server</classpathDependencyExclude>
+ <classpathDependencyExclude>org.glassfish.jersey.core:jersey-client</classpathDependencyExclude>
+ </classpathDependencyExcludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/portability-jersey-1/src/main/java/org/glassfish/jersey/tests/integration/portability/HelloWorldResource.java b/tests/integration/portability-jersey-1/src/main/java/org/glassfish/jersey/tests/integration/portability/HelloWorldResource.java
new file mode 100644
index 0000000..0f34d5b
--- /dev/null
+++ b/tests/integration/portability-jersey-1/src/main/java/org/glassfish/jersey/tests/integration/portability/HelloWorldResource.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.portability;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Martin Matula
+ */
+@Path("helloworld")
+public class HelloWorldResource {
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "Hello World!";
+ }
+}
diff --git a/tests/integration/portability-jersey-1/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey1Application.java b/tests/integration/portability-jersey-1/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey1Application.java
new file mode 100644
index 0000000..c56b9fa
--- /dev/null
+++ b/tests/integration/portability-jersey-1/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey1Application.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.portability;
+
+import com.sun.jersey.api.core.PackagesResourceConfig;
+
+/**
+ * @author Martin Matula
+ */
+public class Jersey1Application extends PackagesResourceConfig {
+ public Jersey1Application() {
+ // do the package scanning
+ super("org.glassfish.jersey.tests.integration.portability");
+
+ // explicitly add unannotated Jersey 1 specific resource
+ getExplicitRootResources().put("jersey", Jersey1Resource.class);
+ }
+}
diff --git a/tests/integration/portability-jersey-1/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey1Resource.java b/tests/integration/portability-jersey-1/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey1Resource.java
new file mode 100644
index 0000000..7444fcd
--- /dev/null
+++ b/tests/integration/portability-jersey-1/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey1Resource.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.portability;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+/**
+ * @author Martin Matula
+ */
+public class Jersey1Resource {
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String getJersey1() {
+ return "Using Jersey 1.x";
+ }
+}
diff --git a/tests/integration/portability-jersey-1/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey2Application.java b/tests/integration/portability-jersey-1/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey2Application.java
new file mode 100644
index 0000000..91e0e1b
--- /dev/null
+++ b/tests/integration/portability-jersey-1/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey2Application.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.portability;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.model.Resource;
+
+/**
+ * @author Martin Matula
+ */
+public class Jersey2Application extends ResourceConfig {
+
+ public Jersey2Application() {
+ // do the package scanning
+ packages("org.glassfish.jersey.tests.integration.portability");
+
+ // explicitly add unannotated Jersey 2 specific resource
+ Resource.Builder rb = Resource.builder(Jersey2Resource.class);
+ registerResources(rb.path("jersey").build());
+ }
+}
diff --git a/tests/integration/portability-jersey-1/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey2Resource.java b/tests/integration/portability-jersey-1/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey2Resource.java
new file mode 100644
index 0000000..f7683e3
--- /dev/null
+++ b/tests/integration/portability-jersey-1/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey2Resource.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.portability;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+/**
+ * @author Martin Matula
+ */
+public class Jersey2Resource {
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String getJersey2() {
+ return "Using Jersey 2.x";
+ }
+}
diff --git a/tests/integration/portability-jersey-1/src/main/webapp/WEB-INF/web.xml b/tests/integration/portability-jersey-1/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..5cd3e4c
--- /dev/null
+++ b/tests/integration/portability-jersey-1/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2012, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>Jersey Web Application</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.portability.PortableServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey1#com.sun.jersey.config.property.resourceConfigClass</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.portability.Jersey1Application</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey2#javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.portability.Jersey2Application</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>Jersey Web Application</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/portability-jersey-1/src/test/java/org/glassfish/jersey/tests/integration/portability/PortabilityITCase.java b/tests/integration/portability-jersey-1/src/test/java/org/glassfish/jersey/tests/integration/portability/PortabilityITCase.java
new file mode 100644
index 0000000..8d805e8
--- /dev/null
+++ b/tests/integration/portability-jersey-1/src/test/java/org/glassfish/jersey/tests/integration/portability/PortabilityITCase.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.portability;
+
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.test.framework.AppDescriptor;
+import com.sun.jersey.test.framework.JerseyTest;
+import com.sun.jersey.test.framework.WebAppDescriptor;
+import com.sun.jersey.test.framework.spi.container.TestContainerException;
+import com.sun.jersey.test.framework.spi.container.TestContainerFactory;
+import com.sun.jersey.test.framework.spi.container.external.ExternalTestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Martin Matula
+ */
+public class PortabilityITCase extends JerseyTest {
+
+ @Override
+ protected AppDescriptor configure() {
+ return new WebAppDescriptor.Builder().build();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testHelloWorld() throws Exception {
+ String s = resource().path("helloworld").get(String.class);
+ assertEquals("Hello World!", s);
+ }
+
+ @Test
+ public void testJersey() {
+ ClientResponse r = resource().path("jersey").get(ClientResponse.class);
+ assertEquals(200, r.getStatus());
+ assertEquals("Using Jersey 1.x", r.getEntity(String.class));
+ }
+
+ /**
+ * The whole project is setup for Jersey 2. Need to get the effective port number
+ * from Jersey 2 properties to make Hudson happy.
+ *
+ * @param defaultPort to use if no other configuration is available
+ * @return port number to use by the client
+ */
+ @Override
+ protected int getPort(int defaultPort) {
+
+ String port = System.getProperty("jersey.config.test.container.port");
+ if (null != port) {
+ try {
+ return Integer.parseInt(port);
+ } catch (NumberFormatException e) {
+ throw new TestContainerException("jersey.config.test.container.port with a "
+ + "value of \"" + port + "\" is not a valid integer.", e);
+ }
+ }
+
+ port = System.getProperty("JERSEY_TEST_PORT");
+ if (null != port) {
+ try {
+ return Integer.parseInt(port);
+ } catch (NumberFormatException e) {
+ throw new TestContainerException("JERSEY_TEST_PORT with a "
+ + "value of \"" + port + "\" is not a valid integer.", e);
+ }
+ }
+ return defaultPort;
+ }
+}
diff --git a/tests/integration/portability-jersey-2/pom.xml b/tests/integration/portability-jersey-2/pom.xml
new file mode 100644
index 0000000..0e63542
--- /dev/null
+++ b/tests/integration/portability-jersey-2/pom.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2012, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>portability-jersey-2</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-portability-jersey-2</name>
+
+ <description>Servlet portability test - testing co-bundling with Jersey 2</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-servlet-portability</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-servlet</artifactId>
+ <version>${jersey1.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <configuration>
+ <classpathDependencyExcludes> <!-- this is to ensure only one Jersey version is present in the classpath -->
+ <classpathDependencyExclude>com.sun.jersey:jersey-core</classpathDependencyExclude>
+ <classpathDependencyExclude>com.sun.jersey:jersey-server</classpathDependencyExclude>
+ <classpathDependencyExclude>com.sun.jersey:jersey-servlet</classpathDependencyExclude>
+ </classpathDependencyExcludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/portability-jersey-2/src/main/java/org/glassfish/jersey/tests/integration/portability/HelloWorldResource.java b/tests/integration/portability-jersey-2/src/main/java/org/glassfish/jersey/tests/integration/portability/HelloWorldResource.java
new file mode 100644
index 0000000..0f34d5b
--- /dev/null
+++ b/tests/integration/portability-jersey-2/src/main/java/org/glassfish/jersey/tests/integration/portability/HelloWorldResource.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.portability;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Martin Matula
+ */
+@Path("helloworld")
+public class HelloWorldResource {
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "Hello World!";
+ }
+}
diff --git a/tests/integration/portability-jersey-2/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey1Application.java b/tests/integration/portability-jersey-2/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey1Application.java
new file mode 100644
index 0000000..c56b9fa
--- /dev/null
+++ b/tests/integration/portability-jersey-2/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey1Application.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.portability;
+
+import com.sun.jersey.api.core.PackagesResourceConfig;
+
+/**
+ * @author Martin Matula
+ */
+public class Jersey1Application extends PackagesResourceConfig {
+ public Jersey1Application() {
+ // do the package scanning
+ super("org.glassfish.jersey.tests.integration.portability");
+
+ // explicitly add unannotated Jersey 1 specific resource
+ getExplicitRootResources().put("jersey", Jersey1Resource.class);
+ }
+}
diff --git a/tests/integration/portability-jersey-2/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey1Resource.java b/tests/integration/portability-jersey-2/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey1Resource.java
new file mode 100644
index 0000000..7444fcd
--- /dev/null
+++ b/tests/integration/portability-jersey-2/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey1Resource.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.portability;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+/**
+ * @author Martin Matula
+ */
+public class Jersey1Resource {
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String getJersey1() {
+ return "Using Jersey 1.x";
+ }
+}
diff --git a/tests/integration/portability-jersey-2/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey2Application.java b/tests/integration/portability-jersey-2/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey2Application.java
new file mode 100644
index 0000000..91e0e1b
--- /dev/null
+++ b/tests/integration/portability-jersey-2/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey2Application.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.portability;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.model.Resource;
+
+/**
+ * @author Martin Matula
+ */
+public class Jersey2Application extends ResourceConfig {
+
+ public Jersey2Application() {
+ // do the package scanning
+ packages("org.glassfish.jersey.tests.integration.portability");
+
+ // explicitly add unannotated Jersey 2 specific resource
+ Resource.Builder rb = Resource.builder(Jersey2Resource.class);
+ registerResources(rb.path("jersey").build());
+ }
+}
diff --git a/tests/integration/portability-jersey-2/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey2Resource.java b/tests/integration/portability-jersey-2/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey2Resource.java
new file mode 100644
index 0000000..f7683e3
--- /dev/null
+++ b/tests/integration/portability-jersey-2/src/main/java/org/glassfish/jersey/tests/integration/portability/Jersey2Resource.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.portability;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+/**
+ * @author Martin Matula
+ */
+public class Jersey2Resource {
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String getJersey2() {
+ return "Using Jersey 2.x";
+ }
+}
diff --git a/tests/integration/portability-jersey-2/src/main/webapp/WEB-INF/web.xml b/tests/integration/portability-jersey-2/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..5cd3e4c
--- /dev/null
+++ b/tests/integration/portability-jersey-2/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2012, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>Jersey Web Application</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.portability.PortableServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey1#com.sun.jersey.config.property.resourceConfigClass</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.portability.Jersey1Application</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey2#javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.portability.Jersey2Application</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>Jersey Web Application</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/portability-jersey-2/src/test/java/org/glassfish/jersey/tests/integration/portability/PortabilityITCase.java b/tests/integration/portability-jersey-2/src/test/java/org/glassfish/jersey/tests/integration/portability/PortabilityITCase.java
new file mode 100644
index 0000000..b158fda
--- /dev/null
+++ b/tests/integration/portability-jersey-2/src/test/java/org/glassfish/jersey/tests/integration/portability/PortabilityITCase.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.portability;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Martin Matula
+ */
+public class PortabilityITCase extends JerseyTest {
+ @Override
+ protected Application configure() {
+ // dummy resource config
+ return new ResourceConfig();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testHelloWorld() throws Exception {
+ String s = target("helloworld").request().get(String.class);
+ assertEquals("Hello World!", s);
+ }
+
+ @Test
+ public void testJersey() {
+ Response r = target("jersey").request().get();
+ assertEquals(200, r.getStatus());
+ assertEquals("Using Jersey 2.x", r.readEntity(String.class));
+ }
+}
diff --git a/tests/integration/property-check/pom.xml b/tests/integration/property-check/pom.xml
new file mode 100644
index 0000000..7fd7e4b
--- /dev/null
+++ b/tests/integration/property-check/pom.xml
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>property-check</artifactId>
+ <packaging>jar</packaging>
+ <name>jersey-tests-integration-property-check</name>
+
+ <description>Property overlapping/duplicate check test</description>
+ <!--
+ Note that whenever new *Properties.java file is created, it has to be added in the test source file
+ in order to be checked for duplicates/overlapping.
+
+ Use find . -name "*Properties.java" in the Jersey root project folder to find files to add.
+ -->
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-common</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-client</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.connectors</groupId>
+ <artifactId>jersey-jetty-connector</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.connectors</groupId>
+ <artifactId>jersey-apache-connector</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.security</groupId>
+ <artifactId>oauth1-server</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-multipart</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-sse</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/property-check/src/test/java/org/glassfish/jersey/tests/integration/propertycheck/PropertyOverlappingCheckTest.java b/tests/integration/property-check/src/test/java/org/glassfish/jersey/tests/integration/propertycheck/PropertyOverlappingCheckTest.java
new file mode 100644
index 0000000..ef7072e
--- /dev/null
+++ b/tests/integration/property-check/src/test/java/org/glassfish/jersey/tests/integration/propertycheck/PropertyOverlappingCheckTest.java
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.propertycheck;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import org.glassfish.jersey.CommonProperties;
+import org.glassfish.jersey.apache.connector.ApacheClientProperties;
+import org.glassfish.jersey.client.ClientProperties;
+import org.glassfish.jersey.internal.util.PropertiesClass;
+import org.glassfish.jersey.internal.util.Property;
+import org.glassfish.jersey.internal.util.PropertyAlias;
+import org.glassfish.jersey.jetty.connector.JettyClientProperties;
+import org.glassfish.jersey.media.multipart.MultiPartProperties;
+import org.glassfish.jersey.media.sse.SseFeature;
+import org.glassfish.jersey.message.MessageProperties;
+import org.glassfish.jersey.server.ServerProperties;
+import org.glassfish.jersey.server.internal.InternalServerProperties;
+import org.glassfish.jersey.server.oauth1.OAuth1ServerProperties;
+import org.glassfish.jersey.servlet.ServletProperties;
+import org.glassfish.jersey.test.TestProperties;
+
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test, that there are no properties with overlapping names in known Jersey {@code *Properties} and {@code *Feature}
+ * classes.
+ * <p>
+ * For technical reasons, we do not want the property names to <i>overlap</i>.
+ * In other words, no property should contain a <i>namespace prefix</i>, that is already used as a concrete property name,
+ * such as {@code a.b} and {@code a.b.c}.
+ * </p>
+ * <p>
+ * Additionally, the test also reports all the duplicates property names found throughout the checked files.
+ * </p>
+ * <p>
+ * Note that the list of files is hardcoded directly in this test in a static array
+ * (to avoid the necessity of writing custom class loader for this test).
+ * If a java class containing properties should by included in the check, it has to be added here.
+ * Also note that the test is relying on {@link Property}, {@link PropertiesClass} and {@link PropertyAlias} annotations
+ * to recognize individual properties.
+ * </p>
+ *
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+public class PropertyOverlappingCheckTest {
+
+ private static final Logger log = Logger.getLogger(PropertyOverlappingCheckTest.class.getName());
+
+ private static final Class<?>[] classes = new Class[] {
+ JettyClientProperties.class,
+ ApacheClientProperties.class,
+ OAuth1ServerProperties.class,
+ ServletProperties.class,
+ CommonProperties.class,
+ MessageProperties.class,
+ ServerProperties.class,
+ InternalServerProperties.class,
+ ClientProperties.class,
+ MultiPartProperties.class,
+ TestProperties.class,
+ SseFeature.class
+ };
+
+ private static class ProblemReport {
+
+ private final String parentProperty;
+ private final String classNameParent;
+ private final String childProperty;
+ private final String classNameChild;
+ private final boolean duplicate;
+
+ private ProblemReport(String parentProperty,
+ String classNameParent,
+ String childProperty,
+ String classNameChild,
+ boolean duplicate) {
+ this.parentProperty = parentProperty;
+ this.classNameParent = classNameParent;
+ this.childProperty = childProperty;
+ this.classNameChild = classNameChild;
+ this.duplicate = duplicate;
+ }
+
+ private ProblemReport(String parentProperty, String classNameParent, String childProperty, String classNameChild) {
+ this(parentProperty, classNameParent, childProperty, classNameChild, false);
+ }
+
+ public String getParentProperty() {
+ return parentProperty;
+ }
+
+ public String getClassNameParent() {
+ return classNameParent;
+ }
+
+ public String getChildProperty() {
+ return childProperty;
+ }
+
+ public String getClassNameChild() {
+ return classNameChild;
+ }
+
+ public boolean isDuplicate() {
+ return duplicate;
+ }
+ }
+
+ @Test
+ public void test() throws IllegalAccessException {
+ List<String> allPropertyNames = new ArrayList<>();
+ Map<String, String> propertyToClassMap = new HashMap<>();
+ List<ProblemReport> problems = new ArrayList<>();
+
+ // iterate over all the string fields of above declared classes
+ for (Class<?> clazz : classes) {
+ final boolean checkFieldPropertyAnnotation = clazz.getAnnotation(PropertiesClass.class) == null;
+ Field[] fields = clazz.getFields();
+ for (Field field : fields) {
+ if (checkFieldPropertyAnnotation && field.getAnnotation(Property.class) == null) {
+ // skip fields not annotated with @Property in classes not annotated with @PropertiesClass
+ continue;
+ }
+ if (field.getAnnotation(PropertyAlias.class) != null) {
+ // skip property aliases
+ continue;
+ }
+ if (field.getType().isAssignableFrom(String.class)) {
+ String propertyValue = (String) field.get(null);
+ allPropertyNames.add(propertyValue);
+ // check if there is already such property in the map; report a problem if true or store the
+ // property-to-class relationship into the map for later use
+ String propertyMapEntry = propertyToClassMap.get(propertyValue);
+ if (propertyToClassMap.get(propertyValue) != null) {
+ // log.info("Duplicate property found: " + propertyValue + " in " +
+ // propertyMapEntry + " and "
+ // + clazz.getName() + ". Test won't fail because of this, as the check
+ // is currently disabled.");
+ // this cannot cause the test to fail, as there are aliases in ClientProperties and ServerProperties,
+ // which are by definition equal to those defined in CommonProperties
+ problems.add(new ProblemReport(propertyValue, propertyMapEntry, propertyValue, clazz.getName(), true));
+ } else {
+ propertyToClassMap.put(propertyValue, clazz.getName());
+ }
+ }
+ }
+ }
+ // sort the properties by name (natural), so that if two properties have overlapping names,
+ // they will appear one after another
+ Collections.sort(allPropertyNames);
+
+ String previousProperty = "";
+ for (String property : allPropertyNames) {
+ // is the property overlapping with the previous one?
+ // do not consider overlapping such as foo.bar vs foo.barbar, just foo.bar vs foo.bar.bar
+ if (property.startsWith(previousProperty + ".")) {
+ problems.add(new ProblemReport(previousProperty, propertyToClassMap.get(previousProperty),
+ property, propertyToClassMap.get(property)));
+ } else {
+ // the "pointer" is moved only if there was no overlapping detected in this iteration
+ // as this would potentially hide the 2nd (or n-th) property overlapping with the same one
+ previousProperty = property;
+ }
+ }
+
+ if (!problems.isEmpty()) {
+ log.severe("Property naming problems detected: ");
+ for (ProblemReport problem : problems) {
+ if (problem.isDuplicate()) {
+ log.severe("Duplicate property name: \n property: " + problem.getParentProperty()
+ + "\n class1: " + problem.getClassNameParent()
+ + "\n class2: " + problem.getClassNameChild() + "\n");
+ } else {
+ log.severe("Overlapping property names: \n property1: "
+ + problem.getParentProperty() + "\n in: " + problem.getClassNameParent()
+ + "\n property2: "
+ + problem.getChildProperty() + "\n in " + problem.getClassNameChild() + "\n");
+ }
+ }
+ }
+ // fail if problems detected
+ assertTrue(problems.isEmpty());
+ }
+}
diff --git a/tests/integration/security-digest/pom.xml b/tests/integration/security-digest/pom.xml
new file mode 100644
index 0000000..4cffdf8
--- /dev/null
+++ b/tests/integration/security-digest/pom.xml
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>project</artifactId>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>security-digest</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-jersey-security-digest</name>
+ <url>http://maven.apache.org</url>
+
+
+ <description>Test of DIGEST authentication</description>
+
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+
+ <configuration>
+ <!-- define login service for jetty and the realm to be used -->
+ <loginServices>
+ <loginService implementation="org.eclipse.jetty.security.HashLoginService">
+ <name>my-realm</name>
+ <config>${basedir}/src/main/resources/jetty/realm.properties</config>
+ </loginService>
+ </loginServices>
+ </configuration>
+ </plugin>
+
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/security-digest/src/main/java/org/glassfish/jersey/tests/integration/securitydigest/MyApplication.java b/tests/integration/security-digest/src/main/java/org/glassfish/jersey/tests/integration/securitydigest/MyApplication.java
new file mode 100644
index 0000000..8c480aa
--- /dev/null
+++ b/tests/integration/security-digest/src/main/java/org/glassfish/jersey/tests/integration/securitydigest/MyApplication.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.securitydigest;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.ServerProperties;
+
+/**
+ *
+ * @author Miroslav Fuksa
+ */
+@ApplicationPath("/rest/*")
+public class MyApplication extends ResourceConfig {
+
+ public MyApplication() {
+ register(MyResource.class);
+ }
+}
diff --git a/tests/integration/security-digest/src/main/java/org/glassfish/jersey/tests/integration/securitydigest/MyResource.java b/tests/integration/security-digest/src/main/java/org/glassfish/jersey/tests/integration/securitydigest/MyResource.java
new file mode 100644
index 0000000..7ebff65
--- /dev/null
+++ b/tests/integration/security-digest/src/main/java/org/glassfish/jersey/tests/integration/securitydigest/MyResource.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.securitydigest;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.SecurityContext;
+
+import javax.inject.Inject;
+
+/**
+ * This resource contains methods that are secured using web.xml declarative security. Names of methods
+ * describe which user roles have access to them.
+ *
+ * @author Miroslav Fuksa
+ */
+@Path("resource")
+public class MyResource {
+ @Inject
+ SecurityContext securityContext;
+
+ @GET
+ public String getUserAdmin() {
+ return securityContext.getUserPrincipal().getName() + getAuth();
+ }
+
+ @POST
+ public String postUserAdmin(String entity) {
+ return "post-" + entity + "-" + securityContext.getUserPrincipal().getName() + getAuth();
+ }
+
+ @GET
+ @Path("sub")
+ public String getAdmin() {
+ return "subget-" + securityContext.getUserPrincipal().getName() + getAuth();
+ }
+
+ @Path("locator")
+ public Class<SubResource> getSubResourceUserAdmin() {
+ return SubResource.class;
+ }
+
+ private String getAuth() {
+ return "/scheme:" + securityContext.getAuthenticationScheme();
+ }
+
+}
diff --git a/tests/integration/security-digest/src/main/java/org/glassfish/jersey/tests/integration/securitydigest/SubResource.java b/tests/integration/security-digest/src/main/java/org/glassfish/jersey/tests/integration/securitydigest/SubResource.java
new file mode 100644
index 0000000..39c6edc
--- /dev/null
+++ b/tests/integration/security-digest/src/main/java/org/glassfish/jersey/tests/integration/securitydigest/SubResource.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.securitydigest;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.SecurityContext;
+
+import javax.inject.Inject;
+
+/**
+ *
+ * @author Miroslav Fuksa
+ */
+public class SubResource {
+ @Inject
+ SecurityContext securityContext;
+
+ @GET
+ public String getUserAdmin() {
+ return "locator-" + securityContext.getUserPrincipal().getName() + getAuth();
+ }
+
+ private String getAuth() {
+ return "/scheme:" + securityContext.getAuthenticationScheme();
+ }
+}
diff --git a/tests/integration/security-digest/src/main/resources/jetty/realm.properties b/tests/integration/security-digest/src/main/resources/jetty/realm.properties
new file mode 100644
index 0000000..3530df0
--- /dev/null
+++ b/tests/integration/security-digest/src/main/resources/jetty/realm.properties
@@ -0,0 +1,19 @@
+#
+# Copyright (c) 2013, 2018 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
+#
+
+homer:Homer,my-user
+marge:Marge,my-admin
+bart:Bart,my-user,my-admin
diff --git a/tests/integration/security-digest/src/main/webapp/WEB-INF/web.xml b/tests/integration/security-digest/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..b704f48
--- /dev/null
+++ b/tests/integration/security-digest/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <display-name>Archetype Created Web Application</display-name>
+ <servlet>
+ <servlet-name>org.glassfish.jersey.tests.integration.securitydigest.MyApplication</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.securitydigest.MyApplication</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>org.glassfish.jersey.tests.integration.securitydigest.MyApplication</servlet-name>
+ <url-pattern>/rest/*</url-pattern>
+ </servlet-mapping>
+ <welcome-file-list>
+ <welcome-file>index.html</welcome-file>
+ </welcome-file-list>
+
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>rest api</web-resource-name>
+ <url-pattern>/rest/*</url-pattern>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>my-user</role-name>
+ <role-name>my-admin</role-name>
+ </auth-constraint>
+ </security-constraint>
+
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>rest api</web-resource-name>
+ <url-pattern>/rest/resource/sub</url-pattern>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>my-admin</role-name>
+ </auth-constraint>
+ </security-constraint>
+
+ <security-role>
+ <role-name>my-user</role-name>
+ </security-role>
+ <security-role>
+ <role-name>my-admin</role-name>
+ </security-role>
+
+
+ <login-config>
+ <auth-method>DIGEST</auth-method>
+ <realm-name>my-realm</realm-name>
+ </login-config>
+
+</web-app>
diff --git a/tests/integration/security-digest/src/test/java/org/glassfish/jersey/tests/integration/securitydigest/SecurityDigestAuthenticationITCase.java b/tests/integration/security-digest/src/test/java/org/glassfish/jersey/tests/integration/securitydigest/SecurityDigestAuthenticationITCase.java
new file mode 100644
index 0000000..22b422c
--- /dev/null
+++ b/tests/integration/security-digest/src/test/java/org/glassfish/jersey/tests/integration/securitydigest/SecurityDigestAuthenticationITCase.java
@@ -0,0 +1,176 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.securitydigest;
+
+import java.util.logging.Logger;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Miroslav Fuksa
+ */
+public class SecurityDigestAuthenticationITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig(MyApplication.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Override
+ protected void configureClient(ClientConfig config) {
+ config.register(new LoggingFeature(Logger.getLogger(SecurityDigestAuthenticationITCase.class.getName()),
+ LoggingFeature.Verbosity.PAYLOAD_ANY));
+ }
+
+ @Test
+ public void testResourceGet() {
+ _testResourceGet(HttpAuthenticationFeature.digest("homer", "Homer"));
+ _testResourceGet(HttpAuthenticationFeature.universal("homer", "Homer"));
+ _testResourceGet(HttpAuthenticationFeature.universalBuilder().credentialsForDigest("homer", "Homer").build());
+ _testResourceGet(HttpAuthenticationFeature.universalBuilder().credentialsForDigest("homer", "Homer")
+ .credentialsForBasic("aaa", "bbb").build());
+ }
+
+ public void _testResourceGet(HttpAuthenticationFeature feature) {
+ final Response response = target().path("rest/resource")
+ .register(feature).request().get();
+
+ Assert.assertEquals(200, response.getStatus());
+ Assert.assertEquals("homer/scheme:DIGEST", response.readEntity(String.class));
+ }
+
+ @Test
+ public void testResourceGet401() {
+ _testResourceGet401(HttpAuthenticationFeature.digest("nonexisting", "foo"));
+ _testResourceGet401(HttpAuthenticationFeature.universalBuilder().credentials("nonexisting", "foo").build());
+ }
+
+ public void _testResourceGet401(HttpAuthenticationFeature feature) {
+ final Response response = target().path("rest/resource")
+ .register(feature).request().get();
+
+ Assert.assertEquals(401, response.getStatus());
+ }
+
+ @Test
+ public void testResourcePost() {
+ _testResourcePost(HttpAuthenticationFeature.digest("homer", "Homer"));
+ _testResourcePost(HttpAuthenticationFeature.universal("homer", "Homer"));
+ }
+
+ public void _testResourcePost(HttpAuthenticationFeature feature) {
+ final Response response = target().path("rest/resource")
+ .register(feature).request()
+ .post(Entity.entity("helloworld", MediaType.TEXT_PLAIN_TYPE));
+
+ Assert.assertEquals(200, response.getStatus());
+ Assert.assertEquals("post-helloworld-homer/scheme:DIGEST", response.readEntity(String.class));
+ }
+
+ @Test
+ public void testResourceSubGet403() {
+ _testResourceSubGet403(HttpAuthenticationFeature.digest("homer", "Homer"));
+ _testResourceSubGet403(HttpAuthenticationFeature.universal("homer", "Homer"));
+ }
+
+ public void _testResourceSubGet403(HttpAuthenticationFeature feature) {
+ final Response response = target().path("rest/resource/sub")
+ .register(feature).request().get();
+
+ Assert.assertEquals(403, response.getStatus());
+ }
+
+ @Test
+ public void testResourceSubGet() {
+ _testResourceSubGet2(HttpAuthenticationFeature.digest("bart", "Bart"));
+ _testResourceSubGet2(HttpAuthenticationFeature.universal("bart", "Bart"));
+ }
+
+ public void _testResourceSubGet2(HttpAuthenticationFeature feature) {
+ final Response response = target().path("rest/resource/sub")
+ .register(feature).request().get();
+
+ Assert.assertEquals(200, response.getStatus());
+ Assert.assertEquals("subget-bart/scheme:DIGEST", response.readEntity(String.class));
+ }
+
+ @Test
+ public void testResourceLocatorGet() {
+ _testResourceLocatorGet(HttpAuthenticationFeature.digest("bart", "Bart"));
+ _testResourceLocatorGet(HttpAuthenticationFeature.universal("bart", "Bart"));
+ }
+
+ public void _testResourceLocatorGet(HttpAuthenticationFeature feature) {
+
+ final Response response = target().path("rest/resource/locator")
+ .register(feature).request().get();
+
+ Assert.assertEquals(200, response.getStatus());
+ Assert.assertEquals("locator-bart/scheme:DIGEST", response.readEntity(String.class));
+ }
+
+ @Test
+ public void testResourceMultipleRequestsWithOneFilter() {
+ _testResourceMultipleRequestsWithOneFilter(HttpAuthenticationFeature.digest("homer", "Homer"));
+ _testResourceMultipleRequestsWithOneFilter(HttpAuthenticationFeature.universal("homer", "Homer"));
+ }
+
+ public void _testResourceMultipleRequestsWithOneFilter(HttpAuthenticationFeature haf) {
+ WebTarget target = target().path("rest/resource")
+ .register(haf);
+ Response response = target.request().get();
+
+ Assert.assertEquals(200, response.getStatus());
+ Assert.assertEquals("homer/scheme:DIGEST", response.readEntity(String.class));
+
+ response = target.request().get();
+ Assert.assertEquals(200, response.getStatus());
+ Assert.assertEquals("homer/scheme:DIGEST", response.readEntity(String.class));
+
+ response = target.path("sub").request().get();
+ Assert.assertEquals(403, response.getStatus());
+
+ response = target.request().get();
+ Assert.assertEquals(200, response.getStatus());
+ Assert.assertEquals("homer/scheme:DIGEST", response.readEntity(String.class));
+
+ response = target.path("locator").request().get();
+ Assert.assertEquals(200, response.getStatus());
+ Assert.assertEquals("locator-homer/scheme:DIGEST", response.readEntity(String.class));
+ }
+
+}
diff --git a/tests/integration/servlet-2.5-autodiscovery-1/pom.xml b/tests/integration/servlet-2.5-autodiscovery-1/pom.xml
new file mode 100644
index 0000000..65d81ff
--- /dev/null
+++ b/tests/integration/servlet-2.5-autodiscovery-1/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-2.5-autodiscovery-1</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-2.5-autodiscovery-1</name>
+
+ <description>Servlet integration test - servlet-2.5-autodiscovery-1 - auto-discovery of UriConnegFilter</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/servlet-2.5-autodiscovery-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_autodiscovery_1/LanguageVariantResource.java b/tests/integration/servlet-2.5-autodiscovery-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_autodiscovery_1/LanguageVariantResource.java
new file mode 100644
index 0000000..cc161c9
--- /dev/null
+++ b/tests/integration/servlet-2.5-autodiscovery-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_autodiscovery_1/LanguageVariantResource.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_autodiscovery_1;
+
+import java.util.List;
+import java.util.Locale;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Variant;
+
+/**
+ * @author Martin Matula
+ * @author Michal Gajdos
+ */
+@Path("/abc")
+public class LanguageVariantResource {
+
+ @GET
+ public Response doGet(@Context Request r) {
+ List<Variant> vs = Variant.VariantListBuilder.newInstance()
+ .mediaTypes(MediaType.valueOf("application/foo"))
+ .languages(new Locale("en")).languages(new Locale("fr")).add()
+ .mediaTypes(MediaType.valueOf("application/bar"))
+ .languages(new Locale("en")).languages(new Locale("fr")).add()
+ .build();
+
+ Variant v = r.selectVariant(vs);
+ if (v == null) {
+ return Response.notAcceptable(vs).build();
+ } else {
+ return Response.ok(v.getMediaType().toString() + ", " + v.getLanguage(), v).build();
+ }
+ }
+}
diff --git a/tests/integration/servlet-2.5-autodiscovery-1/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-2.5-autodiscovery-1/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..d45de83
--- /dev/null
+++ b/tests/integration/servlet-2.5-autodiscovery-1/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>testAutoDiscovery1</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.packages</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_25_autodiscovery_1</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.server.mediaTypeMappings</param-name>
+ <param-value>foo : application/foo, bar : application/bar</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.server.languageMappings</param-name>
+ <param-value>english : en, french : fr</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>testAutoDiscovery1</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/servlet-2.5-autodiscovery-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_autodiscovery_1/LanguageVariantResourceITCase.java b/tests/integration/servlet-2.5-autodiscovery-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_autodiscovery_1/LanguageVariantResourceITCase.java
new file mode 100644
index 0000000..af45d99
--- /dev/null
+++ b/tests/integration/servlet-2.5-autodiscovery-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_autodiscovery_1/LanguageVariantResourceITCase.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_autodiscovery_1;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Michal Gajdos
+ */
+public class LanguageVariantResourceITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig(LanguageVariantResource.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testMediaTypesAndLanguages() {
+ _test("english", "foo", "en", "application/foo");
+ _test("french", "foo", "fr", "application/foo");
+
+ _test("english", "bar", "en", "application/bar");
+ _test("french", "bar", "fr", "application/bar");
+ }
+
+ private void _test(String ul, String um, String l, String m) {
+ Response r = target().path("abc." + ul + "." + um).request().get();
+ assertEquals(m + ", " + l, r.readEntity(String.class));
+ assertEquals(l, r.getLanguage().toString());
+ assertEquals(m, r.getMediaType().toString());
+
+ r = target().path("abc." + um + "." + ul).request().get();
+ assertEquals(m + ", " + l, r.readEntity(String.class));
+ assertEquals(l, r.getLanguage().toString());
+ assertEquals(m, r.getMediaType().toString());
+
+ r = target().path("abc").request(m).header(HttpHeaders.ACCEPT_LANGUAGE, l).get();
+ assertEquals(m + ", " + l, r.readEntity(String.class));
+ assertEquals(l, r.getLanguage().toString());
+ assertEquals(m, r.getMediaType().toString());
+ }
+}
diff --git a/tests/integration/servlet-2.5-autodiscovery-2/pom.xml b/tests/integration/servlet-2.5-autodiscovery-2/pom.xml
new file mode 100644
index 0000000..cc220e3
--- /dev/null
+++ b/tests/integration/servlet-2.5-autodiscovery-2/pom.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-2.5-autodiscovery-2</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-2.5-autodiscovery-2</name>
+
+ <description>Servlet integration test - servlet-2.5-autodiscovery-2 - auto-discovery of Bean Validation (JAX-RS bundle)</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.bundles</groupId>
+ <artifactId>jaxrs-ri</artifactId>
+ <type>jar</type>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-bean-validation</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/servlet-2.5-autodiscovery-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_autodiscovery_2/ValidationResource.java b/tests/integration/servlet-2.5-autodiscovery-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_autodiscovery_2/ValidationResource.java
new file mode 100644
index 0000000..50158e8
--- /dev/null
+++ b/tests/integration/servlet-2.5-autodiscovery-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_autodiscovery_2/ValidationResource.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_autodiscovery_2;
+
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Michal Gajdos
+ */
+@Path("/")
+public class ValidationResource {
+
+ @POST
+ @NotNull
+ public String post(@NotNull @Size(min = 1) final String value) {
+ return value.isEmpty() || "|".equals(value) ? null : value;
+ }
+}
diff --git a/tests/integration/servlet-2.5-autodiscovery-2/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-2.5-autodiscovery-2/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..fbadfc6
--- /dev/null
+++ b/tests/integration/servlet-2.5-autodiscovery-2/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>testAutoDiscovery2</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.packages</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_25_autodiscovery_2</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>testAutoDiscovery2</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/servlet-2.5-autodiscovery-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_autodiscovery_2/ValidationResourceITCase.java b/tests/integration/servlet-2.5-autodiscovery-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_autodiscovery_2/ValidationResourceITCase.java
new file mode 100644
index 0000000..646aeda
--- /dev/null
+++ b/tests/integration/servlet-2.5-autodiscovery-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_autodiscovery_2/ValidationResourceITCase.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_autodiscovery_2;
+
+import javax.ws.rs.client.Entity;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Michal Gajdos
+ */
+public class ValidationResourceITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig(ValidationResource.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testValidationPositive() {
+ assertEquals("value", target().request().post(Entity.text("value")).readEntity(String.class));
+ }
+
+ @Test
+ public void testValidationRequestNegative() {
+ assertEquals(500, target().request().post(Entity.text("|")).getStatus());
+ }
+
+ @Test
+ public void testValidatioResponsenNegative() {
+ assertEquals(400, target().request().post(null).getStatus());
+ }
+}
diff --git a/tests/integration/servlet-2.5-filter/pom.xml b/tests/integration/servlet-2.5-filter/pom.xml
new file mode 100644
index 0000000..60416db
--- /dev/null
+++ b/tests/integration/servlet-2.5-filter/pom.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-2.5-filter</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-2.5-filter</name>
+
+ <description>Servlet integration test - servlet-2.5-filter</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/servlet-2.5-filter/src/main/java/org/glassfish/jersey/tests/integration/servlet_2_5_filter/MyResource.java b/tests/integration/servlet-2.5-filter/src/main/java/org/glassfish/jersey/tests/integration/servlet_2_5_filter/MyResource.java
new file mode 100644
index 0000000..3f0a802
--- /dev/null
+++ b/tests/integration/servlet-2.5-filter/src/main/java/org/glassfish/jersey/tests/integration/servlet_2_5_filter/MyResource.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_2_5_filter;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+@Path("myresource")
+public class MyResource {
+
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "OK";
+ }
+}
diff --git a/tests/integration/servlet-2.5-filter/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-2.5-filter/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..4b8aefa
--- /dev/null
+++ b/tests/integration/servlet-2.5-filter/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <filter>
+ <filter-name>Jersey Web Application</filter-name>
+ <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.packages</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_2_5_filter</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.servlet.filter.contextPath</param-name>
+ <param-value>/myapp/</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>Jersey Web Application</filter-name>
+ <url-pattern>/myapp/*</url-pattern>
+ </filter-mapping>
+</web-app>
diff --git a/tests/integration/servlet-2.5-filter/src/test/java/org/glassfish/jersey/tests/integration/servlet_2_5_filter/MyResourceITCase.java b/tests/integration/servlet-2.5-filter/src/test/java/org/glassfish/jersey/tests/integration/servlet_2_5_filter/MyResourceITCase.java
new file mode 100644
index 0000000..824a01c
--- /dev/null
+++ b/tests/integration/servlet-2.5-filter/src/test/java/org/glassfish/jersey/tests/integration/servlet_2_5_filter/MyResourceITCase.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_2_5_filter;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+public class MyResourceITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ final ResourceConfig rc = new ResourceConfig();
+ return rc.packages(MyResourceITCase.class.getPackage().getName());
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testMyResource() throws Exception {
+ final Response response = target().path("myapp").path("myresource").request().get();
+ assertEquals(200, response.getStatus());
+ assertEquals("OK", response.readEntity(String.class));
+ }
+
+ @Test
+ public void testWadl() {
+ final Response response = target().path("myapp/application.wadl").request().get();
+ assertEquals(200, response.getStatus());
+ assertTrue(response.readEntity(String.class).startsWith("<?xml version=\"1.0\""));
+ }
+}
diff --git a/tests/integration/servlet-2.5-inflector-1/pom.xml b/tests/integration/servlet-2.5-inflector-1/pom.xml
new file mode 100644
index 0000000..a9f968c
--- /dev/null
+++ b/tests/integration/servlet-2.5-inflector-1/pom.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-2.5-inflector-1</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-2.5-inflector-1</name>
+
+ <description>
+ Servlet integration test - servlet-2.5-inflector-1 - Check that inflectors in programmatically created resources are
+ properly injected.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${servlet2.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/servlet-2.5-inflector-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_inflector_1/MyApplication.java b/tests/integration/servlet-2.5-inflector-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_inflector_1/MyApplication.java
new file mode 100644
index 0000000..ec9d5ec
--- /dev/null
+++ b/tests/integration/servlet-2.5-inflector-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_inflector_1/MyApplication.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_inflector_1;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.model.Resource;
+
+/**
+ * @author Michal Gajdos
+ */
+public class MyApplication extends ResourceConfig {
+
+ public MyApplication() {
+ final Resource.Builder resourceBuilder = Resource.builder("resource");
+
+ resourceBuilder.addChildResource("class")
+ .addMethod("GET")
+ .handledBy(MyInflector.class);
+ resourceBuilder.addChildResource("instance")
+ .addMethod("GET")
+ .handledBy(new MyInflector());
+
+ registerResources(resourceBuilder.build());
+ }
+}
diff --git a/tests/integration/servlet-2.5-inflector-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_inflector_1/MyInflector.java b/tests/integration/servlet-2.5-inflector-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_inflector_1/MyInflector.java
new file mode 100644
index 0000000..84c9a3b
--- /dev/null
+++ b/tests/integration/servlet-2.5-inflector-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_inflector_1/MyInflector.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_inflector_1;
+
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.core.Response;
+
+import javax.inject.Inject;
+import javax.inject.Provider;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.glassfish.jersey.process.Inflector;
+
+/**
+ * @author Michal Gajdos
+ */
+public class MyInflector implements Inflector<ContainerRequestContext, Response> {
+
+ @Inject
+ private Provider<HttpServletRequest> requestProvider;
+ @Inject
+ private Provider<HttpServletResponse> responseProvider;
+
+ @Override
+ public Response apply(final ContainerRequestContext requestContext) {
+ final StringBuilder stringBuilder = new StringBuilder();
+
+ // Request provider & request.
+ if (requestProvider != null) {
+ stringBuilder.append("requestProvider_");
+ stringBuilder.append(requestProvider.get() != null ? "request" : null);
+ } else {
+ stringBuilder.append("null_null");
+ }
+
+ stringBuilder.append('_');
+
+ // Response provider & response.
+ if (responseProvider != null) {
+ stringBuilder.append("responseProvider_");
+ stringBuilder.append(responseProvider.get() != null ? "response" : null);
+ } else {
+ stringBuilder.append("null_null");
+ }
+
+ return Response.ok(stringBuilder.toString()).build();
+ }
+}
diff --git a/tests/integration/servlet-2.5-inflector-1/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-2.5-inflector-1/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..2806fe6
--- /dev/null
+++ b/tests/integration/servlet-2.5-inflector-1/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>org.glassfish.jersey.tests.integration.servlet_25_inflector_1.MyApplication</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_25_inflector_1.MyApplication</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>org.glassfish.jersey.tests.integration.servlet_25_inflector_1.MyApplication</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/servlet-2.5-inflector-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_inflector_1/InflectorInjectionTestITCase.java b/tests/integration/servlet-2.5-inflector-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_inflector_1/InflectorInjectionTestITCase.java
new file mode 100644
index 0000000..9ccb2cb
--- /dev/null
+++ b/tests/integration/servlet-2.5-inflector-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_inflector_1/InflectorInjectionTestITCase.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_inflector_1;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Michal Gajdos
+ */
+public class InflectorInjectionTestITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new MyApplication();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testInflectorClassInjection() throws Exception {
+ _testInflectorInjection("class");
+ }
+
+ @Test
+ public void testInflectorInstanceInjection() throws Exception {
+ _testInflectorInjection("instance");
+ }
+
+ private void _testInflectorInjection(final String path) {
+ final Response response = target("resource").path(path).request().get();
+
+ assertEquals(200, response.getStatus());
+ assertEquals("requestProvider_request_responseProvider_response", response.readEntity(String.class));
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-1/pom.xml b/tests/integration/servlet-2.5-init-1/pom.xml
new file mode 100644
index 0000000..71dd7e5
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-1/pom.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-2.5-init-1</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-2.5-init-1</name>
+
+ <description>Servlet integration test - servlet-2.5-init-1 - configured via jax-rs application</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${servlet2.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/servlet-2.5-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_1/ClientUsingResource.java b/tests/integration/servlet-2.5-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_1/ClientUsingResource.java
new file mode 100644
index 0000000..0728579
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_1/ClientUsingResource.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_init_1;
+
+import java.net.URI;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * A resource that instantiated & uses JAX-RS/Jersey client to access another resource.
+ *
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+@Path("viaclient")
+public class ClientUsingResource {
+ @Path("helloworld")
+ @GET
+ public String getProxiedMessage(@Context UriInfo uriInfo) {
+ return ClientBuilder.newClient()
+ .target(uriInfo.resolve(URI.create("helloworld")))
+ .request("text/plain")
+ .get(String.class);
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_1/HelloWorldResource.java b/tests/integration/servlet-2.5-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_1/HelloWorldResource.java
new file mode 100644
index 0000000..2ab6f5b
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_1/HelloWorldResource.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_1;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.glassfish.jersey.servlet.WebConfig;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ * @author Martin Matula
+ */
+@Path("helloworld")
+public class HelloWorldResource {
+
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "Hello World! " + this.getClass().getPackage().getName();
+ }
+
+ @GET
+ @Path("injection")
+ public String getInjection(@Context HttpServletRequest request, @Context HttpServletResponse response,
+ @Context WebConfig webConfig, @Context ServletConfig servletConfig,
+ @Context ServletContext servletContext) {
+ return request.getMethod() + (response != null) + webConfig.getName() + servletConfig.getServletName()
+ + servletContext.getServletContextName();
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_1/MultipleLinksResource.java b/tests/integration/servlet-2.5-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_1/MultipleLinksResource.java
new file mode 100644
index 0000000..adcafea
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_1/MultipleLinksResource.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_init_1;
+
+import java.net.URI;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Link;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * Reproducer for JERSEY-1801. See also E2E {@code LinkTest}.
+ *
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+@Path("links")
+public class MultipleLinksResource {
+
+ @GET
+ public Response get(@Context UriInfo uriInfo) throws Exception {
+ URI test1 = URI.create(uriInfo.getAbsolutePath().toString() + "test1");
+ URI test2 = URI.create(uriInfo.getAbsolutePath().toString() + "test2");
+
+ return Response.ok()
+ .link("http://oracle.com", "parent")
+ .link(new URI("http://jersey.java.net"), "framework")
+ .links(
+ Link.fromUri(uriInfo.relativize(test1)).rel("test1").build(),
+ Link.fromUri(test2).rel("test2").build(),
+ Link.fromUri(uriInfo.relativize(URI.create("links/test3"))).rel("test3").build()
+ ).build();
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_1/Servlet25init1.java b/tests/integration/servlet-2.5-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_1/Servlet25init1.java
new file mode 100644
index 0000000..b6aec66
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_1/Servlet25init1.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_1;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * JAX-RS application for the Servlet 2.5 initialization test #01.
+ *
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+@ApplicationPath("application_path")
+public class Servlet25init1 extends Application {
+ @SuppressWarnings({"unchecked"})
+ @Override
+ public Set<Class<?>> getClasses() {
+ return new HashSet<>(
+ Arrays.asList(HelloWorldResource.class, MultipleLinksResource.class, ClientUsingResource.class));
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_1/UnreachableResource.java b/tests/integration/servlet-2.5-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_1/UnreachableResource.java
new file mode 100644
index 0000000..42e042a
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_1/UnreachableResource.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_1;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+/**
+ *
+ * @author Martin Matula
+ */
+@Path("unreachable")
+public class UnreachableResource {
+ @GET
+ public Response get() {
+ return Response.ok().build();
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-1/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-2.5-init-1/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..d5a0798
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-1/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>testServlet1</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_25_init_1.Servlet25init1</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>testServlet1</servlet-name>
+ <url-pattern>/servlet_path/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/servlet-2.5-init-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_1/Servlet25Init1ITCase.java b/tests/integration/servlet-2.5-init-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_1/Servlet25Init1ITCase.java
new file mode 100644
index 0000000..7ee6968
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_1/Servlet25Init1ITCase.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_init_1;
+
+import java.net.URI;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+import org.glassfish.jersey.uri.UriTemplate;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Servlet 2.5 initialization test #01.
+ *
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ * @author Martin Matula
+ */
+public class Servlet25Init1ITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Servlet25init1();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testHelloWorld() throws Exception {
+ String s = target().path("servlet_path/helloworld").request().get(String.class);
+ assertEquals("Hello World! " + this.getClass().getPackage().getName(), s);
+ }
+
+ @Test
+ public void testHelloWorldAtWrongPath() {
+ Response r = target().path("application_path/helloworld").request().get();
+ assertTrue(
+ "Request to application_path/helloworld should have failed, but did not. That means two applications are "
+ + "registered.",
+ r.getStatus() >= 400);
+ }
+
+ @Test
+ public void testHelloWorldViaClientInResource() throws Exception {
+ String s = target().path("servlet_path/viaclient/helloworld").request().get(String.class);
+ assertEquals("Hello World! " + this.getClass().getPackage().getName(), s);
+ }
+
+ @Test
+ public void testUnreachableResource() {
+ Response r = target().path("servlet_path/unreachable").request().get();
+ assertTrue("Managed to reach a resource that is not registered in the application.", r.getStatus() >= 400);
+ }
+
+ @Test
+ public void testUnreachableResourceAtWrongPath() {
+ Response r = target().path("application_path/unreachable").request().get();
+ assertTrue("Managed to reach a resource that is not registered in the application.", r.getStatus() >= 400);
+ }
+
+ @Test
+ public void testInjection() {
+ String s = target().path("servlet_path/helloworld/injection").request().get(String.class);
+ assertEquals("GETtruetestServlet1testServlet1/", s);
+ }
+
+ // Reproducer for JERSEY-1801
+ @Test
+ public void multipleLinksTest() {
+ final WebTarget target = target("/servlet_path/links/");
+ final Response response = target.request().get();
+ assertThat(response.getStatus(), equalTo(200));
+
+ final URI targetUri = target.getUri();
+ assertThat(response.getLink("parent").getUri(), equalTo(URI.create("http://oracle.com")));
+ assertThat(response.getLink("framework").getUri(), equalTo(URI.create("http://jersey.java.net")));
+
+ assertThat(response.getLink("test1").getUri(), equalTo(UriTemplate.resolve(targetUri, "test1")));
+ assertThat(response.getLink("test2").getUri(), equalTo(UriTemplate.resolve(targetUri, "test2")));
+ assertThat(response.getLink("test3").getUri(), equalTo(UriTemplate.resolve(targetUri, "test3")));
+ }
+
+}
diff --git a/tests/integration/servlet-2.5-init-2/pom.xml b/tests/integration/servlet-2.5-init-2/pom.xml
new file mode 100644
index 0000000..b069eff
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-2/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-2.5-init-2</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-2.5-init-2</name>
+
+ <description>Servlet integration test - servlet-2.5-init-2 - configured using package scanning</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/servlet-2.5-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/CustomFeature.java b/tests/integration/servlet-2.5-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/CustomFeature.java
new file mode 100644
index 0000000..1f99758
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/CustomFeature.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_2;
+
+import javax.ws.rs.core.Feature;
+import javax.ws.rs.core.FeatureContext;
+import javax.ws.rs.ext.Provider;
+
+import org.glassfish.jersey.tests.integration.servlet_25_init_2.ext.Ext1WriterInterceptor;
+import org.glassfish.jersey.tests.integration.servlet_25_init_2.ext.Ext2WriterInterceptor;
+import org.glassfish.jersey.tests.integration.servlet_25_init_2.ext.Ext3WriterInterceptor;
+import org.glassfish.jersey.tests.integration.servlet_25_init_2.ext.Ext4WriterInterceptor;
+
+/**
+ * @author Michal Gajdos
+ */
+@Provider
+public class CustomFeature implements Feature {
+
+ @Override
+ public boolean configure(final FeatureContext context) {
+ context.register(Ext3WriterInterceptor.class, 1000);
+ context.register(Ext2WriterInterceptor.class, 100);
+ context.register(Ext1WriterInterceptor.INSTANCE, 500);
+ context.register(Ext4WriterInterceptor.INSTANCE, 1);
+ return true;
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/HelloWorldResource.java b/tests/integration/servlet-2.5-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/HelloWorldResource.java
new file mode 100644
index 0000000..3867cd2
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/HelloWorldResource.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_2;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+@Path("helloworld")
+public class HelloWorldResource {
+
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "Hello World! " + this.getClass().getPackage().getName();
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/ext/Ext1WriterInterceptor.java b/tests/integration/servlet-2.5-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/ext/Ext1WriterInterceptor.java
new file mode 100644
index 0000000..1ff8e53
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/ext/Ext1WriterInterceptor.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_2.ext;
+
+import java.io.IOException;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.WriterInterceptor;
+import javax.ws.rs.ext.WriterInterceptorContext;
+
+/**
+ * @author Michal Gajdos
+ */
+@Provider
+public class Ext1WriterInterceptor implements WriterInterceptor {
+
+ public static final Ext1WriterInterceptor INSTANCE = new Ext1WriterInterceptor();
+
+ @Override
+ public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException {
+ context.setEntity(context.getEntity() + "-ext1");
+ context.proceed();
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/ext/Ext2WriterInterceptor.java b/tests/integration/servlet-2.5-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/ext/Ext2WriterInterceptor.java
new file mode 100644
index 0000000..80eebfe
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/ext/Ext2WriterInterceptor.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_2.ext;
+
+import java.io.IOException;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.WriterInterceptor;
+import javax.ws.rs.ext.WriterInterceptorContext;
+
+/**
+ * @author Michal Gajdos
+ */
+@Provider
+public class Ext2WriterInterceptor implements WriterInterceptor {
+
+ @Override
+ public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException {
+ context.setEntity(context.getEntity() + "-ext2");
+ context.proceed();
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/ext/Ext3WriterInterceptor.java b/tests/integration/servlet-2.5-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/ext/Ext3WriterInterceptor.java
new file mode 100644
index 0000000..885f151
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/ext/Ext3WriterInterceptor.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_2.ext;
+
+import java.io.IOException;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.WriterInterceptor;
+import javax.ws.rs.ext.WriterInterceptorContext;
+
+/**
+ * @author Michal Gajdos
+ */
+@Provider
+public class Ext3WriterInterceptor implements WriterInterceptor {
+
+ @Override
+ public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException {
+ context.setEntity(context.getEntity() + "-ext3");
+ context.proceed();
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/ext/Ext4WriterInterceptor.java b/tests/integration/servlet-2.5-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/ext/Ext4WriterInterceptor.java
new file mode 100644
index 0000000..d90988a
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/ext/Ext4WriterInterceptor.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_2.ext;
+
+import java.io.IOException;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.WriterInterceptor;
+import javax.ws.rs.ext.WriterInterceptorContext;
+
+/**
+ * @author Michal Gajdos
+ */
+@Provider
+public class Ext4WriterInterceptor implements WriterInterceptor {
+
+ public static final Ext4WriterInterceptor INSTANCE = new Ext4WriterInterceptor();
+
+ @Override
+ public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException {
+ context.setEntity(context.getEntity() + "-ext4");
+ context.proceed();
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-2/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-2.5-init-2/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..7066c4b
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-2/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>testServlet2</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.packages</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_25_init_2</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.server.provider.scanning.recursive</param-name>
+ <param-value>false</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>testServlet2</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/servlet-2.5-init-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/HelloWorldResourceITCase.java b/tests/integration/servlet-2.5-init-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/HelloWorldResourceITCase.java
new file mode 100644
index 0000000..89071b3
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_2/HelloWorldResourceITCase.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_2;
+
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+public class HelloWorldResourceITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig(HelloWorldResource.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testHelloWorld() throws Exception {
+ Response r = target().path("helloworld").request().get();
+ assertEquals(200, r.getStatus());
+ assertEquals("Hello World! " + this.getClass().getPackage().getName() + "-ext4-ext2-ext1-ext3",
+ r.readEntity(String.class));
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-3/pom.xml b/tests/integration/servlet-2.5-init-3/pom.xml
new file mode 100644
index 0000000..2271b3d
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-3/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-2.5-init-3</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-2.5-init-3</name>
+
+ <description>Servlet integration test - servlet-2.5-init-3 - configured by explicitly set resource classes</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/servlet-2.5-init-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_3/HelloWorldResource.java b/tests/integration/servlet-2.5-init-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_3/HelloWorldResource.java
new file mode 100644
index 0000000..3df9bbe
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_3/HelloWorldResource.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_3;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+@Path("helloworld")
+public class HelloWorldResource {
+
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "Hello World! " + this.getClass().getPackage().getName();
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-3/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-2.5-init-3/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..ad4c999
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-3/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>testServlet3</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_25_init_3.HelloWorldResource</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>testServlet3</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/servlet-2.5-init-3/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_3/HelloWorldResourceITCase.java b/tests/integration/servlet-2.5-init-3/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_3/HelloWorldResourceITCase.java
new file mode 100644
index 0000000..ac2c4fe
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-3/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_3/HelloWorldResourceITCase.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_3;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+public class HelloWorldResourceITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig(HelloWorldResource.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testHelloWorld() throws Exception {
+ String s = target().path("helloworld").request().get(String.class);
+ assertTrue(s.equals("Hello World! " + this.getClass().getPackage().getName()));
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-4/pom.xml b/tests/integration/servlet-2.5-init-4/pom.xml
new file mode 100644
index 0000000..2b119f0
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-4/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-2.5-init-4</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-2.5-init-4</name>
+
+ <description>Servlet integration test - servlet-2.5-init-4 - configured by explicitly set resource and provider class name</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/servlet-2.5-init-4/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_4/HelloWorldResource.java b/tests/integration/servlet-2.5-init-4/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_4/HelloWorldResource.java
new file mode 100644
index 0000000..ebf7b5b
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-4/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_4/HelloWorldResource.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_4;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+@Path("helloworld")
+public class HelloWorldResource {
+
+ @GET
+ @Produces("text/plain")
+ public Hello get() {
+ return new Hello();
+ }
+
+ public static class Hello {
+
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-4/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_4/HelloWriter.java b/tests/integration/servlet-2.5-init-4/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_4/HelloWriter.java
new file mode 100644
index 0000000..54113d1
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-4/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_4/HelloWriter.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_4;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+import org.glassfish.jersey.message.MessageUtils;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+@Provider
+public class HelloWriter implements MessageBodyWriter<HelloWorldResource.Hello> {
+ @Override
+ public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType) {
+ return type.equals(HelloWorldResource.Hello.class);
+ }
+
+ @Override
+ public long getSize(final HelloWorldResource.Hello hello, final Class<?> type, final Type genericType,
+ final Annotation[] annotations, final MediaType mediaType) {
+ return -1;
+ }
+
+ @Override
+ public void writeTo(final HelloWorldResource.Hello hello, final Class<?> type, final Type genericType,
+ final Annotation[] annotations, final MediaType mediaType,
+ final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream)
+ throws IOException, WebApplicationException {
+ entityStream.write(("Hello World! " + this.getClass().getPackage().getName())
+ .getBytes(MessageUtils.getCharset(mediaType)));
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-4/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-2.5-init-4/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..b3b168e
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-4/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>testServlet4</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_25_init_4.HelloWorldResource;org.glassfish.jersey.tests.integration.servlet_25_init_4.HelloWriter</param-value>
+ </init-param>
+
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>testServlet4</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/servlet-2.5-init-4/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_4/HelloWorldResourceITCase.java b/tests/integration/servlet-2.5-init-4/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_4/HelloWorldResourceITCase.java
new file mode 100644
index 0000000..c16b5ff
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-4/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_4/HelloWorldResourceITCase.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_4;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+public class HelloWorldResourceITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig(HelloWorldResource.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testHelloWorld() throws Exception {
+ String s = target().path("helloworld").request().get(String.class);
+ assertTrue(s.equals("Hello World! " + this.getClass().getPackage().getName()));
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-5/pom.xml b/tests/integration/servlet-2.5-init-5/pom.xml
new file mode 100644
index 0000000..bce35f3
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-5/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-2.5-init-5</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-2.5-init-5</name>
+
+ <description>Servlet integration test - servlet-2.5-init-5 - filter with specified jax rs application class</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/servlet-2.5-init-5/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_5/HelloWorldResource.java b/tests/integration/servlet-2.5-init-5/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_5/HelloWorldResource.java
new file mode 100644
index 0000000..16003d3
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-5/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_5/HelloWorldResource.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_5;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+@Path("filter_path/helloworld")
+public class HelloWorldResource {
+
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "Hello World! " + this.getClass().getPackage().getName();
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-5/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_5/Servlet25init5.java b/tests/integration/servlet-2.5-init-5/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_5/Servlet25init5.java
new file mode 100644
index 0000000..272e070
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-5/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_5/Servlet25init5.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_5;
+
+import java.util.Collections;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+@ApplicationPath("application_path")
+public class Servlet25init5 extends Application{
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return Collections.singleton(HelloWorldResource.class);
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-5/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_5/UnreachableResource.java b/tests/integration/servlet-2.5-init-5/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_5/UnreachableResource.java
new file mode 100644
index 0000000..24eee33
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-5/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_5/UnreachableResource.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_5;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+/**
+ *
+ * @author Martin Matula
+ */
+@Path("filter_path/unreachable")
+public class UnreachableResource {
+ @GET
+ public Response get() {
+ return Response.ok().build();
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-5/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-2.5-init-5/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..271170f
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-5/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <filter>
+ <filter-name>testServlet5</filter-name>
+ <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_25_init_5.Servlet25init5</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>testServlet5</filter-name>
+ <url-pattern>/filter_path/*</url-pattern>
+ </filter-mapping>
+</web-app>
diff --git a/tests/integration/servlet-2.5-init-5/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_5/HelloWorldResourceITCase.java b/tests/integration/servlet-2.5-init-5/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_5/HelloWorldResourceITCase.java
new file mode 100644
index 0000000..561412a
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-5/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_5/HelloWorldResourceITCase.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_5;
+
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+public class HelloWorldResourceITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig(HelloWorldResource.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testHelloWorld() throws Exception {
+ String s = target().path("filter_path/helloworld").request().get(String.class);
+ assertEquals("Hello World! " + this.getClass().getPackage().getName(), s);
+ }
+
+ @Test
+ public void testHelloWorldAtWrongPath() {
+ Response r = target().path("application_path/filter_path/helloworld").request().get();
+ assertTrue(
+ "Request to application_path/helloworld should have failed, but did not. That means two applications are "
+ + "registered.",
+ r.getStatus() >= 400);
+ }
+
+ @Test
+ @Ignore
+ public void testUnreachableResource() {
+ Response r = target().path("filter_path/unreachable").request().get();
+ assertTrue("Managed to reach a resource that is not registered in the application.", r.getStatus() >= 400);
+ }
+
+ @Test
+ public void testUnreachableResourceAtWrongPath() {
+ Response r = target().path("application_path/filter_path/unreachable").request().get();
+ assertTrue("Managed to reach a resource that is not registered in the application.", r.getStatus() >= 400);
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-6/pom.xml b/tests/integration/servlet-2.5-init-6/pom.xml
new file mode 100644
index 0000000..aa89759
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-6/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-2.5-init-6</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-2.5-init-6</name>
+
+ <description>Servlet integration test - servlet-2.5-init-6 - filter - configured using package scanning</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/servlet-2.5-init-6/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_6/HelloWorldResource.java b/tests/integration/servlet-2.5-init-6/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_6/HelloWorldResource.java
new file mode 100644
index 0000000..0d5c6e3
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-6/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_6/HelloWorldResource.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_6;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+@Path("helloworld")
+public class HelloWorldResource {
+
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "Hello World! " + this.getClass().getPackage().getName();
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-6/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-2.5-init-6/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..df4e84f
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-6/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <filter>
+ <filter-name>testServlet6</filter-name>
+ <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.packages</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_25_init_6</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>testServlet6</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+</web-app>
diff --git a/tests/integration/servlet-2.5-init-6/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_6/HelloWorldResourceITCase.java b/tests/integration/servlet-2.5-init-6/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_6/HelloWorldResourceITCase.java
new file mode 100644
index 0000000..e10063f
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-6/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_6/HelloWorldResourceITCase.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_6;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+public class HelloWorldResourceITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig(HelloWorldResource.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testHelloWorld() throws Exception {
+ String s = target().path("helloworld").request().get(String.class);
+ assertTrue(s.equals("Hello World! " + this.getClass().getPackage().getName()));
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-7/pom.xml b/tests/integration/servlet-2.5-init-7/pom.xml
new file mode 100644
index 0000000..231efe9
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-7/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-2.5-init-7</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-2.5-init-7</name>
+
+ <description>Servlet integration test - servlet-2.5-init-7 - filter - configured by explicitly set resource classes</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/servlet-2.5-init-7/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_7/HelloWorldResource.java b/tests/integration/servlet-2.5-init-7/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_7/HelloWorldResource.java
new file mode 100644
index 0000000..3b924d4
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-7/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_7/HelloWorldResource.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_7;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+@Path("helloworld")
+public class HelloWorldResource {
+
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "Hello World! " + this.getClass().getPackage().getName();
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-7/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-2.5-init-7/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..859d505
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-7/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <filter>
+ <filter-name>testServlet7</filter-name>
+ <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_25_init_7.HelloWorldResource</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>testServlet7</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+</web-app>
diff --git a/tests/integration/servlet-2.5-init-7/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_7/HelloWorldResourceITCase.java b/tests/integration/servlet-2.5-init-7/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_7/HelloWorldResourceITCase.java
new file mode 100644
index 0000000..b1edf72
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-7/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_7/HelloWorldResourceITCase.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_7;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+public class HelloWorldResourceITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig(HelloWorldResource.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testHelloWorld() throws Exception {
+ String s = target().path("helloworld").request().get(String.class);
+ assertTrue(s.equals("Hello World! " + this.getClass().getPackage().getName()));
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-8/pom.xml b/tests/integration/servlet-2.5-init-8/pom.xml
new file mode 100644
index 0000000..bb916ce
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-8/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-2.5-init-8</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-2.5-init-8</name>
+
+ <description>Servlet integration test - servlet-2.5-init-8 - filter - configured by explicitly set resource and provider class name</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/servlet-2.5-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_8/HelloWorldResource.java b/tests/integration/servlet-2.5-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_8/HelloWorldResource.java
new file mode 100644
index 0000000..ab3917d
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_8/HelloWorldResource.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_8;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+@Path("helloworld")
+public class HelloWorldResource {
+
+ @GET
+ @Produces("text/plain")
+ public Hello get() {
+ return new Hello();
+ }
+
+ public static class Hello {
+
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_8/HelloWriter.java b/tests/integration/servlet-2.5-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_8/HelloWriter.java
new file mode 100644
index 0000000..62dcb6f
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_init_8/HelloWriter.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_8;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+import org.glassfish.jersey.message.MessageUtils;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+@Provider
+public class HelloWriter implements MessageBodyWriter<HelloWorldResource.Hello> {
+ @Override
+ public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType) {
+ return type.equals(HelloWorldResource.Hello.class);
+ }
+
+ @Override
+ public long getSize(final HelloWorldResource.Hello hello, final Class<?> type, final Type genericType,
+ final Annotation[] annotations, final MediaType mediaType) {
+ return -1;
+ }
+
+ @Override
+ public void writeTo(final HelloWorldResource.Hello hello, final Class<?> type, final Type genericType,
+ final Annotation[] annotations, final MediaType mediaType,
+ final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream)
+ throws IOException, WebApplicationException {
+ entityStream.write(("Hello World! " + this.getClass().getPackage().getName())
+ .getBytes(MessageUtils.getCharset(mediaType)));
+ }
+}
diff --git a/tests/integration/servlet-2.5-init-8/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-2.5-init-8/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..1aaa6d3
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-8/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <filter>
+ <filter-name>testServlet8</filter-name>
+ <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_25_init_8.HelloWorldResource;org.glassfish.jersey.tests.integration.servlet_25_init_8.HelloWriter</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>testServlet8</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+</web-app>
diff --git a/tests/integration/servlet-2.5-init-8/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_8/HelloWorldResourceITCase.java b/tests/integration/servlet-2.5-init-8/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_8/HelloWorldResourceITCase.java
new file mode 100644
index 0000000..ba304ba
--- /dev/null
+++ b/tests/integration/servlet-2.5-init-8/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_init_8/HelloWorldResourceITCase.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_init_8;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+public class HelloWorldResourceITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig(HelloWorldResource.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testHelloWorld() throws Exception {
+ String s = target().path("helloworld").request().get(String.class);
+ assertTrue(s.equals("Hello World! " + this.getClass().getPackage().getName()));
+ }
+}
diff --git a/tests/integration/servlet-2.5-mvc-1/pom.xml b/tests/integration/servlet-2.5-mvc-1/pom.xml
new file mode 100644
index 0000000..4423806
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-1/pom.xml
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-2.5-mvc-1</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-2.5-mvc-1</name>
+
+ <description>Servlet integration test - servlet-2.5-mvc-1 - filter - MVC</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-mvc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-mvc-jsp</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${servlet2.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/servlet-2.5-mvc-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/MyApplication.java b/tests/integration/servlet-2.5-mvc-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/MyApplication.java
new file mode 100644
index 0000000..973f3ce
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/MyApplication.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_1;
+
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.mvc.jsp.JspMvcFeature;
+import org.glassfish.jersey.tests.integration.servlet_25_mvc_1.resource.Bookstore;
+
+/**
+ * @author Michal Gajdos
+ */
+public class MyApplication extends ResourceConfig {
+
+ public MyApplication() {
+ // Resources.
+ packages(Bookstore.class.getPackage().getName());
+
+ // MVC.
+ register(JspMvcFeature.class);
+
+ // Logging.
+ register(LoggingFeature.class);
+ }
+}
diff --git a/tests/integration/servlet-2.5-mvc-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Book.java b/tests/integration/servlet-2.5-mvc-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Book.java
new file mode 100644
index 0000000..8401757
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Book.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_1.resource;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class Book extends Item {
+
+ public Book() {
+ }
+
+ public Book(final String title, final String author) {
+ super(title, author);
+ }
+
+
+}
diff --git a/tests/integration/servlet-2.5-mvc-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Bookstore.java b/tests/integration/servlet-2.5-mvc-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Bookstore.java
new file mode 100644
index 0000000..f66b7b3
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Bookstore.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_1.resource;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.NotFoundException;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import javax.inject.Singleton;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.glassfish.jersey.server.mvc.Template;
+
+@Path("/")
+@Singleton
+@Template
+@Produces("text/html")
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class Bookstore {
+
+ private final Map<String, Item> items = new TreeMap<String, Item>();
+ private String name;
+
+ public Bookstore() {
+ setName("Czech Bookstore");
+ getItems().put("1", new Book("Svejk", "Jaroslav Hasek"));
+ getItems().put("2", new Book("Krakatit", "Karel Capek"));
+ }
+
+ @Path("items/{itemid}/")
+ public Item getItem(@PathParam("itemid") String itemid) {
+ Item i = getItems().get(itemid);
+ if (i == null) {
+ throw new NotFoundException(Response
+ .status(Response.Status.NOT_FOUND)
+ .entity("Item, " + itemid + ", is not found")
+ .build());
+ }
+
+ return i;
+ }
+
+ @GET
+ @Produces({MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
+ public Bookstore getXml() {
+ return this;
+ }
+
+ public Map<String, Item> getItems() {
+ return items;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/tests/integration/servlet-2.5-mvc-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Item.java b/tests/integration/servlet-2.5-mvc-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Item.java
new file mode 100644
index 0000000..9a01b41
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Item.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_1.resource;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.glassfish.jersey.server.mvc.Template;
+
+@Template
+@Produces("text/html")
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class Item {
+
+ private String title;
+ private String author;
+
+ public Item() {
+ }
+
+ public Item(final String title, final String author) {
+ this.title = title;
+ this.author = author;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ @GET
+ @Produces({MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
+ public Item getXml() {
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return "Item{"
+ + "title='" + title + '\''
+ + ", author='" + author + '\''
+ + '}';
+ }
+}
diff --git a/tests/integration/servlet-2.5-mvc-1/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-2.5-mvc-1/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..7692801
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-1/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <filter>
+ <filter-name>org.glassfish.jersey.tests.integration.servlet_25_mvc_1.MyApplication</filter-name>
+ <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_25_mvc_1.MyApplication</param-value>
+ </init-param>
+ <!-- pass to next filter if Jersey/App returns 404 -->
+ <init-param>
+ <param-name>jersey.config.servlet.filter.forwardOn404</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>org.glassfish.jersey.tests.integration.servlet_25_mvc_1.MyApplication</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+</web-app>
diff --git a/tests/integration/servlet-2.5-mvc-1/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Book/index.jsp b/tests/integration/servlet-2.5-mvc-1/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Book/index.jsp
new file mode 100644
index 0000000..bff6020
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-1/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Book/index.jsp
@@ -0,0 +1,46 @@
+<%--
+
+ Copyright (c) 2010, 2018 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
+
+--%>
+
+<%@page contentType="text/html"%>
+<%@page pageEncoding="UTF-8"%>
+<%--
+The taglib directive below imports the JSTL library. If you uncomment it,
+you must also add the JSTL library to the project. The Add Library... action
+on Libraries node in Projects view can be used to add the JSTL 1.1 library.
+--%>
+<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
+<%@taglib prefix="rbt" uri="urn:org:glassfish:jersey:servlet:mvc" %>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+"http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Book</title>
+ </head>
+ <body>
+
+ <h1>${it.title}</h1>
+
+ Book from ${it.author}
+
+ <rbt:include page="footer.jsp"/>
+
+ </body>
+</html>
diff --git a/tests/integration/servlet-2.5-mvc-1/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Bookstore/count.jsp b/tests/integration/servlet-2.5-mvc-1/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Bookstore/count.jsp
new file mode 100644
index 0000000..2fe7542
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-1/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Bookstore/count.jsp
@@ -0,0 +1,27 @@
+<%--
+
+ Copyright (c) 2010, 2018 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
+
+--%>
+
+<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
+<%--
+ An example of another side JSP.
+--%>
+<html>
+ <body>
+ # of items: ${fn:length(it.items)}
+ </body>
+</html>
diff --git a/tests/integration/servlet-2.5-mvc-1/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Bookstore/index.jsp b/tests/integration/servlet-2.5-mvc-1/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Bookstore/index.jsp
new file mode 100644
index 0000000..2ddb202
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-1/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Bookstore/index.jsp
@@ -0,0 +1,56 @@
+<%--
+
+ Copyright (c) 2010, 2018 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
+
+--%>
+
+<%@page contentType="text/html"%>
+<%@page pageEncoding="UTF-8"%>
+
+<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <style type="text/css" media="screen">
+ @import url( <c:url value="/css/style.css"/> );
+ </style>
+ <title>REST Bookstore Sample</title>
+ </head>
+ <body>
+
+ <h1>${it.name}</h1>
+
+ <h2>Item List</h2>
+
+ <ul>
+ <c:forEach var="i" items="${it.items}">
+ <li><a href="items/${i.key}/">${i.value.title}</a>
+ </c:forEach>
+ </ul>
+
+ <h2>Others</h2>
+ <p>
+ <a href="count">count inventory</a>
+ <p>
+ <a href="time">get the system time</a>
+ <p>
+ <a href="jsp/help.jsp">regular resources</a>
+ </p>
+ </body>
+</html>
diff --git a/tests/integration/servlet-2.5-mvc-1/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Bookstore/time.jsp b/tests/integration/servlet-2.5-mvc-1/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Bookstore/time.jsp
new file mode 100644
index 0000000..527e22f
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-1/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Bookstore/time.jsp
@@ -0,0 +1,24 @@
+<%--
+
+ Copyright (c) 2010, 2018 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
+
+--%>
+
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+ <body>
+ Current system time is ${it.systemTime}
+ </body>
+</html>
diff --git a/tests/integration/servlet-2.5-mvc-1/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Item/footer.jsp b/tests/integration/servlet-2.5-mvc-1/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Item/footer.jsp
new file mode 100644
index 0000000..fdff710
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-1/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/resource/Item/footer.jsp
@@ -0,0 +1,24 @@
+<%--
+
+ Copyright (c) 2010, 2018 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
+
+--%>
+
+<p>
+<a href="../../">Back</a>
+<hr>
+<div align="right">
+ Common footer (title ${it.title})
+</div>
diff --git a/tests/integration/servlet-2.5-mvc-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/BookstoreITCase.java b/tests/integration/servlet-2.5-mvc-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/BookstoreITCase.java
new file mode 100644
index 0000000..a751b9c
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/BookstoreITCase.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_1;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.tests.integration.servlet_25_mvc_1.resource.Bookstore;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class BookstoreITCase extends TestSupport {
+
+ @Test
+ public void testResourceAsHtml() throws Exception {
+ // NOTE: HttpUrlConnector sends several accepted types by default when not explicitly set by the caller.
+ // In such case, the .accept("text/html") call is not necessary. However, other connectors act in a different way and
+ // this leads in different behaviour when selecting the MessageBodyWriter. Leaving the definition explicit for broader
+ // compatibility.
+ assertBookstoreHtmlResponse(target().request(MediaType.TEXT_HTML_TYPE).get(String.class));
+ }
+
+ @Test
+ public void testResourceAsXml() throws Exception {
+ final Bookstore response = target().request("application/xml").get(Bookstore.class);
+
+ assertNotNull("Should have returned a bookstore!", response);
+ assertEquals("bookstore name", "Czech Bookstore", response.getName());
+ }
+
+ @Test
+ public void testSingleContentTypeAndContentLengthValueInXmlResponse() throws Exception {
+ assertStatusContentTypeAndLength(target().request("application/xml").get());
+ assertStatusContentTypeAndLength(target()
+ .request("text/html", "application/xhtml+xml", "application/xml;q=0.9", "*/*;q=0.8").get());
+ }
+
+ private void assertStatusContentTypeAndLength(Response response) {
+ assertEquals("Should have returned a 200 response!", 200, response.getStatus());
+ assertTrue("Should contain a Content-Type header!", response.getHeaders().containsKey(HttpHeaders.CONTENT_TYPE));
+ assertEquals("Should have a single Content-Type header!", 1, response.getHeaders().get(HttpHeaders.CONTENT_TYPE).size());
+ assertTrue("Should contain a Content-Length header!", response.getHeaders().containsKey(HttpHeaders.CONTENT_LENGTH));
+ assertEquals("Should have a single Content-Length header!",
+ 1, response.getHeaders().get(HttpHeaders.CONTENT_LENGTH).size());
+ }
+
+ @Test
+ public void testResourceAsHtmlUsingWebKitAcceptHeaders() throws Exception {
+ final String response = target().request(
+ "text/html",
+ "application/xhtml+xml",
+ "application/xml;q=0.9",
+ "*/*;q=0.8").get(String.class);
+
+ assertBookstoreHtmlResponse(response);
+ }
+
+ protected void assertBookstoreHtmlResponse(String response) {
+ assertHtmlResponse(response);
+ assertResponseContains(response, "Bookstore");
+ assertResponseContains(response, "Item List");
+ }
+}
diff --git a/tests/integration/servlet-2.5-mvc-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/ItemITCase.java b/tests/integration/servlet-2.5-mvc-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/ItemITCase.java
new file mode 100644
index 0000000..90d9118
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/ItemITCase.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_1;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+
+import org.glassfish.jersey.tests.integration.servlet_25_mvc_1.resource.Book;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class ItemITCase extends TestSupport {
+
+ @Test
+ public void testResourceAsHtml() throws Exception {
+ // NOTE: HttpUrlConnector sends several accepted types by default when not explicitly set by the caller.
+ // In such case, the .accept("text/html") call is not necessary. However, other connectors act in a different way and
+ // this leads in different behaviour when selecting the MessageBodyWriter. Leaving the definition explicit for broader
+ // compatibility.
+ final String response = item1resource().request(MediaType.TEXT_HTML).get(String.class);
+ assertItemHtmlResponse(response);
+ }
+
+ @Test
+ public void testResourceAsXml() throws Exception {
+ final String text = item1resource().request("application/xml").get(String.class);
+ System.out.println("Item XML is: " + text);
+
+ final Book response = item1resource().request("application/xml").get(Book.class);
+ assertNotNull("Should have returned an item!", response);
+ assertEquals("item title", "Svejk", response.getTitle());
+ }
+
+ @Test
+ public void testResourceAsHtmlUsingWebKitAcceptHeaders() throws Exception {
+ final String response = item1resource().request(
+ "text/html",
+ "application/xhtml+xml",
+ "application/xml;q=0.9",
+ "*/*;q=0.8").get(String.class);
+
+ assertItemHtmlResponse(response);
+ }
+
+ protected void assertItemHtmlResponse(String response) {
+ assertHtmlResponse(response);
+ assertResponseContains(response, "<title>Book</title>");
+ assertResponseContains(response, "<h1>Svejk</h1>");
+ }
+
+ protected WebTarget item1resource() {
+ return target().path("/items/1");
+ }
+
+}
diff --git a/tests/integration/servlet-2.5-mvc-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/TestSupport.java b/tests/integration/servlet-2.5-mvc-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/TestSupport.java
new file mode 100644
index 0000000..0ae958f
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_1/TestSupport.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_1;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * A base class for test cases which boots up a GlassFish server for in container testing of RESTful resources.
+ *
+ * @author James Strachan
+ * @author Naresh
+ */
+public abstract class TestSupport extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new MyApplication();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ protected void assertHtmlResponse(String response) {
+ assertNotNull("No text returned!", response);
+
+ assertResponseContains(response, "<html>");
+ assertResponseContains(response, "</html>");
+ }
+
+ protected void assertResponseContains(String response, String text) {
+ assertTrue("Response should contain " + text + " but was: " + response, response.contains(text));
+ }
+}
diff --git a/tests/integration/servlet-2.5-mvc-2/pom.xml b/tests/integration/servlet-2.5-mvc-2/pom.xml
new file mode 100644
index 0000000..a34c50d
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-2/pom.xml
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-2.5-mvc-2</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-2.5-mvc-2</name>
+
+ <description>Servlet integration test - servlet-2.5-mvc-2 - filter - MVC - jersey.config.servlet.jsp.disableJspTemplateProcessor</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-mvc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-mvc-jsp</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${servlet2.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/servlet-2.5-mvc-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/MyApplication.java b/tests/integration/servlet-2.5-mvc-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/MyApplication.java
new file mode 100644
index 0000000..b3f7066
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/MyApplication.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_2;
+
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.mvc.jsp.JspMvcFeature;
+import org.glassfish.jersey.tests.integration.servlet_25_mvc_2.resource.Bookstore;
+
+/**
+ * @author Michal Gajdos
+ */
+public class MyApplication extends ResourceConfig {
+
+ public MyApplication() {
+ // Resources.
+ packages(Bookstore.class.getPackage().getName());
+
+ // MVC.
+ register(JspMvcFeature.class);
+
+ // Logging.
+ register(LoggingFeature.class);
+ }
+}
diff --git a/tests/integration/servlet-2.5-mvc-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Book.java b/tests/integration/servlet-2.5-mvc-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Book.java
new file mode 100644
index 0000000..5b64e83
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Book.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_2.resource;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class Book extends Item {
+
+ public Book() {
+ }
+
+ public Book(final String title, final String author) {
+ super(title, author);
+ }
+
+
+}
diff --git a/tests/integration/servlet-2.5-mvc-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Bookstore.java b/tests/integration/servlet-2.5-mvc-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Bookstore.java
new file mode 100644
index 0000000..aeb0812
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Bookstore.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_2.resource;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.NotFoundException;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import javax.inject.Singleton;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.glassfish.jersey.server.mvc.Template;
+
+@Path("/")
+@Singleton
+@Template
+@Produces("text/html")
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class Bookstore {
+
+ private final Map<String, Item> items = new TreeMap<String, Item>();
+ private String name;
+
+ public Bookstore() {
+ setName("Czech Bookstore");
+ getItems().put("1", new Book("Svejk", "Jaroslav Hasek"));
+ getItems().put("2", new Book("Krakatit", "Karel Capek"));
+ }
+
+ @Path("items/{itemid}/")
+ public Item getItem(@PathParam("itemid") String itemid) {
+ Item i = getItems().get(itemid);
+ if (i == null) {
+ throw new NotFoundException(Response
+ .status(Response.Status.NOT_FOUND)
+ .entity("Item, " + itemid + ", is not found")
+ .build());
+ }
+
+ return i;
+ }
+
+ @GET
+ @Produces({MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
+ public Bookstore getXml() {
+ return this;
+ }
+
+ public Map<String, Item> getItems() {
+ return items;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/tests/integration/servlet-2.5-mvc-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Item.java b/tests/integration/servlet-2.5-mvc-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Item.java
new file mode 100644
index 0000000..42ef066
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Item.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_2.resource;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.glassfish.jersey.server.mvc.Template;
+
+@Template
+@Produces("text/html")
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class Item {
+
+ private String title;
+ private String author;
+
+ public Item() {
+ }
+
+ public Item(final String title, final String author) {
+ this.title = title;
+ this.author = author;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ @GET
+ @Produces({MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
+ public Item getXml() {
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return "Item{"
+ + "title='" + title + '\''
+ + ", author='" + author + '\''
+ + '}';
+ }
+}
diff --git a/tests/integration/servlet-2.5-mvc-2/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-2.5-mvc-2/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..4fa05ba
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-2/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <filter>
+ <filter-name>org.glassfish.jersey.tests.integration.servlet_25_mvc_2.MyApplication</filter-name>
+ <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_25_mvc_2.MyApplication</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.server.mvc.templateBasePath.jsp</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ <!-- pass to next filter if Jersey/App returns 404 -->
+ <init-param>
+ <param-name>jersey.config.servlet.filter.forwardOn404</param-name>
+ <param-value>false</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>org.glassfish.jersey.tests.integration.servlet_25_mvc_2.MyApplication</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+</web-app>
diff --git a/tests/integration/servlet-2.5-mvc-2/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Book/index.jsp b/tests/integration/servlet-2.5-mvc-2/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Book/index.jsp
new file mode 100644
index 0000000..bff6020
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-2/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Book/index.jsp
@@ -0,0 +1,46 @@
+<%--
+
+ Copyright (c) 2010, 2018 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
+
+--%>
+
+<%@page contentType="text/html"%>
+<%@page pageEncoding="UTF-8"%>
+<%--
+The taglib directive below imports the JSTL library. If you uncomment it,
+you must also add the JSTL library to the project. The Add Library... action
+on Libraries node in Projects view can be used to add the JSTL 1.1 library.
+--%>
+<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
+<%@taglib prefix="rbt" uri="urn:org:glassfish:jersey:servlet:mvc" %>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+"http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Book</title>
+ </head>
+ <body>
+
+ <h1>${it.title}</h1>
+
+ Book from ${it.author}
+
+ <rbt:include page="footer.jsp"/>
+
+ </body>
+</html>
diff --git a/tests/integration/servlet-2.5-mvc-2/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Bookstore/count.jsp b/tests/integration/servlet-2.5-mvc-2/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Bookstore/count.jsp
new file mode 100644
index 0000000..2fe7542
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-2/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Bookstore/count.jsp
@@ -0,0 +1,27 @@
+<%--
+
+ Copyright (c) 2010, 2018 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
+
+--%>
+
+<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
+<%--
+ An example of another side JSP.
+--%>
+<html>
+ <body>
+ # of items: ${fn:length(it.items)}
+ </body>
+</html>
diff --git a/tests/integration/servlet-2.5-mvc-2/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Bookstore/index.jsp b/tests/integration/servlet-2.5-mvc-2/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Bookstore/index.jsp
new file mode 100644
index 0000000..2ddb202
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-2/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Bookstore/index.jsp
@@ -0,0 +1,56 @@
+<%--
+
+ Copyright (c) 2010, 2018 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
+
+--%>
+
+<%@page contentType="text/html"%>
+<%@page pageEncoding="UTF-8"%>
+
+<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <style type="text/css" media="screen">
+ @import url( <c:url value="/css/style.css"/> );
+ </style>
+ <title>REST Bookstore Sample</title>
+ </head>
+ <body>
+
+ <h1>${it.name}</h1>
+
+ <h2>Item List</h2>
+
+ <ul>
+ <c:forEach var="i" items="${it.items}">
+ <li><a href="items/${i.key}/">${i.value.title}</a>
+ </c:forEach>
+ </ul>
+
+ <h2>Others</h2>
+ <p>
+ <a href="count">count inventory</a>
+ <p>
+ <a href="time">get the system time</a>
+ <p>
+ <a href="jsp/help.jsp">regular resources</a>
+ </p>
+ </body>
+</html>
diff --git a/tests/integration/servlet-2.5-mvc-2/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Bookstore/time.jsp b/tests/integration/servlet-2.5-mvc-2/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Bookstore/time.jsp
new file mode 100644
index 0000000..527e22f
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-2/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Bookstore/time.jsp
@@ -0,0 +1,24 @@
+<%--
+
+ Copyright (c) 2010, 2018 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
+
+--%>
+
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+ <body>
+ Current system time is ${it.systemTime}
+ </body>
+</html>
diff --git a/tests/integration/servlet-2.5-mvc-2/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Item/footer.jsp b/tests/integration/servlet-2.5-mvc-2/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Item/footer.jsp
new file mode 100644
index 0000000..fdff710
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-2/src/main/webapp/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/resource/Item/footer.jsp
@@ -0,0 +1,24 @@
+<%--
+
+ Copyright (c) 2010, 2018 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
+
+--%>
+
+<p>
+<a href="../../">Back</a>
+<hr>
+<div align="right">
+ Common footer (title ${it.title})
+</div>
diff --git a/tests/integration/servlet-2.5-mvc-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/BookstoreITCase.java b/tests/integration/servlet-2.5-mvc-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/BookstoreITCase.java
new file mode 100644
index 0000000..0d20972
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/BookstoreITCase.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_2;
+
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.tests.integration.servlet_25_mvc_2.resource.Bookstore;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class BookstoreITCase extends TestSupport {
+
+ @Test
+ public void testResourceAsXml() throws Exception {
+ final Bookstore response = target().request("application/xml").get(Bookstore.class);
+
+ assertBookstoreXmlResponse(response);
+ }
+
+ @Test
+ public void testResourceAsHtmlUsingWebKitAcceptHeaders() throws Exception {
+ final Response response = target().request(
+ "text/html",
+ "application/xhtml+xml",
+ "application/xml;q=0.9",
+ "*/*;q=0.8").get(Response.class);
+
+ assertEquals(404, response.getStatus());
+ }
+
+ protected void assertBookstoreXmlResponse(final Bookstore response) {
+ assertNotNull("Should have returned a bookstore!", response);
+ assertEquals("bookstore name", "Czech Bookstore", response.getName());
+ }
+}
diff --git a/tests/integration/servlet-2.5-mvc-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/ItemITCase.java b/tests/integration/servlet-2.5-mvc-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/ItemITCase.java
new file mode 100644
index 0000000..e4a793b
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/ItemITCase.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_2;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.tests.integration.servlet_25_mvc_2.resource.Book;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class ItemITCase extends TestSupport {
+
+ @Test
+ public void testResourceAsXml() throws Exception {
+ final String text = item1resource().request("application/xml").get(String.class);
+ System.out.println("Item XML is: " + text);
+
+ final Book response = item1resource().request("application/xml").get(Book.class);
+ assertItemXmlResponse(response);
+ }
+
+ @Test
+ public void testResourceAsHtmlUsingWebKitAcceptHeaders() throws Exception {
+ final Response response = item1resource().request(
+ "text/html",
+ "application/xhtml+xml",
+ "application/xml;q=0.9",
+ "*/*;q=0.8").get(Response.class);
+
+ assertEquals(404, response.getStatus());
+ }
+
+ private void assertItemXmlResponse(final Book response) {
+ assertNotNull("Should have returned an item!", response);
+ assertEquals("item title", "Svejk", response.getTitle());
+ }
+
+ protected WebTarget item1resource() {
+ return target().path("/items/1");
+ }
+}
diff --git a/tests/integration/servlet-2.5-mvc-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/TestSupport.java b/tests/integration/servlet-2.5-mvc-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/TestSupport.java
new file mode 100644
index 0000000..d9d2099
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_2/TestSupport.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_2;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.TestProperties;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+/**
+ * A base class for test cases which boots up a GlassFish server for in container testing of RESTful resources.
+ *
+ * @author James Strachan
+ * @author Naresh
+ */
+public abstract class TestSupport extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new MyApplication();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+}
diff --git a/tests/integration/servlet-2.5-mvc-3/pom.xml b/tests/integration/servlet-2.5-mvc-3/pom.xml
new file mode 100644
index 0000000..962b2ba
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-3/pom.xml
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-2.5-mvc-3</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-2.5-mvc-3</name>
+
+ <description>Servlet integration test - servlet-2.5-mvc-3 - filter - MVC - jersey.config.servlet.JspTemplatesBasePath</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-mvc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-mvc-jsp</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${servlet2.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/servlet-2.5-mvc-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/MyApplication.java b/tests/integration/servlet-2.5-mvc-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/MyApplication.java
new file mode 100644
index 0000000..998b5d4
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/MyApplication.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_3;
+
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.mvc.jsp.JspMvcFeature;
+import org.glassfish.jersey.tests.integration.servlet_25_mvc_3.resource.Bookstore;
+
+/**
+ * @author Michal Gajdos
+ */
+public class MyApplication extends ResourceConfig {
+
+ public MyApplication() {
+ // Resources.
+ packages(Bookstore.class.getPackage().getName());
+
+ // MVC.
+ register(JspMvcFeature.class);
+
+ // Logging.
+ register(LoggingFeature.class);
+ }
+}
diff --git a/tests/integration/servlet-2.5-mvc-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Book.java b/tests/integration/servlet-2.5-mvc-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Book.java
new file mode 100644
index 0000000..049a8f2
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Book.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_3.resource;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class Book extends Item {
+
+ public Book() {
+ }
+
+ public Book(final String title, final String author) {
+ super(title, author);
+ }
+
+
+}
diff --git a/tests/integration/servlet-2.5-mvc-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Bookstore.java b/tests/integration/servlet-2.5-mvc-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Bookstore.java
new file mode 100644
index 0000000..d52888b
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Bookstore.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_3.resource;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.NotFoundException;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import javax.inject.Singleton;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.glassfish.jersey.server.mvc.Template;
+
+@Path("/")
+@Singleton
+@Template
+@Produces("text/html")
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class Bookstore {
+
+ private final Map<String, Item> items = new TreeMap<String, Item>();
+ private String name;
+
+ public Bookstore() {
+ setName("Czech Bookstore");
+ getItems().put("1", new Book("Svejk", "Jaroslav Ha\u0161ek"));
+ getItems().put("2", new Book("Krakatit", "Karel Capek"));
+ }
+
+ @Path("items/{itemid}/")
+ public Item getItem(@PathParam("itemid") String itemid) {
+ Item i = getItems().get(itemid);
+ if (i == null) {
+ throw new NotFoundException(Response
+ .status(Response.Status.NOT_FOUND)
+ .entity("Item, " + itemid + ", is not found")
+ .build());
+ }
+
+ return i;
+ }
+
+ @GET
+ @Produces({MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
+ public Bookstore getXml() {
+ return this;
+ }
+
+ public Map<String, Item> getItems() {
+ return items;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/tests/integration/servlet-2.5-mvc-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Item.java b/tests/integration/servlet-2.5-mvc-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Item.java
new file mode 100644
index 0000000..85eb6cb
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Item.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_3.resource;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.glassfish.jersey.server.mvc.Template;
+import org.glassfish.jersey.server.mvc.Viewable;
+
+@Template
+@Produces("text/html")
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class Item {
+
+ private String title;
+ private String author;
+
+ public Item() {
+ }
+
+ public Item(final String title, final String author) {
+ this.title = title;
+ this.author = author;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ @GET
+ @Produces({MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
+ public Item getXml() {
+ return this;
+ }
+
+ @GET
+ @Path("utf")
+ public Viewable getItemUtf8() {
+ return new Viewable("index.utf8.jsp", this);
+ }
+
+ @GET
+ @Path("iso")
+ public Viewable getItemIso88592() {
+ return new Viewable("index.iso88592.jsp", this);
+ }
+
+ @Override
+ public String toString() {
+ return "Item{"
+ + "title='" + title + '\''
+ + ", author='" + author + '\''
+ + '}';
+ }
+}
diff --git a/tests/integration/servlet-2.5-mvc-3/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-2.5-mvc-3/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..bcc550e
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-3/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <filter>
+ <filter-name>org.glassfish.jersey.tests.integration.servlet_25_mvc_3.MyApplication</filter-name>
+ <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_25_mvc_3.MyApplication</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.server.mvc.templateBasePath.jsp</param-name>
+ <param-value>/jsp/</param-value>
+ </init-param>
+ <!-- pass to next filter if Jersey/App returns 404 -->
+ <init-param>
+ <param-name>jersey.config.servlet.filter.forwardOn404</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>org.glassfish.jersey.tests.integration.servlet_25_mvc_3.MyApplication</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+</web-app>
diff --git a/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Book/index.iso88592.jsp b/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Book/index.iso88592.jsp
new file mode 100644
index 0000000..57643b6
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Book/index.iso88592.jsp
@@ -0,0 +1,45 @@
+<%--
+
+ Copyright (c) 2010, 2018 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
+
+--%>
+
+<%@page contentType="text/html"%>
+<%@page pageEncoding="ISO-8859-2"%>
+<%--
+The taglib directive below imports the JSTL library. If you uncomment it,
+you must also add the JSTL library to the project. The Add Library... action
+on Libraries node in Projects view can be used to add the JSTL 1.1 library.
+--%>
+<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
+<%@taglib prefix="rbt" uri="urn:org:glassfish:jersey:servlet:mvc" %>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+"http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+ <head>
+ <title>Book</title>
+ </head>
+ <body>
+
+ <h1>${it.title}</h1>
+
+ Book from ${it.author}
+
+ <rbt:include page="footer.jsp"/>
+
+ </body>
+</html>
diff --git a/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Book/index.jsp b/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Book/index.jsp
new file mode 100644
index 0000000..bff6020
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Book/index.jsp
@@ -0,0 +1,46 @@
+<%--
+
+ Copyright (c) 2010, 2018 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
+
+--%>
+
+<%@page contentType="text/html"%>
+<%@page pageEncoding="UTF-8"%>
+<%--
+The taglib directive below imports the JSTL library. If you uncomment it,
+you must also add the JSTL library to the project. The Add Library... action
+on Libraries node in Projects view can be used to add the JSTL 1.1 library.
+--%>
+<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
+<%@taglib prefix="rbt" uri="urn:org:glassfish:jersey:servlet:mvc" %>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+"http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Book</title>
+ </head>
+ <body>
+
+ <h1>${it.title}</h1>
+
+ Book from ${it.author}
+
+ <rbt:include page="footer.jsp"/>
+
+ </body>
+</html>
diff --git a/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Book/index.utf8.jsp b/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Book/index.utf8.jsp
new file mode 100644
index 0000000..3410c60
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Book/index.utf8.jsp
@@ -0,0 +1,45 @@
+<%--
+
+ Copyright (c) 2010, 2018 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
+
+--%>
+
+<%@page contentType="text/html"%>
+<%@page pageEncoding="UTF-8"%>
+<%--
+The taglib directive below imports the JSTL library. If you uncomment it,
+you must also add the JSTL library to the project. The Add Library... action
+on Libraries node in Projects view can be used to add the JSTL 1.1 library.
+--%>
+<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
+<%@taglib prefix="rbt" uri="urn:org:glassfish:jersey:servlet:mvc" %>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+"http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+ <head>
+ <title>Book</title>
+ </head>
+ <body>
+
+ <h1>${it.title}</h1>
+
+ Book from ${it.author}
+
+ <rbt:include page="footer.jsp"/>
+
+ </body>
+</html>
diff --git a/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Bookstore/count.jsp b/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Bookstore/count.jsp
new file mode 100644
index 0000000..2fe7542
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Bookstore/count.jsp
@@ -0,0 +1,27 @@
+<%--
+
+ Copyright (c) 2010, 2018 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
+
+--%>
+
+<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
+<%--
+ An example of another side JSP.
+--%>
+<html>
+ <body>
+ # of items: ${fn:length(it.items)}
+ </body>
+</html>
diff --git a/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Bookstore/index.jsp b/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Bookstore/index.jsp
new file mode 100644
index 0000000..91796e2
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Bookstore/index.jsp
@@ -0,0 +1,56 @@
+<%--
+
+ Copyright (c) 2010, 2018 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
+
+--%>
+
+<%@page contentType="text/html"%>
+<%@page pageEncoding="UTF-8"%>
+
+<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <style type="text/css" media="screen">
+ @import url( <c:url value="/css/style.css"/> );
+ </style>
+ <title>REST Bookstore Sample</title>
+ </head>
+ <body>
+
+ <h1>${it.name}</h1>
+
+ <h2>Item List</h2>
+
+ <ul>
+ <c:forEach var="i" items="${it.items}">
+ <li><a href="items/${i.key}/">${i.value.title}</a>
+ </c:forEach>
+ </ul>
+
+ <h2>Others</h2>
+ <p>
+ <a href="count">count inventory</a>
+ <p>
+ <a href="time">get the system time</a>
+ <p>
+ <a href="jsp/help.jsp">regular resources</a>
+ </p>
+ </body>
+</html>
diff --git a/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Bookstore/time.jsp b/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Bookstore/time.jsp
new file mode 100644
index 0000000..527e22f
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Bookstore/time.jsp
@@ -0,0 +1,24 @@
+<%--
+
+ Copyright (c) 2010, 2018 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
+
+--%>
+
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+ <body>
+ Current system time is ${it.systemTime}
+ </body>
+</html>
diff --git a/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Item/footer.jsp b/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Item/footer.jsp
new file mode 100644
index 0000000..fdff710
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-3/src/main/webapp/jsp/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/resource/Item/footer.jsp
@@ -0,0 +1,24 @@
+<%--
+
+ Copyright (c) 2010, 2018 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
+
+--%>
+
+<p>
+<a href="../../">Back</a>
+<hr>
+<div align="right">
+ Common footer (title ${it.title})
+</div>
diff --git a/tests/integration/servlet-2.5-mvc-3/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/BookstoreITCase.java b/tests/integration/servlet-2.5-mvc-3/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/BookstoreITCase.java
new file mode 100644
index 0000000..11f57e4
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-3/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/BookstoreITCase.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_3;
+
+import javax.ws.rs.core.MediaType;
+
+import org.glassfish.jersey.tests.integration.servlet_25_mvc_3.resource.Bookstore;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class BookstoreITCase extends TestSupport {
+
+ @Test
+ public void testResourceAsHtml() throws Exception {
+ // NOTE: HttpUrlConnector sends several accepted types by default when not explicitly set by the caller.
+ // In such case, the .accept("text/html") call is not necessary. However, other connectors act in a different way and
+ // this leads in different behaviour when selecting the MessageBodyWriter. Leaving the definition explicit for broader
+ // compatibility.
+ assertBookstoreHtmlResponse(target().request(MediaType.TEXT_HTML).get(String.class));
+ }
+
+ @Test
+ public void testResourceAsXml() throws Exception {
+ final Bookstore response = target().request("application/xml").get(Bookstore.class);
+
+ assertNotNull("Should have returned a bookstore!", response);
+ assertEquals("bookstore name", "Czech Bookstore", response.getName());
+ }
+
+ @Test
+ public void testResourceAsHtmlUsingWebKitAcceptHeaders() throws Exception {
+ final String response = target().request(
+ "text/html",
+ "application/xhtml+xml",
+ "application/xml;q=0.9",
+ "*/*;q=0.8").get(String.class);
+
+ assertBookstoreHtmlResponse(response);
+ }
+
+ protected void assertBookstoreHtmlResponse(String response) {
+ assertHtmlResponse(response);
+ assertResponseContains(response, "Bookstore");
+ assertResponseContains(response, "Item List");
+ }
+}
diff --git a/tests/integration/servlet-2.5-mvc-3/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/ItemITCase.java b/tests/integration/servlet-2.5-mvc-3/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/ItemITCase.java
new file mode 100644
index 0000000..b3c3e39
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-3/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/ItemITCase.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_3;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.tests.integration.servlet_25_mvc_3.resource.Book;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+public class ItemITCase extends TestSupport {
+
+ @Test
+ public void testResourceAsHtml() throws Exception {
+ // NOTE: HttpUrlConnector sends several accepted types by default when not explicitly set by the caller.
+ // In such case, the .accept("text/html") call is not necessary. However, other connectors act in a different way and
+ // this leads in different behaviour when selecting the MessageBodyWriter. Leaving the definition explicit for broader
+ // compatibility.
+ final String response = item1resource().request(MediaType.TEXT_HTML).get(String.class);
+ assertItemHtmlResponse(response);
+ }
+
+ @Test
+ public void testResourceAsHtmlUtf8() throws Exception {
+ final Response response = item1resource().path("utf").request().get();
+ final String html = response.readEntity(String.class);
+
+ assertItemHtmlResponse(html);
+ assertResponseContains(html, "Ha\u0161ek");
+ }
+
+ @Test
+ public void testResourceAsHtmlIso88592() throws Exception {
+ final Response response = item1resource().path("iso").request().get();
+ response.bufferEntity();
+
+ final String htmlUtf8 = response.readEntity(String.class);
+
+ assertItemHtmlResponse(htmlUtf8);
+ assertFalse("Response shouldn't contain Ha\u0161ek but was: " + htmlUtf8, htmlUtf8.contains("Ha\u0161ek"));
+
+ final byte[] bytes = response.readEntity(byte[].class);
+ final String htmlIso = new String(bytes, "ISO-8859-2");
+
+ assertItemHtmlResponse(htmlIso);
+ assertFalse("Response shouldn't contain Ha\u0161ek but was: " + htmlIso, htmlIso.contains("Ha\u0161ek"));
+ assertResponseContains(htmlIso, new String("Ha\u0161ek".getBytes(), "ISO-8859-2"));
+ }
+
+ @Test
+ public void testResourceAsXml() throws Exception {
+ final String text = item1resource().request("application/xml").get(String.class);
+ System.out.println("Item XML is: " + text);
+
+ final Book response = item1resource().request("application/xml").get(Book.class);
+ assertNotNull("Should have returned an item!", response);
+ assertEquals("item title", "Svejk", response.getTitle());
+ }
+
+ @Test
+ public void testResourceAsHtmlUsingWebKitAcceptHeaders() throws Exception {
+ final String response = item1resource().request(
+ "text/html",
+ "application/xhtml+xml",
+ "application/xml;q=0.9",
+ "*/*;q=0.8").get(String.class);
+
+ assertItemHtmlResponse(response);
+ }
+
+ protected void assertItemHtmlResponse(final String response) {
+ assertHtmlResponse(response);
+ assertResponseContains(response, "<title>Book</title>");
+ assertResponseContains(response, "<h1>Svejk</h1>");
+ }
+
+ protected WebTarget item1resource() {
+ return target().path("/items/1");
+ }
+}
diff --git a/tests/integration/servlet-2.5-mvc-3/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/TestSupport.java b/tests/integration/servlet-2.5-mvc-3/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/TestSupport.java
new file mode 100644
index 0000000..69121ee
--- /dev/null
+++ b/tests/integration/servlet-2.5-mvc-3/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_mvc_3/TestSupport.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_25_mvc_3;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.TestProperties;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * A base class for test cases which boots up a GlassFish server for in container testing of RESTful resources.
+ *
+ * @author James Strachan
+ * @author Naresh
+ */
+public abstract class TestSupport extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ enable(TestProperties.LOG_TRAFFIC);
+ enable(TestProperties.DUMP_ENTITY);
+ return new MyApplication();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ protected void assertHtmlResponse(final String response) {
+ assertNotNull("No text returned!", response);
+
+ assertResponseContains(response, "<html>");
+ assertResponseContains(response, "</html>");
+ }
+
+ protected void assertResponseContains(final String response, final String text) {
+ assertTrue("Response should contain " + text + " but was: " + response, response.contains(text));
+ }
+}
diff --git a/tests/integration/servlet-2.5-reload/pom.xml b/tests/integration/servlet-2.5-reload/pom.xml
new file mode 100644
index 0000000..29de897
--- /dev/null
+++ b/tests/integration/servlet-2.5-reload/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-2.5-reload</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-2.5-reload</name>
+
+ <description>Servlet integration test - servlet-2.5-reload - reload resource triggers application reload</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/servlet-2.5-reload/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_config_reload/AnotherResource.java b/tests/integration/servlet-2.5-reload/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_config_reload/AnotherResource.java
new file mode 100644
index 0000000..49e28ec
--- /dev/null
+++ b/tests/integration/servlet-2.5-reload/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_config_reload/AnotherResource.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_config_reload;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("another")
+public class AnotherResource {
+
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "Another resource";
+ }
+}
diff --git a/tests/integration/servlet-2.5-reload/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_config_reload/HelloWorldResource.java b/tests/integration/servlet-2.5-reload/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_config_reload/HelloWorldResource.java
new file mode 100644
index 0000000..2fdcb63
--- /dev/null
+++ b/tests/integration/servlet-2.5-reload/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_config_reload/HelloWorldResource.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_config_reload;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+@Path("helloworld")
+public class HelloWorldResource {
+
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "Hello World! " + this.getClass().getPackage().getName();
+ }
+}
diff --git a/tests/integration/servlet-2.5-reload/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_config_reload/ReloadContainerLifecycleListener.java b/tests/integration/servlet-2.5-reload/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_config_reload/ReloadContainerLifecycleListener.java
new file mode 100644
index 0000000..ceee204
--- /dev/null
+++ b/tests/integration/servlet-2.5-reload/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_config_reload/ReloadContainerLifecycleListener.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_config_reload;
+
+import javax.ws.rs.ext.Provider;
+
+import org.glassfish.jersey.server.spi.AbstractContainerLifecycleListener;
+import org.glassfish.jersey.server.spi.Container;
+
+/**
+ * @author Miroslav Fuksa
+ */
+@Provider
+public class ReloadContainerLifecycleListener extends AbstractContainerLifecycleListener {
+
+ private static Container container;
+
+ @Override
+ public void onStartup(final Container container) {
+ ReloadContainerLifecycleListener.setContainer(container);
+ }
+
+ public static Container getContainer() {
+ return container;
+ }
+
+ public static void setContainer(final Container container) {
+ ReloadContainerLifecycleListener.container = container;
+ }
+
+}
diff --git a/tests/integration/servlet-2.5-reload/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_config_reload/ReloadResource.java b/tests/integration/servlet-2.5-reload/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_config_reload/ReloadResource.java
new file mode 100644
index 0000000..e2c1c46
--- /dev/null
+++ b/tests/integration/servlet-2.5-reload/src/main/java/org/glassfish/jersey/tests/integration/servlet_25_config_reload/ReloadResource.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_config_reload;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("reload")
+public class ReloadResource {
+
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ try {
+ ReloadContainerLifecycleListener.getContainer().reload(
+ new ResourceConfig(HelloWorldResource.class,
+ ReloadResource.class,
+ AnotherResource.class,
+ ReloadContainerLifecycleListener.class)
+ );
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ return "Reload resource";
+ }
+}
diff --git a/tests/integration/servlet-2.5-reload/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-2.5-reload/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..14a0f9c
--- /dev/null
+++ b/tests/integration/servlet-2.5-reload/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>JerseyReloadServlet</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_25_config_reload.ReloadResource org.glassfish.jersey.tests.integration.servlet_25_config_reload.HelloWorldResource
+ org.glassfish.jersey.tests.integration.servlet_25_config_reload.ReloadResource org.glassfish.jersey.tests.integration.servlet_25_config_reload.ReloadContainerLifecycleListener</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>JerseyReloadServlet</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/servlet-2.5-reload/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_config_reload/ReloadTestIT.java b/tests/integration/servlet-2.5-reload/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_config_reload/ReloadTestIT.java
new file mode 100644
index 0000000..af22617
--- /dev/null
+++ b/tests/integration/servlet-2.5-reload/src/test/java/org/glassfish/jersey/tests/integration/servlet_25_config_reload/ReloadTestIT.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_25_config_reload;
+
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class ReloadTestIT extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig(HelloWorldResource.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testReload() throws Exception {
+ Response response = target().path("helloworld").request().get();
+ assertEquals(200, response.getStatus());
+ assertEquals("Hello World! " + this.getClass().getPackage().getName(), response.readEntity(String.class));
+
+ response = target().path("another").request().get();
+ assertEquals(404, response.getStatus());
+
+ response = target().path("reload").request().get();
+ assertEquals(200, response.getStatus());
+
+ response = target().path("another").request().get();
+ assertEquals(200, response.getStatus());
+ }
+}
diff --git a/tests/integration/servlet-3-async/pom.xml b/tests/integration/servlet-3-async/pom.xml
new file mode 100644
index 0000000..a959490
--- /dev/null
+++ b/tests/integration/servlet-3-async/pom.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-3-async</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-3-async</name>
+
+ <description>Servlet integration test - servlet-3-async - configured via jax-rs application annotated with @javax.ws.rs.ApplicationPath</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/servlet-3-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncServletResource.java b/tests/integration/servlet-3-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncServletResource.java
new file mode 100644
index 0000000..2f96055
--- /dev/null
+++ b/tests/integration/servlet-3-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncServletResource.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_3_async;
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.Executors;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+
+import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.Suspended;
+
+/**
+ * Asynchronous servlet-deployed resource.
+ *
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+@Path("async")
+public class AsyncServletResource {
+ /**
+ * Hello world message.
+ */
+ public static final String HELLO_ASYNC_WORLD = "Hello Async World!";
+ public static final String CANCELED = "Canceled";
+
+ private static BlockingQueue<CanceledRequest> cancelingQueue = new ArrayBlockingQueue<CanceledRequest>(5);
+
+ private static class CanceledRequest {
+ private final String id;
+ private final AsyncResponse asyncResponse;
+
+ private CanceledRequest(String id, AsyncResponse asyncResponse) {
+ this.id = id;
+ this.asyncResponse = asyncResponse;
+ }
+ }
+
+ /**
+ * Get the async "Hello World" message.
+ */
+ @GET
+ @Produces("text/plain")
+ public void get(@Suspended final AsyncResponse ar) {
+ Executors.newSingleThreadExecutor().execute(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Thread.sleep(100);
+ ar.resume(HELLO_ASYNC_WORLD);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+
+ /**
+ * Get a canceled request.
+ *
+ * @param id request id.
+ * @throws InterruptedException in case of not being able to put the request
+ * to an internal queue for canceling.
+ */
+ @GET
+ @Path("canceled")
+ public void getCanceled(@Suspended final AsyncResponse ar, @QueryParam("id") final String id) throws InterruptedException {
+ cancelingQueue.put(new CanceledRequest(id, ar));
+ }
+
+ /**
+ * Cancel a request that is on top of the canceling queue.
+ *
+ * @return notification message about successful request canceling.
+ * @throws InterruptedException in case of not being able to take a cancelled request
+ * from an internal canceling queue.
+ */
+ @POST
+ @Produces("text/plain")
+ @Path("canceled")
+ public String cancel(String requestId) throws InterruptedException {
+ final CanceledRequest canceledRequest = cancelingQueue.take();
+ canceledRequest.asyncResponse.cancel();
+
+ return CANCELED + " " + canceledRequest.id + " by POST " + requestId;
+ }
+
+}
diff --git a/tests/integration/servlet-3-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncTimeoutResource.java b/tests/integration/servlet-3-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncTimeoutResource.java
new file mode 100644
index 0000000..23c000b
--- /dev/null
+++ b/tests/integration/servlet-3-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncTimeoutResource.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_async;
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.Suspended;
+import javax.ws.rs.container.TimeoutHandler;
+
+/**
+ * Asynchronous servlet-deployed resource for testing {@link javax.ws.rs.container.AsyncResponse async response} timeouts.
+ *
+ * @author Michal Gajdos
+ */
+@Path("timeout")
+public class AsyncTimeoutResource {
+
+ private static final BlockingQueue<AsyncResponse> queue = new ArrayBlockingQueue<AsyncResponse>(1);
+
+ @GET
+ @Path("suspend")
+ public void suspend(@Suspended final AsyncResponse asyncResponse) {
+ queue.add(asyncResponse);
+ }
+
+ @POST
+ @Path("timeout")
+ public void setTimeOut(final Integer millis) throws InterruptedException {
+ final AsyncResponse asyncResponse = queue.take();
+
+ final boolean timeout1 = asyncResponse.setTimeout(millis, TimeUnit.MILLISECONDS);
+ asyncResponse.setTimeoutHandler(new TimeoutHandler() {
+
+ @Override
+ public void handleTimeout(final AsyncResponse asyncResponse) {
+ final boolean timeout2 = asyncResponse.setTimeout(millis, TimeUnit.MILLISECONDS);
+ asyncResponse.setTimeoutHandler(new TimeoutHandler() {
+
+ @Override
+ public void handleTimeout(final AsyncResponse asyncResponse) {
+ asyncResponse.resume("timeout1=" + timeout1 + "_timeout2=" + timeout2 + "_handled");
+ asyncResponse.cancel();
+ }
+ });
+ }
+ });
+ }
+}
diff --git a/tests/integration/servlet-3-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/Servlet3Async.java b/tests/integration/servlet-3-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/Servlet3Async.java
new file mode 100644
index 0000000..5787a1d
--- /dev/null
+++ b/tests/integration/servlet-3-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/Servlet3Async.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_3_async;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * Asynchronous servlet-deployed resource application.
+ *
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+@ApplicationPath("/")
+public class Servlet3Async extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> hashSet = new HashSet<Class<?>>();
+ hashSet.add(AsyncServletResource.class);
+ hashSet.add(AsyncTimeoutResource.class);
+ return hashSet;
+ }
+}
diff --git a/tests/integration/servlet-3-async/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncServletResourceITCase.java b/tests/integration/servlet-3-async/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncServletResourceITCase.java
new file mode 100644
index 0000000..6cdfb9a
--- /dev/null
+++ b/tests/integration/servlet-3-async/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncServletResourceITCase.java
@@ -0,0 +1,294 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_3_async;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Logger;
+
+import javax.ws.rs.ProcessingException;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.internal.guava.ThreadFactoryBuilder;
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.process.JerseyProcessingUncaughtExceptionHandler;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Asynchronous servlet-deployed resource test.
+ *
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+public class AsyncServletResourceITCase extends JerseyTest {
+ private static final Logger LOGGER = Logger.getLogger(AsyncServletResourceITCase.class.getName());
+
+ private static class ResponseRecord {
+ final int status;
+ final String message;
+
+ private ResponseRecord(int status, String message) {
+ this.status = status;
+ this.message = message;
+ }
+
+ @Override
+ public String toString() {
+ return status + " : \"" + message + '\"';
+ }
+ }
+
+ @Override
+ protected Application configure() {
+ return new Application();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ /**
+ * Test asynchronous servlet-deployed resource.
+ *
+ * @throws InterruptedException in case the waiting for all requests to complete was interrupted.
+ */
+ @Test
+ public void testAsyncServlet() throws InterruptedException {
+ final WebTarget resourceTarget = target("async");
+ resourceTarget.register(LoggingFeature.class);
+ final String expectedResponse = AsyncServletResource.HELLO_ASYNC_WORLD;
+
+ final int MAX_MESSAGES = 50;
+ final int LATCH_WAIT_TIMEOUT = 10 * getAsyncTimeoutMultiplier();
+ final boolean debugMode = false;
+ final boolean sequentialGet = false;
+ final Object sequentialGetLock = new Object();
+
+ final ExecutorService executor = Executors.newCachedThreadPool(new ThreadFactoryBuilder()
+ .setNameFormat("async-resource-test-%d")
+ .setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler())
+ .build());
+
+ final Map<Integer, ResponseRecord> getResponses = new ConcurrentHashMap<Integer, ResponseRecord>();
+
+ final CountDownLatch getRequestLatch = new CountDownLatch(MAX_MESSAGES);
+
+ try {
+ for (int i = 0; i < MAX_MESSAGES; i++) {
+ final int requestId = i;
+ executor.submit(new Runnable() {
+
+ @Override
+ public void run() {
+ //noinspection PointlessBooleanExpression,ConstantConditions
+ if (debugMode || sequentialGet) {
+ synchronized (sequentialGetLock) {
+ get();
+ }
+ } else {
+ get();
+ }
+ }
+
+ private void get() {
+ try {
+ final Response response = resourceTarget.request().get();
+ getResponses.put(
+ requestId,
+ new ResponseRecord(response.getStatus(), response.readEntity(String.class)));
+ } catch (Throwable t) {
+ t.printStackTrace();
+ } finally {
+ getRequestLatch.countDown();
+ }
+ }
+ });
+ }
+
+ //noinspection ConstantConditions
+ if (debugMode) {
+ getRequestLatch.await();
+ } else {
+ assertTrue("Waiting for all GET requests to complete has timed out.", getRequestLatch.await(LATCH_WAIT_TIMEOUT,
+ TimeUnit.SECONDS));
+ }
+ } finally {
+ executor.shutdownNow();
+ }
+
+ StringBuilder messageBuilder = new StringBuilder();
+ for (Map.Entry<Integer, ResponseRecord> getResponseEntry : getResponses.entrySet()) {
+ messageBuilder.append("GET response for message ")
+ .append(getResponseEntry.getKey()).append(": ")
+ .append(getResponseEntry.getValue().toString()).append('\n');
+ }
+ LOGGER.info(messageBuilder.toString());
+
+ assertEquals(MAX_MESSAGES, getResponses.size());
+ for (Map.Entry<Integer, ResponseRecord> entry : getResponses.entrySet()) {
+ assertEquals(
+ "Unexpected GET response status for request " + entry.getKey(),
+ 200, entry.getValue().status);
+ assertEquals(
+ "Unexpected GET response message for request " + entry.getKey(),
+ expectedResponse, entry.getValue().message);
+ }
+ }
+
+ /**
+ * Test canceling of an async request to a servlet-deployed resource.
+ *
+ * @throws InterruptedException in case the waiting for all requests to complete was interrupted.
+ */
+ @Test
+ public void testAsyncRequestCanceling() throws InterruptedException {
+ final WebTarget resourceTarget = target("async/canceled");
+ resourceTarget.register(LoggingFeature.class);
+
+ final int MAX_MESSAGES = 10;
+ final int LATCH_WAIT_TIMEOUT = 10 * getAsyncTimeoutMultiplier();
+ final boolean debugMode = false;
+ final boolean sequentialGet = false;
+ final boolean sequentialPost = false;
+ final Object sequentialGetLock = new Object();
+ final Object sequentialPostLock = new Object();
+
+ final ExecutorService executor = Executors.newCachedThreadPool(new ThreadFactoryBuilder()
+ .setNameFormat("async-canceled-resource-test-%d")
+ .setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler())
+ .build());
+
+ final Map<Integer, String> postResponses = new ConcurrentHashMap<Integer, String>();
+ final Map<Integer, String> getResponses = new ConcurrentHashMap<Integer, String>();
+
+ final CountDownLatch postRequestLatch = new CountDownLatch(MAX_MESSAGES);
+ final CountDownLatch getRequestLatch = new CountDownLatch(MAX_MESSAGES);
+
+ try {
+ for (int i = 0; i < MAX_MESSAGES; i++) {
+ final int requestId = i;
+ executor.submit(new Runnable() {
+
+ @Override
+ public void run() {
+ //noinspection PointlessBooleanExpression,ConstantConditions
+ if (debugMode || sequentialGet) {
+ synchronized (sequentialGetLock) {
+ get();
+ }
+ } else {
+ get();
+ }
+ }
+
+ private void get() {
+ try {
+ final String response = resourceTarget.queryParam("id", requestId).request().get(String.class);
+ getResponses.put(requestId, response);
+ } catch (WebApplicationException ex) {
+ final Response response = ex.getResponse();
+ getResponses.put(requestId, response.getStatus() + ": " + response.readEntity(String.class));
+ } finally {
+ getRequestLatch.countDown();
+ }
+ }
+ });
+ executor.submit(new Runnable() {
+
+ @Override
+ public void run() {
+ //noinspection PointlessBooleanExpression,ConstantConditions
+ if (debugMode || sequentialPost) {
+ synchronized (sequentialPostLock) {
+ post();
+ }
+ } else {
+ post();
+ }
+ }
+
+ private void post() throws ProcessingException {
+ try {
+ final String response = resourceTarget.request().post(Entity.text("" + requestId), String.class);
+ postResponses.put(requestId, response);
+ } finally {
+ postRequestLatch.countDown();
+ }
+ }
+ });
+ }
+
+ //noinspection ConstantConditions
+ if (debugMode) {
+ postRequestLatch.await();
+ getRequestLatch.await();
+ } else {
+ assertTrue("Waiting for all POST requests to complete has timed out.",
+ postRequestLatch.await(LATCH_WAIT_TIMEOUT, TimeUnit.SECONDS));
+ assertTrue("Waiting for all GET requests to complete has timed out.", getRequestLatch.await(LATCH_WAIT_TIMEOUT,
+ TimeUnit.SECONDS));
+ }
+ } finally {
+ executor.shutdownNow();
+ }
+
+ StringBuilder messageBuilder = new StringBuilder();
+ for (Map.Entry<Integer, String> postResponseEntry : postResponses.entrySet()) {
+ messageBuilder.append("POST response for message ")
+ .append(postResponseEntry.getKey()).append(": ")
+ .append(postResponseEntry.getValue()).append('\n');
+ }
+ messageBuilder.append('\n');
+ for (Map.Entry<Integer, String> getResponseEntry : getResponses.entrySet()) {
+ messageBuilder.append("GET response for message ")
+ .append(getResponseEntry.getKey()).append(": ")
+ .append(getResponseEntry.getValue()).append('\n');
+ }
+ LOGGER.info(messageBuilder.toString());
+
+ assertEquals(MAX_MESSAGES, postResponses.size());
+ for (Map.Entry<Integer, String> postResponseEntry : postResponses.entrySet()) {
+ assertTrue("Unexpected POST notification response for message " + postResponseEntry.getKey(),
+ postResponseEntry.getValue().startsWith(AsyncServletResource.CANCELED));
+ }
+
+ assertEquals(MAX_MESSAGES, getResponses.size());
+ final Collection<Integer> getResponseKeys = getResponses.keySet();
+ for (int i = 0; i < MAX_MESSAGES; i++) {
+ assertTrue("Detected a GET message response loss: " + i, getResponseKeys.contains(i));
+ final String getResponseEntry = getResponses.get(i);
+ assertTrue("Unexpected canceled GET response status for request " + i,
+ getResponseEntry.startsWith("503: "));
+ }
+ }
+}
diff --git a/tests/integration/servlet-3-async/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncTimeoutResourceITCase.java b/tests/integration/servlet-3-async/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncTimeoutResourceITCase.java
new file mode 100644
index 0000000..8bfb646
--- /dev/null
+++ b/tests/integration/servlet-3-async/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncTimeoutResourceITCase.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_async;
+
+import java.util.concurrent.Future;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Asynchronous servlet-deployed resource for testing {@link javax.ws.rs.container.AsyncResponse async response} timeouts.
+ *
+ * @author Michal Gajdos
+ */
+public class AsyncTimeoutResourceITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Application();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testTimeout() throws Exception {
+ final WebTarget resourceTarget = target("timeout");
+ resourceTarget.register(LoggingFeature.class);
+ final Future<Response> responseFuture = resourceTarget.path("suspend").request().async().get();
+
+ // Set timeout.
+ assertThat(resourceTarget.path("timeout").request().post(Entity.text("500")).getStatus(), equalTo(204));
+
+ // Wait for it.
+ assertThat(responseFuture.get().readEntity(String.class), equalTo("timeout1=true_timeout2=true_handled"));
+ }
+}
diff --git a/tests/integration/servlet-3-chunked-io/pom.xml b/tests/integration/servlet-3-chunked-io/pom.xml
new file mode 100644
index 0000000..4caa4b5
--- /dev/null
+++ b/tests/integration/servlet-3-chunked-io/pom.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-3-chunked-io</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-3-chunked-io</name>
+
+ <description>Servlet integration test - servlet-3-chunked-io</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-moxy</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.connectors</groupId>
+ <artifactId>jersey-grizzly-connector</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/servlet-3-chunked-io/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_chunked_io/App.java b/tests/integration/servlet-3-chunked-io/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_chunked_io/App.java
new file mode 100644
index 0000000..2495c51
--- /dev/null
+++ b/tests/integration/servlet-3-chunked-io/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_chunked_io/App.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_chunked_io;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.ext.ContextResolver;
+
+import org.glassfish.jersey.moxy.json.MoxyJsonConfig;
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * Chunked I/O test JAX-RS application class.
+ *
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+@ApplicationPath("resources")
+public class App extends ResourceConfig {
+
+ /**
+ * Chunked I/O test JAX-RS application.
+ */
+ public App() {
+ super(TestResource.class);
+
+ register(createMoxyJsonResolver());
+ }
+
+ /**
+ * Create MOXy JSON config context resolver.
+ *
+ * @return new MOXy JSON config context resolver.
+ */
+ public static ContextResolver<MoxyJsonConfig> createMoxyJsonResolver() {
+ final Map<String, String> namespacePrefixMapper = new HashMap<>(1);
+ namespacePrefixMapper.put("http://www.w3.org/2001/XMLSchema-instance", "xsi");
+
+ return new MoxyJsonConfig()
+ .setNamespacePrefixMapper(namespacePrefixMapper)
+ .setNamespaceSeparator(':')
+ .resolver();
+ }
+
+}
diff --git a/tests/integration/servlet-3-chunked-io/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_chunked_io/Message.java b/tests/integration/servlet-3-chunked-io/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_chunked_io/Message.java
new file mode 100644
index 0000000..e8b3304
--- /dev/null
+++ b/tests/integration/servlet-3-chunked-io/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_chunked_io/Message.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_chunked_io;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Message POJO.
+ *
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class Message {
+
+ /**
+ * Message id.
+ */
+ public int id;
+ /**
+ * Message content.
+ */
+ public String data;
+
+ /**
+ * Create new message.
+ */
+ public Message() {
+ this.id = -1;
+ this.data = "";
+ }
+
+ /**
+ * Create new message.
+ * @param id message id.
+ * @param data message content.
+ */
+ public Message(int id, String data) {
+ if (data == null) {
+ throw new IllegalArgumentException("Message data must not be null.");
+ }
+
+ this.id = id;
+ this.data = data;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ Message message = (Message) o;
+
+ if (id != message.id) {
+ return false;
+ }
+ if (!data.equals(message.data)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = id;
+ result = 31 * result + data.hashCode();
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"id\":" + id + ",\"data\":\"" + data + "\"}";
+ }
+}
diff --git a/tests/integration/servlet-3-chunked-io/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_chunked_io/TestResource.java b/tests/integration/servlet-3-chunked-io/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_chunked_io/TestResource.java
new file mode 100644
index 0000000..6069a99
--- /dev/null
+++ b/tests/integration/servlet-3-chunked-io/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_chunked_io/TestResource.java
@@ -0,0 +1,222 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_chunked_io;
+
+import java.io.IOException;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.InternalServerErrorException;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.Suspended;
+import javax.ws.rs.core.MediaType;
+
+import org.glassfish.jersey.server.ChunkedOutput;
+
+/**
+ * Test resource.
+ *
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+@Path("/test")
+public class TestResource {
+
+ private static final Logger LOGGER = Logger.getLogger(TestResource.class.getName());
+
+ /**
+ * Get chunk stream of JSON data - from JSON POJOs.
+ *
+ * @return chunk stream.
+ */
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("from-pojo")
+ public ChunkedOutput<Message> getFromPojo() {
+ final ChunkedOutput<Message> output = new ChunkedOutput<>(Message.class, "\r\n");
+
+ new Thread() {
+ @Override
+ public void run() {
+ try {
+ for (int i = 0; i < 3; i++) {
+ output.write(new Message(i, "test"));
+ Thread.sleep(200);
+ }
+ } catch (final IOException e) {
+ LOGGER.log(Level.SEVERE, "Error writing chunk.", e);
+ } catch (final InterruptedException e) {
+ LOGGER.log(Level.SEVERE, "Sleep interrupted.", e);
+ Thread.currentThread().interrupt();
+ } finally {
+ try {
+ output.close();
+ } catch (final IOException e) {
+ LOGGER.log(Level.INFO, "Error closing chunked output.", e);
+ }
+ }
+ }
+ }.start();
+
+ return output;
+ }
+
+ /**
+ * Get chunk stream of JSON data - from string.
+ *
+ * @return chunk stream.
+ */
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("from-string")
+ public ChunkedOutput<String> getFromText() {
+ final ChunkedOutput<String> output = new ChunkedOutput<>(String.class);
+
+ new Thread() {
+ @Override
+ public void run() {
+ try {
+ for (int i = 0; i < 3; i++) {
+ output.write(new Message(i, "test").toString() + "\r\n");
+ Thread.sleep(200);
+ }
+ } catch (final IOException e) {
+ LOGGER.log(Level.SEVERE, "Error writing chunk.", e);
+ } catch (final InterruptedException e) {
+ LOGGER.log(Level.SEVERE, "Sleep interrupted.", e);
+ Thread.currentThread().interrupt();
+ } finally {
+ try {
+ output.close();
+ } catch (final IOException e) {
+ LOGGER.log(Level.INFO, "Error closing chunked output.", e);
+ }
+ }
+ }
+ }.start();
+
+ return output;
+ }
+
+ /**
+ * {@link org.glassfish.jersey.server.ChunkedOutput#close()} is called before method returns it's entity. Resource reproduces
+ * JERSEY-2558 issue.
+ *
+ * @return (closed) chunk stream.
+ */
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("close-before-return")
+ public ChunkedOutput<Message> closeBeforeReturn() {
+ final ChunkedOutput<Message> output = new ChunkedOutput<>(Message.class, "\r\n");
+ final CountDownLatch latch = new CountDownLatch(1);
+
+ new Thread() {
+ @Override
+ public void run() {
+ try {
+ for (int i = 0; i < 3; i++) {
+ output.write(new Message(i, "test"));
+ Thread.sleep(200);
+ }
+ } catch (final IOException e) {
+ LOGGER.log(Level.SEVERE, "Error writing chunk.", e);
+ } catch (final InterruptedException e) {
+ LOGGER.log(Level.SEVERE, "Sleep interrupted.", e);
+ Thread.currentThread().interrupt();
+ } finally {
+ try {
+ output.close();
+ // Worker thread can continue.
+ latch.countDown();
+ } catch (final IOException e) {
+ LOGGER.log(Level.INFO, "Error closing chunked output.", e);
+ }
+ }
+ }
+ }.start();
+
+ try {
+ // Wait till new thread closes the chunked output.
+ latch.await();
+ return output;
+ } catch (final InterruptedException e) {
+ throw new InternalServerErrorException(e);
+ }
+ }
+
+ /**
+ * Test combination of AsyncResponse and ChunkedOutput.
+ *
+ * @param response async response.
+ */
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("chunked-async")
+ public void closeBeforeReturnAsync(@Suspended final AsyncResponse response) {
+ // Set timeout to able to resume but not send the chunks (setting the ChunkedOutput should remove the timeout).
+ response.setTimeout(1500, TimeUnit.SECONDS);
+
+ new Thread() {
+
+ @Override
+ public void run() {
+ final ChunkedOutput<Message> output = new ChunkedOutput<>(Message.class, "\r\n");
+
+ try {
+ // Let the method return.
+ Thread.sleep(1000);
+ // Resume.
+ response.resume(output);
+ // Wait for resume to complete.
+ Thread.sleep(1000);
+
+ new Thread() {
+
+ @Override
+ public void run() {
+ try {
+ for (int i = 0; i < 3; i++) {
+ output.write(new Message(i, "test"));
+ Thread.sleep(200);
+ }
+ } catch (final IOException e) {
+ LOGGER.log(Level.SEVERE, "Error writing chunk.", e);
+ } catch (final InterruptedException e) {
+ LOGGER.log(Level.SEVERE, "Sleep interrupted.", e);
+ Thread.currentThread().interrupt();
+ } finally {
+ try {
+ output.close();
+ } catch (final IOException e) {
+ LOGGER.log(Level.INFO, "Error closing chunked output.", e);
+ }
+ }
+ }
+ }.start();
+ } catch (final InterruptedException e) {
+ LOGGER.log(Level.SEVERE, "Sleep interrupted.", e);
+ Thread.currentThread().interrupt();
+ }
+ }
+ }.start();
+ }
+}
diff --git a/tests/integration/servlet-3-chunked-io/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_chunked_io/ChunkedInputOutputITCase.java b/tests/integration/servlet-3-chunked-io/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_chunked_io/ChunkedInputOutputITCase.java
new file mode 100644
index 0000000..40d57af
--- /dev/null
+++ b/tests/integration/servlet-3-chunked-io/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_chunked_io/ChunkedInputOutputITCase.java
@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_chunked_io;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.URI;
+import java.net.URLConnection;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.client.ChunkedInput;
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.client.ClientProperties;
+import org.glassfish.jersey.grizzly.connector.GrizzlyConnectorProvider;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Chunked I/O integration tests.
+ *
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+public class ChunkedInputOutputITCase extends JerseyTest {
+
+ private static final int MAX_LISTENERS = 5;
+
+ @Override
+ protected Application configure() {
+ return new Application();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Override
+ protected void configureClient(final ClientConfig config) {
+ config.register(App.createMoxyJsonResolver());
+
+ config.property(ClientProperties.CONNECT_TIMEOUT, 15000)
+ .property(ClientProperties.READ_TIMEOUT, 5000)
+ .property(ClientProperties.ASYNC_THREADPOOL_SIZE, MAX_LISTENERS + 1)
+ .connectorProvider(new GrizzlyConnectorProvider());
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ final UriBuilder baseUriBuilder = UriBuilder.fromUri(super.getBaseUri());
+ final boolean externalFactoryInUse = getTestContainerFactory() instanceof ExternalTestContainerFactory;
+ return externalFactoryInUse ? baseUriBuilder.path("resources").build() : baseUriBuilder.build();
+ }
+
+ /**
+ * Test retrieving string-based chunked stream as a single response string.
+ *
+ * @throws Exception in case of a failure during the test execution.
+ */
+ @Test
+ public void testChunkedOutputToSingleString() throws Exception {
+ final String response = target().path("test/from-string").request(MediaType.APPLICATION_JSON_TYPE).get(String.class);
+
+ assertEquals("Unexpected value of chunked response unmarshalled as a single string.",
+ "{\"id\":0,\"data\":\"test\"}\r\n"
+ + "{\"id\":1,\"data\":\"test\"}\r\n"
+ + "{\"id\":2,\"data\":\"test\"}\r\n",
+ response);
+ }
+
+ /**
+ * Test retrieving string-based chunked stream sequentially as individual chunks using chunked input.
+ *
+ * @throws Exception in case of a failure during the test execution.
+ */
+ @Test
+ public void testChunkedOutputToChunkInputFromString() throws Exception {
+ final ChunkedInput<Message> input = target().path("test/from-string").request(MediaType.APPLICATION_JSON_TYPE)
+ .get(new GenericType<ChunkedInput<Message>>() {
+ });
+
+ int counter = 0;
+ Message chunk;
+ while ((chunk = input.read()) != null) {
+ assertEquals("Unexpected value of chunk " + counter, new Message(counter, "test"), chunk);
+ counter++;
+ }
+
+ assertEquals("Unexpected numbed of received chunks.", 3, counter);
+ }
+
+ /**
+ * Test retrieving POJO-based chunked stream sequentially as individual chunks using chunked input.
+ *
+ * @throws Exception in case of a failure during the test execution.
+ */
+ @Test
+ public void testChunkedOutputToChunkInputFromPojo() throws Exception {
+ final ChunkedInput<Message> input = target().path("test/from-pojo").request(MediaType.APPLICATION_JSON_TYPE)
+ .get(new GenericType<ChunkedInput<Message>>() {
+ });
+
+ int counter = 0;
+ Message chunk;
+ while ((chunk = input.read()) != null) {
+ assertEquals("Unexpected value of chunk " + counter, new Message(counter, "test"), chunk);
+ counter++;
+ }
+
+ assertEquals("Unexpected numbed of received chunks.", 3, counter);
+ }
+
+ /**
+ * Test combination of AsyncResponse and ChunkedOutput.
+ */
+ @Test
+ public void chunkedOutputWithAsyncResponse() throws Exception {
+ final ChunkedInput<Message> input = target().path("test/chunked-async").request(MediaType.APPLICATION_JSON_TYPE)
+ .get(new GenericType<ChunkedInput<Message>>() {
+ });
+
+ int counter = 0;
+ Message chunk;
+ while ((chunk = input.read()) != null) {
+ assertEquals("Unexpected value of chunk " + counter, new Message(counter, "test"), chunk);
+ counter++;
+ }
+
+ assertEquals("Unexpected numbed of received chunks.", 3, counter);
+ }
+
+ /**
+ * Reproducer for JERSEY-2558. Checking that the connection is properly closed even when the
+ * {@link org.glassfish.jersey.server.ChunkedOutput#close()} is called before the response is processed by the runtime.
+ */
+ @Test
+ public void checkConnectionIsClosedUrlConnection() throws Exception {
+ final URI uri = UriBuilder.fromUri(super.getBaseUri()).path("test/close-before-return").build();
+ final URLConnection connection = uri.toURL().openConnection();
+
+ connection.setConnectTimeout(15000);
+ connection.setReadTimeout(15000);
+ connection.connect();
+
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+
+ String line;
+ int counter = 0;
+ while ((line = reader.readLine()) != null) {
+ assertEquals("Unexpected value of chunk " + counter, new Message(counter, "test").toString(), line);
+ counter++;
+ }
+
+ assertEquals("Unexpected numbed of received chunks.", 3, counter);
+ }
+}
diff --git a/tests/integration/servlet-3-filter/pom.xml b/tests/integration/servlet-3-filter/pom.xml
new file mode 100644
index 0000000..1bbe427
--- /dev/null
+++ b/tests/integration/servlet-3-filter/pom.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-3-filter</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-3-filter</name>
+
+ <description>Servlet integration test - servlet-3-filter</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/servlet-3-filter/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_filter/MyResource.java b/tests/integration/servlet-3-filter/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_filter/MyResource.java
new file mode 100644
index 0000000..ca3c3a7
--- /dev/null
+++ b/tests/integration/servlet-3-filter/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_filter/MyResource.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_3_filter;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+@Path("myresource")
+public class MyResource {
+
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "OK";
+ }
+}
diff --git a/tests/integration/servlet-3-filter/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-3-filter/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..3dcf4e4
--- /dev/null
+++ b/tests/integration/servlet-3-filter/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <filter>
+ <filter-name>Jersey Web Application</filter-name>
+ <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.packages</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_3_filter</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>Jersey Web Application</filter-name>
+ <url-pattern>/myapp/*</url-pattern>
+ </filter-mapping>
+</web-app>
diff --git a/tests/integration/servlet-3-filter/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_filter/MyResourceITCase.java b/tests/integration/servlet-3-filter/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_filter/MyResourceITCase.java
new file mode 100644
index 0000000..226ac74
--- /dev/null
+++ b/tests/integration/servlet-3-filter/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_filter/MyResourceITCase.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_3_filter;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Adam Lindenthal (adam.lindenthal at oracle.com)
+ */
+public class MyResourceITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ final ResourceConfig rc = new ResourceConfig();
+ return rc.packages(MyResourceITCase.class.getPackage().getName());
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testMyResource() throws Exception {
+ final Response response = target().path("myapp").path("myresource").request().get();
+ assertEquals(200, response.getStatus());
+ assertEquals("OK", response.readEntity(String.class));
+ }
+
+ @Test
+ public void testWadl() {
+ final Response response = target().path("myapp/application.wadl").request().get();
+ assertEquals(200, response.getStatus());
+ assertTrue(response.readEntity(String.class).startsWith("<?xml version=\"1.0\""));
+ }
+}
diff --git a/tests/integration/servlet-3-gf-async/pom.xml b/tests/integration/servlet-3-gf-async/pom.xml
new file mode 100644
index 0000000..9d53935
--- /dev/null
+++ b/tests/integration/servlet-3-gf-async/pom.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-3-gf-async</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-3-gf-async</name>
+
+ <description>Servlet (GF) integration test - servlet-3-gf-async - configured via jax-rs application annotated with @javax.ws.rs.ApplicationPath</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
+ <jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ <skipTests>true</skipTests>
+ <testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
+ <testContainerPort>8080</testContainerPort>
+ </properties>
+</project>
diff --git a/tests/integration/servlet-3-gf-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncCancelTimeoutResource.java b/tests/integration/servlet-3-gf-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncCancelTimeoutResource.java
new file mode 100644
index 0000000..f67f854
--- /dev/null
+++ b/tests/integration/servlet-3-gf-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncCancelTimeoutResource.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.servlet_3_async;
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.Suspended;
+import javax.ws.rs.container.TimeoutHandler;
+
+/**
+ * Asynchronous servlet-deployed resource for testing {@link javax.ws.rs.container.AsyncResponse async response} timeouts.
+ *
+ * @author Michal Gajdos
+ */
+@Path("cancel-timeout")
+public class AsyncCancelTimeoutResource {
+
+ @SuppressWarnings("unchecked")
+ private static final BlockingQueue<AsyncResponse>[] stages = new BlockingQueue[]{
+ new ArrayBlockingQueue<AsyncResponse>(1),
+ new ArrayBlockingQueue<AsyncResponse>(1)
+ };
+
+ @GET
+ @Path("suspend")
+ public void suspend(@Suspended final AsyncResponse asyncResponse) {
+ stages[0].add(asyncResponse);
+ }
+
+ @POST
+ @Path("timeout")
+ public void setTimeout(final String stage) throws Exception {
+ final AsyncResponse async = stages[Integer.parseInt(stage)].take();
+
+ async.setTimeoutHandler(new TimeoutHandler() {
+ @Override
+ public void handleTimeout(final AsyncResponse response) {
+ response.cancel();
+ }
+ });
+ async.setTimeout(200L, TimeUnit.MILLISECONDS);
+
+ stages[Integer.parseInt(stage) + 1].add(async);
+ }
+}
diff --git a/tests/integration/servlet-3-gf-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncResumeTimeoutResource.java b/tests/integration/servlet-3-gf-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncResumeTimeoutResource.java
new file mode 100644
index 0000000..e6ad2dc
--- /dev/null
+++ b/tests/integration/servlet-3-gf-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncResumeTimeoutResource.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.servlet_3_async;
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.Suspended;
+import javax.ws.rs.container.TimeoutHandler;
+
+/**
+ * Asynchronous servlet-deployed resource for testing {@link javax.ws.rs.container.AsyncResponse async response} timeouts.
+ *
+ * @author Michal Gajdos
+ */
+@Path("resume-timeout")
+public class AsyncResumeTimeoutResource {
+
+ private static final BlockingQueue<AsyncResponse> queue = new ArrayBlockingQueue<>(1);
+
+ @GET
+ @Path("suspend")
+ public void suspend(@Suspended final AsyncResponse asyncResponse) {
+ queue.add(asyncResponse);
+ }
+
+ @POST
+ @Path("timeout")
+ public void setTimeOut(final Integer millis) throws InterruptedException {
+ final AsyncResponse asyncResponse = queue.take();
+
+ final boolean timeout1 = asyncResponse.setTimeout(millis, TimeUnit.MILLISECONDS);
+ asyncResponse.setTimeoutHandler(new TimeoutHandler() {
+
+ @Override
+ public void handleTimeout(final AsyncResponse asyncResponse) {
+ final boolean timeout2 = asyncResponse.setTimeout(millis, TimeUnit.MILLISECONDS);
+ asyncResponse.setTimeoutHandler(new TimeoutHandler() {
+
+ @Override
+ public void handleTimeout(final AsyncResponse asyncResponse) {
+ asyncResponse.resume("timeout1=" + timeout1 + "_timeout2=" + timeout2 + "_handled");
+ }
+ });
+ }
+ });
+ }
+}
diff --git a/tests/integration/servlet-3-gf-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncServletResource.java b/tests/integration/servlet-3-gf-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncServletResource.java
new file mode 100644
index 0000000..3cd45ec
--- /dev/null
+++ b/tests/integration/servlet-3-gf-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncServletResource.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_3_async;
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.Executors;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+
+import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.Suspended;
+
+/**
+ * Asynchronous servlet-deployed resource.
+ *
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+@Path("async")
+public class AsyncServletResource {
+ /**
+ * Hello world message.
+ */
+ public static final String HELLO_ASYNC_WORLD = "Hello Async World!";
+ public static final String CANCELED = "Canceled";
+
+ private static BlockingQueue<CanceledRequest> cancelingQueue = new ArrayBlockingQueue<CanceledRequest>(5);
+
+ private static class CanceledRequest {
+ private final String id;
+ private final AsyncResponse asyncResponse;
+
+ private CanceledRequest(final String id, final AsyncResponse asyncResponse) {
+ this.id = id;
+ this.asyncResponse = asyncResponse;
+ }
+ }
+
+ /**
+ * Get the async "Hello World" message.
+ */
+ @GET
+ @Produces("text/plain")
+ public void get(@Suspended final AsyncResponse ar) {
+ Executors.newSingleThreadExecutor().execute(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Thread.sleep(100);
+ ar.resume(HELLO_ASYNC_WORLD);
+ } catch (final InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+
+ /**
+ * Get a canceled request.
+ *
+ * @param id request id.
+ * @throws InterruptedException in case of not being able to put the request
+ * to an internal queue for canceling.
+ */
+ @GET
+ @Path("canceled")
+ public void getCanceled(@Suspended final AsyncResponse ar, @QueryParam("id") final String id) throws InterruptedException {
+ cancelingQueue.put(new CanceledRequest(id, ar));
+ }
+
+ /**
+ * Cancel a request that is on top of the canceling queue.
+ *
+ * @return notification message about successful request canceling.
+ * @throws InterruptedException in case of not being able to take a cancelled request
+ * from an internal canceling queue.
+ */
+ @POST
+ @Produces("text/plain")
+ @Path("canceled")
+ public String cancel(final String requestId) throws InterruptedException {
+ final CanceledRequest canceledRequest = cancelingQueue.take();
+ canceledRequest.asyncResponse.cancel();
+
+ return CANCELED + " " + canceledRequest.id + " by POST " + requestId;
+ }
+
+}
diff --git a/tests/integration/servlet-3-gf-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/Servlet3Async.java b/tests/integration/servlet-3-gf-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/Servlet3Async.java
new file mode 100644
index 0000000..c0be482
--- /dev/null
+++ b/tests/integration/servlet-3-gf-async/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_async/Servlet3Async.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.servlet_3_async;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * Asynchronous servlet-deployed resource application.
+ *
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+@ApplicationPath("/")
+public class Servlet3Async extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> hashSet = new HashSet<>();
+ hashSet.add(AsyncServletResource.class);
+ hashSet.add(AsyncResumeTimeoutResource.class);
+ hashSet.add(AsyncCancelTimeoutResource.class);
+ return hashSet;
+ }
+}
diff --git a/tests/integration/servlet-3-gf-async/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncCancelTimeoutResourceTest.java b/tests/integration/servlet-3-gf-async/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncCancelTimeoutResourceTest.java
new file mode 100644
index 0000000..5735317
--- /dev/null
+++ b/tests/integration/servlet-3-gf-async/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncCancelTimeoutResourceTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.servlet_3_async;
+
+import java.util.concurrent.Future;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.DeploymentContext;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.ServletDeploymentContext;
+import org.glassfish.jersey.test.TestProperties;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Asynchronous servlet-deployed resource for testing {@link javax.ws.rs.container.AsyncResponse async response} timeouts.
+ *
+ * @author Michal Gajdos
+ */
+public class AsyncCancelTimeoutResourceTest extends JerseyTest {
+
+ public AsyncCancelTimeoutResourceTest() {
+ enable(TestProperties.LOG_TRAFFIC);
+ }
+
+ @Override
+ protected DeploymentContext configureDeployment() {
+ return ServletDeploymentContext.builder(new Application())
+ .contextPath("servlet-3-gf-async")
+ .build();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testTimeout() throws Exception {
+ final WebTarget resourceTarget = target("cancel-timeout");
+ final Future<Response> suspend = resourceTarget.path("suspend").request().async().get();
+ final Future<Response> timeout = resourceTarget.path("timeout").request().async().post(Entity.text(0));
+
+ assertThat(timeout.get().getStatus(), is(Response.Status.NO_CONTENT.getStatusCode()));
+ assertThat(suspend.get().getStatus(), is(Response.Status.SERVICE_UNAVAILABLE.getStatusCode()));
+ }
+}
diff --git a/tests/integration/servlet-3-gf-async/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncResumeTimeoutResourceTest.java b/tests/integration/servlet-3-gf-async/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncResumeTimeoutResourceTest.java
new file mode 100644
index 0000000..a40976a
--- /dev/null
+++ b/tests/integration/servlet-3-gf-async/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncResumeTimeoutResourceTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.servlet_3_async;
+
+import java.util.concurrent.Future;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.DeploymentContext;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.ServletDeploymentContext;
+import org.glassfish.jersey.test.TestProperties;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Asynchronous servlet-deployed resource for testing {@link javax.ws.rs.container.AsyncResponse async response} timeouts.
+ *
+ * @author Michal Gajdos
+ */
+public class AsyncResumeTimeoutResourceTest extends JerseyTest {
+
+ public AsyncResumeTimeoutResourceTest() {
+ enable(TestProperties.LOG_TRAFFIC);
+ }
+
+ @Override
+ protected DeploymentContext configureDeployment() {
+ return ServletDeploymentContext.builder(new Application())
+ .contextPath("servlet-3-gf-async")
+ .build();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testTimeout() throws Exception {
+ final WebTarget resourceTarget = target("resume-timeout");
+ final Future<Response> responseFuture = resourceTarget.path("suspend").request().async().get();
+
+ // Set timeout.
+ assertThat(resourceTarget.path("timeout").request().post(Entity.text("500")).getStatus(), equalTo(204));
+
+ // Wait for it.
+ assertThat(responseFuture.get().readEntity(String.class), equalTo("timeout1=true_timeout2=true_handled"));
+ }
+}
diff --git a/tests/integration/servlet-3-gf-async/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncServletResourceTest.java b/tests/integration/servlet-3-gf-async/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncServletResourceTest.java
new file mode 100644
index 0000000..69ac18f
--- /dev/null
+++ b/tests/integration/servlet-3-gf-async/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_async/AsyncServletResourceTest.java
@@ -0,0 +1,293 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.servlet_3_async;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Logger;
+
+import javax.ws.rs.ProcessingException;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.internal.guava.ThreadFactoryBuilder;
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.process.JerseyProcessingUncaughtExceptionHandler;
+import org.glassfish.jersey.test.DeploymentContext;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.ServletDeploymentContext;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Asynchronous servlet-deployed resource test.
+ *
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+public class AsyncServletResourceTest extends JerseyTest {
+
+ private static final Logger LOGGER = Logger.getLogger(AsyncServletResourceTest.class.getName());
+
+ private static class ResponseRecord {
+
+ final int status;
+ final String message;
+
+ private ResponseRecord(final int status, final String message) {
+ this.status = status;
+ this.message = message;
+ }
+
+ @Override
+ public String toString() {
+ return status + " : \"" + message + '\"';
+ }
+ }
+
+ @Override
+ protected DeploymentContext configureDeployment() {
+ return ServletDeploymentContext.builder(new Application())
+ .contextPath("servlet-3-gf-async")
+ .build();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ /**
+ * Test asynchronous servlet-deployed resource.
+ *
+ * @throws InterruptedException in case the waiting for all requests to complete was interrupted.
+ */
+ @Test
+ public void testAsyncServlet() throws InterruptedException {
+ final WebTarget resourceTarget = target("async");
+ resourceTarget.register(LoggingFeature.class);
+ final String expectedResponse = AsyncServletResource.HELLO_ASYNC_WORLD;
+
+ final int MAX_MESSAGES = 50;
+ final int LATCH_WAIT_TIMEOUT = 10;
+ final boolean debugMode = false;
+ final boolean sequentialGet = false;
+ final Object sequentialGetLock = new Object();
+
+ final ExecutorService executor = Executors.newCachedThreadPool(new ThreadFactoryBuilder()
+ .setNameFormat("async-resource-test-%d")
+ .setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler())
+ .build());
+
+ final Map<Integer, ResponseRecord> getResponses = new ConcurrentHashMap<>();
+
+ final CountDownLatch getRequestLatch = new CountDownLatch(MAX_MESSAGES);
+
+ try {
+ for (int i = 0; i < MAX_MESSAGES; i++) {
+ final int requestId = i;
+ executor.submit(new Runnable() {
+
+ @Override
+ public void run() {
+ //noinspection PointlessBooleanExpression,ConstantConditions
+ if (debugMode || sequentialGet) {
+ synchronized (sequentialGetLock) {
+ get();
+ }
+ } else {
+ get();
+ }
+ }
+
+ private void get() {
+ try {
+ final Response response = resourceTarget.request().get();
+ getResponses.put(requestId, new ResponseRecord(response.getStatus(),
+ response.readEntity(String.class)));
+ } catch (final Throwable t) {
+ t.printStackTrace();
+ } finally {
+ getRequestLatch.countDown();
+ }
+ }
+ });
+ }
+
+ //noinspection ConstantConditions
+ if (debugMode) {
+ getRequestLatch.await();
+ } else {
+ assertTrue("Waiting for all GET requests to complete has timed out.",
+ getRequestLatch.await(LATCH_WAIT_TIMEOUT * getAsyncTimeoutMultiplier(), TimeUnit.SECONDS));
+ }
+ } finally {
+ executor.shutdownNow();
+ }
+
+ final StringBuilder messageBuilder = new StringBuilder();
+ for (final Map.Entry<Integer, ResponseRecord> getResponseEntry : getResponses.entrySet()) {
+ messageBuilder.append("GET response for message ").append(getResponseEntry.getKey()).append(": ")
+ .append(getResponseEntry.getValue().toString()).append('\n');
+ }
+ LOGGER.info(messageBuilder.toString());
+
+ assertEquals(MAX_MESSAGES, getResponses.size());
+ for (final Map.Entry<Integer, ResponseRecord> entry : getResponses.entrySet()) {
+ assertEquals("Unexpected GET response status for request " + entry.getKey(), 200, entry.getValue().status);
+ assertEquals("Unexpected GET response message for request " + entry.getKey(), expectedResponse,
+ entry.getValue().message);
+ }
+ }
+
+ /**
+ * Test canceling of an async request to a servlet-deployed resource.
+ *
+ * @throws InterruptedException in case the waiting for all requests to complete was interrupted.
+ */
+ @Test
+ public void testAsyncRequestCanceling() throws InterruptedException {
+ final WebTarget resourceTarget = target("async/canceled");
+ resourceTarget.register(LoggingFeature.class);
+
+ final int MAX_MESSAGES = 10;
+ final int LATCH_WAIT_TIMEOUT = 10;
+ final boolean debugMode = false;
+ final boolean sequentialGet = false;
+ final boolean sequentialPost = false;
+ final Object sequentialGetLock = new Object();
+ final Object sequentialPostLock = new Object();
+
+ final ExecutorService executor = Executors.newCachedThreadPool(new ThreadFactoryBuilder()
+ .setNameFormat("async-canceled-resource-test-%d")
+ .setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler())
+ .build());
+
+ final Map<Integer, String> postResponses = new ConcurrentHashMap<>();
+ final Map<Integer, String> getResponses = new ConcurrentHashMap<>();
+
+ final CountDownLatch postRequestLatch = new CountDownLatch(MAX_MESSAGES);
+ final CountDownLatch getRequestLatch = new CountDownLatch(MAX_MESSAGES);
+
+ try {
+ for (int i = 0; i < MAX_MESSAGES; i++) {
+ final int requestId = i;
+ executor.submit(new Runnable() {
+
+ @Override
+ public void run() {
+ //noinspection PointlessBooleanExpression,ConstantConditions
+ if (debugMode || sequentialGet) {
+ synchronized (sequentialGetLock) {
+ get();
+ }
+ } else {
+ get();
+ }
+ }
+
+ private void get() {
+ try {
+ final String response = resourceTarget.queryParam("id", requestId).request().get(String.class);
+ getResponses.put(requestId, response);
+ } catch (final WebApplicationException ex) {
+ final Response response = ex.getResponse();
+ getResponses.put(requestId, response.getStatus() + ": " + response.readEntity(String.class));
+ } finally {
+ getRequestLatch.countDown();
+ }
+ }
+ });
+ executor.submit(new Runnable() {
+
+ @Override
+ public void run() {
+ //noinspection PointlessBooleanExpression,ConstantConditions
+ if (debugMode || sequentialPost) {
+ synchronized (sequentialPostLock) {
+ post();
+ }
+ } else {
+ post();
+ }
+ }
+
+ private void post() throws ProcessingException {
+ try {
+ final String response = resourceTarget.request().post(Entity.text("" + requestId), String.class);
+ postResponses.put(requestId, response);
+ } finally {
+ postRequestLatch.countDown();
+ }
+ }
+ });
+ }
+
+ //noinspection ConstantConditions
+ if (debugMode) {
+ postRequestLatch.await();
+ getRequestLatch.await();
+ } else {
+ assertTrue("Waiting for all POST requests to complete has timed out.",
+ postRequestLatch.await(LATCH_WAIT_TIMEOUT * getAsyncTimeoutMultiplier(), TimeUnit.SECONDS));
+ assertTrue("Waiting for all GET requests to complete has timed out.",
+ getRequestLatch.await(LATCH_WAIT_TIMEOUT * getAsyncTimeoutMultiplier(),
+ TimeUnit.SECONDS));
+ }
+ } finally {
+ executor.shutdownNow();
+ }
+
+ final StringBuilder messageBuilder = new StringBuilder();
+ for (final Map.Entry<Integer, String> postResponseEntry : postResponses.entrySet()) {
+ messageBuilder.append("POST response for message ").append(postResponseEntry.getKey()).append(": ")
+ .append(postResponseEntry.getValue()).append('\n');
+ }
+ messageBuilder.append('\n');
+ for (final Map.Entry<Integer, String> getResponseEntry : getResponses.entrySet()) {
+ messageBuilder.append("GET response for message ").append(getResponseEntry.getKey()).append(": ")
+ .append(getResponseEntry.getValue()).append('\n');
+ }
+ LOGGER.info(messageBuilder.toString());
+
+ assertEquals(MAX_MESSAGES, postResponses.size());
+ for (final Map.Entry<Integer, String> postResponseEntry : postResponses.entrySet()) {
+ assertTrue("Unexpected POST notification response for message " + postResponseEntry.getKey(),
+ postResponseEntry.getValue().startsWith(AsyncServletResource.CANCELED));
+ }
+
+ assertEquals(MAX_MESSAGES, getResponses.size());
+ final Collection<Integer> getResponseKeys = getResponses.keySet();
+ for (int i = 0; i < MAX_MESSAGES; i++) {
+ assertTrue("Detected a GET message response loss: " + i, getResponseKeys.contains(i));
+ final String getResponseEntry = getResponses.get(i);
+ assertTrue("Unexpected canceled GET response status for request " + i, getResponseEntry.startsWith("503: "));
+ }
+ }
+}
diff --git a/tests/integration/servlet-3-inflector-1/pom.xml b/tests/integration/servlet-3-inflector-1/pom.xml
new file mode 100644
index 0000000..312ec21
--- /dev/null
+++ b/tests/integration/servlet-3-inflector-1/pom.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-3-inflector-1</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-3-inflector-1</name>
+
+ <description>
+ Servlet integration test - servlet-3-inflector-1 - Check that inflectors in programmatically created resources are
+ properly injected.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>${servlet3.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/servlet-3-inflector-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_inflector_1/MyApplication.java b/tests/integration/servlet-3-inflector-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_inflector_1/MyApplication.java
new file mode 100644
index 0000000..7c7a797
--- /dev/null
+++ b/tests/integration/servlet-3-inflector-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_inflector_1/MyApplication.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_inflector_1;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.model.Resource;
+
+/**
+ * @author Michal Gajdos
+ */
+@ApplicationPath("/")
+public class MyApplication extends ResourceConfig {
+
+ public MyApplication() {
+ final Resource.Builder resourceBuilder = Resource.builder("resource");
+
+ resourceBuilder.addChildResource("class")
+ .addMethod("GET")
+ .handledBy(MyInflector.class);
+ resourceBuilder.addChildResource("instance")
+ .addMethod("GET")
+ .handledBy(new MyInflector());
+
+ registerResources(resourceBuilder.build());
+ }
+}
diff --git a/tests/integration/servlet-3-inflector-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_inflector_1/MyInflector.java b/tests/integration/servlet-3-inflector-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_inflector_1/MyInflector.java
new file mode 100644
index 0000000..7315a7d
--- /dev/null
+++ b/tests/integration/servlet-3-inflector-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_inflector_1/MyInflector.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_inflector_1;
+
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.core.Response;
+
+import javax.inject.Inject;
+import javax.inject.Provider;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.glassfish.jersey.process.Inflector;
+
+/**
+ * @author Michal Gajdos
+ */
+public class MyInflector implements Inflector<ContainerRequestContext, Response> {
+
+ @Inject
+ private Provider<HttpServletRequest> requestProvider;
+ @Inject
+ private Provider<HttpServletResponse> responseProvider;
+
+ @Override
+ public Response apply(final ContainerRequestContext requestContext) {
+ final StringBuilder stringBuilder = new StringBuilder();
+
+ // Request provider & request.
+ if (requestProvider != null) {
+ stringBuilder.append("requestProvider_");
+ stringBuilder.append(requestProvider.get() != null ? "request" : null);
+ } else {
+ stringBuilder.append("null_null");
+ }
+
+ stringBuilder.append('_');
+
+ // Response provider & response.
+ if (responseProvider != null) {
+ stringBuilder.append("responseProvider_");
+ stringBuilder.append(responseProvider.get() != null ? "response" : null);
+ } else {
+ stringBuilder.append("null_null");
+ }
+
+ return Response.ok(stringBuilder.toString()).build();
+ }
+}
diff --git a/tests/integration/servlet-3-inflector-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_inflector_1/InflectorInjectionTestITCase.java b/tests/integration/servlet-3-inflector-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_inflector_1/InflectorInjectionTestITCase.java
new file mode 100644
index 0000000..4dff377
--- /dev/null
+++ b/tests/integration/servlet-3-inflector-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_inflector_1/InflectorInjectionTestITCase.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_inflector_1;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Michal Gajdos
+ */
+public class InflectorInjectionTestITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new MyApplication();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testInflectorClassInjection() throws Exception {
+ _testInflectorInjection("class");
+ }
+
+ @Test
+ public void testInflectorInstanceInjection() throws Exception {
+ _testInflectorInjection("instance");
+ }
+
+ private void _testInflectorInjection(final String path) {
+ final Response response = target("resource").path(path).request().get();
+
+ assertEquals(200, response.getStatus());
+ assertEquals("requestProvider_request_responseProvider_response", response.readEntity(String.class));
+ }
+}
diff --git a/tests/integration/servlet-3-init-1/pom.xml b/tests/integration/servlet-3-init-1/pom.xml
new file mode 100644
index 0000000..b0a1d04
--- /dev/null
+++ b/tests/integration/servlet-3-init-1/pom.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-3-init-1</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-3-init-1</name>
+
+ <description>Servlet integration test - servlet-3-init-1 - configured via jax-rs application annotated with @javax.ws.rs.ApplicationPath</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/servlet-3-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_1/HelloWorldResource.java b/tests/integration/servlet-3-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_1/HelloWorldResource.java
new file mode 100644
index 0000000..ea4d55f
--- /dev/null
+++ b/tests/integration/servlet-3-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_1/HelloWorldResource.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_3_init_1;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+@Path("helloworld")
+public class HelloWorldResource {
+
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "Hello World!";
+ }
+}
diff --git a/tests/integration/servlet-3-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_1/Servlet3init1.java b/tests/integration/servlet-3-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_1/Servlet3init1.java
new file mode 100644
index 0000000..13b7c88
--- /dev/null
+++ b/tests/integration/servlet-3-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_1/Servlet3init1.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_3_init_1;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+@ApplicationPath("/")
+public class Servlet3init1 extends Application {
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> hashSet = new HashSet<Class<?>>();
+ hashSet.add(HelloWorldResource.class);
+ return hashSet;
+ }
+}
diff --git a/tests/integration/servlet-3-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_1/UnreachableResource.java b/tests/integration/servlet-3-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_1/UnreachableResource.java
new file mode 100644
index 0000000..5251265
--- /dev/null
+++ b/tests/integration/servlet-3-init-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_1/UnreachableResource.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_3_init_1;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+/**
+ *
+ * @author Martin Matula
+ */
+@Path("unreachable")
+public class UnreachableResource {
+ @GET
+ public Response get() {
+ return Response.ok().build();
+ }
+}
diff --git a/tests/integration/servlet-3-init-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_1/HelloWorldResourceITCase.java b/tests/integration/servlet-3-init-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_1/HelloWorldResourceITCase.java
new file mode 100644
index 0000000..b2edbf7
--- /dev/null
+++ b/tests/integration/servlet-3-init-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_1/HelloWorldResourceITCase.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_3_init_1;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ * @author Martin Matula
+ */
+public class HelloWorldResourceITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Application();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testHelloWorld() throws Exception {
+ WebTarget t = target();
+ t.register(LoggingFeature.class);
+ Response r = t.path("helloworld").request().get();
+ assertEquals(200, r.getStatus());
+ assertEquals("Hello World!", r.readEntity(String.class));
+ }
+
+ @Test
+ public void testUnreachableResource() {
+ Response r = target().path("unreachable").request().get();
+ assertEquals("Managed to reach a resource that is not registered in the application.", 404, r.getStatus());
+ }
+}
diff --git a/tests/integration/servlet-3-init-2/pom.xml b/tests/integration/servlet-3-init-2/pom.xml
new file mode 100644
index 0000000..0b37d39
--- /dev/null
+++ b/tests/integration/servlet-3-init-2/pom.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2012, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-3-init-2</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-3-init-2</name>
+
+ <description>
+ Servlet integration test - servlet-3-init-2 - configured via jax-rs application annotated with @javax.ws.rs.ApplicationPath
+ and providers annotated with @javax.ws.rs.ext.Provider.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.10</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/CustomFeature.java b/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/CustomFeature.java
new file mode 100644
index 0000000..e36c557
--- /dev/null
+++ b/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/CustomFeature.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_3_init_2;
+
+import javax.ws.rs.core.Feature;
+import javax.ws.rs.core.FeatureContext;
+import javax.ws.rs.ext.Provider;
+
+import org.glassfish.jersey.tests.integration.servlet_3_init_2.ext.Ext1WriterInterceptor;
+import org.glassfish.jersey.tests.integration.servlet_3_init_2.ext.Ext2WriterInterceptor;
+import org.glassfish.jersey.tests.integration.servlet_3_init_2.ext.Ext3WriterInterceptor;
+import org.glassfish.jersey.tests.integration.servlet_3_init_2.ext.Ext4WriterInterceptor;
+
+/**
+ * @author Michal Gajdos
+ */
+@Provider
+public class CustomFeature implements Feature {
+
+ @Override
+ public boolean configure(final FeatureContext context) {
+ context.register(Ext3WriterInterceptor.class, 1000);
+ context.register(Ext2WriterInterceptor.class, 100);
+ context.register(Ext1WriterInterceptor.INSTANCE, 500);
+ context.register(Ext4WriterInterceptor.INSTANCE, 1);
+ return true;
+ }
+}
diff --git a/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/HelloWorldResource.java b/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/HelloWorldResource.java
new file mode 100644
index 0000000..27b3797
--- /dev/null
+++ b/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/HelloWorldResource.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_3_init_2;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+@Path("helloworld")
+public class HelloWorldResource {
+
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "Hello World!";
+ }
+}
diff --git a/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/Servlet3init2.java b/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/Servlet3init2.java
new file mode 100644
index 0000000..011254f
--- /dev/null
+++ b/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/Servlet3init2.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_3_init_2;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ * @author Michal Gajdos
+ */
+@ApplicationPath("/")
+public class Servlet3init2 extends ResourceConfig {
+
+ public Servlet3init2() {
+ packages(false, Servlet3init2.class.getPackage().getName());
+ }
+}
diff --git a/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/ext/Ext1WriterInterceptor.java b/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/ext/Ext1WriterInterceptor.java
new file mode 100644
index 0000000..84e4b05
--- /dev/null
+++ b/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/ext/Ext1WriterInterceptor.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_3_init_2.ext;
+
+import java.io.IOException;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.WriterInterceptor;
+import javax.ws.rs.ext.WriterInterceptorContext;
+
+/**
+ * @author Michal Gajdos
+ */
+@Provider
+public class Ext1WriterInterceptor implements WriterInterceptor {
+
+ public static final Ext1WriterInterceptor INSTANCE = new Ext1WriterInterceptor();
+
+ @Override
+ public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException {
+ context.setEntity(context.getEntity() + "-ext1");
+ context.proceed();
+ }
+}
diff --git a/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/ext/Ext2WriterInterceptor.java b/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/ext/Ext2WriterInterceptor.java
new file mode 100644
index 0000000..2bc9a05
--- /dev/null
+++ b/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/ext/Ext2WriterInterceptor.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_3_init_2.ext;
+
+import java.io.IOException;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.WriterInterceptor;
+import javax.ws.rs.ext.WriterInterceptorContext;
+
+/**
+ * @author Michal Gajdos
+ */
+@Provider
+public class Ext2WriterInterceptor implements WriterInterceptor {
+
+ @Override
+ public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException {
+ context.setEntity(context.getEntity() + "-ext2");
+ context.proceed();
+ }
+}
diff --git a/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/ext/Ext3WriterInterceptor.java b/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/ext/Ext3WriterInterceptor.java
new file mode 100644
index 0000000..802b1bb
--- /dev/null
+++ b/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/ext/Ext3WriterInterceptor.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_3_init_2.ext;
+
+import java.io.IOException;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.WriterInterceptor;
+import javax.ws.rs.ext.WriterInterceptorContext;
+
+/**
+ * @author Michal Gajdos
+ */
+@Provider
+public class Ext3WriterInterceptor implements WriterInterceptor {
+
+ @Override
+ public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException {
+ context.setEntity(context.getEntity() + "-ext3");
+ context.proceed();
+ }
+}
diff --git a/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/ext/Ext4WriterInterceptor.java b/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/ext/Ext4WriterInterceptor.java
new file mode 100644
index 0000000..77bb734
--- /dev/null
+++ b/tests/integration/servlet-3-init-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/ext/Ext4WriterInterceptor.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_3_init_2.ext;
+
+import java.io.IOException;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.WriterInterceptor;
+import javax.ws.rs.ext.WriterInterceptorContext;
+
+/**
+ * @author Michal Gajdos
+ */
+@Provider
+public class Ext4WriterInterceptor implements WriterInterceptor {
+
+ public static final Ext4WriterInterceptor INSTANCE = new Ext4WriterInterceptor();
+
+ @Override
+ public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException {
+ context.setEntity(context.getEntity() + "-ext4");
+ context.proceed();
+ }
+}
diff --git a/tests/integration/servlet-3-init-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/HelloWorldResourceITCase.java b/tests/integration/servlet-3-init-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/HelloWorldResourceITCase.java
new file mode 100644
index 0000000..c0fbdb0
--- /dev/null
+++ b/tests/integration/servlet-3-init-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_2/HelloWorldResourceITCase.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlet_3_init_2;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ * @author Martin Matula
+ * @author Michal Gajdos
+ */
+public class HelloWorldResourceITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Application();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testHelloWorld() throws Exception {
+ Response r = target().path("helloworld").request().get();
+ assertEquals(200, r.getStatus());
+ assertEquals("Hello World!-ext4-ext2-ext1-ext3", r.readEntity(String.class));
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-3/pom.xml b/tests/integration/servlet-3-init-3/pom.xml
new file mode 100644
index 0000000..71ea462
--- /dev/null
+++ b/tests/integration/servlet-3-init-3/pom.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-3-init-3</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-3-init-3</name>
+
+ <description>Servlet integration test - servlet-3-init-3 - both Application.getClasses and Application.getSingletons return an empty collection</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>${servlet3.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/servlet-3-init-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_3/EmptyApplication.java b/tests/integration/servlet-3-init-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_3/EmptyApplication.java
new file mode 100644
index 0000000..e4f3783
--- /dev/null
+++ b/tests/integration/servlet-3-init-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_3/EmptyApplication.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_3;
+
+import javax.ws.rs.core.Application;
+
+/**
+ * @author Michal Gajdos
+ */
+public class EmptyApplication extends Application {
+}
diff --git a/tests/integration/servlet-3-init-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_3/resource/ResourceOne.java b/tests/integration/servlet-3-init-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_3/resource/ResourceOne.java
new file mode 100644
index 0000000..a31e39a
--- /dev/null
+++ b/tests/integration/servlet-3-init-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_3/resource/ResourceOne.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_3.resource;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * @author Michal Gajdos
+ */
+@Path("one")
+public class ResourceOne {
+
+ @GET
+ public String get() {
+ return ResourceOne.class.getSimpleName();
+ }
+}
diff --git a/tests/integration/servlet-3-init-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_3/resource/ResourceTwo.java b/tests/integration/servlet-3-init-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_3/resource/ResourceTwo.java
new file mode 100644
index 0000000..e6ce245
--- /dev/null
+++ b/tests/integration/servlet-3-init-3/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_3/resource/ResourceTwo.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_3.resource;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * @author Michal Gajdos
+ */
+@Path("two")
+public class ResourceTwo {
+
+ @GET
+ public String get() {
+ return ResourceTwo.class.getSimpleName();
+ }
+}
diff --git a/tests/integration/servlet-3-init-3/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-3-init-3/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..c1ed518
--- /dev/null
+++ b/tests/integration/servlet-3-init-3/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <servlet>
+ <servlet-name>org.glassfish.jersey.tests.integration.servlet_3_init_3.EmptyApplication</servlet-name>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>org.glassfish.jersey.tests.integration.servlet_3_init_3.EmptyApplication</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/servlet-3-init-3/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_3/EmptyApplicationTestITCase.java b/tests/integration/servlet-3-init-3/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_3/EmptyApplicationTestITCase.java
new file mode 100644
index 0000000..f762576
--- /dev/null
+++ b/tests/integration/servlet-3-init-3/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_3/EmptyApplicationTestITCase.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_3;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+import org.glassfish.jersey.tests.integration.servlet_3_init_3.resource.ResourceOne;
+import org.glassfish.jersey.tests.integration.servlet_3_init_3.resource.ResourceTwo;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Michal Gajdos
+ */
+public class EmptyApplicationTestITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new EmptyApplication();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testResourceOne() throws Exception {
+ final Response response = target("one").request().get();
+
+ assertEquals(200, response.getStatus());
+ assertEquals(ResourceOne.class.getSimpleName(), response.readEntity(String.class));
+ }
+
+ @Test
+ public void testResourceTwo() throws Exception {
+ final Response response = target("two").request().get();
+
+ assertEquals(200, response.getStatus());
+ assertEquals(ResourceTwo.class.getSimpleName(), response.readEntity(String.class));
+ }
+}
diff --git a/tests/integration/servlet-3-init-4/pom.xml b/tests/integration/servlet-3-init-4/pom.xml
new file mode 100644
index 0000000..470666d
--- /dev/null
+++ b/tests/integration/servlet-3-init-4/pom.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-3-init-4</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-3-init-4</name>
+
+ <description>
+ Servlet integration test - servlet-3-init-4 - both Application.getClasses and Application.getSingletons return an empty
+ collection, @ApplicationPath present
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>${servlet3.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/servlet-3-init-4/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_4/EmptyApplication.java b/tests/integration/servlet-3-init-4/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_4/EmptyApplication.java
new file mode 100644
index 0000000..5a2042a
--- /dev/null
+++ b/tests/integration/servlet-3-init-4/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_4/EmptyApplication.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_4;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * @author Michal Gajdos
+ */
+@ApplicationPath("/")
+public class EmptyApplication extends Application {
+}
diff --git a/tests/integration/servlet-3-init-4/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_4/resource/ResourceOne.java b/tests/integration/servlet-3-init-4/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_4/resource/ResourceOne.java
new file mode 100644
index 0000000..f43e50c
--- /dev/null
+++ b/tests/integration/servlet-3-init-4/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_4/resource/ResourceOne.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_4.resource;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * @author Michal Gajdos
+ */
+@Path("one")
+public class ResourceOne {
+
+ @GET
+ public String get() {
+ return ResourceOne.class.getSimpleName();
+ }
+}
diff --git a/tests/integration/servlet-3-init-4/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_4/resource/ResourceTwo.java b/tests/integration/servlet-3-init-4/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_4/resource/ResourceTwo.java
new file mode 100644
index 0000000..45e9de4
--- /dev/null
+++ b/tests/integration/servlet-3-init-4/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_4/resource/ResourceTwo.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_4.resource;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * @author Michal Gajdos
+ */
+@Path("two")
+public class ResourceTwo {
+
+ @GET
+ public String get() {
+ return ResourceTwo.class.getSimpleName();
+ }
+}
diff --git a/tests/integration/servlet-3-init-4/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_4/EmptyApplicationTestITCase.java b/tests/integration/servlet-3-init-4/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_4/EmptyApplicationTestITCase.java
new file mode 100644
index 0000000..4c3b2b6
--- /dev/null
+++ b/tests/integration/servlet-3-init-4/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_4/EmptyApplicationTestITCase.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_4;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+import org.glassfish.jersey.tests.integration.servlet_3_init_4.resource.ResourceOne;
+import org.glassfish.jersey.tests.integration.servlet_3_init_4.resource.ResourceTwo;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Michal Gajdos
+ */
+public class EmptyApplicationTestITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new EmptyApplication();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testResourceOne() throws Exception {
+ final Response response = target("one").request().get();
+
+ assertEquals(200, response.getStatus());
+ assertEquals(ResourceOne.class.getSimpleName(), response.readEntity(String.class));
+ }
+
+ @Test
+ public void testResourceTwo() throws Exception {
+ final Response response = target("two").request().get();
+
+ assertEquals(200, response.getStatus());
+ assertEquals(ResourceTwo.class.getSimpleName(), response.readEntity(String.class));
+ }
+}
diff --git a/tests/integration/servlet-3-init-5/pom.xml b/tests/integration/servlet-3-init-5/pom.xml
new file mode 100644
index 0000000..e96aac6
--- /dev/null
+++ b/tests/integration/servlet-3-init-5/pom.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-3-init-5</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-3-init-5</name>
+
+ <description>Servlet integration test - servlet-3-init-5 - no Application subclass is present;
+ dynamically add a servlet and set its name to javax.ws.rs.core.Application</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>${servlet3.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/servlet-3-init-5/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_5/HelloWorldResource.java b/tests/integration/servlet-3-init-5/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_5/HelloWorldResource.java
new file mode 100644
index 0000000..91d8093
--- /dev/null
+++ b/tests/integration/servlet-3-init-5/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_5/HelloWorldResource.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_5;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Path("helloworld")
+public class HelloWorldResource {
+
+ @GET
+ @Produces("text/plain")
+ public Hello get() {
+ return new Hello();
+ }
+
+ public static class Hello {
+
+ }
+}
diff --git a/tests/integration/servlet-3-init-5/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_5/HelloWriter.java b/tests/integration/servlet-3-init-5/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_5/HelloWriter.java
new file mode 100644
index 0000000..d70573a
--- /dev/null
+++ b/tests/integration/servlet-3-init-5/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_5/HelloWriter.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_5;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+import org.glassfish.jersey.message.MessageUtils;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Provider
+public class HelloWriter implements MessageBodyWriter<HelloWorldResource.Hello> {
+ @Override
+ public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType) {
+ return type.equals(HelloWorldResource.Hello.class);
+ }
+
+ @Override
+ public long getSize(final HelloWorldResource.Hello hello, final Class<?> type, final Type genericType,
+ final Annotation[] annotations, final MediaType mediaType) {
+ return -1;
+ }
+
+ @Override
+ public void writeTo(final HelloWorldResource.Hello hello, final Class<?> type, final Type genericType,
+ final Annotation[] annotations, final MediaType mediaType,
+ final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream)
+ throws IOException, WebApplicationException {
+ entityStream.write(("Hello World! " + this.getClass().getPackage().getName())
+ .getBytes(MessageUtils.getCharset(mediaType)));
+ }
+}
diff --git a/tests/integration/servlet-3-init-5/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-3-init-5/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..520cb3e
--- /dev/null
+++ b/tests/integration/servlet-3-init-5/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <servlet>
+ <servlet-name>javax.ws.rs.core.Application</servlet-name>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>javax.ws.rs.core.Application</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/servlet-3-init-5/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_5/HelloWorldResourceITCase.java b/tests/integration/servlet-3-init-5/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_5/HelloWorldResourceITCase.java
new file mode 100644
index 0000000..af14376
--- /dev/null
+++ b/tests/integration/servlet-3-init-5/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_5/HelloWorldResourceITCase.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_5;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.TestProperties;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class HelloWorldResourceITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ enable(TestProperties.LOG_TRAFFIC);
+
+ return new ResourceConfig(HelloWorldResource.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testHelloWorld() throws Exception {
+ String s = target().path("helloworld").request().get(String.class);
+ assertTrue(s.equals("Hello World! " + this.getClass().getPackage().getName()));
+ }
+}
diff --git a/tests/integration/servlet-3-init-6/pom.xml b/tests/integration/servlet-3-init-6/pom.xml
new file mode 100644
index 0000000..709c875
--- /dev/null
+++ b/tests/integration/servlet-3-init-6/pom.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-3-init-6</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-3-init-6</name>
+
+ <description>Servlet integration test - servlet-3-init-5 - Application subclass is present;
+ servlet-mapping in web.xml</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>${servlet3.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/servlet-3-init-6/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_6/EmptyApplication.java b/tests/integration/servlet-3-init-6/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_6/EmptyApplication.java
new file mode 100644
index 0000000..760f1c5
--- /dev/null
+++ b/tests/integration/servlet-3-init-6/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_6/EmptyApplication.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.servlet_3_init_6;
+
+import javax.ws.rs.core.Application;
+
+/**
+ * @author Michal Gajdos
+ */
+public class EmptyApplication extends Application {
+}
diff --git a/tests/integration/servlet-3-init-6/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_6/resource/ResourceOne.java b/tests/integration/servlet-3-init-6/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_6/resource/ResourceOne.java
new file mode 100644
index 0000000..a4da8ea
--- /dev/null
+++ b/tests/integration/servlet-3-init-6/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_6/resource/ResourceOne.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.servlet_3_init_6.resource;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * @author Michal Gajdos
+ */
+@Path("one")
+public class ResourceOne {
+
+ @GET
+ public String get() {
+ return ResourceOne.class.getSimpleName();
+ }
+}
diff --git a/tests/integration/servlet-3-init-6/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_6/resource/ResourceTwo.java b/tests/integration/servlet-3-init-6/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_6/resource/ResourceTwo.java
new file mode 100644
index 0000000..8d4e270
--- /dev/null
+++ b/tests/integration/servlet-3-init-6/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_6/resource/ResourceTwo.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.servlet_3_init_6.resource;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * @author Michal Gajdos
+ */
+@Path("two")
+public class ResourceTwo {
+
+ @GET
+ public String get() {
+ return ResourceTwo.class.getSimpleName();
+ }
+}
diff --git a/tests/integration/servlet-3-init-6/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-3-init-6/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..d5bf156
--- /dev/null
+++ b/tests/integration/servlet-3-init-6/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <servlet>
+ <servlet-name>org.glassfish.jersey.tests.integration.servlet_3_init_6.EmptyApplication</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>org.glassfish.jersey.tests.integration.servlet_3_init_6.EmptyApplication</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/servlet-3-init-6/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_6/EmptyApplicationITCase.java b/tests/integration/servlet-3-init-6/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_6/EmptyApplicationITCase.java
new file mode 100644
index 0000000..c85d8bb
--- /dev/null
+++ b/tests/integration/servlet-3-init-6/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_6/EmptyApplicationITCase.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.servlet_3_init_6;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+import org.glassfish.jersey.tests.integration.servlet_3_init_6.resource.ResourceOne;
+import org.glassfish.jersey.tests.integration.servlet_3_init_6.resource.ResourceTwo;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * @author Michal Gajdos
+ */
+public class EmptyApplicationITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new EmptyApplication();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testResourceOne() throws Exception {
+ final Response response = target("one").request().get();
+
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), is(ResourceOne.class.getSimpleName()));
+ }
+
+ @Test
+ public void testResourceTwo() throws Exception {
+ final Response response = target("two").request().get();
+
+ assertThat(response.getStatus(), is(200));
+ assertThat(response.readEntity(String.class), is(ResourceTwo.class.getSimpleName()));
+ }
+}
diff --git a/tests/integration/servlet-3-init-7/pom.xml b/tests/integration/servlet-3-init-7/pom.xml
new file mode 100644
index 0000000..30869d5
--- /dev/null
+++ b/tests/integration/servlet-3-init-7/pom.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-3-init-7</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-3-init-7</name>
+
+ <description>Servlet integration test - servlet-3-init-7 - no Application subclass is present;
+ dynamically add a servlet and set its name to javax.ws.rs.core.Application;
+ servlet-mapping in web.xml</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>${servlet3.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/servlet-3-init-7/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_7/HelloWorldResource.java b/tests/integration/servlet-3-init-7/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_7/HelloWorldResource.java
new file mode 100644
index 0000000..acaaf92
--- /dev/null
+++ b/tests/integration/servlet-3-init-7/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_7/HelloWorldResource.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.servlet_3_init_7;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Path("helloworld")
+public class HelloWorldResource {
+
+ @GET
+ @Produces("text/plain")
+ public Hello get() {
+ return new Hello();
+ }
+
+ public static class Hello {
+
+ }
+}
diff --git a/tests/integration/servlet-3-init-7/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_7/HelloWriter.java b/tests/integration/servlet-3-init-7/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_7/HelloWriter.java
new file mode 100644
index 0000000..3e9898f
--- /dev/null
+++ b/tests/integration/servlet-3-init-7/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_7/HelloWriter.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.servlet_3_init_7;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Provider
+public class HelloWriter implements MessageBodyWriter<HelloWorldResource.Hello> {
+
+ @Override
+ public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType) {
+ return type.equals(HelloWorldResource.Hello.class);
+ }
+
+ @Override
+ public long getSize(final HelloWorldResource.Hello hello, final Class<?> type, final Type genericType,
+ final Annotation[] annotations, final MediaType mediaType) {
+ return -1;
+ }
+
+ @Override
+ public void writeTo(final HelloWorldResource.Hello hello,
+ final Class<?> type,
+ final Type genericType,
+ final Annotation[] annotations,
+ final MediaType mediaType,
+ final MultivaluedMap<String, Object> httpHeaders,
+ final OutputStream entityStream) throws IOException, WebApplicationException {
+ entityStream.write(("Hello World! " + this.getClass().getPackage().getName()).getBytes());
+ }
+}
diff --git a/tests/integration/servlet-3-init-7/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-3-init-7/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..c87f441
--- /dev/null
+++ b/tests/integration/servlet-3-init-7/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2014, 2018 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
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <servlet>
+ <servlet-name>javax.ws.rs.core.Application</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>javax.ws.rs.core.Application</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/servlet-3-init-7/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_7/HelloWorldResourceITCase.java b/tests/integration/servlet-3-init-7/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_7/HelloWorldResourceITCase.java
new file mode 100644
index 0000000..43f36e3
--- /dev/null
+++ b/tests/integration/servlet-3-init-7/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_7/HelloWorldResourceITCase.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2014, 2018 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.integration.servlet_3_init_7;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.TestProperties;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class HelloWorldResourceITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ enable(TestProperties.LOG_TRAFFIC);
+
+ return new ResourceConfig(HelloWorldResource.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testHelloWorld() throws Exception {
+ String s = target().path("helloworld").request().get(String.class);
+ assertTrue(s.equals("Hello World! " + this.getClass().getPackage().getName()));
+ }
+}
diff --git a/tests/integration/servlet-3-init-8/pom.xml b/tests/integration/servlet-3-init-8/pom.xml
new file mode 100644
index 0000000..094fcfa
--- /dev/null
+++ b/tests/integration/servlet-3-init-8/pom.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-3-init-8</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-3-init-8</name>
+
+ <description>Servlet integration test - servlet-3-init-8 - more jax-rs applications
+ (annotated with @javax.ws.rs.ApplicationPath and/or configured in web.xml).
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/HelloWorld1Resource.java b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/HelloWorld1Resource.java
new file mode 100644
index 0000000..5604139
--- /dev/null
+++ b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/HelloWorld1Resource.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_3_init_8;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Path("helloworld1")
+public class HelloWorld1Resource {
+
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "Hello World 1!";
+ }
+}
diff --git a/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/HelloWorld2Resource.java b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/HelloWorld2Resource.java
new file mode 100644
index 0000000..cba1bdd
--- /dev/null
+++ b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/HelloWorld2Resource.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_3_init_8;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Path("helloworld2")
+public class HelloWorld2Resource {
+
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "Hello World 2!";
+ }
+}
diff --git a/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/HelloWorld3Resource.java b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/HelloWorld3Resource.java
new file mode 100644
index 0000000..010ae62
--- /dev/null
+++ b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/HelloWorld3Resource.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_3_init_8;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Path("helloworld3")
+public class HelloWorld3Resource {
+
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "Hello World 3!";
+ }
+}
diff --git a/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/HelloWorld4Resource.java b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/HelloWorld4Resource.java
new file mode 100644
index 0000000..82936a1
--- /dev/null
+++ b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/HelloWorld4Resource.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_3_init_8;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Path("helloworld4")
+public class HelloWorld4Resource {
+
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "Hello World 4!";
+ }
+}
diff --git a/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/Servlet3Init8App1.java b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/Servlet3Init8App1.java
new file mode 100644
index 0000000..e32c718
--- /dev/null
+++ b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/Servlet3Init8App1.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_3_init_8;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * The application is fully configured in {@code web.xml} ({@code servlet} as well as {@code servlet-mapping}).
+ * It means {@code ApplicationPath.value} ({@code /app1ann}) is overridden using a {@code servlet-mapping} element.
+ * The application also explicitly register JAX-RS resource.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@ApplicationPath("/app1ann")
+public class Servlet3Init8App1 extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> hashSet = new HashSet<>();
+ hashSet.add(HelloWorld1Resource.class);
+ return hashSet;
+ }
+}
diff --git a/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/Servlet3Init8App2.java b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/Servlet3Init8App2.java
new file mode 100644
index 0000000..1ca6ecf
--- /dev/null
+++ b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/Servlet3Init8App2.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_3_init_8;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * The application is partially configured in {@code web.xml} (just {@code servlet} element).
+ * It means {@code ApplicationPath.value} ({@code /app2ann}) is used as base servlet URI.
+ * The application also explicitly register JAX-RS resource.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@ApplicationPath("/app2ann")
+public class Servlet3Init8App2 extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> hashSet = new HashSet<>();
+ hashSet.add(HelloWorld2Resource.class);
+ return hashSet;
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/Servlet3Init8App3.java b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/Servlet3Init8App3.java
new file mode 100644
index 0000000..c7163e1
--- /dev/null
+++ b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/Servlet3Init8App3.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_3_init_8;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * The application is not configured in {@code web.xml}.
+ * It means {@code ApplicationPath.value} ({@code /app3ann}) is used as base servlet URI.
+ * The application also explicitly register JAX-RS resource.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@ApplicationPath("/app3ann")
+public class Servlet3Init8App3 extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> hashSet = new HashSet<>();
+ hashSet.add(HelloWorld3Resource.class);
+ return hashSet;
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/Servlet3Init8App4.java b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/Servlet3Init8App4.java
new file mode 100644
index 0000000..9a3667c
--- /dev/null
+++ b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/Servlet3Init8App4.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_3_init_8;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+/**
+ * The application is fully configured in {@code web.xml} ({@code servlet} as well as {@code servlet-mapping}).
+ * And there is no {@code ApplicationPath} annotation on the class.
+ * The application also explicitly register JAX-RS resource.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class Servlet3Init8App4 extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> hashSet = new HashSet<>();
+ hashSet.add(HelloWorld4Resource.class);
+ return hashSet;
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/Servlet3Init8App5.java b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/Servlet3Init8App5.java
new file mode 100644
index 0000000..b1f2ea8
--- /dev/null
+++ b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/Servlet3Init8App5.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_3_init_8;
+
+import javax.ws.rs.core.Application;
+
+/**
+ * The application is fully configured in {@code web.xml} ({@code servlet} as well as {@code servlet-mapping}).
+ * And there is no {@code ApplicationPath} annotation on the class.
+ * The application does NOT explicitly register any JAX-RS resource. All available resources are automatically registered.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class Servlet3Init8App5 extends Application {
+
+}
diff --git a/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/UnreachableResource.java b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/UnreachableResource.java
new file mode 100644
index 0000000..99f9710
--- /dev/null
+++ b/tests/integration/servlet-3-init-8/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/UnreachableResource.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_3_init_8;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Path("unreachable")
+public class UnreachableResource {
+
+ @GET
+ @Produces("text/plain")
+ public String get() {
+ return "Hello Unreachable!";
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-8/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-3-init-8/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..d5c3a63
--- /dev/null
+++ b/tests/integration/servlet-3-init-8/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
+ <servlet>
+ <servlet-name>org.glassfish.jersey.tests.integration.servlet_3_init_8.Servlet3Init8App1</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>org.glassfish.jersey.tests.integration.servlet_3_init_8.Servlet3Init8App1</servlet-name>
+ <url-pattern>/app1/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet>
+ <servlet-name>org.glassfish.jersey.tests.integration.servlet_3_init_8.Servlet3Init8App2</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ </servlet>
+
+ <servlet>
+ <servlet-name>org.glassfish.jersey.tests.integration.servlet_3_init_8.Servlet3Init8App4</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>org.glassfish.jersey.tests.integration.servlet_3_init_8.Servlet3Init8App4</servlet-name>
+ <url-pattern>/app4/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet>
+ <servlet-name>org.glassfish.jersey.tests.integration.servlet_3_init_8.Servlet3Init8App5</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>org.glassfish.jersey.tests.integration.servlet_3_init_8.Servlet3Init8App5</servlet-name>
+ <url-pattern>/app5/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/servlet-3-init-8/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/HelloWorldResourceITCase.java b/tests/integration/servlet-3-init-8/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/HelloWorldResourceITCase.java
new file mode 100644
index 0000000..0955681
--- /dev/null
+++ b/tests/integration/servlet-3-init-8/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/HelloWorldResourceITCase.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_3_init_8;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test reachable resources.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class HelloWorldResourceITCase extends JerseyTest {
+
+ private final String appPath;
+ private final String resourcePath;
+ private final String helloName;
+
+ public HelloWorldResourceITCase(String appPath, String resourcePath, String helloName) {
+ this.appPath = appPath;
+ this.resourcePath = resourcePath;
+ this.helloName = helloName;
+ }
+
+ @Parameterized.Parameters(name = "{index}: {0}/{1} \"{2}\"")
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"/app1", "helloworld1", "World 1"}, //app1 - overridden using a servlet-mapping element in the web.xml
+ {"/app2ann", "helloworld2", "World 2"}, //app2ann - no servlet-mapping in the web.xml, used ApplicationPath.value
+ {"/app3ann", "helloworld3", "World 3"}, //app3ann - no servlet in the web.xml, used ApplicationPath.value
+ {"/app4", "helloworld4", "World 4"}, //app4 - fully configured in web.xml
+ //app5 - automatic registration of all resources, no explicit classes/singletons provided by Servlet3Init8App5
+ {"/app5", "helloworld1", "World 1"},
+ {"/app5", "helloworld2", "World 2"},
+ {"/app5", "helloworld3", "World 3"},
+ {"/app5", "helloworld4", "World 4"},
+ {"/app5", "unreachable", "Unreachable"},
+ });
+ }
+
+ @Override
+ protected Application configure() {
+ return new Application();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testHelloWorld() throws Exception {
+ WebTarget t = target(appPath);
+ t.register(LoggingFeature.class);
+ Response r = t.path(resourcePath).request().get();
+ assertEquals(200, r.getStatus());
+ assertEquals("Hello " + helloName + "!", r.readEntity(String.class));
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-8/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/HelloWorldResourceUnreachableITCase.java b/tests/integration/servlet-3-init-8/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/HelloWorldResourceUnreachableITCase.java
new file mode 100644
index 0000000..914687d
--- /dev/null
+++ b/tests/integration/servlet-3-init-8/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_8/HelloWorldResourceUnreachableITCase.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_3_init_8;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test unreachable resources.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class HelloWorldResourceUnreachableITCase extends JerseyTest {
+
+ private final String appPath;
+ private final String resourcePath;
+
+ public HelloWorldResourceUnreachableITCase(String appPath,
+ String resourcePath) {
+ this.appPath = appPath;
+ this.resourcePath = resourcePath;
+ }
+
+ @Parameterized.Parameters(name = "{index}: {0}/{1}")
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"/app1", "unreachable"}, //unreachable - no explicitly mentioned resource
+ {"/app1ann", "helloworld1"}, //app1ann - overridden using a servlet-mapping element in the web.xml
+ {"/app2ann", "unreachable"}, //unreachable - no explicitly mentioned resource
+ {"/app3ann", "unreachable"}, //unreachable - no explicitly mentioned resource
+ {"/app4", "unreachable"}, //unreachable - no explicitly mentioned resource
+ });
+ }
+
+ @Override
+ protected Application configure() {
+ return new Application();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testUnreachableResource() {
+ WebTarget t = target(appPath);
+ t.register(LoggingFeature.class);
+ Response r = t.path(resourcePath).request().get();
+ assertEquals(404, r.getStatus());
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-provider/pom.xml b/tests/integration/servlet-3-init-provider/pom.xml
new file mode 100644
index 0000000..75417cb
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/pom.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-3-init-provider</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-3-init-provider</name>
+
+ <description>Servlet integration test - servlet-3-init-provider - ServletContainerProviderFactory, ServletContainerProvider</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-servlet-portability</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>${servlet3.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/AbstractHelloWorldResource.java b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/AbstractHelloWorldResource.java
new file mode 100644
index 0000000..489a50b
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/AbstractHelloWorldResource.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public abstract class AbstractHelloWorldResource {
+
+ public static final int NUMBER_OF_APPLICATIONS = 5;
+
+ @GET
+ @Produces("text/plain")
+ public Hello get() {
+ return new Hello(createName());
+ }
+
+ protected abstract String createName();
+
+
+ public static class Hello {
+ private final String name;
+
+ public Hello(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+ }
+}
diff --git a/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/Application1.java b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/Application1.java
new file mode 100644
index 0000000..8316b40
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/Application1.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class Application1 extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> hashSet = new HashSet<Class<?>>();
+ hashSet.add(HelloWorld1Resource.class);
+ hashSet.add(HelloWriter.class);
+ return hashSet;
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/Application2.java b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/Application2.java
new file mode 100644
index 0000000..89f1683
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/Application2.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class Application2 extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> hashSet = new HashSet<Class<?>>();
+ hashSet.add(HelloWorld2Resource.class);
+ hashSet.add(HelloWriter.class);
+ return hashSet;
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/Application3.java b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/Application3.java
new file mode 100644
index 0000000..20932c5
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/Application3.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class Application3 extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> hashSet = new HashSet<Class<?>>();
+ hashSet.add(HelloWorld3Resource.class);
+ hashSet.add(HelloWriter.class);
+ return hashSet;
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/Application4.java b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/Application4.java
new file mode 100644
index 0000000..e89767d
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/Application4.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@ApplicationPath("/application4/*")
+public class Application4 extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ final Set<Class<?>> hashSet = new HashSet<Class<?>>();
+ hashSet.add(HelloWorld4Resource.class);
+ hashSet.add(HelloWriter.class);
+ return hashSet;
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld1Resource.java b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld1Resource.java
new file mode 100644
index 0000000..9ffd315
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld1Resource.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Path("helloworld1")
+public class HelloWorld1Resource extends AbstractHelloWorldResource {
+
+ @Override
+ protected String createName() {
+ return "World #1";
+ }
+
+ @GET
+ @Path("servlets")
+ public int getServletsCount() {
+ return TestServletContainerProvider.getServletNames().size();
+ }
+
+ @GET
+ @Path("servlets/{name}")
+ public boolean hasServletName(@PathParam("name") String servletName) {
+ return TestServletContainerProvider.getServletNames().contains(servletName);
+ }
+
+ @GET
+ @Path("immutableServletNames")
+ public boolean isImmutableServletNames() {
+ return TestServletContainerProvider.isImmutableServletNames();
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld2Resource.java b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld2Resource.java
new file mode 100644
index 0000000..99cc572
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld2Resource.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+import javax.ws.rs.Path;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Path("helloworld2")
+public class HelloWorld2Resource extends AbstractHelloWorldResource {
+
+ @Override
+ protected String createName() {
+ return "World #2";
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld3Resource.java b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld3Resource.java
new file mode 100644
index 0000000..9f510e0
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld3Resource.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Path("helloworld3")
+public class HelloWorld3Resource extends AbstractHelloWorldResource {
+
+ @Override
+ protected String createName() {
+ return "World #3";
+ }
+
+ @GET
+ @Path("containers")
+ public int getContainersCount() throws InterruptedException {
+ return TestContainerLifecycleListener.getStartupCount();
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld4Resource.java b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld4Resource.java
new file mode 100644
index 0000000..f8db2e3
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld4Resource.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+import javax.ws.rs.Path;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Path("helloworld4")
+public class HelloWorld4Resource extends AbstractHelloWorldResource {
+
+ @Override
+ protected String createName() {
+ return "World #4";
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld5Resource.java b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld5Resource.java
new file mode 100644
index 0000000..aa8350a
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld5Resource.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+import java.util.Enumeration;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Path("helloworld5")
+public class HelloWorld5Resource extends AbstractHelloWorldResource {
+
+ @Context
+ private HttpServletRequest request;
+
+ @Override
+ protected String createName() {
+ return "World #5";
+ }
+
+ @GET
+ @Path("filter")
+ public String getFilter() {
+ return (String) request.getAttribute("FILTER");
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWriter.java b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWriter.java
new file mode 100644
index 0000000..cb061cd
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWriter.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+import org.glassfish.jersey.message.MessageUtils;
+
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Provider
+public class HelloWriter implements MessageBodyWriter<AbstractHelloWorldResource.Hello> {
+ @Override
+ public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType) {
+ return type.equals(AbstractHelloWorldResource.Hello.class);
+ }
+
+ @Override
+ public long getSize(final AbstractHelloWorldResource.Hello hello, final Class<?> type, final Type genericType,
+ final Annotation[] annotations, final MediaType mediaType) {
+ return -1;
+ }
+
+ @Override
+ public void writeTo(final AbstractHelloWorldResource.Hello hello, final Class<?> type, final Type genericType,
+ final Annotation[] annotations, final MediaType mediaType,
+ final MultivaluedMap<String, Object> httpHeaders,
+ final OutputStream entityStream) throws IOException, WebApplicationException {
+ final String value = String.format("Hello %s!", hello.getName());
+ entityStream.write(value.getBytes(MessageUtils.getCharset(mediaType)));
+ }
+}
diff --git a/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/TestContainerLifecycleListener.java b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/TestContainerLifecycleListener.java
new file mode 100644
index 0000000..e8a1b0e
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/TestContainerLifecycleListener.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.spi.Container;
+import org.glassfish.jersey.server.spi.ContainerLifecycleListener;
+
+/**
+ * This is just test purpose implementation of Jersey SPI {@link ContainerLifecycleListener}.
+ * The listener class is registered in {@link TestServletContainerProvider} to {@link ResourceConfig}.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class TestContainerLifecycleListener implements ContainerLifecycleListener {
+
+ private static int startupCount = 0;
+
+ private static CountDownLatch latch = new CountDownLatch(AbstractHelloWorldResource.NUMBER_OF_APPLICATIONS);
+
+ @Override
+ public void onStartup(Container container) {
+ latch.countDown();
+ startupCount++;
+ }
+
+ @Override
+ public void onReload(Container container) {
+ }
+
+ @Override
+ public void onShutdown(Container container) {
+ }
+
+ public static int getStartupCount() throws InterruptedException {
+ latch.await(5, TimeUnit.SECONDS);
+ return startupCount;
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/TestFilter.java b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/TestFilter.java
new file mode 100644
index 0000000..27093c3
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/TestFilter.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * This is just test purpose {@link Filter servlet filter} implementation to demonstrate how to register filter for any Jersey
+ * Servlet.
+ * The filter class is added in {@link TestServletContainerProvider}.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class TestFilter implements Filter {
+
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+ }
+
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+ throws IOException, ServletException {
+ if (((HttpServletRequest) request).getRequestURI().startsWith("/application5")) {
+ request.setAttribute("FILTER", TestServletContainerProvider.TEST_FILTER);
+ }
+
+ chain.doFilter(request, response);
+ }
+
+ @Override
+ public void destroy() {
+ }
+}
diff --git a/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/TestServletContainerProvider.java b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/TestServletContainerProvider.java
new file mode 100644
index 0000000..abe1a50
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/TestServletContainerProvider.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+import java.util.EnumSet;
+import java.util.Set;
+
+import javax.servlet.DispatcherType;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.servlet.internal.spi.RequestScopedInitializerProvider;
+import org.glassfish.jersey.servlet.internal.spi.ServletContainerProvider;
+
+/**
+ * This is just test purpose implementation of Jersey internal SPI {@link ServletContainerProvider}.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class TestServletContainerProvider implements ServletContainerProvider {
+
+ public static final String TEST_FILTER = "TestFilter";
+
+ private static Set<String> SERVLET_NAMES;
+ private static boolean immutableServletNames = false;
+
+ @Override
+ public void preInit(final ServletContext servletContext, final Set<Class<?>> classes) throws ServletException {
+ classes.add(AbstractHelloWorldResource.class);
+ }
+
+ @Override
+ public void postInit(final ServletContext servletContext, final Set<Class<?>> classes, final Set<String> servletNames)
+ throws ServletException {
+ try {
+ servletNames.add("TEST");
+ } catch (final UnsupportedOperationException ex) {
+ TestServletContainerProvider.setImmutableServletNames(true);
+ }
+ }
+
+ @Override
+ public void onRegister(final ServletContext servletContext, final Set<String> servletNames) throws ServletException {
+ TestServletContainerProvider.setServletNames(servletNames);
+
+ servletContext.addFilter(TEST_FILTER, TestFilter.class)
+ .addMappingForServletNames(EnumSet.allOf(DispatcherType.class), false,
+ servletNames.toArray(new String[servletNames.size()]));
+ }
+
+ @Override
+ public void configure(final ResourceConfig resourceConfig) throws ServletException {
+ if (!resourceConfig.isRegistered(TestContainerLifecycleListener.class)) {
+ resourceConfig.register(TestContainerLifecycleListener.class);
+ }
+ }
+
+ public static Set<String> getServletNames() {
+ return SERVLET_NAMES;
+ }
+
+ public static boolean isImmutableServletNames() {
+ return immutableServletNames;
+ }
+
+ private static void setServletNames(final Set<String> servletNames) {
+ TestServletContainerProvider.SERVLET_NAMES = servletNames;
+ }
+
+ public static void setImmutableServletNames(final boolean immutableServletNames) {
+ TestServletContainerProvider.immutableServletNames = immutableServletNames;
+ }
+}
diff --git a/tests/integration/servlet-3-init-provider/src/main/resources/META-INF/services/org.glassfish.jersey.servlet.internal.spi.ServletContainerProvider b/tests/integration/servlet-3-init-provider/src/main/resources/META-INF/services/org.glassfish.jersey.servlet.internal.spi.ServletContainerProvider
new file mode 100644
index 0000000..14fedce
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/main/resources/META-INF/services/org.glassfish.jersey.servlet.internal.spi.ServletContainerProvider
@@ -0,0 +1 @@
+org.glassfish.jersey.tests.integration.servlet_3_init_provider.TestServletContainerProvider
\ No newline at end of file
diff --git a/tests/integration/servlet-3-init-provider/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-3-init-provider/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..aa1f9ea
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <servlet>
+ <servlet-name>org.glassfish.jersey.tests.integration.servlet_3_init_provider.Application1</servlet-name>
+ </servlet>
+ <servlet>
+ <servlet-name>application2</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_3_init_provider.Application2</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet>
+ <servlet-name>application3</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.portability.PortableServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey2#javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_3_init_provider.Application3</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet>
+ <servlet-name>javax.ws.rs.core.Application</servlet-name>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_3_init_provider.HelloWorld5Resource,
+ org.glassfish.jersey.tests.integration.servlet_3_init_provider.HelloWriter
+ </param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>org.glassfish.jersey.tests.integration.servlet_3_init_provider.Application1</servlet-name>
+ <url-pattern>/application1/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>application2</servlet-name>
+ <url-pattern>/application2/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>application3</servlet-name>
+ <url-pattern>/application3/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>javax.ws.rs.core.Application</servlet-name>
+ <url-pattern>/application5/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/servlet-3-init-provider/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/AbstractHelloWorldResourceTest.java b/tests/integration/servlet-3-init-provider/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/AbstractHelloWorldResourceTest.java
new file mode 100644
index 0000000..fec1830
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/AbstractHelloWorldResourceTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.TestProperties;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import org.junit.Assert;
+
+import javax.ws.rs.NotFoundException;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public abstract class AbstractHelloWorldResourceTest extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ enable(TestProperties.LOG_TRAFFIC);
+
+ return new ResourceConfig(getResourceClass());
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testHelloWorld() throws Exception {
+ for (int i = 1; i <= AbstractHelloWorldResource.NUMBER_OF_APPLICATIONS; i++) {
+ try {
+ String actual = target("application" + getIndex()).path("helloworld" + i).request().get(String.class);
+ if (i == getIndex()) {
+ Assert.assertEquals("Hello World #" + getIndex() + "!", actual);
+ } else {
+ Assert.fail("i: " + i + " | [" + actual + "]");
+ }
+ } catch (NotFoundException ex) {
+ if (i != getIndex()) {
+ Assert.assertEquals(404, ex.getResponse().getStatus());
+ } else {
+ Assert.fail("!!! i: " + i);
+ }
+ }
+ }
+ }
+
+ protected abstract Class<?> getResourceClass();
+
+ protected abstract int getIndex();
+
+}
diff --git a/tests/integration/servlet-3-init-provider/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld1ResourceITCase.java b/tests/integration/servlet-3-init-provider/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld1ResourceITCase.java
new file mode 100644
index 0000000..1299390
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld1ResourceITCase.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+import javax.ws.rs.client.WebTarget;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class HelloWorld1ResourceITCase extends AbstractHelloWorldResourceTest {
+
+ protected Class<?> getResourceClass() {
+ return HelloWorld1Resource.class;
+ }
+
+ protected int getIndex() {
+ return 1;
+ }
+
+ @Test
+ public void testRegisteredServletNames() throws Exception {
+ WebTarget target = target("application" + getIndex()).path("helloworld" + getIndex()).path("servlets");
+ Assert.assertEquals(AbstractHelloWorldResource.NUMBER_OF_APPLICATIONS, (int) target.request().get(Integer.TYPE));
+
+ target = target.path("{name}");
+ testRegisteredServletNames(target, "org.glassfish.jersey.tests.integration.servlet_3_init_provider.Application1");
+ testRegisteredServletNames(target, "application2");
+ testRegisteredServletNames(target, "application3");
+ testRegisteredServletNames(target, "org.glassfish.jersey.tests.integration.servlet_3_init_provider.Application4");
+ testRegisteredServletNames(target, "javax.ws.rs.core.Application");
+ }
+
+ private void testRegisteredServletNames(WebTarget target, String servletName) throws Exception {
+ Assert.assertTrue(target.resolveTemplate("name", servletName).request().get(Boolean.TYPE));
+ }
+
+ @Test
+ public void testImmutableServletNames() {
+ WebTarget target = target("application" + getIndex()).path("helloworld" + getIndex()).path("immutableServletNames");
+ Assert.assertTrue(target.request().get(Boolean.TYPE));
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-provider/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld2ResourceITCase.java b/tests/integration/servlet-3-init-provider/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld2ResourceITCase.java
new file mode 100644
index 0000000..e38ac59
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld2ResourceITCase.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class HelloWorld2ResourceITCase extends AbstractHelloWorldResourceTest {
+
+ protected Class<?> getResourceClass() {
+ return HelloWorld2Resource.class;
+ }
+
+ protected int getIndex() {
+ return 2;
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-provider/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld3ResourceITCase.java b/tests/integration/servlet-3-init-provider/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld3ResourceITCase.java
new file mode 100644
index 0000000..6a16e46
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld3ResourceITCase.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.ws.rs.client.WebTarget;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class HelloWorld3ResourceITCase extends AbstractHelloWorldResourceTest {
+
+ protected Class<?> getResourceClass() {
+ return HelloWorld3Resource.class;
+ }
+
+ protected int getIndex() {
+ return 3;
+ }
+
+ @Test
+ public void testStartupContainers() throws Exception {
+ WebTarget target = target("application" + getIndex()).path("helloworld" + getIndex()).path("containers");
+ Assert.assertEquals(AbstractHelloWorldResource.NUMBER_OF_APPLICATIONS, (int) target.request().get(Integer.TYPE));
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-provider/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld4ResourceITCase.java b/tests/integration/servlet-3-init-provider/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld4ResourceITCase.java
new file mode 100644
index 0000000..9d39e25
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld4ResourceITCase.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.ws.rs.core.Response;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class HelloWorld4ResourceITCase extends AbstractHelloWorldResourceTest {
+
+ protected Class<?> getResourceClass() {
+ return HelloWorld4Resource.class;
+ }
+
+ protected int getIndex() {
+ return 4;
+ }
+
+ @Test
+ public void testRegisterFilter() throws Exception {
+ Response response = target("application" + getIndex()).path("helloworld" + getIndex()).path("filter").request().get();
+ Assert.assertEquals(404, response.getStatus());
+ }
+
+}
diff --git a/tests/integration/servlet-3-init-provider/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld5ResourceITCase.java b/tests/integration/servlet-3-init-provider/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld5ResourceITCase.java
new file mode 100644
index 0000000..81dae7b
--- /dev/null
+++ b/tests/integration/servlet-3-init-provider/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_init_provider/HelloWorld5ResourceITCase.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_init_provider;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class HelloWorld5ResourceITCase extends AbstractHelloWorldResourceTest {
+
+ protected Class<?> getResourceClass() {
+ return HelloWorld5Resource.class;
+ }
+
+ protected int getIndex() {
+ return 5;
+ }
+
+ @Test
+ public void testRegisterFilter() throws Exception {
+ String actual = target("application" + getIndex()).path("helloworld" + getIndex()).path("filter").request()
+ .get(String.class);
+ Assert.assertEquals(TestServletContainerProvider.TEST_FILTER, actual);
+ }
+
+}
diff --git a/tests/integration/servlet-3-params/pom.xml b/tests/integration/servlet-3-params/pom.xml
new file mode 100644
index 0000000..c0a5ceb
--- /dev/null
+++ b/tests/integration/servlet-3-params/pom.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-3-params</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-3-params</name>
+
+ <description>Servlet integration test - servlet-3-params</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>${servlet3.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/servlet-3-params/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_params/CustomContextListener.java b/tests/integration/servlet-3-params/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_params/CustomContextListener.java
new file mode 100644
index 0000000..82a54c8
--- /dev/null
+++ b/tests/integration/servlet-3-params/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_params/CustomContextListener.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_params;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.annotation.WebListener;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+@WebListener
+public class CustomContextListener implements ServletContextListener {
+
+ @Override
+ public void contextInitialized(ServletContextEvent servletContextEvent) {
+ servletContextEvent.getServletContext().setAttribute("myContextParam", "myValue");
+ }
+
+ @Override
+ public void contextDestroyed(ServletContextEvent servletContextEvent) {
+
+ }
+}
+
diff --git a/tests/integration/servlet-3-params/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_params/ParamResource.java b/tests/integration/servlet-3-params/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_params/ParamResource.java
new file mode 100644
index 0000000..79ef7a8
--- /dev/null
+++ b/tests/integration/servlet-3-params/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_params/ParamResource.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_params;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Context;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+@Path("params")
+public class ParamResource {
+
+ @Context
+ Application application;
+
+ @GET
+ @Produces("text/plain")
+ public String get(@QueryParam("param-name") String paramName) {
+ return application.getProperties().get(paramName).toString();
+ }
+}
diff --git a/tests/integration/servlet-3-params/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-3-params/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..1f118a7
--- /dev/null
+++ b/tests/integration/servlet-3-params/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <servlet>
+ <servlet-name>testServlet1</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_3_params.ParamResource</param-value>
+ </init-param>
+ <init-param>
+ <param-name>myInitParam</param-name>
+ <param-value>myValue</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>testServlet1</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/servlet-3-params/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_params/ParamsTestITCase.java b/tests/integration/servlet-3-params/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_params/ParamsTestITCase.java
new file mode 100644
index 0000000..5dc4151
--- /dev/null
+++ b/tests/integration/servlet-3-params/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_params/ParamsTestITCase.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_params;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
+ */
+public class ParamsTestITCase extends JerseyTest {
+ @Override
+ protected Application configure() {
+ return new Application();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ // see web.xml
+ @Test
+ public void testInitParam() throws Exception {
+ Response r = target().path("params").queryParam("param-name", "myInitParam").request().get();
+ assertEquals(200, r.getStatus());
+ assertEquals("myValue", r.readEntity(String.class));
+ }
+
+ // see CustomContextListener.java
+ @Test
+ public void testContextParam() throws Exception {
+ Response r = target().path("params").queryParam("param-name", "myContextParam").request().get();
+ assertEquals(200, r.getStatus());
+ assertEquals("myValue", r.readEntity(String.class));
+ }
+}
diff --git a/tests/integration/servlet-3-sse-1/pom.xml b/tests/integration/servlet-3-sse-1/pom.xml
new file mode 100644
index 0000000..d7ea408
--- /dev/null
+++ b/tests/integration/servlet-3-sse-1/pom.xml
@@ -0,0 +1,109 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-3-sse-1</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-3-sse-1</name>
+
+ <description>Servlet integration test - servlet-3-sse-1</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-sse</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.connectors</groupId>
+ <artifactId>jersey-grizzly-connector</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <!--plugin>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ <configuration>
+ <scanIntervalSeconds>0</scanIntervalSeconds>
+ <stopPort>9999</stopPort>
+ <stopKey>STOP</stopKey>
+ <contextPath>/</contextPath>
+ <webApp>
+ <contextPath>/</contextPath>
+ </webApp>
+ <war>${project.build.directory}/${project.build.finalName}.war</war>
+ <systemProperties>
+ <systemProperty>
+ <name>jetty.port</name>
+ <value>${jersey.config.test.container.port}</value>
+ </systemProperty>
+ </systemProperties>
+ </configuration>
+ <executions>
+ <execution>
+ <id>start-jetty</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>run-war</goal>
+ </goals>
+ <configuration>
+ <daemon>true</daemon>
+ </configuration>
+ </execution>
+ <execution>
+ <id>stop-jetty</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>stop</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin-->
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/servlet-3-sse-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_sse_1/ItemStoreApp.java b/tests/integration/servlet-3-sse-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_sse_1/ItemStoreApp.java
new file mode 100644
index 0000000..3e37025
--- /dev/null
+++ b/tests/integration/servlet-3-sse-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_sse_1/ItemStoreApp.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_sse_1;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.media.sse.SseFeature;
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * SSE item store JAX-RS application class.
+ *
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+@ApplicationPath("resources")
+public class ItemStoreApp extends ResourceConfig {
+ /**
+ * Create new SSE Item Store Example JAX-RS application.
+ */
+ public ItemStoreApp() {
+ super(ItemStoreResource.class, SseFeature.class);
+ }
+}
diff --git a/tests/integration/servlet-3-sse-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_sse_1/ItemStoreResource.java b/tests/integration/servlet-3-sse-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_sse_1/ItemStoreResource.java
new file mode 100644
index 0000000..dbbb285
--- /dev/null
+++ b/tests/integration/servlet-3-sse-1/src/main/java/org/glassfish/jersey/tests/integration/servlet_3_sse_1/ItemStoreResource.java
@@ -0,0 +1,200 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_sse_1;
+
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.ListIterator;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.logging.Logger;
+
+import javax.ws.rs.BadRequestException;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.InternalServerErrorException;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.ServiceUnavailableException;
+import javax.ws.rs.core.MediaType;
+
+import org.glassfish.jersey.media.sse.EventOutput;
+import org.glassfish.jersey.media.sse.OutboundEvent;
+import org.glassfish.jersey.media.sse.SseBroadcaster;
+import org.glassfish.jersey.media.sse.SseFeature;
+
+/**
+ * A resource for storing named items.
+ *
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+@Path("items")
+public class ItemStoreResource {
+ private static final Logger LOGGER = Logger.getLogger(ItemStoreResource.class.getName());
+
+ private static final ReentrantReadWriteLock storeLock = new ReentrantReadWriteLock();
+ private static final LinkedList<String> itemStore = new LinkedList<String>();
+ private static final SseBroadcaster broadcaster = new SseBroadcaster();
+
+ private static volatile long reconnectDelay = 0;
+
+ /**
+ * List all stored items.
+ *
+ * @return list of all stored items.
+ */
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String listItems() {
+ try {
+ storeLock.readLock().lock();
+ return itemStore.toString();
+ } finally {
+ storeLock.readLock().unlock();
+ }
+ }
+
+ /**
+ * Receive & process commands sent by the test client that control the internal resource state.
+ *
+ * Following is the list of recognized commands:
+ * <ul>
+ * <li><b>disconnect</b> - disconnect all registered event streams.</li>
+ * <li><b>reconnect now</b> - enable client reconnecting.</li>
+ * <li><b>reconnect <seconds></b> - disable client reconnecting.
+ * Reconnecting clients will receive a HTTP 503 response with
+ * {@value javax.ws.rs.core.HttpHeaders#RETRY_AFTER} set to the amount of
+ * milliseconds specified.</li>
+ * </ul>
+ *
+ * @param command command to be processed.
+ * @return message about processing result.
+ * @throws BadRequestException in case the command is not recognized or not specified.
+ */
+ @POST
+ @Path("commands")
+ public String processCommand(String command) {
+ if (command == null || command.isEmpty()) {
+ throw new BadRequestException("No command specified.");
+ }
+
+ if ("disconnect".equals(command)) {
+ broadcaster.closeAll();
+ return "Disconnected.";
+ } else if (command.length() > "reconnect ".length() && command.startsWith("reconnect ")) {
+ final String when = command.substring("reconnect ".length());
+ try {
+ reconnectDelay = "now".equals(when) ? 0 : Long.parseLong(when);
+ return "Reconnect strategy updated: " + when;
+ } catch (NumberFormatException ignore) {
+ // ignored
+ }
+ }
+
+ throw new BadRequestException("Command not recognized: '" + command + "'");
+ }
+
+ /**
+ * Connect or re-connect to SSE event stream.
+ *
+ * @param lastEventId Value of custom SSE HTTP <tt>{@value SseFeature#LAST_EVENT_ID_HEADER}</tt> header.
+ * Defaults to {@code -1} if not set.
+ * @return new SSE event output stream representing the (re-)established SSE client connection.
+ * @throws InternalServerErrorException in case replaying missed events to the reconnected output stream fails.
+ * @throws ServiceUnavailableException in case the reconnect delay is set to a positive value.
+ */
+ @GET
+ @Path("events")
+ @Produces(SseFeature.SERVER_SENT_EVENTS)
+ public EventOutput itemEvents(
+ @HeaderParam(SseFeature.LAST_EVENT_ID_HEADER) @DefaultValue("-1") int lastEventId) {
+ final EventOutput eventOutput = new EventOutput();
+
+ if (lastEventId >= 0) {
+ LOGGER.info("Received last event id :" + lastEventId);
+
+ // decide the reconnect handling strategy based on current reconnect delay value.
+ final long delay = reconnectDelay;
+ if (delay > 0) {
+ LOGGER.info("Non-zero reconnect delay [" + delay + "] - responding with HTTP 503.");
+ throw new ServiceUnavailableException(delay);
+ } else {
+ LOGGER.info("Zero reconnect delay - reconnecting.");
+ replayMissedEvents(lastEventId, eventOutput);
+ }
+ }
+
+ if (!broadcaster.add(eventOutput)) {
+ LOGGER.severe("!!! Unable to add new event output to the broadcaster !!!");
+ // let's try to force a 5s delayed client reconnect attempt
+ throw new ServiceUnavailableException(5L);
+ }
+
+ return eventOutput;
+ }
+
+ private void replayMissedEvents(final int lastEventId, final EventOutput eventOutput) {
+ try {
+ storeLock.readLock().lock();
+ final int firstUnreceived = lastEventId + 1;
+ final int missingCount = itemStore.size() - firstUnreceived;
+ if (missingCount > 0) {
+ LOGGER.info("Replaying events - starting with id " + firstUnreceived);
+ final ListIterator<String> it = itemStore.subList(firstUnreceived, itemStore.size()).listIterator();
+ while (it.hasNext()) {
+ eventOutput.write(createItemEvent(it.nextIndex() + firstUnreceived, it.next()));
+ }
+ } else {
+ LOGGER.info("No events to replay.");
+ }
+ } catch (IOException ex) {
+ throw new InternalServerErrorException("Error replaying missed events", ex);
+ } finally {
+ storeLock.readLock().unlock();
+ }
+ }
+
+ /**
+ * Add new item to the item store.
+ *
+ * Invoking this method will fire 2 new SSE events - 1st about newly added item and 2nd about the new item store size.
+ *
+ * @param name item name.
+ */
+ @POST
+ public void addItem(@FormParam("name") String name) {
+ final int eventId;
+ try {
+ storeLock.writeLock().lock();
+ eventId = itemStore.size();
+ itemStore.add(name);
+ // Broadcasting an un-named event with the name of the newly added item in data
+ broadcaster.broadcast(createItemEvent(eventId, name));
+ // Broadcasting a named "size" event with the current size of the items collection in data
+ broadcaster.broadcast(new OutboundEvent.Builder().name("size").data(Integer.class, eventId + 1).build());
+ } finally {
+ storeLock.writeLock().unlock();
+ }
+ }
+
+ private OutboundEvent createItemEvent(final int eventId, final String name) {
+ Logger.getLogger(ItemStoreResource.class.getName()).info("Creating event id [" + eventId + "] name [" + name + "]");
+ return new OutboundEvent.Builder().id("" + eventId).data(String.class, name).build();
+ }
+}
diff --git a/tests/integration/servlet-3-sse-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_sse_1/ItemStoreResourceITCase.java b/tests/integration/servlet-3-sse-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_sse_1/ItemStoreResourceITCase.java
new file mode 100644
index 0000000..70bdd76
--- /dev/null
+++ b/tests/integration/servlet-3-sse-1/src/test/java/org/glassfish/jersey/tests/integration/servlet_3_sse_1/ItemStoreResourceITCase.java
@@ -0,0 +1,298 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlet_3_sse_1;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.ws.rs.ProcessingException;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Form;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.client.ClientProperties;
+import org.glassfish.jersey.grizzly.connector.GrizzlyConnectorProvider;
+import org.glassfish.jersey.media.sse.EventListener;
+import org.glassfish.jersey.media.sse.EventSource;
+import org.glassfish.jersey.media.sse.InboundEvent;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.describedAs;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.hasItems;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Item store test.
+ *
+ * @author Marek Potociar (marek.potociar at oracle.com)
+ */
+@Ignore
+public class ItemStoreResourceITCase extends JerseyTest {
+
+ private static final Logger LOGGER = Logger.getLogger(ItemStoreResourceITCase.class.getName());
+ private static final int MAX_LISTENERS = 5;
+ private static final int MAX_ITEMS = 10;
+
+
+ @Override
+ protected Application configure() {
+ return new ItemStoreApp();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Override
+ protected void configureClient(ClientConfig config) {
+ config.property(ClientProperties.CONNECT_TIMEOUT, 15000)
+ .property(ClientProperties.READ_TIMEOUT, 2000)
+ .property(ClientProperties.ASYNC_THREADPOOL_SIZE, MAX_LISTENERS + 1)
+ .connectorProvider(new GrizzlyConnectorProvider());
+ }
+
+ @Override
+ protected URI getBaseUri() {
+ final UriBuilder baseUriBuilder = UriBuilder.fromUri(super.getBaseUri());
+ final boolean externalFactoryInUse = getTestContainerFactory() instanceof ExternalTestContainerFactory;
+ return externalFactoryInUse ? baseUriBuilder.path("resources").build() : baseUriBuilder.build();
+ }
+
+ /**
+ * Test the item addition, addition event broadcasting and item retrieval from {@link ItemStoreResource}.
+ *
+ * @throws Exception in case of a test failure.
+ */
+ @Test
+ public void testItemsStore() throws Exception {
+ final List<String> items = Collections.unmodifiableList(Arrays.asList(
+ "foo",
+ "bar",
+ "baz"));
+ final WebTarget itemsTarget = target("items");
+ final CountDownLatch latch = new CountDownLatch(items.size() * MAX_LISTENERS * 2); // countdown on all events
+ final List<Queue<Integer>> indexQueues = new ArrayList<Queue<Integer>>(MAX_LISTENERS);
+ final EventSource[] sources = new EventSource[MAX_LISTENERS];
+ final AtomicInteger sizeEventsCount = new AtomicInteger(0);
+
+ for (int i = 0; i < MAX_LISTENERS; i++) {
+ final int id = i;
+ final EventSource es = EventSource.target(itemsTarget.path("events"))
+ .named("SOURCE " + id).build();
+ sources[id] = es;
+
+ final Queue<Integer> indexes = new ConcurrentLinkedQueue<Integer>();
+ indexQueues.add(indexes);
+
+ es.register(new EventListener() {
+ @Override
+ @SuppressWarnings("MagicNumber")
+ public void onEvent(InboundEvent inboundEvent) {
+ try {
+ if (inboundEvent.getName() == null) {
+ final String data = inboundEvent.readData();
+ LOGGER.info("[-i-] SOURCE " + id + ": Received event id=" + inboundEvent.getId() + " data=" + data);
+ indexes.add(items.indexOf(data));
+ } else if ("size".equals(inboundEvent.getName())) {
+ sizeEventsCount.incrementAndGet();
+ }
+ } catch (ProcessingException ex) {
+ LOGGER.log(Level.SEVERE, "[-x-] SOURCE " + id + ": Error getting event data.", ex);
+ indexes.add(-999);
+ } finally {
+ latch.countDown();
+ }
+ }
+ });
+ }
+
+ try {
+ open(sources);
+
+ for (String item : items) {
+ postItem(itemsTarget, item);
+ }
+
+ assertTrue("Waiting to receive all events has timed out.",
+ latch.await((1000 + MAX_LISTENERS * EventSource.RECONNECT_DEFAULT) * getAsyncTimeoutMultiplier(),
+ TimeUnit.MILLISECONDS));
+
+ // need to force disconnect on server in order for EventSource.close(...) to succeed with HttpUrlConnection
+ sendCommand(itemsTarget, "disconnect");
+ } finally {
+ close(sources);
+ }
+
+ String postedItems = itemsTarget.request().get(String.class);
+ for (String item : items) {
+ assertTrue("Item '" + item + "' not stored on server.", postedItems.contains(item));
+ }
+
+ int queueId = 0;
+ for (Queue<Integer> indexes : indexQueues) {
+ for (int i = 0; i < items.size(); i++) {
+ assertTrue("Event for '" + items.get(i) + "' not received in queue " + queueId, indexes.contains(i));
+ }
+ assertEquals("Not received the expected number of events in queue " + queueId, items.size(), indexes.size());
+ queueId++;
+ }
+
+ assertEquals("Number of received 'size' events does not match.", items.size() * MAX_LISTENERS, sizeEventsCount.get());
+ }
+
+ /**
+ * Test the {@link EventSource} reconnect feature.
+ *
+ * @throws Exception in case of a test failure.
+ */
+ @Test
+ public void testEventSourceReconnect() throws Exception {
+ final WebTarget itemsTarget = target("items");
+ final CountDownLatch latch = new CountDownLatch(MAX_ITEMS * MAX_LISTENERS * 2); // countdown only on new item events
+ final List<Queue<String>> receivedQueues = new ArrayList<Queue<String>>(MAX_LISTENERS);
+ final EventSource[] sources = new EventSource[MAX_LISTENERS];
+
+ for (int i = 0; i < MAX_LISTENERS; i++) {
+ final int id = i;
+ final EventSource es = EventSource.target(itemsTarget.path("events")).named("SOURCE " + id).build();
+ sources[id] = es;
+
+ final Queue<String> received = new ConcurrentLinkedQueue<String>();
+ receivedQueues.add(received);
+
+ es.register(new EventListener() {
+ @Override
+ public void onEvent(InboundEvent inboundEvent) {
+ try {
+ if (inboundEvent.getName() == null) {
+ latch.countDown();
+ final String data = inboundEvent.readData();
+ LOGGER.info("[-i-] SOURCE " + id + ": Received event id=" + inboundEvent.getId() + " data=" + data);
+ received.add(data);
+ }
+ } catch (ProcessingException ex) {
+ LOGGER.log(Level.SEVERE, "[-x-] SOURCE " + id + ": Error getting event data.", ex);
+ received.add("[data processing error]");
+ }
+ }
+ });
+ }
+
+ final String[] postedItems = new String[MAX_ITEMS * 2];
+ try {
+ open(sources);
+
+ for (int i = 0; i < MAX_ITEMS; i++) {
+ final String item = String.format("round-1-%02d", i);
+ postItem(itemsTarget, item);
+ postedItems[i] = item;
+ sendCommand(itemsTarget, "disconnect");
+ Thread.sleep(100);
+ }
+
+ final int reconnectDelay = 1;
+ sendCommand(itemsTarget, "reconnect " + reconnectDelay);
+ sendCommand(itemsTarget, "disconnect");
+
+ Thread.sleep(reconnectDelay * 1000);
+
+ for (int i = 0; i < MAX_ITEMS; i++) {
+ final String item = String.format("round-2-%02d", i);
+ postedItems[i + MAX_ITEMS] = item;
+ postItem(itemsTarget, item);
+ }
+
+ sendCommand(itemsTarget, "reconnect now");
+
+ assertTrue("Waiting to receive all events has timed out.",
+ latch.await((1 + MAX_LISTENERS * (MAX_ITEMS + 1) * reconnectDelay) * getAsyncTimeoutMultiplier(), TimeUnit.SECONDS));
+
+ // need to force disconnect on server in order for EventSource.close(...) to succeed with HttpUrlConnection
+ sendCommand(itemsTarget, "disconnect");
+ } finally {
+ close(sources);
+ }
+
+ final String storedItems = itemsTarget.request().get(String.class);
+ for (String item : postedItems) {
+ assertThat("Posted item '" + item + "' stored on server", storedItems, containsString(item));
+ }
+
+ int sourceId = 0;
+ for (Queue<String> queue : receivedQueues) {
+ assertThat("Received events in source " + sourceId, queue,
+ describedAs("Collection containing %0", hasItems(postedItems), Arrays.asList(postedItems).toString()));
+ assertThat("Size of received queue for source " + sourceId, queue.size(), equalTo(postedItems.length));
+ sourceId++;
+ }
+ }
+
+ private static void postItem(final WebTarget itemsTarget, final String item) {
+ final Response response = itemsTarget.request().post(Entity.form(new Form("name", item)));
+ assertEquals("Posting new item has failed.", 204, response.getStatus());
+ LOGGER.info("[-i-] POSTed item: '" + item + "'");
+ }
+
+ private static void open(final EventSource[] sources) {
+ int i = 0;
+ for (EventSource source : sources) {
+ source.open();
+ LOGGER.info("[-->] SOURCE " + i++ + " opened.");
+ }
+ }
+
+ private static void close(final EventSource[] sources) {
+ int i = 0;
+ for (EventSource source : sources) {
+ if (source.isOpen()) {
+ assertTrue("Waiting to close a source has timed out.", source.close(1, TimeUnit.SECONDS));
+// source.close(100, TimeUnit.MILLISECONDS);
+ LOGGER.info("[<--] SOURCE " + i++ + " closed.");
+ }
+ }
+ }
+
+ private static void sendCommand(final WebTarget itemsTarget, final String command) {
+ final Response response = itemsTarget.path("commands").request().post(Entity.text(command));
+ assertEquals("'" + command + "' command has failed.", 200, response.getStatus());
+ LOGGER.info("[-!-] COMMAND '" + command + "' has been processed.");
+ }
+}
diff --git a/tests/integration/servlet-request-wrapper-binding-2/pom.xml b/tests/integration/servlet-request-wrapper-binding-2/pom.xml
new file mode 100644
index 0000000..b47561b
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding-2/pom.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-request-wrappper-binding-2</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-request-wrapper-binding-2</name>
+
+ <description>Servlet integration test - Request wrapper binding 2 - ServletContainerProviderFactory, ServletContainerProvider</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-servlet-portability</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>${servlet3.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/servlet-request-wrapper-binding-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding2/JaxRsApplicationAutodetected.java b/tests/integration/servlet-request-wrapper-binding-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding2/JaxRsApplicationAutodetected.java
new file mode 100644
index 0000000..fe3f465
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding2/JaxRsApplicationAutodetected.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_request_wrapper_binding2;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * Test application. This one gets registered automatically.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("autodetected")
+public class JaxRsApplicationAutodetected extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return new HashSet<Class<?>>() {
+ {
+ add(RequestResponseInjectedResource.class);
+ add(RequestResponseInjectedSingletonResource.class);
+ }
+ };
+ }
+}
diff --git a/tests/integration/servlet-request-wrapper-binding-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding2/RequestResponseInjectedResource.java b/tests/integration/servlet-request-wrapper-binding-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding2/RequestResponseInjectedResource.java
new file mode 100644
index 0000000..47370b8
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding2/RequestResponseInjectedResource.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_request_wrapper_binding2;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+
+/**
+ * Test resource that gets injected with the actual {@link HttpServletRequest} and
+ * {@link HttpServletResponse} instance, so that we could testify custom implementations
+ * has been used there.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("/")
+public class RequestResponseInjectedResource {
+
+ ExecutorService executor = Executors.newSingleThreadExecutor();
+
+ @Context
+ HttpServletRequest request;
+
+ @Context
+ HttpServletResponse response;
+
+ @GET
+ @Path("requestType")
+ public String getRequestType() throws Exception {
+
+ // make sure we can access underlying request from another thread
+ return executor.submit(new Callable<String>() {
+ @Override
+ public String call() throws Exception {
+ return ((HttpServletRequestWrapper) request).getRequest().getClass().getName();
+ }
+ }).get();
+ }
+
+ @GET
+ @Path("responseType")
+ public String getResponseType() {
+
+ return ((HttpServletResponseWrapper) response).getResponse().getClass().getName();
+ }
+}
diff --git a/tests/integration/servlet-request-wrapper-binding-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding2/RequestResponseInjectedSingletonResource.java b/tests/integration/servlet-request-wrapper-binding-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding2/RequestResponseInjectedSingletonResource.java
new file mode 100644
index 0000000..f916f7e
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding2/RequestResponseInjectedSingletonResource.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_request_wrapper_binding2;
+
+import javax.inject.Singleton;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+
+/**
+ * Test resource that gets injected with the actual {@link HttpServletRequest} and
+ * {@link HttpServletResponse} instance, so that we could testify custom implementations
+ * has been used there.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("/singleton")
+@Singleton
+public class RequestResponseInjectedSingletonResource {
+
+ @Context
+ HttpServletRequest request;
+
+ @Context
+ HttpServletResponse response;
+
+ @GET
+ @Path("requestType")
+ public String getRequestType() {
+
+ return ((HttpServletRequestWrapper) request).getRequest().getClass().getName();
+ }
+
+ @GET
+ @Path("request/param")
+ public String getRequestAttr() {
+
+ return request.getParameter("q");
+ }
+
+ @GET
+ @Path("responseType")
+ public String getResponseType() {
+
+ return ((HttpServletResponseWrapper) response).getResponse().getClass().getName();
+ }
+}
diff --git a/tests/integration/servlet-request-wrapper-binding-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding2/RequestResponseWrapperProvider.java b/tests/integration/servlet-request-wrapper-binding-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding2/RequestResponseWrapperProvider.java
new file mode 100644
index 0000000..db50a72
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding-2/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding2/RequestResponseWrapperProvider.java
@@ -0,0 +1,839 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_request_wrapper_binding2;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.security.Principal;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Supplier;
+
+import javax.ws.rs.core.GenericType;
+
+import javax.inject.Inject;
+import javax.inject.Provider;
+import javax.servlet.AsyncContext;
+import javax.servlet.DispatcherType;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.Part;
+
+import org.glassfish.jersey.inject.hk2.DelayedHk2InjectionManager;
+import org.glassfish.jersey.inject.hk2.ImmediateHk2InjectionManager;
+import org.glassfish.jersey.internal.inject.AbstractBinder;
+import org.glassfish.jersey.internal.inject.InjectionManager;
+import org.glassfish.jersey.internal.inject.ReferencingFactory;
+import org.glassfish.jersey.internal.util.collection.Ref;
+import org.glassfish.jersey.process.internal.RequestScoped;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.spi.ComponentProvider;
+import org.glassfish.jersey.server.spi.RequestScopedInitializer;
+import org.glassfish.jersey.servlet.internal.spi.NoOpServletContainerProvider;
+import org.glassfish.jersey.servlet.internal.spi.RequestContextProvider;
+import org.glassfish.jersey.servlet.internal.spi.RequestScopedInitializerProvider;
+
+import org.glassfish.hk2.api.DescriptorType;
+import org.glassfish.hk2.api.DescriptorVisibility;
+import org.glassfish.hk2.api.PerLookup;
+import org.glassfish.hk2.api.ServiceHandle;
+import org.glassfish.hk2.api.ServiceLocator;
+import org.glassfish.hk2.api.TypeLiteral;
+import org.glassfish.hk2.utilities.AbstractActiveDescriptor;
+import org.glassfish.hk2.utilities.ServiceLocatorUtilities;
+
+import org.jvnet.hk2.internal.ServiceHandleImpl;
+
+/**
+ * Servlet container provider that wraps the original Servlet request/response.
+ * The request wrapper contains a direct reference to the underlying container request
+ * in case it gets injected into a request scoped component.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class RequestResponseWrapperProvider extends NoOpServletContainerProvider {
+
+ private final Type REQUEST_TYPE = (new TypeLiteral<Ref<HttpServletRequestWrapper>>() {
+ }).getType();
+ private final Type RESPONSE_TYPE = (new TypeLiteral<Ref<HttpServletResponseWrapper>>() {
+ }).getType();
+
+ public static class DescriptorProvider implements ComponentProvider {
+
+ @Override
+ public void initialize(InjectionManager injectionManager) {
+ ServiceLocator locator = getServiceLocator(injectionManager);
+ ServiceLocatorUtilities.addOneDescriptor(locator, new HttpServletRequestDescriptor(locator));
+ }
+
+ @Override
+ public boolean bind(Class<?> component, Set<Class<?>> providerContracts) {
+ return false;
+ }
+
+ @Override
+ public void done() {
+ // nop
+ }
+ }
+
+ /**
+ * Subclass standard wrapper so that we make 100 % sure we are getting the right type.
+ * It is also final, i.e. not proxiable, which we workaround by using custom http servlet request impl.
+ */
+ public static final class RequestWrapper extends HttpServletRequestWrapper {
+
+ public RequestWrapper(HttpServletRequest request) {
+ super(request);
+ }
+ }
+
+ /**
+ * Subclass standard wrapper so that we make 100 % sure we are getting the right type.
+ * It is also final, i.e. not proxiable, which we workaround by using custom http servlet response impl.
+ */
+ public static final class ResponseWrapper extends HttpServletResponseWrapper {
+
+ public ResponseWrapper(HttpServletResponse response) {
+ super(response);
+ }
+ }
+
+ @Override
+ public boolean bindsServletRequestResponse() {
+ return true;
+ }
+
+ @Override
+ public RequestScopedInitializerProvider getRequestScopedInitializerProvider() {
+ return new RequestScopedInitializerProvider() {
+
+ @Override
+ public RequestScopedInitializer get(final RequestContextProvider context) {
+ return new RequestScopedInitializer() {
+ @Override
+ public void initialize(InjectionManager injectionManager) {
+ ServiceLocator locator = getServiceLocator(injectionManager);
+ locator.<Ref<HttpServletRequest>>getService(REQUEST_TYPE)
+ .set(finalWrap(context.getHttpServletRequest()));
+ locator.<Ref<HttpServletResponse>>getService(RESPONSE_TYPE)
+ .set(finalWrap(context.getHttpServletResponse()));
+ }
+ };
+ }
+ };
+ }
+
+ private final class Binder extends AbstractBinder {
+
+ @Override
+ protected void configure() {
+
+ bindFactory(HttpServletRequestReferencingFactory.class)
+ .to(HttpServletRequestWrapper.class).in(RequestScoped.class);
+
+ bindFactory(ReferencingFactory.<HttpServletRequestWrapper>referenceFactory())
+ .to(new GenericType<Ref<HttpServletRequestWrapper>>() {
+ }).in(RequestScoped.class);
+
+ bindFactory(HttpServletResponseFactory.class).to(HttpServletResponse.class);
+
+ bindFactory(HttpServletResponseReferencingFactory.class)
+ .to(HttpServletResponseWrapper.class).in(RequestScoped.class);
+
+ bindFactory(ReferencingFactory.<HttpServletResponseWrapper>referenceFactory())
+ .to(new GenericType<Ref<HttpServletResponseWrapper>>() {
+ }).in(RequestScoped.class);
+
+ }
+ }
+
+ private static class HttpServletRequestDescriptor extends AbstractActiveDescriptor<HttpServletRequest> {
+
+ static Set<Type> advertisedContracts = new HashSet<Type>() {
+ {
+ add(HttpServletRequest.class);
+ }
+ };
+
+ final ServiceLocator locator;
+ volatile javax.inject.Provider<Ref<HttpServletRequestWrapper>> request;
+
+ public HttpServletRequestDescriptor(final ServiceLocator locator) {
+ super(advertisedContracts,
+ PerLookup.class,
+ null, new HashSet<Annotation>(),
+ DescriptorType.CLASS, DescriptorVisibility.LOCAL,
+ 0, null, null, null, null);
+ this.locator = locator;
+ }
+
+ @Override
+ public Class<?> getImplementationClass() {
+ return HttpServletRequest.class;
+ }
+
+ @Override
+ public Type getImplementationType() {
+ return getImplementationClass();
+ }
+
+ @Override
+ public synchronized String getImplementation() {
+ return HttpServletRequest.class.getName();
+ }
+
+ @Override
+ public HttpServletRequest create(ServiceHandle<?> serviceHandle) {
+ if (request == null) {
+ request = locator.getService(new TypeLiteral<Provider<Ref<HttpServletRequestWrapper>>>() {
+ }.getType());
+ }
+
+ boolean direct = false;
+
+ if (serviceHandle instanceof ServiceHandleImpl) {
+ final ServiceHandleImpl serviceHandleImpl = (ServiceHandleImpl) serviceHandle;
+ final Class<? extends Annotation> scopeAnnotation =
+ serviceHandleImpl.getOriginalRequest().getInjecteeDescriptor().getScopeAnnotation();
+
+ if (scopeAnnotation == RequestScoped.class || scopeAnnotation == null) {
+ direct = true;
+ }
+ }
+
+
+ return !direct ? new HttpServletRequestWrapper(new MyHttpServletRequestImpl() {
+ @Override
+ HttpServletRequest getHttpServletRequest() {
+ return request.get().get();
+ }
+ }) {
+ @Override
+ public ServletRequest getRequest() {
+ return request.get().get();
+ }
+
+ }
+ : new HttpServletRequestWrapper(request.get().get());
+ }
+ }
+
+ private static class HttpServletResponseFactory implements Supplier<HttpServletResponse> {
+ private final javax.inject.Provider<Ref<HttpServletResponseWrapper>> response;
+
+ @Inject
+ public HttpServletResponseFactory(javax.inject.Provider<Ref<HttpServletResponseWrapper>> response) {
+ this.response = response;
+ }
+
+ @Override
+ @PerLookup
+ public HttpServletResponse get() {
+ return new HttpServletResponseWrapper(new HttpServletResponse() {
+
+ private HttpServletResponse getHttpServletResponse() {
+ return response.get().get();
+ }
+
+ @Override
+ public void addCookie(Cookie cookie) {
+ getHttpServletResponse().addCookie(cookie);
+ }
+
+ @Override
+ public boolean containsHeader(String s) {
+ return getHttpServletResponse().containsHeader(s);
+ }
+
+ @Override
+ public String encodeURL(String s) {
+ return getHttpServletResponse().encodeURL(s);
+ }
+
+ @Override
+ public String encodeRedirectURL(String s) {
+ return getHttpServletResponse().encodeRedirectURL(s);
+ }
+
+ @Override
+ public String encodeUrl(String s) {
+ return getHttpServletResponse().encodeUrl(s);
+ }
+
+ @Override
+ public String encodeRedirectUrl(String s) {
+ return getHttpServletResponse().encodeRedirectUrl(s);
+ }
+
+ @Override
+ public void sendError(int i, String s) throws IOException {
+ getHttpServletResponse().sendError(i, s);
+ }
+
+ @Override
+ public void sendError(int i) throws IOException {
+ getHttpServletResponse().sendError(i);
+ }
+
+ @Override
+ public void sendRedirect(String s) throws IOException {
+ getHttpServletResponse().sendRedirect(s);
+ }
+
+ @Override
+ public void setDateHeader(String s, long l) {
+ getHttpServletResponse().setDateHeader(s, l);
+ }
+
+ @Override
+ public void addDateHeader(String s, long l) {
+ getHttpServletResponse().addDateHeader(s, l);
+ }
+
+ @Override
+ public void setHeader(String h, String v) {
+ getHttpServletResponse().setHeader(h, v);
+ }
+
+ public Collection<String> getHeaderNames() {
+ return getHttpServletResponse().getHeaderNames();
+ }
+
+ public Collection<String> getHeaders(String s) {
+ return getHttpServletResponse().getHeaders(s);
+ }
+
+ public String getHeader(String s) {
+ return getHttpServletResponse().getHeader(s);
+ }
+
+ @Override
+ public void addHeader(String h, String v) {
+ getHttpServletResponse().addHeader(h, v);
+ }
+
+ @Override
+ public void setIntHeader(String s, int i) {
+ getHttpServletResponse().setIntHeader(s, i);
+ }
+
+ @Override
+ public void addIntHeader(String s, int i) {
+ getHttpServletResponse().addIntHeader(s, i);
+ }
+
+ @Override
+ public void setStatus(int i) {
+ getHttpServletResponse().setStatus(i);
+ }
+
+ @Override
+ public int getStatus() {
+ return getHttpServletResponse().getStatus();
+ }
+
+ @Override
+ public void setStatus(int i, String s) {
+ getHttpServletResponse().setStatus(i, s);
+ }
+
+ @Override
+ public String getCharacterEncoding() {
+ return getHttpServletResponse().getCharacterEncoding();
+ }
+
+ @Override
+ public String getContentType() {
+ return getHttpServletResponse().getContentType();
+ }
+
+ @Override
+ public ServletOutputStream getOutputStream() throws IOException {
+ return getHttpServletResponse().getOutputStream();
+ }
+
+ @Override
+ public PrintWriter getWriter() throws IOException {
+ return getHttpServletResponse().getWriter();
+ }
+
+ @Override
+ public void setCharacterEncoding(String s) {
+ getHttpServletResponse().setCharacterEncoding(s);
+ }
+
+ @Override
+ public void setContentLength(int i) {
+ getHttpServletResponse().setContentLength(i);
+ }
+
+ @Override
+ public void setContentType(String s) {
+ getHttpServletResponse().setContentType(s);
+ }
+
+ @Override
+ public void setBufferSize(int i) {
+ getHttpServletResponse().setBufferSize(i);
+ }
+
+ @Override
+ public int getBufferSize() {
+ return getHttpServletResponse().getBufferSize();
+ }
+
+ @Override
+ public void flushBuffer() throws IOException {
+ getHttpServletResponse().flushBuffer();
+ }
+
+ @Override
+ public void resetBuffer() {
+ getHttpServletResponse().resetBuffer();
+ }
+
+ @Override
+ public boolean isCommitted() {
+ return getHttpServletResponse().isCommitted();
+ }
+
+ @Override
+ public void reset() {
+ getHttpServletResponse().reset();
+ }
+
+ @Override
+ public void setLocale(Locale locale) {
+ getHttpServletResponse().setLocale(locale);
+ }
+
+ @Override
+ public Locale getLocale() {
+ return getHttpServletResponse().getLocale();
+ }
+ }
+ ) {
+ @Override
+ public ServletResponse getResponse() {
+ return response.get().get();
+ }
+ };
+ }
+
+ }
+
+ @SuppressWarnings("JavaDoc")
+ private static class HttpServletRequestReferencingFactory extends ReferencingFactory<HttpServletRequestWrapper> {
+
+ @Inject
+ public HttpServletRequestReferencingFactory(
+ final javax.inject.Provider<Ref<HttpServletRequestWrapper>> referenceFactory) {
+
+ super(referenceFactory);
+ }
+ }
+
+ @SuppressWarnings("JavaDoc")
+ private static class HttpServletResponseReferencingFactory extends ReferencingFactory<HttpServletResponseWrapper> {
+
+ @Inject
+ public HttpServletResponseReferencingFactory(
+ final javax.inject.Provider<Ref<HttpServletResponseWrapper>> referenceFactory) {
+
+ super(referenceFactory);
+ }
+
+ }
+
+ @Override
+ public void configure(final ResourceConfig resourceConfig) throws ServletException {
+ resourceConfig.register(new Binder());
+ }
+
+ private HttpServletRequest finalWrap(final HttpServletRequest request) {
+ return new RequestWrapper(request);
+ }
+
+ private HttpServletResponse finalWrap(final HttpServletResponse response) {
+ return new ResponseWrapper(response);
+ }
+
+ private abstract static class MyHttpServletRequestImpl implements HttpServletRequest {
+
+ @Override
+ public String getAuthType() {
+ return getHttpServletRequest().getAuthType();
+ }
+
+ @Override
+ public boolean authenticate(HttpServletResponse response) throws IOException, ServletException {
+ return getHttpServletRequest().authenticate(response);
+ }
+
+ @Override
+ public boolean isAsyncSupported() {
+ return getHttpServletRequest().isAsyncSupported();
+ }
+
+ @Override
+ public boolean isAsyncStarted() {
+ return getHttpServletRequest().isAsyncStarted();
+ }
+
+ @Override
+ public AsyncContext startAsync() throws IllegalStateException {
+ return getHttpServletRequest().startAsync();
+ }
+
+ @Override
+ public AsyncContext startAsync(ServletRequest request, ServletResponse response) throws IllegalStateException {
+ return getHttpServletRequest().startAsync(request, response);
+ }
+
+ abstract HttpServletRequest getHttpServletRequest();
+
+ @Override
+ public Cookie[] getCookies() {
+ return getHttpServletRequest().getCookies();
+ }
+
+ @Override
+ public long getDateHeader(String s) {
+ return getHttpServletRequest().getDateHeader(s);
+ }
+
+ @Override
+ public Part getPart(String s) throws ServletException, IOException {
+ return getHttpServletRequest().getPart(s);
+ }
+
+ @Override
+ public Collection<Part> getParts() throws ServletException, IOException {
+ return getHttpServletRequest().getParts();
+ }
+
+ @Override
+ public String getHeader(String s) {
+ return getHttpServletRequest().getHeader(s);
+ }
+
+ @Override
+ public Enumeration getHeaders(String s) {
+ return getHttpServletRequest().getHeaders(s);
+ }
+
+ @Override
+ public Enumeration getHeaderNames() {
+ return getHttpServletRequest().getHeaderNames();
+ }
+
+ @Override
+ public int getIntHeader(String s) {
+ return getHttpServletRequest().getIntHeader(s);
+ }
+
+ @Override
+ public String getMethod() {
+ return getHttpServletRequest().getMethod();
+ }
+
+ @Override
+ public String getPathInfo() {
+ return getHttpServletRequest().getPathInfo();
+ }
+
+ @Override
+ public String getPathTranslated() {
+ return getHttpServletRequest().getPathTranslated();
+ }
+
+ @Override
+ public String getContextPath() {
+ return getHttpServletRequest().getContextPath();
+ }
+
+ @Override
+ public String getQueryString() {
+ return getHttpServletRequest().getQueryString();
+ }
+
+ @Override
+ public String getRemoteUser() {
+ return getHttpServletRequest().getRemoteUser();
+ }
+
+ @Override
+ public boolean isUserInRole(String s) {
+ return getHttpServletRequest().isUserInRole(s);
+ }
+
+ @Override
+ public Principal getUserPrincipal() {
+ return getHttpServletRequest().getUserPrincipal();
+ }
+
+ @Override
+ public String getRequestedSessionId() {
+ return getHttpServletRequest().getRequestedSessionId();
+ }
+
+ @Override
+ public String getRequestURI() {
+ return getHttpServletRequest().getRequestURI();
+ }
+
+ @Override
+ public StringBuffer getRequestURL() {
+ return getHttpServletRequest().getRequestURL();
+ }
+
+ @Override
+ public String getServletPath() {
+ return getHttpServletRequest().getServletPath();
+ }
+
+ @Override
+ public HttpSession getSession(boolean b) {
+ return getHttpServletRequest().getSession(b);
+ }
+
+ @Override
+ public HttpSession getSession() {
+ return getHttpServletRequest().getSession();
+ }
+
+ @Override
+ public boolean isRequestedSessionIdValid() {
+ return getHttpServletRequest().isRequestedSessionIdValid();
+ }
+
+ @Override
+ public boolean isRequestedSessionIdFromCookie() {
+ return getHttpServletRequest().isRequestedSessionIdFromCookie();
+ }
+
+ @Override
+ public boolean isRequestedSessionIdFromURL() {
+ return getHttpServletRequest().isRequestedSessionIdFromURL();
+ }
+
+ @Override
+ public boolean isRequestedSessionIdFromUrl() {
+ return getHttpServletRequest().isRequestedSessionIdFromUrl();
+ }
+
+ @Override
+ public Object getAttribute(String s) {
+ return getHttpServletRequest().getAttribute(s);
+ }
+
+ @Override
+ public Enumeration getAttributeNames() {
+ return getHttpServletRequest().getAttributeNames();
+ }
+
+ @Override
+ public String getCharacterEncoding() {
+ return getHttpServletRequest().getCharacterEncoding();
+ }
+
+ @Override
+ public void setCharacterEncoding(String s) throws UnsupportedEncodingException {
+ getHttpServletRequest().setCharacterEncoding(s);
+ }
+
+ @Override
+ public int getContentLength() {
+ return getHttpServletRequest().getContentLength();
+ }
+
+ @Override
+ public String getContentType() {
+ return getHttpServletRequest().getContentType();
+ }
+
+ @Override
+ public ServletInputStream getInputStream() throws IOException {
+ return getHttpServletRequest().getInputStream();
+ }
+
+ @Override
+ public String getParameter(String s) {
+ return getHttpServletRequest().getParameter(s);
+ }
+
+ @Override
+ public Enumeration getParameterNames() {
+ return getHttpServletRequest().getParameterNames();
+ }
+
+ @Override
+ public String[] getParameterValues(String s) {
+ return getHttpServletRequest().getParameterValues(s);
+ }
+
+ @Override
+ public Map getParameterMap() {
+ return getHttpServletRequest().getParameterMap();
+ }
+
+ @Override
+ public String getProtocol() {
+ return getHttpServletRequest().getProtocol();
+ }
+
+ @Override
+ public String getScheme() {
+ return getHttpServletRequest().getScheme();
+ }
+
+ @Override
+ public String getServerName() {
+ return getHttpServletRequest().getServerName();
+ }
+
+ @Override
+ public int getServerPort() {
+ return getHttpServletRequest().getServerPort();
+ }
+
+ @Override
+ public BufferedReader getReader() throws IOException {
+ return getHttpServletRequest().getReader();
+ }
+
+ @Override
+ public String getRemoteAddr() {
+ return getHttpServletRequest().getRemoteAddr();
+ }
+
+ @Override
+ public String getRemoteHost() {
+ return getHttpServletRequest().getRemoteHost();
+ }
+
+ @Override
+ public void setAttribute(String s, Object o) {
+ getHttpServletRequest().setAttribute(s, o);
+ }
+
+ @Override
+ public void removeAttribute(String s) {
+ getHttpServletRequest().removeAttribute(s);
+ }
+
+ @Override
+ public Locale getLocale() {
+ return getHttpServletRequest().getLocale();
+ }
+
+ @Override
+ public Enumeration getLocales() {
+ return getHttpServletRequest().getLocales();
+ }
+
+ @Override
+ public boolean isSecure() {
+ return getHttpServletRequest().isSecure();
+ }
+
+ @Override
+ public RequestDispatcher getRequestDispatcher(String s) {
+ return getHttpServletRequest().getRequestDispatcher(s);
+ }
+
+ @Override
+ public String getRealPath(String s) {
+ return getHttpServletRequest().getRealPath(s);
+ }
+
+ @Override
+ public int getRemotePort() {
+ return getHttpServletRequest().getRemotePort();
+ }
+
+ @Override
+ public String getLocalName() {
+ return getHttpServletRequest().getLocalName();
+ }
+
+ @Override
+ public String getLocalAddr() {
+ return getHttpServletRequest().getLocalAddr();
+ }
+
+ @Override
+ public int getLocalPort() {
+ return getHttpServletRequest().getLocalPort();
+ }
+
+ @Override
+ public DispatcherType getDispatcherType() {
+ return getHttpServletRequest().getDispatcherType();
+ }
+
+ @Override
+ public AsyncContext getAsyncContext() {
+ return getHttpServletRequest().getAsyncContext();
+ }
+
+ @Override
+ public ServletContext getServletContext() {
+ return getHttpServletRequest().getServletContext();
+ }
+
+ @Override
+ public void logout() throws ServletException {
+ getHttpServletRequest().logout();
+ }
+
+ @Override
+ public void login(String u, String p) throws ServletException {
+ getHttpServletRequest().login(u, p);
+ }
+ }
+
+ private static ServiceLocator getServiceLocator(InjectionManager injectionManager) {
+ if (injectionManager instanceof ImmediateHk2InjectionManager) {
+ return ((ImmediateHk2InjectionManager) injectionManager).getServiceLocator();
+ } else if (injectionManager instanceof DelayedHk2InjectionManager) {
+ return ((DelayedHk2InjectionManager) injectionManager).getServiceLocator();
+ } else {
+ throw new RuntimeException("Invalid InjectionManager");
+ }
+ }
+}
diff --git a/tests/integration/servlet-request-wrapper-binding-2/src/main/resources/META-INF/services/org.glassfish.jersey.server.spi.ComponentProvider b/tests/integration/servlet-request-wrapper-binding-2/src/main/resources/META-INF/services/org.glassfish.jersey.server.spi.ComponentProvider
new file mode 100644
index 0000000..e6780ff
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding-2/src/main/resources/META-INF/services/org.glassfish.jersey.server.spi.ComponentProvider
@@ -0,0 +1 @@
+org.glassfish.jersey.tests.integration.servlet_request_wrapper_binding2.RequestResponseWrapperProvider$DescriptorProvider
\ No newline at end of file
diff --git a/tests/integration/servlet-request-wrapper-binding-2/src/main/resources/META-INF/services/org.glassfish.jersey.servlet.internal.spi.ServletContainerProvider b/tests/integration/servlet-request-wrapper-binding-2/src/main/resources/META-INF/services/org.glassfish.jersey.servlet.internal.spi.ServletContainerProvider
new file mode 100644
index 0000000..543851e
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding-2/src/main/resources/META-INF/services/org.glassfish.jersey.servlet.internal.spi.ServletContainerProvider
@@ -0,0 +1 @@
+org.glassfish.jersey.tests.integration.servlet_request_wrapper_binding2.RequestResponseWrapperProvider
\ No newline at end of file
diff --git a/tests/integration/servlet-request-wrapper-binding-2/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-request-wrapper-binding-2/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..aab05c4
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding-2/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+
+ <servlet>
+ <servlet-name>jerseyApp</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_request_wrapper_binding2.RequestResponseInjectedResource,
+ org.glassfish.jersey.tests.integration.servlet_request_wrapper_binding2.RequestResponseInjectedSingletonResource
+ </param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>jerseyApp</servlet-name>
+ <url-pattern>/webxmlconfigured/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/servlet-request-wrapper-binding-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper2/AbstractRequestResponseTypeTest.java b/tests/integration/servlet-request-wrapper-binding-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper2/AbstractRequestResponseTypeTest.java
new file mode 100644
index 0000000..5631450
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper2/AbstractRequestResponseTypeTest.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_request_wrapper2;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+import org.glassfish.jersey.tests.integration.servlet_request_wrapper_binding2.RequestResponseWrapperProvider;
+
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Make sure that injected request/response instances
+ * are of the types injected by {@link RequestResponseWrapperProvider}.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public abstract class AbstractRequestResponseTypeTest extends JerseyTest {
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testRequestType() throws Exception {
+ final String requestType = target(getAppBasePath()).path("requestType").request().get(String.class);
+ assertThat(requestType, is(equalTo(RequestResponseWrapperProvider.RequestWrapper.class.getName())));
+ }
+
+ @Test
+ public void testResponseType() throws Exception {
+ final String requestType = target(getAppBasePath()).path("responseType").request().get(String.class);
+ assertThat(requestType, is(equalTo(RequestResponseWrapperProvider.ResponseWrapper.class.getName())));
+ }
+
+ @Test
+ public void testSingletonRequestType() throws Exception {
+ final String requestType = target(getAppBasePath()).path("singleton/requestType").request().get(String.class);
+ assertThat(requestType, is(equalTo(RequestResponseWrapperProvider.RequestWrapper.class.getName())));
+ }
+
+ @Test
+ public void testSingletonRequestAttr() throws Exception {
+ for (String q : new String[] {"1", "2", "3", "95", "98", "NT", "2000", "XP", "Vista", "7", "8", "10"}) {
+ _testSingletonRequestAttr("one");
+ }
+ }
+
+ public void _testSingletonRequestAttr(String q) throws Exception {
+ final String requestType = target(getAppBasePath()).path("singleton/request/param")
+ .queryParam("q", q).request().get(String.class);
+ assertThat(requestType, is(equalTo(q)));
+ }
+
+ @Test
+ public void testSingletonResponseType() throws Exception {
+ final String requestType = target(getAppBasePath()).path("singleton/responseType").request().get(String.class);
+ assertThat(requestType, is(equalTo(RequestResponseWrapperProvider.ResponseWrapper.class.getName())));
+ }
+
+ protected abstract String getAppBasePath();
+}
diff --git a/tests/integration/servlet-request-wrapper-binding-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper2/AutodetectedAppRequestResponseTypeITCase.java b/tests/integration/servlet-request-wrapper-binding-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper2/AutodetectedAppRequestResponseTypeITCase.java
new file mode 100644
index 0000000..13a6063
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper2/AutodetectedAppRequestResponseTypeITCase.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_request_wrapper2;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.tests.integration.servlet_request_wrapper_binding2.JaxRsApplicationAutodetected;
+
+/**
+ * Test for the autodetected JAX-RS app.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class AutodetectedAppRequestResponseTypeITCase extends AbstractRequestResponseTypeTest {
+
+ @Override
+ protected String getAppBasePath() {
+ return "autodetected";
+ }
+
+ @Override
+ protected Application configure() {
+ return ResourceConfig.forApplicationClass(JaxRsApplicationAutodetected.class);
+ }
+}
diff --git a/tests/integration/servlet-request-wrapper-binding-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper2/WebXmlConfiguredAppRequestResponseTypeITCase.java b/tests/integration/servlet-request-wrapper-binding-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper2/WebXmlConfiguredAppRequestResponseTypeITCase.java
new file mode 100644
index 0000000..9a028dc
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding-2/src/test/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper2/WebXmlConfiguredAppRequestResponseTypeITCase.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_request_wrapper2;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.tests.integration.servlet_request_wrapper_binding2.RequestResponseInjectedResource;
+
+/**
+ * Test for the web.xml configured JAX-RS app.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class WebXmlConfiguredAppRequestResponseTypeITCase extends AbstractRequestResponseTypeTest {
+
+ @Override
+ protected String getAppBasePath() {
+ return "webxmlconfigured";
+ }
+
+ @Override
+ protected Application configure() {
+ return new ResourceConfig(RequestResponseInjectedResource.class);
+ }
+}
diff --git a/tests/integration/servlet-request-wrapper-binding/pom.xml b/tests/integration/servlet-request-wrapper-binding/pom.xml
new file mode 100644
index 0000000..8e869c4
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding/pom.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-request-wrappper-binding</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-request-wrapper-binding</name>
+
+ <description>Servlet integration test - Request wrapper binding - ServletContainerProviderFactory, ServletContainerProvider</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-servlet-portability</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>${servlet3.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/servlet-request-wrapper-binding/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding/JaxRsApplicationAutodetected.java b/tests/integration/servlet-request-wrapper-binding/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding/JaxRsApplicationAutodetected.java
new file mode 100644
index 0000000..1fe4126
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding/JaxRsApplicationAutodetected.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_request_wrapper_binding;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+/**
+ * Test application. This one gets registered automatically.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@ApplicationPath("autodetected")
+public class JaxRsApplicationAutodetected extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ return new HashSet<Class<?>>() {
+ {
+ add(RequestResponseInjectedResource.class);
+ }
+ };
+ }
+}
diff --git a/tests/integration/servlet-request-wrapper-binding/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding/RequestResponseInjectedResource.java b/tests/integration/servlet-request-wrapper-binding/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding/RequestResponseInjectedResource.java
new file mode 100644
index 0000000..54cc690
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding/RequestResponseInjectedResource.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_request_wrapper_binding;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Context;
+
+/**
+ * Test resource that gets injected with the actual {@link HttpServletRequest} and
+ * {@link HttpServletResponse} instance, so that we could testify custom implementations
+ * has been used there.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+@Path("/")
+public class RequestResponseInjectedResource {
+
+ @Context
+ HttpServletRequest request;
+
+ @Context
+ HttpServletResponse response;
+
+ @GET
+ @Path("requestType")
+ public String getRequestType() {
+
+ return request.getClass().getName();
+ }
+
+ @GET
+ @Path("responseType")
+ public String getResponseType() {
+
+ return response.getClass().getName();
+ }
+}
diff --git a/tests/integration/servlet-request-wrapper-binding/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding/RequestResponseWrapperProvider.java b/tests/integration/servlet-request-wrapper-binding/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding/RequestResponseWrapperProvider.java
new file mode 100644
index 0000000..09f40a7
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding/src/main/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper_binding/RequestResponseWrapperProvider.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_request_wrapper_binding;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+
+import org.glassfish.jersey.internal.util.collection.Ref;
+import org.glassfish.jersey.server.spi.RequestScopedInitializer;
+import org.glassfish.jersey.servlet.internal.spi.NoOpServletContainerProvider;
+import org.glassfish.jersey.servlet.internal.spi.RequestScopedInitializerProvider;
+
+/**
+ * Servlet container provider that wraps the original Servlet request/response.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class RequestResponseWrapperProvider extends NoOpServletContainerProvider {
+
+ /**
+ * Subclass standard wrapper so that we make 100 % sure we are getting the right type.
+ */
+ public static class RequestWrapper extends HttpServletRequestWrapper {
+
+ public RequestWrapper(HttpServletRequest request) {
+ super(request);
+ }
+ }
+
+ /**
+ * Subclass standard wrapper so that we make 100 % sure we are getting the right type.
+ */
+ public static class ResponseWrapper extends HttpServletResponseWrapper {
+
+ public ResponseWrapper(HttpServletResponse response) {
+ super(response);
+ }
+ }
+
+ @Override
+ public RequestScopedInitializerProvider getRequestScopedInitializerProvider() {
+ return context -> (RequestScopedInitializer) injectionManager -> {
+ injectionManager.<Ref<HttpServletRequest>>getInstance(HTTP_SERVLET_REQUEST_TYPE)
+ .set(wrapped(context.getHttpServletRequest()));
+ injectionManager.<Ref<HttpServletResponse>>getInstance(HTTP_SERVLET_RESPONSE_TYPE)
+ .set(wrapped(context.getHttpServletResponse()));
+ };
+ }
+
+ private HttpServletRequest wrapped(final HttpServletRequest request) {
+ return new RequestWrapper(request);
+ }
+
+ private HttpServletResponse wrapped(final HttpServletResponse response) {
+ return new ResponseWrapper(response);
+ }
+}
diff --git a/tests/integration/servlet-request-wrapper-binding/src/main/resources/META-INF/services/org.glassfish.jersey.servlet.internal.spi.ServletContainerProvider b/tests/integration/servlet-request-wrapper-binding/src/main/resources/META-INF/services/org.glassfish.jersey.servlet.internal.spi.ServletContainerProvider
new file mode 100644
index 0000000..fd57f7c
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding/src/main/resources/META-INF/services/org.glassfish.jersey.servlet.internal.spi.ServletContainerProvider
@@ -0,0 +1 @@
+org.glassfish.jersey.tests.integration.servlet_request_wrapper_binding.RequestResponseWrapperProvider
\ No newline at end of file
diff --git a/tests/integration/servlet-request-wrapper-binding/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-request-wrapper-binding/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..0cee595
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+
+ <servlet>
+ <servlet-name>jerseyApp</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlet_request_wrapper_binding.RequestResponseInjectedResource</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>jerseyApp</servlet-name>
+ <url-pattern>/webxmlconfigured/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/servlet-request-wrapper-binding/src/test/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper/AbstractRequestResponseTypeTest.java b/tests/integration/servlet-request-wrapper-binding/src/test/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper/AbstractRequestResponseTypeTest.java
new file mode 100644
index 0000000..4f4710d
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding/src/test/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper/AbstractRequestResponseTypeTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_request_wrapper;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+import org.glassfish.jersey.tests.integration.servlet_request_wrapper_binding.RequestResponseWrapperProvider;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.equalTo;
+
+import org.junit.Test;
+
+/**
+ * Make sure that injected request/response instances
+ * are of the types injected by {@link RequestResponseWrapperProvider}.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public abstract class AbstractRequestResponseTypeTest extends JerseyTest {
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testRequestType() throws Exception {
+ final String requestType = target(getAppBasePath()).path("requestType").request().get(String.class);
+ assertThat(requestType, is(equalTo(RequestResponseWrapperProvider.RequestWrapper.class.getName())));
+ }
+
+ @Test
+ public void testResponseType() throws Exception {
+ final String requestType = target(getAppBasePath()).path("responseType").request().get(String.class);
+ assertThat(requestType, is(equalTo(RequestResponseWrapperProvider.ResponseWrapper.class.getName())));
+ }
+
+ protected abstract String getAppBasePath();
+}
diff --git a/tests/integration/servlet-request-wrapper-binding/src/test/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper/AutodetectedAppRequestResponseTypeITCase.java b/tests/integration/servlet-request-wrapper-binding/src/test/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper/AutodetectedAppRequestResponseTypeITCase.java
new file mode 100644
index 0000000..7b7403a
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding/src/test/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper/AutodetectedAppRequestResponseTypeITCase.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_request_wrapper;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.tests.integration.servlet_request_wrapper_binding.JaxRsApplicationAutodetected;
+
+/**
+ * Test for the autodetected JAX-RS app.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class AutodetectedAppRequestResponseTypeITCase extends AbstractRequestResponseTypeTest {
+
+ @Override
+ protected String getAppBasePath() {
+ return "autodetected";
+ }
+
+ @Override
+ protected Application configure() {
+ return ResourceConfig.forApplicationClass(JaxRsApplicationAutodetected.class);
+ }
+}
diff --git a/tests/integration/servlet-request-wrapper-binding/src/test/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper/WebXmlConfiguredAppRequestResponseTypeITCase.java b/tests/integration/servlet-request-wrapper-binding/src/test/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper/WebXmlConfiguredAppRequestResponseTypeITCase.java
new file mode 100644
index 0000000..f6a85ad
--- /dev/null
+++ b/tests/integration/servlet-request-wrapper-binding/src/test/java/org/glassfish/jersey/tests/integration/servlet_request_wrapper/WebXmlConfiguredAppRequestResponseTypeITCase.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlet_request_wrapper;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.tests.integration.servlet_request_wrapper_binding.RequestResponseInjectedResource;
+
+/**
+ * Test for the web.xml configured JAX-RS app.
+ *
+ * @author Jakub Podlesak (jakub.podlesak at oracle.com)
+ */
+public class WebXmlConfiguredAppRequestResponseTypeITCase extends AbstractRequestResponseTypeTest {
+
+ @Override
+ protected String getAppBasePath() {
+ return "webxmlconfigured";
+ }
+
+ @Override
+ protected Application configure() {
+ return new ResourceConfig(RequestResponseInjectedResource.class);
+ }
+}
diff --git a/tests/integration/servlet-tests/pom.xml b/tests/integration/servlet-tests/pom.xml
new file mode 100644
index 0000000..015852d
--- /dev/null
+++ b/tests/integration/servlet-tests/pom.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2011, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servlet-tests</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-servlet-tests</name>
+
+ <description>Set of smaller unrelated servlet-specific tests.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${servlet2.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/CacheControlOn404Resource.java b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/CacheControlOn404Resource.java
new file mode 100644
index 0000000..4fca464
--- /dev/null
+++ b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/CacheControlOn404Resource.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlettests;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.CacheControl;
+import javax.ws.rs.core.Response;
+
+/**
+ * @author Martin Matula
+ */
+@Path("404")
+public class CacheControlOn404Resource {
+ @GET
+ public Response get404() {
+ CacheControl cc = new CacheControl();
+ cc.setMaxAge(10);
+ return Response.status(Response.Status.NOT_FOUND).cacheControl(cc).type("text/plain").entity("404 Not Found").build();
+ }
+}
diff --git a/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/CustomMediaTypeAnd404Resource.java b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/CustomMediaTypeAnd404Resource.java
new file mode 100644
index 0000000..08d2952
--- /dev/null
+++ b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/CustomMediaTypeAnd404Resource.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlettests;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+/**
+ *
+ * @author Miroslav Fuksa
+ */
+@Path("resource404")
+public class CustomMediaTypeAnd404Resource {
+ @Path("content-type-entity")
+ @GET
+ public Response getSpecialContentType() {
+ return Response.status(Response.Status.NOT_FOUND).type("application/something").entity("not found custom entity").build();
+ }
+
+ @Path("content-type-empty-entity")
+ @GET
+ public Response getSpecialContentTypeWithEmptyEntityString() {
+ return Response.status(Response.Status.NOT_FOUND).type("application/something").entity("").build();
+ }
+}
diff --git a/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/FilterContextPathResource.java b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/FilterContextPathResource.java
new file mode 100644
index 0000000..11b5c2a
--- /dev/null
+++ b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/FilterContextPathResource.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlettests;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * @author Martin Matula
+ */
+@Path("contextPathResource")
+public class FilterContextPathResource {
+ @GET
+ public String get() {
+ return "contextPathResource";
+ }
+}
diff --git a/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/FilterForwardOn404Resource.java b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/FilterForwardOn404Resource.java
new file mode 100644
index 0000000..316b007
--- /dev/null
+++ b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/FilterForwardOn404Resource.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlettests;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * @author Martin Matula
+ */
+@Path("forwardingFilter/resource")
+public class FilterForwardOn404Resource {
+ @GET
+ public String get() {
+ return "forwardingFilter/resource";
+ }
+}
diff --git a/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/FilterNoContextPathResource.java b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/FilterNoContextPathResource.java
new file mode 100644
index 0000000..739a2d0
--- /dev/null
+++ b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/FilterNoContextPathResource.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlettests;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * @author Martin Matula
+ */
+@Path("filter/resource")
+public class FilterNoContextPathResource {
+ @GET
+ public String get() {
+ return "filter/resource";
+ }
+}
diff --git a/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/FilterStaticContentResource.java b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/FilterStaticContentResource.java
new file mode 100644
index 0000000..256ab41
--- /dev/null
+++ b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/FilterStaticContentResource.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlettests;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * @author Martin Matula
+ */
+@Path("staticContentFilter/resource")
+public class FilterStaticContentResource {
+ @GET
+ public String get() {
+ return "staticContentFilter/resource";
+ }
+}
diff --git a/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/FormConsumptionFilter.java b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/FormConsumptionFilter.java
new file mode 100644
index 0000000..bda0d3a
--- /dev/null
+++ b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/FormConsumptionFilter.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlettests;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+ * @author Martin Matula
+ */
+public class FormConsumptionFilter implements Filter {
+
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+ }
+
+ @Override
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
+ throws IOException, ServletException {
+ // consume entity
+ servletRequest.getParameter("text");
+ filterChain.doFilter(servletRequest, servletResponse);
+ }
+
+ @Override
+ public void destroy() {
+ }
+}
diff --git a/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/FormConsumptionResource.java b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/FormConsumptionResource.java
new file mode 100644
index 0000000..f0910fd
--- /dev/null
+++ b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/FormConsumptionResource.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlettests;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Encoded;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+/**
+ * @author Martin Matula
+ */
+@Path("form-consumption")
+public class FormConsumptionResource {
+ @POST
+ @Produces(MediaType.TEXT_PLAIN)
+ @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
+ public String postIt(@FormParam("text") String text) {
+ return text;
+ }
+
+
+ @POST
+ @Produces(MediaType.TEXT_PLAIN)
+ @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
+ @Path("encoding")
+ public String postEncoding(@Encoded @FormParam("text") String text) throws UnsupportedEncodingException {
+ return URLDecoder.decode(text, "UTF-8");
+ }
+
+ @PUT
+ @Produces(MediaType.TEXT_PLAIN)
+ @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
+ public String putIt(@FormParam("text") String text) {
+ return text;
+ }
+}
diff --git a/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/SecuredResource.java b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/SecuredResource.java
new file mode 100644
index 0000000..6137675
--- /dev/null
+++ b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/SecuredResource.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlettests;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+import javax.annotation.security.RolesAllowed;
+
+/**
+ * @author Petr Bouda
+ */
+@Path("admin")
+public class SecuredResource {
+
+ @GET
+ @RolesAllowed("admin")
+ public String secured() {
+ return "Secured";
+ }
+
+}
diff --git a/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/SuppressContentLengthFilter.java b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/SuppressContentLengthFilter.java
new file mode 100644
index 0000000..abb2ac6
--- /dev/null
+++ b/tests/integration/servlet-tests/src/main/java/org/glassfish/jersey/tests/integration/servlettests/SuppressContentLengthFilter.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlettests;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+
+/**
+ * JERSEY-2936 reproducer filter.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class SuppressContentLengthFilter implements Filter {
+
+ public static final String PARAMETER_NAME_SUPPRESS_CONTENT_LENGTH = "SuppressContentLength";
+
+ public void doFilter(final ServletRequest request, ServletResponse response, final FilterChain chain)
+ throws IOException, ServletException {
+ if (Boolean.parseBoolean(request.getParameter(PARAMETER_NAME_SUPPRESS_CONTENT_LENGTH))) {
+ response = new HttpServletResponseWrapper((HttpServletResponse) response) {
+ @Override
+ public void setContentLength(int len) {
+ // do not delegate to original ServletResponse -> response is NOT committed
+ }
+ };
+ }
+ chain.doFilter(request, response);
+ }
+
+ public void init(FilterConfig filterConfig) {
+ //NOOP
+ }
+
+ public void destroy() {
+ //NOOP
+ }
+
+}
diff --git a/tests/integration/servlet-tests/src/main/webapp/WEB-INF/web.xml b/tests/integration/servlet-tests/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..5d9d99e
--- /dev/null
+++ b/tests/integration/servlet-tests/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,160 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <!-- servlet for generic use (has all resources) -->
+ <servlet>
+ <servlet-name>testServlet</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.packages</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlettests</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>testServlet</servlet-name>
+ <url-pattern>/servlet/*</url-pattern>
+ </servlet-mapping>
+
+ <!-- filter to test NOT commited responses -->
+ <filter>
+ <filter-name>SuppressContentLengthFilter</filter-name>
+ <filter-class>org.glassfish.jersey.tests.integration.servlettests.SuppressContentLengthFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>SuppressContentLengthFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
+ <!-- filter for generic use (has all resources) -->
+ <filter>
+ <filter-name>testFilter</filter-name>
+ <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.packages</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlettests</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>testFilter</filter-name>
+ <url-pattern>/filter/*</url-pattern>
+ </filter-mapping>
+
+ <!-- filter context path -->
+ <filter>
+ <filter-name>testFilter2</filter-name>
+ <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlettests.FilterContextPathResource
+ org.glassfish.jersey.tests.integration.servlettests.FilterNoContextPathResource</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.servlet.filter.contextPath</param-name>
+ <param-value>/contextPathFilter/</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>testFilter2</filter-name>
+ <url-pattern>/contextPathFilter/*</url-pattern>
+ </filter-mapping>
+
+ <!-- forward on 404 -->
+ <filter>
+ <filter-name>testFilter3</filter-name>
+ <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlettests.FilterForwardOn404Resource</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.servlet.filter.forwardOn404</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>testFilter3</filter-name>
+ <url-pattern>/forwardingFilter/*</url-pattern>
+ </filter-mapping>
+
+ <!-- static content regex -->
+ <filter>
+ <filter-name>testFilter4</filter-name>
+ <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlettests.FilterStaticContentResource</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.servlet.filter.staticContentRegex</param-name>
+ <param-value>/staticContentFilter/.*\.jsp</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>testFilter4</filter-name>
+ <url-pattern>/staticContentFilter/*</url-pattern>
+ </filter-mapping>
+
+ <!-- form consumption -->
+ <filter>
+ <filter-name>FormConsumptionFilter</filter-name>
+ <filter-class>org.glassfish.jersey.tests.integration.servlettests.FormConsumptionFilter</filter-class>
+ </filter>
+ <servlet>
+ <servlet-name>FormConsumptionServlet</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlettests.FormConsumptionResource</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>FormConsumptionServlet</servlet-name>
+ <url-pattern>/form-consumption/*</url-pattern>
+ </servlet-mapping>
+ <filter-mapping>
+ <filter-name>FormConsumptionFilter</filter-name>
+ <url-pattern>/form-consumption/*</url-pattern>
+ </filter-mapping>
+
+ <!-- 404 -->
+ <filter>
+ <filter-name>custom404</filter-name>
+ <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.servlettests.CustomMediaTypeAnd404Resource</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.servlet.filter.contextPath</param-name>
+ <param-value>/custom404/</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>custom404</filter-name>
+ <url-pattern>/custom404/*</url-pattern>
+ </filter-mapping>
+</web-app>
diff --git a/tests/integration/servlet-tests/src/main/webapp/filter/index.jsp b/tests/integration/servlet-tests/src/main/webapp/filter/index.jsp
new file mode 100644
index 0000000..6017d94
--- /dev/null
+++ b/tests/integration/servlet-tests/src/main/webapp/filter/index.jsp
@@ -0,0 +1,27 @@
+<%--
+
+ Copyright (c) 2012, 2018 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
+
+--%>
+
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head>
+ <title></title>
+</head>
+<body>
+
+</body>
+</html>
diff --git a/tests/integration/servlet-tests/src/main/webapp/forwardingFilter/index.jsp b/tests/integration/servlet-tests/src/main/webapp/forwardingFilter/index.jsp
new file mode 100644
index 0000000..6017d94
--- /dev/null
+++ b/tests/integration/servlet-tests/src/main/webapp/forwardingFilter/index.jsp
@@ -0,0 +1,27 @@
+<%--
+
+ Copyright (c) 2012, 2018 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
+
+--%>
+
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head>
+ <title></title>
+</head>
+<body>
+
+</body>
+</html>
diff --git a/tests/integration/servlet-tests/src/main/webapp/staticContentFilter/index.jsp b/tests/integration/servlet-tests/src/main/webapp/staticContentFilter/index.jsp
new file mode 100644
index 0000000..6017d94
--- /dev/null
+++ b/tests/integration/servlet-tests/src/main/webapp/staticContentFilter/index.jsp
@@ -0,0 +1,27 @@
+<%--
+
+ Copyright (c) 2012, 2018 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
+
+--%>
+
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head>
+ <title></title>
+</head>
+<body>
+
+</body>
+</html>
diff --git a/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/CacheControlOn404ITCase.java b/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/CacheControlOn404ITCase.java
new file mode 100644
index 0000000..5697e39
--- /dev/null
+++ b/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/CacheControlOn404ITCase.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlettests;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test class related to issue JERSEY-1189.
+ * Confirms that if one sends an entity with the error status, the cache control
+ * headers don't get reset by the container.
+ *
+ * @author Martin Matula
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class CacheControlOn404ITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig(CacheControlOn404Resource.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void test404() throws Exception {
+ test404Impl(false);
+ }
+
+ @Test
+ public void test404SuppressContentLength() throws Exception {
+ test404Impl(true);
+ }
+
+ private void test404Impl(final boolean suppressContentLength) {
+ Response r = target("servlet").path("404")
+ .queryParam(SuppressContentLengthFilter.PARAMETER_NAME_SUPPRESS_CONTENT_LENGTH, suppressContentLength)
+ .request().get();
+ assertEquals(404, r.getStatus());
+ assertEquals("404 Not Found", r.readEntity(String.class));
+ final String[] values = r.getHeaderString(HttpHeaders.CACHE_CONTROL).split(",");
+ assertEquals(2, values.length);
+ assertEquals("no-transform", values[0].trim());
+ assertEquals("max-age=10", values[1].trim());
+ }
+
+}
diff --git a/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/Custom404MediaTypeITCase.java b/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/Custom404MediaTypeITCase.java
new file mode 100644
index 0000000..619d5ba
--- /dev/null
+++ b/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/Custom404MediaTypeITCase.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.servlettests;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Miroslav Fuksa
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class Custom404MediaTypeITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ // dummy resource config
+ return new ResourceConfig();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testCustom404() {
+ testCustom404Impl(false);
+ }
+
+ @Test
+ public void testCustom404WithEmtpyEntityString() {
+ testCustom404WithEmtpyEntityStringImpl(false);
+ }
+
+ @Test
+ public void testCustom404SuppressContentLength() {
+ testCustom404Impl(true);
+ }
+
+ @Test
+ public void testCustom404WithEmtpyEntityStringSuppressContentLength() {
+ testCustom404WithEmtpyEntityStringImpl(true);
+ }
+
+ private void testCustom404Impl(final boolean suppressContentLength) {
+ final Response response = target().path("custom404/resource404/content-type-entity")
+ .queryParam(SuppressContentLengthFilter.PARAMETER_NAME_SUPPRESS_CONTENT_LENGTH, suppressContentLength)
+ .request()
+ .get();
+ Assert.assertEquals(404, response.getStatus());
+ Assert.assertEquals("application/something", response.getMediaType().toString());
+ Assert.assertEquals("not found custom entity", response.readEntity(String.class));
+ }
+
+ private void testCustom404WithEmtpyEntityStringImpl(final boolean suppressContentLength) {
+ final Response response = target().path("custom404/resource404/content-type-empty-entity")
+ .queryParam(SuppressContentLengthFilter.PARAMETER_NAME_SUPPRESS_CONTENT_LENGTH, suppressContentLength)
+ .request().get();
+ Assert.assertEquals(404, response.getStatus());
+ Assert.assertEquals("application/something", response.getMediaType().toString());
+ Assert.assertEquals("", response.readEntity(String.class));
+ }
+
+}
diff --git a/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/DuplicateHeaderITCase.java b/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/DuplicateHeaderITCase.java
new file mode 100644
index 0000000..2856ecb
--- /dev/null
+++ b/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/DuplicateHeaderITCase.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlettests;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.UriBuilder;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class DuplicateHeaderITCase extends JerseyTest {
+ @Override
+ protected Application configure() {
+ // dummy resource config
+ return new ResourceConfig();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testDuplicateHeader() throws IOException {
+ testDuplicateHeaderImpl("contextPathFilter/contextPathResource");
+ testDuplicateHeaderImpl("servlet/contextPathResource");
+ }
+
+ private void testDuplicateHeaderImpl(final String path) throws IOException {
+ testDuplicateHeaderImpl(0, HttpURLConnection.HTTP_OK, path);
+ testDuplicateHeaderImpl(1, HttpURLConnection.HTTP_OK, path);
+ testDuplicateHeaderImpl(2, HttpURLConnection.HTTP_BAD_REQUEST, path);
+ }
+
+ private void testDuplicateHeaderImpl(final int headerCount, int expectedResponseCode, final String path)
+ throws IOException {
+ final String headerName = HttpHeaders.CONTENT_TYPE;
+ URL getUrl = UriBuilder.fromUri(getBaseUri()).path(path).build().toURL();
+ HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection();
+ try {
+ connection.setRequestMethod("GET");
+ for (int i = 0; i < headerCount; i++) {
+ connection.addRequestProperty(headerName, "N/A");
+ }
+ connection.connect();
+ assertEquals(path + " [" + headerName + ":" + headerCount + "x]", expectedResponseCode, connection.getResponseCode());
+ } finally {
+ connection.disconnect();
+ }
+ }
+
+}
diff --git a/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/FilterContextPathITCase.java b/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/FilterContextPathITCase.java
new file mode 100644
index 0000000..60e99d3
--- /dev/null
+++ b/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/FilterContextPathITCase.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlettests;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Martin Matula
+ */
+public class FilterContextPathITCase extends JerseyTest {
+ @Override
+ protected Application configure() {
+ // dummy resource config
+ return new ResourceConfig();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testContextPathResource() {
+ assertEquals("contextPathResource", target("contextPathFilter/contextPathResource").request().get(String.class));
+ }
+
+ @Test
+ public void testNoContextPathResource() {
+ assertEquals("filter/resource", target("filter/resource").request().get(String.class));
+ }
+
+ @Test
+ public void testOtherResourceUnreachable() {
+ Response r = target("filter/contextPathResource").request().get();
+ assertEquals(404, r.getStatus());
+ }
+}
diff --git a/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/FormConsumptionITCase.java b/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/FormConsumptionITCase.java
new file mode 100644
index 0000000..af7a5f9
--- /dev/null
+++ b/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/FormConsumptionITCase.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlettests;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Form;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Martin Matula
+ */
+public class FormConsumptionITCase extends JerseyTest {
+ @Override
+ protected Application configure() {
+ // dummy resource config
+ return new ResourceConfig();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testPut() {
+ Form form = new Form();
+ form.param("text", "this is a test");
+ String result = target("form-consumption/form-consumption").request().put(Entity.form(form), String.class);
+ assertEquals(form.asMap().getFirst("text"), result);
+ }
+
+ @Test
+ public void testPost() {
+ Form form = new Form();
+ form.param("text", "this is a test");
+ String result = target("form-consumption/form-consumption").request().post(Entity.form(form), String.class);
+ assertEquals(form.asMap().getFirst("text"), result);
+ }
+
+ @Test
+ public void testPostWithEncoding() {
+ Form form = new Form();
+ form.param("text", "this is an encoding test +-*/=");
+ String result = target("form-consumption/form-consumption/encoding").request().post(Entity.form(form), String.class);
+ assertEquals(form.asMap().getFirst("text"), result);
+ }
+}
diff --git a/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/ForwardOn404ITCase.java b/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/ForwardOn404ITCase.java
new file mode 100644
index 0000000..1bc99e9
--- /dev/null
+++ b/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/ForwardOn404ITCase.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlettests;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Martin Matula
+ */
+public class ForwardOn404ITCase extends JerseyTest {
+ @Override
+ protected Application configure() {
+ // dummy resource config
+ return new ResourceConfig();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testResourceReachable() {
+ assertEquals("forwardingFilter/resource", target("forwardingFilter/resource").request().get(String.class));
+ }
+
+ @Test
+ public void testIndexReachable() {
+ Response r = target("forwardingFilter/index.jsp").request().get();
+ assertEquals(200, r.getStatus());
+ }
+}
diff --git a/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/InvalidRequestUriITCase.java b/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/InvalidRequestUriITCase.java
new file mode 100644
index 0000000..db67e95
--- /dev/null
+++ b/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/InvalidRequestUriITCase.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlettests;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test class related to issue JERSEY-2680.
+ *
+ * @author Michal Gajdos
+ */
+public class InvalidRequestUriITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ return new ResourceConfig();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testInvalidRequestUriFilter() throws Exception {
+ invalidRequestUri("filter");
+ }
+
+ @Test
+ public void testInvalidRequestUriServlet() throws Exception {
+ invalidRequestUri("servlet");
+ }
+
+ public void invalidRequestUri(final String path) throws Exception {
+ final URL url = new URL(getBaseUri().toString() + path + "/resource{");
+ final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Accept", "text/plain");
+ connection.connect();
+
+ assertEquals(400, connection.getResponseCode());
+ }
+}
diff --git a/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/RolesAllowedFilterITCase.java b/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/RolesAllowedFilterITCase.java
new file mode 100644
index 0000000..a22f0c8
--- /dev/null
+++ b/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/RolesAllowedFilterITCase.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.servlettests;
+
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Petr Bouda
+ */
+public class RolesAllowedFilterITCase extends JerseyTest {
+
+ @Override
+ protected ResourceConfig configure() {
+ // Dummy resource config
+ return new ResourceConfig();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void test403() throws Exception {
+ Response r = target("servlet/admin").request().get();
+ assertEquals(403, r.getStatus());
+ }
+}
diff --git a/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/StaticContentRegexITCase.java b/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/StaticContentRegexITCase.java
new file mode 100644
index 0000000..70647e2
--- /dev/null
+++ b/tests/integration/servlet-tests/src/test/java/org/glassfish/jersey/tests/integration/servlettests/StaticContentRegexITCase.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2012, 2018 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.integration.servlettests;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Martin Matula
+ */
+public class StaticContentRegexITCase extends JerseyTest {
+ @Override
+ protected Application configure() {
+ // dummy resource config
+ return new ResourceConfig();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testIndexUnreachable() {
+ Response r = target("filter").path("index.jsp").request().get();
+ assertEquals(404, r.getStatus());
+ }
+
+ @Test
+ public void testIndexReachable() {
+ Response r = target("staticContentFilter/index.jsp").request().get();
+ assertEquals(200, r.getStatus());
+ }
+
+ @Test
+ public void testResourceReachable() {
+ Response r = target("staticContentFilter/resource").request().get();
+ assertEquals(200, r.getStatus());
+ assertEquals("staticContentFilter/resource", r.readEntity(String.class));
+ }
+}
diff --git a/tests/integration/sonar-test/pom.xml b/tests/integration/sonar-test/pom.xml
new file mode 100644
index 0000000..b897be8
--- /dev/null
+++ b/tests/integration/sonar-test/pom.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>sonar-test</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-sonar-test</name>
+
+ <description>
+ The purpose of this module is to provide an ability to check whether Sonar's code coverage includes
+ lines of code executed from an externally executed JVM, Jetty web server in this case.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tests/integration/sonar-test/src/main/java/org/glassfish/jersey/tests/integration/sonar/TestApplication.java b/tests/integration/sonar-test/src/main/java/org/glassfish/jersey/tests/integration/sonar/TestApplication.java
new file mode 100644
index 0000000..d5b67e7
--- /dev/null
+++ b/tests/integration/sonar-test/src/main/java/org/glassfish/jersey/tests/integration/sonar/TestApplication.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.sonar;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * Jersey application for code coverage testing.
+ *
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+@ApplicationPath("/")
+public class TestApplication extends ResourceConfig {
+
+ public TestApplication() {
+ register(TestResource.class);
+ }
+}
diff --git a/tests/integration/sonar-test/src/main/java/org/glassfish/jersey/tests/integration/sonar/TestResource.java b/tests/integration/sonar-test/src/main/java/org/glassfish/jersey/tests/integration/sonar/TestResource.java
new file mode 100644
index 0000000..b8bfaab
--- /dev/null
+++ b/tests/integration/sonar-test/src/main/java/org/glassfish/jersey/tests/integration/sonar/TestResource.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.sonar;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.glassfish.jersey.internal.sonar.SonarJerseyCommon;
+import org.glassfish.jersey.server.internal.sonar.SonarJerseyServer;
+
+/**
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+@Path("/")
+@Produces("text/plain")
+public class TestResource {
+
+ @GET
+ @Path("test")
+ public String helloServer() {
+ return new SonarJerseyCommon().integrationServerJvm() + " " + new SonarJerseyServer().integrationServerJvm();
+ }
+
+}
diff --git a/tests/integration/sonar-test/src/main/webapp/WEB-INF/web.xml b/tests/integration/sonar-test/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..ab6014a
--- /dev/null
+++ b/tests/integration/sonar-test/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2015, 2018 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
+
+-->
+
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>jersey</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.glassfish.jersey.tests.integration.sonar.TestApplication</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>jersey</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tests/integration/sonar-test/src/test/java/org/glassfish/jersey/tests/integration/sonar/JerseySonarITCase.java b/tests/integration/sonar-test/src/test/java/org/glassfish/jersey/tests/integration/sonar/JerseySonarITCase.java
new file mode 100644
index 0000000..1c9f078
--- /dev/null
+++ b/tests/integration/sonar-test/src/test/java/org/glassfish/jersey/tests/integration/sonar/JerseySonarITCase.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.sonar;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.internal.sonar.SonarJerseyCommon;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.internal.sonar.SonarJerseyServer;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Stepan Vavra (stepan.vavra at oracle.com)
+ */
+public class JerseySonarITCase extends JerseyTest {
+
+ @Test
+ public void testIntegrationServerJvm() {
+ final String string = target("test").request().get(String.class);
+
+ Assert.assertEquals("common server jvm server server jvm", string);
+ }
+
+ @Test
+ public void testIntegrationTestJvm() {
+ final String string = new SonarJerseyCommon().integrationTestJvm() + " " + new SonarJerseyServer().integrationTestJvm();
+
+ Assert.assertEquals("common test jvm server test jvm", string);
+ }
+
+ @Override
+ protected Application configure() {
+ return new ResourceConfig(TestApplication.class);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+}
diff --git a/tests/integration/spring4/README.txt b/tests/integration/spring4/README.txt
new file mode 100644
index 0000000..9a105f7
--- /dev/null
+++ b/tests/integration/spring4/README.txt
@@ -0,0 +1,30 @@
+
+tests
+=====
+
+Tests are located in jersey-spring-test module.
+The module contains a test webapp and test code.
+The tests can be run in Jersey test container or an external container.
+
+- Running tests in Jersey test container
+ mvn clean test
+
+- Running tests in an external container
+ build the test app
+ deploy to an external container
+ configure container connection info in jersey-spring-test/pom.xml, if needed
+ run tests in integration test mode:
+ mvn -Pit verify
+
+- Running tests in embedded Jetty instance
+ build the test app
+ deploy to Jetty:
+ mvn -Pjetty jetty:run
+ run tests in integration test mode in another console session:
+ mvn -Pit verify
+
+test class naming conventions
+- *ITTest.java: run in unit and IT test mode
+- *Test.java: run as unit tests
+- *IT.java: run as IT tests
+
diff --git a/tests/integration/spring4/pom.xml b/tests/integration/spring4/pom.xml
new file mode 100644
index 0000000..c5e93ab
--- /dev/null
+++ b/tests/integration/spring4/pom.xml
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2012, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.26-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>spring4</artifactId>
+
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-spring4</name>
+
+ <description>
+ Jersey tests for Spring 4 integration
+ </description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${servlet2.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.ext</groupId>
+ <artifactId>jersey-spring4</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework</groupId>
+ <artifactId>jersey-test-framework-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ <configuration>
+ <webApp>
+ <contextPath>/</contextPath>
+ <webInfIncludeJarPattern>.*\.jar$</webInfIncludeJarPattern>
+ </webApp>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>delayed-strategy-skip-test</id>
+ <activation>
+ <property>
+ <name>org.glassfish.jersey.injection.manager.strategy</name>
+ <value>delayed</value>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <configuration>
+ <skipTests>true</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
diff --git a/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/AccountJerseyResource.java b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/AccountJerseyResource.java
new file mode 100644
index 0000000..80af7bb
--- /dev/null
+++ b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/AccountJerseyResource.java
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import java.math.BigDecimal;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.MediaType;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.servlet.http.HttpServletRequest;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+
+/**
+ * Jersey managed JAX-RS resource for testing jersey-spring.
+ *
+ * @author Marko Asplund (marko.asplund at yahoo.com)
+ */
+@Path("/jersey/account")
+public class AccountJerseyResource {
+
+ @Inject
+ @Named("AccountService-singleton")
+ private AccountService accountServiceInject;
+
+ @Autowired
+ @Qualifier("AccountService-singleton")
+ private AccountService accountServiceAutowired;
+
+ @Inject
+ @Named("AccountService-request-1")
+ private AccountService accountServiceRequest1;
+
+ @Autowired
+ @Qualifier("AccountService-request-1")
+ private AccountService accountServiceRequest2;
+
+ @Autowired
+ @Qualifier("AccountService-prototype-1")
+ private AccountService accountServicePrototype1;
+
+ @Autowired
+ @Qualifier("AccountService-prototype-1")
+ private AccountService accountServicePrototype2;
+
+ @Autowired
+ private HttpServletRequest httpServletRequest;
+
+ @Inject
+ private HK2ServiceSingleton hk2Singleton;
+
+ @Inject
+ private HK2ServiceRequestScoped hk2RequestScoped;
+
+ @Inject
+ private HK2ServicePerLookup hk2PerLookup;
+
+ private String message = "n/a";
+
+ // resource methods for testing resource class scope
+ @GET
+ @Path("message")
+ public String getMessage() {
+ return message;
+ }
+
+ @PUT
+ @Path("message")
+ @Consumes(MediaType.TEXT_PLAIN)
+ public String setMessage(final String message) {
+ this.message = message;
+ return message;
+ }
+
+ // JERSEY-2506 FIX VERIFICATION
+ @GET
+ @Path("server")
+ public String verifyServletRequestInjection() {
+ return "PASSED: " + httpServletRequest.getServerName();
+ }
+
+ @GET
+ @Path("singleton/server")
+ public String verifyServletRequestInjectionIntoSingleton() {
+ return accountServiceInject.verifyServletRequestInjection();
+ }
+
+ @GET
+ @Path("singleton/autowired/server")
+ public String verifyServletRequestInjectionIntoAutowiredSingleton() {
+ return accountServiceAutowired.verifyServletRequestInjection();
+ }
+
+ @GET
+ @Path("request/server")
+ public String verifyServletRequestInjectionIntoRequestScopedBean() {
+ return accountServiceRequest1.verifyServletRequestInjection();
+ }
+
+ @GET
+ @Path("prototype/server")
+ public String verifyServletRequestInjectionIntoPrototypeScopedBean() {
+ return accountServicePrototype1.verifyServletRequestInjection();
+ }
+
+ // resource methods for testing singleton scoped beans
+ @GET
+ @Path("singleton/inject/{accountId}")
+ public BigDecimal getAccountBalanceSingletonInject(@PathParam("accountId") final String accountId) {
+ return accountServiceInject.getAccountBalance(accountId);
+ }
+
+ @GET
+ @Path("singleton/autowired/{accountId}")
+ public BigDecimal getAccountBalanceSingletonAutowired(@PathParam("accountId") final String accountId) {
+ return accountServiceAutowired.getAccountBalance(accountId);
+ }
+
+ @PUT
+ @Path("singleton/{accountId}")
+ @Consumes(MediaType.TEXT_PLAIN)
+ public void setAccountBalanceSingleton(@PathParam("accountId") final String accountId, final String balance) {
+ accountServiceInject.setAccountBalance(accountId, new BigDecimal(balance));
+ }
+
+ // resource methods for testing request scoped beans
+ @PUT
+ @Path("request/{accountId}")
+ @Consumes(MediaType.TEXT_PLAIN)
+ public BigDecimal setAccountBalanceRequest(@PathParam("accountId") final String accountId, final String balance) {
+ accountServiceRequest1.setAccountBalance(accountId, new BigDecimal(balance));
+ return accountServiceRequest2.getAccountBalance(accountId);
+ }
+
+ // resource methods for testing prototype scoped beans
+ @PUT
+ @Path("prototype/{accountId}")
+ @Consumes(MediaType.TEXT_PLAIN)
+ public BigDecimal setAccountBalancePrototype(@PathParam("accountId") final String accountId, final String balance) {
+ accountServicePrototype1.setAccountBalance(accountId, new BigDecimal(balance));
+ return accountServicePrototype2.getAccountBalance(accountId);
+ }
+}
diff --git a/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/AccountService.java b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/AccountService.java
new file mode 100644
index 0000000..851e215
--- /dev/null
+++ b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/AccountService.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import java.math.BigDecimal;
+
+/**
+ * Simple account service to testify injection into different scopes.
+ *
+ * @author Marko Asplund (marko.asplund at yahoo.com)
+ */
+public interface AccountService {
+
+ void setAccountBalance(String accountId, BigDecimal balance);
+
+ BigDecimal getAccountBalance(String accountId);
+
+ String verifyServletRequestInjection();
+}
diff --git a/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/AccountServiceImpl.java b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/AccountServiceImpl.java
new file mode 100644
index 0000000..8b99e62
--- /dev/null
+++ b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/AccountServiceImpl.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * AccountService implementation.
+ *
+ * @author Marko Asplund (marko.asplund at yahoo.com)
+ */
+public class AccountServiceImpl implements AccountService {
+
+ private Map<String, BigDecimal> accounts = new HashMap<>();
+ private BigDecimal defaultAccountBalance;
+
+ // JERSEY-2506 FIX VERIFICATION
+ @Autowired
+ private HttpServletRequest httpServletRequest;
+
+ @Override
+ public void setAccountBalance(String accountId, BigDecimal balance) {
+ accounts.put(accountId, balance);
+ }
+
+ @Override
+ public BigDecimal getAccountBalance(String accountId) {
+ BigDecimal balance = accounts.get(accountId);
+ if (balance == null) {
+ return defaultAccountBalance;
+ }
+ return balance;
+ }
+
+ public void setDefaultAccountBalance(String defaultAccountBalance) {
+ this.defaultAccountBalance = new BigDecimal(defaultAccountBalance);
+ }
+
+ public String verifyServletRequestInjection() {
+ return "PASSED: " + httpServletRequest.getServerName();
+ }
+
+}
diff --git a/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/AccountSpringResource.java b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/AccountSpringResource.java
new file mode 100644
index 0000000..6a6e6c2
--- /dev/null
+++ b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/AccountSpringResource.java
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import java.math.BigDecimal;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.MediaType;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.servlet.http.HttpServletRequest;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Component;
+
+/**
+ * Spring managed JAX-RS resource for testing jersey-spring.
+ *
+ * @author Marko Asplund (marko.asplund at yahoo.com)
+ */
+@Path("/spring/account")
+@Component
+public class AccountSpringResource {
+
+ @Inject
+ @Named("AccountService-singleton")
+ private AccountService accountServiceInject;
+
+ @Autowired
+ @Qualifier("AccountService-singleton")
+ private AccountService accountServiceAutowired;
+
+ @Inject
+ @Named("AccountService-request-1")
+ private AccountService accountServiceRequest1;
+
+ @Autowired
+ @Qualifier("AccountService-request-1")
+ private AccountService accountServiceRequest2;
+
+ @Autowired
+ @Qualifier("AccountService-prototype-1")
+ private AccountService accountServicePrototype1;
+
+ @Autowired
+ @Qualifier("AccountService-prototype-1")
+ private AccountService accountServicePrototype2;
+
+ @Autowired
+ private HttpServletRequest httpServletRequest;
+
+ @Inject
+ private HK2ServiceSingleton hk2Singleton;
+
+ @Inject
+ private HK2ServiceRequestScoped hk2RequestScoped;
+
+ @Inject
+ private HK2ServicePerLookup hk2PerLookup;
+
+ private String message = "n/a";
+
+ // resource methods for testing resource class scope
+ @GET
+ @Path("message")
+ public String getMessage() {
+ return message;
+ }
+
+ @PUT
+ @Path("message")
+ @Consumes(MediaType.TEXT_PLAIN)
+ public String setMessage(String message) {
+ this.message = message;
+ return message;
+ }
+
+ // JERSEY-2506 FIX VERIFICATION
+ @GET
+ @Path("server")
+ public String verifyServletRequestInjection() {
+ return "PASSED: " + httpServletRequest.getServerName();
+ }
+
+ @GET
+ @Path("singleton/server")
+ public String verifyServletRequestInjectionIntoSingleton() {
+ return accountServiceInject.verifyServletRequestInjection();
+ }
+
+ @GET
+ @Path("singleton/autowired/server")
+ public String verifyServletRequestInjectionIntoAutowiredSingleton() {
+ return accountServiceAutowired.verifyServletRequestInjection();
+ }
+
+ @GET
+ @Path("request/server")
+ public String verifyServletRequestInjectionIntoRequestScopedBean() {
+ return accountServiceRequest1.verifyServletRequestInjection();
+ }
+
+ @GET
+ @Path("prototype/server")
+ public String verifyServletRequestInjectionIntoPrototypeScopedBean() {
+ return accountServicePrototype1.verifyServletRequestInjection();
+ }
+
+ // resource methods for testing singleton scoped beans
+ @GET
+ @Path("singleton/inject/{accountId}")
+ public BigDecimal getAccountBalanceSingletonInject(@PathParam("accountId") String accountId) {
+ return accountServiceInject.getAccountBalance(accountId);
+ }
+
+ @GET
+ @Path("singleton/autowired/{accountId}")
+ public BigDecimal getAccountBalanceSingletonAutowired(@PathParam("accountId") String accountId) {
+ return accountServiceAutowired.getAccountBalance(accountId);
+ }
+
+ @PUT
+ @Path("singleton/{accountId}")
+ @Consumes(MediaType.TEXT_PLAIN)
+ public void setAccountBalanceSingleton(@PathParam("accountId") String accountId, String balance) {
+ accountServiceInject.setAccountBalance(accountId, new BigDecimal(balance));
+ }
+
+ // resource methods for testing request scoped beans
+ @PUT
+ @Path("request/{accountId}")
+ @Consumes(MediaType.TEXT_PLAIN)
+ public BigDecimal setAccountBalanceRequest(@PathParam("accountId") String accountId, String balance) {
+ accountServiceRequest1.setAccountBalance(accountId, new BigDecimal(balance));
+ return accountServiceRequest2.getAccountBalance(accountId);
+ }
+
+ // resource methods for testing prototype scoped beans
+ @PUT
+ @Path("prototype/{accountId}")
+ @Consumes(MediaType.TEXT_PLAIN)
+ public BigDecimal setAccountBalancePrototype(@PathParam("accountId") String accountId, String balance) {
+ accountServicePrototype1.setAccountBalance(accountId, new BigDecimal(balance));
+ return accountServicePrototype2.getAccountBalance(accountId);
+ }
+
+}
diff --git a/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/ControllerResource.java b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/ControllerResource.java
new file mode 100644
index 0000000..7714c22
--- /dev/null
+++ b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/ControllerResource.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.MediaType;
+
+import org.springframework.stereotype.Controller;
+
+/**
+ * @author Konrad Garus (konrad.garus at gmail.com)
+ */
+@Controller
+@Path("/spring/controller")
+public class ControllerResource {
+
+ private String message;
+
+ @PUT
+ @Path("message")
+ @Consumes(MediaType.TEXT_PLAIN)
+ public String setMessage(final String message) {
+ this.message = message;
+ return message;
+ }
+
+ @GET
+ @Path("message")
+ public String getMessage() {
+ return message;
+ }
+}
diff --git a/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/Endpoint.java b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/Endpoint.java
new file mode 100644
index 0000000..da9f170
--- /dev/null
+++ b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/Endpoint.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.springframework.stereotype.Component;
+
+/**
+ * @author Konrad Garus (konrad.garus at gmail.com)
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+@Component
+public @interface Endpoint {
+
+}
diff --git a/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/EndpointResource.java b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/EndpointResource.java
new file mode 100644
index 0000000..9af0858
--- /dev/null
+++ b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/EndpointResource.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.MediaType;
+
+/**
+ * @author Konrad Garus (konrad.garus at gmail.com)
+ */
+@Endpoint
+@Path("/spring/endpoint")
+public class EndpointResource {
+
+ private String message;
+
+ @PUT
+ @Path("message")
+ @Consumes(MediaType.TEXT_PLAIN)
+ public String setMessage(final String message) {
+ this.message = message;
+ return message;
+ }
+
+ @GET
+ @Path("message")
+ public String getMessage() {
+ return message;
+ }
+}
diff --git a/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/HK2ServicePerLookup.java b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/HK2ServicePerLookup.java
new file mode 100644
index 0000000..ff689c6
--- /dev/null
+++ b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/HK2ServicePerLookup.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+/**
+ * Type to be handled as HK2 per-lookup bean.
+ *
+ * @author Marko Asplund (marko.asplund at yahoo.com)
+ */
+public class HK2ServicePerLookup {
+}
diff --git a/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/HK2ServiceRequestScoped.java b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/HK2ServiceRequestScoped.java
new file mode 100644
index 0000000..da45aea
--- /dev/null
+++ b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/HK2ServiceRequestScoped.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+/**
+ * Type to be handled as HK2 request scoped bean.
+ *
+ * @author Marko Asplund (marko.asplund at yahoo.com)
+ */
+public class HK2ServiceRequestScoped {
+}
diff --git a/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/HK2ServiceSingleton.java b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/HK2ServiceSingleton.java
new file mode 100644
index 0000000..a7b8fa8
--- /dev/null
+++ b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/HK2ServiceSingleton.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+/**
+ * Type to be handled as HK2 singleton.
+ *
+ * @author Marko Asplund (marko.asplund at yahoo.com)
+ */
+public class HK2ServiceSingleton {
+}
diff --git a/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/MyApplication.java b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/MyApplication.java
new file mode 100644
index 0000000..568f30f
--- /dev/null
+++ b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/MyApplication.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import javax.ws.rs.core.Application;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.glassfish.jersey.internal.inject.AbstractBinder;
+import org.glassfish.jersey.internal.inject.Binder;
+import org.glassfish.jersey.internal.inject.InjectionManager;
+import org.glassfish.jersey.internal.inject.PerLookup;
+import org.glassfish.jersey.process.internal.RequestScoped;
+
+/**
+ * JAX-RS application class for configuring injectable services in HK2 registry for testing purposes.
+ *
+ * @author Marko Asplund (marko.asplund at yahoo.com)
+ */
+public class MyApplication extends Application {
+
+ @Inject
+ public MyApplication(final InjectionManager injectionManager) {
+ Binder binder = new AbstractBinder() {
+ @Override
+ protected void configure() {
+ bindAsContract(HK2ServiceSingleton.class).in(Singleton.class);
+ bindAsContract(HK2ServiceRequestScoped.class).in(RequestScoped.class);
+ bindAsContract(HK2ServicePerLookup.class).in(PerLookup.class);
+ }
+ };
+
+ injectionManager.register(binder);
+ }
+}
diff --git a/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/RepositoryResource.java b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/RepositoryResource.java
new file mode 100644
index 0000000..8c3b563
--- /dev/null
+++ b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/RepositoryResource.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.MediaType;
+
+import org.springframework.stereotype.Repository;
+
+/**
+ * @author Konrad Garus (konrad.garus at gmail.com)
+ */
+@Repository
+@Path("/spring/repository")
+public class RepositoryResource {
+
+ private String message;
+
+ @PUT
+ @Path("message")
+ @Consumes(MediaType.TEXT_PLAIN)
+ public String setMessage(final String message) {
+ this.message = message;
+ return message;
+ }
+
+ @GET
+ @Path("message")
+ public String getMessage() {
+ return message;
+ }
+}
diff --git a/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/ServiceResource.java b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/ServiceResource.java
new file mode 100644
index 0000000..3516dcf
--- /dev/null
+++ b/tests/integration/spring4/src/main/java/org/glassfish/jersey/server/spring/test/ServiceResource.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.MediaType;
+
+import org.springframework.stereotype.Service;
+
+/**
+ * @author Konrad Garus (konrad.garus at gmail.com)
+ */
+@Service
+@Path("/spring/service")
+public class ServiceResource {
+
+ private String message;
+
+ @PUT
+ @Path("message")
+ @Consumes(MediaType.TEXT_PLAIN)
+ public String setMessage(final String message) {
+ this.message = message;
+ return message;
+ }
+
+ @GET
+ @Path("message")
+ public String getMessage() {
+ return message;
+ }
+}
diff --git a/tests/integration/spring4/src/main/resources/applicationContext.xml b/tests/integration/spring4/src/main/resources/applicationContext.xml
new file mode 100644
index 0000000..0cc9127
--- /dev/null
+++ b/tests/integration/spring4/src/main/resources/applicationContext.xml
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2012, 2018 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
+
+-->
+
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop
+ http://www.springframework.org/schema/aop/spring-aop.xsd">
+
+ <!--<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>-->
+ <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor">
+ <property name="autowiredAnnotationTypes">
+ <set>
+ <value>org.springframework.beans.factory.annotation.Autowired</value>
+ <value>org.springframework.beans.factory.annotation.Value</value>
+ </set>
+ </property>
+ </bean>
+
+ <bean name="AccountService-singleton" class="org.glassfish.jersey.server.spring.test.AccountServiceImpl" />
+
+ <bean name="AccountService-request-1" class="org.glassfish.jersey.server.spring.test.AccountServiceImpl" scope="request">
+ <aop:scoped-proxy/>
+ </bean>
+
+ <bean name="AccountService-request-2" class="org.glassfish.jersey.server.spring.test.AccountServiceImpl" scope="request"/>
+
+ <bean name="AccountService-prototype-1" class="org.glassfish.jersey.server.spring.test.AccountServiceImpl" scope="prototype">
+ <property name="defaultAccountBalance" value="987.65"/>
+ </bean>
+
+ <bean name="AccountService-prototype-2" class="org.glassfish.jersey.server.spring.test.AccountServiceImpl" scope="prototype"/>
+
+ <!-- Spring managed JAX-RS resources -->
+ <bean class="org.glassfish.jersey.server.spring.test.AccountSpringResource"/>
+
+ <bean class="org.glassfish.jersey.server.spring.test.ServiceResource"/>
+
+ <bean class="org.glassfish.jersey.server.spring.test.ControllerResource"/>
+
+ <bean class="org.glassfish.jersey.server.spring.test.RepositoryResource"/>
+
+ <bean class="org.glassfish.jersey.server.spring.test.EndpointResource"/>
+
+</beans>
diff --git a/tests/integration/spring4/src/main/webapp/WEB-INF/web.xml b/tests/integration/spring4/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..c3cff9d
--- /dev/null
+++ b/tests/integration/spring4/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
+
+ <module-name>jersey-spring-test</module-name>
+
+ <!-- use this to explicitly configure Spring -->
+ <!--
+ <listener>
+ <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+ </listener>
+ <listener>
+ <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
+ </listener>
+ <context-param>
+ <param-name>contextConfigLocation</param-name>
+ <param-value>classpath:/applicationContext.xml</param-value>
+ </context-param>
+ -->
+
+ <servlet>
+ <servlet-name>org.glassfish.jersey.server.spring.test.MyApplication</servlet-name>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>org.glassfish.jersey.server.spring.test.MyApplication</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+
+
+</web-app>
+
diff --git a/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/AccountResourceITCase.java b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/AccountResourceITCase.java
new file mode 100644
index 0000000..c9f9f17
--- /dev/null
+++ b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/AccountResourceITCase.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+import org.glassfish.jersey.test.JerseyTest;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class AccountResourceITCase extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new Application();
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ final String r = target().path("/jersey/account/message").request().get(String.class);
+ assertEquals(r, "n/a");
+ }
+}
diff --git a/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/AccountResourceTestBase.java b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/AccountResourceTestBase.java
new file mode 100644
index 0000000..5c7774b
--- /dev/null
+++ b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/AccountResourceTestBase.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import java.math.BigDecimal;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+
+import org.junit.Test;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Base class for JAX-RS resource tests.
+ *
+ * @author Marko Asplund (marko.asplund at yahoo.com)
+ */
+public abstract class AccountResourceTestBase extends ResourceTestBase {
+
+ // test singleton scoped Spring bean injection using @Inject + @Autowired
+ @Test
+ public void testSingletonScopedSpringService() {
+ final BigDecimal newBalance = new BigDecimal(Math.random());
+ final WebTarget t = target(getResourceFullPath());
+
+ t.path("/singleton/xyz123").request().put(Entity.entity(newBalance.toString(), MediaType.TEXT_PLAIN_TYPE));
+ final BigDecimal balance = t.path("/singleton/autowired/xyz123").request().get(BigDecimal.class);
+ assertEquals(newBalance, balance);
+ }
+
+ @Test
+ public void testRequestScopedSpringService() {
+ final BigDecimal newBalance = new BigDecimal(Math.random());
+ final WebTarget t = target(getResourceFullPath());
+ final BigDecimal balance = t.path("request/abc456").request().put(Entity.text(newBalance), BigDecimal.class);
+ assertEquals(newBalance, balance);
+ }
+
+ @Test
+ public void testPrototypeScopedSpringService() {
+ final BigDecimal newBalance = new BigDecimal(Math.random());
+ final WebTarget t = target(getResourceFullPath());
+ final BigDecimal balance = t.path("prototype/abc456").request().put(Entity.text(newBalance), BigDecimal.class);
+ assertEquals(new BigDecimal("987.65"), balance);
+ }
+
+ @Test
+ public void testServletInjection() {
+ final WebTarget t = target(getResourceFullPath());
+
+ String server = t.path("server").request().get(String.class);
+ assertThat(server, startsWith("PASSED: "));
+
+ server = t.path("singleton/server").request().get(String.class);
+ assertThat(server, startsWith("PASSED: "));
+
+ server = t.path("singleton/autowired/server").request().get(String.class);
+ assertThat(server, startsWith("PASSED: "));
+
+ server = t.path("request/server").request().get(String.class);
+ assertThat(server, startsWith("PASSED: "));
+
+ server = t.path("prototype/server").request().get(String.class);
+ assertThat(server, startsWith("PASSED: "));
+ }
+}
diff --git a/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/JerseyManagedITCase.java b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/JerseyManagedITCase.java
new file mode 100644
index 0000000..4815e0e
--- /dev/null
+++ b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/JerseyManagedITCase.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for Jersey managed JAX-RS resources.
+ *
+ * @author Marko Asplund (marko.asplund at yahoo.com)
+ */
+public class JerseyManagedITCase extends AccountResourceTestBase {
+
+ @Override
+ protected ResourceConfig configure(final ResourceConfig rc) {
+ return rc.register(AccountJerseyResource.class);
+ }
+
+ @Override
+ protected String getResourcePath() {
+ return "/jersey/account";
+ }
+
+ @Test
+ public void testResourceScope() {
+ final WebTarget t = target(getResourceFullPath());
+ final String message = "hello, world";
+ final String echo = t.path("message").request().put(Entity.text(message), String.class);
+ assertEquals(message, echo);
+ final String msg = t.path("message").request().get(String.class);
+ assertEquals("n/a", msg);
+ }
+
+}
diff --git a/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/ResourceTestBase.java b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/ResourceTestBase.java
new file mode 100644
index 0000000..c460d7e
--- /dev/null
+++ b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/ResourceTestBase.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import javax.ws.rs.core.Application;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.spring.SpringLifecycleListener;
+import org.glassfish.jersey.server.spring.scope.RequestContextFilter;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.TestProperties;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+/**
+ * Base class for JAX-RS resource tests.
+ *
+ * @author Marko Asplund (marko.asplund at yahoo.com)
+ */
+public abstract class ResourceTestBase extends JerseyTest {
+
+ private static final String TEST_WEBAPP_CONTEXT_PATH = "jersey.spring.test.contextPath";
+ private static final String TEST_CONTAINER_FACTORY_EXTERNAL = "org.glassfish.jersey.test.external"
+ + ".ExternalTestContainerFactory";
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ @Override
+ protected Application configure() {
+ final ResourceConfig rc = new ResourceConfig()
+ .register(SpringLifecycleListener.class)
+ .register(RequestContextFilter.class);
+ TestUtil.registerHK2Services(rc);
+ rc.property("contextConfigLocation", "classpath:applicationContext.xml");
+ return configure(rc);
+ }
+
+ protected abstract ResourceConfig configure(ResourceConfig rc);
+
+ protected abstract String getResourcePath();
+
+ protected String getResourceFullPath() {
+ final String containerFactory = System.getProperty(TestProperties.CONTAINER_FACTORY);
+ if (TEST_CONTAINER_FACTORY_EXTERNAL.equals(containerFactory)) {
+ return System.getProperty(TEST_WEBAPP_CONTEXT_PATH) + getResourcePath();
+ }
+ return getResourcePath();
+ }
+}
diff --git a/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/SpringManagedControllerITCase.java b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/SpringManagedControllerITCase.java
new file mode 100644
index 0000000..cbe42c6
--- /dev/null
+++ b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/SpringManagedControllerITCase.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for Spring managed JAX-RS resources with @Controller archetype.
+ *
+ * @author Konrad Garus (konrad.garus at gmail.com)
+ */
+public class SpringManagedControllerITCase extends ResourceTestBase {
+
+ @Override
+ protected ResourceConfig configure(final ResourceConfig rc) {
+ return rc.register(ControllerResource.class);
+ }
+
+ @Override
+ protected String getResourcePath() {
+ return "/spring/controller";
+ }
+
+ @Test
+ public void testResourceScope() {
+ final WebTarget t = target(getResourceFullPath());
+ final String message = "hello, world";
+ final String echo = t.path("message").request().put(Entity.text(message), String.class);
+ assertEquals(message, echo);
+ final String msg = t.path("message").request().get(String.class);
+ assertEquals(message, msg);
+ }
+}
diff --git a/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/SpringManagedEndpointITCase.java b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/SpringManagedEndpointITCase.java
new file mode 100644
index 0000000..fe96090
--- /dev/null
+++ b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/SpringManagedEndpointITCase.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for Spring managed JAX-RS resources with custom composite
+ * annotation that derives from @Component.
+ *
+ * @author Konrad Garus (konrad.garus at gmail.com)
+ */
+public class SpringManagedEndpointITCase extends ResourceTestBase {
+
+ @Override
+ protected ResourceConfig configure(final ResourceConfig rc) {
+ return rc.register(EndpointResource.class);
+ }
+
+ @Override
+ protected String getResourcePath() {
+ return "/spring/endpoint";
+ }
+
+ @Test
+ public void testResourceScope() {
+ final WebTarget t = target(getResourceFullPath());
+ final String message = "hello, world";
+ final String echo = t.path("message").request().put(Entity.text(message), String.class);
+ assertEquals(message, echo);
+ final String msg = t.path("message").request().get(String.class);
+ assertEquals(message, msg);
+ }
+}
diff --git a/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/SpringManagedITCase.java b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/SpringManagedITCase.java
new file mode 100644
index 0000000..5eea429
--- /dev/null
+++ b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/SpringManagedITCase.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for Spring managed JAX-RS resources.
+ *
+ * @author Marko Asplund (marko.asplund at yahoo.com)
+ */
+public class SpringManagedITCase extends AccountResourceTestBase {
+
+ @Override
+ protected ResourceConfig configure(final ResourceConfig rc) {
+ return rc.register(AccountSpringResource.class);
+ }
+
+ @Override
+ protected String getResourcePath() {
+ return "/spring/account";
+ }
+
+ @Test
+ public void testResourceScope() {
+ final WebTarget t = target(getResourceFullPath());
+ final String message = "hello, world";
+ final String echo = t.path("message").request().put(Entity.text(message), String.class);
+ assertEquals(message, echo);
+ final String msg = t.path("message").request().get(String.class);
+ assertEquals(message, msg);
+ }
+
+}
diff --git a/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/SpringManagedRepositoryITCase.java b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/SpringManagedRepositoryITCase.java
new file mode 100644
index 0000000..5302a9e
--- /dev/null
+++ b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/SpringManagedRepositoryITCase.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for Spring managed JAX-RS resources with @Repository archetype.
+ *
+ * @author Konrad Garus (konrad.garus at gmail.com)
+ */
+public class SpringManagedRepositoryITCase extends ResourceTestBase {
+
+ @Override
+ protected ResourceConfig configure(final ResourceConfig rc) {
+ return rc.register(RepositoryResource.class);
+ }
+
+ @Override
+ protected String getResourcePath() {
+ return "/spring/repository";
+ }
+
+ @Test
+ public void testResourceScope() {
+ final WebTarget t = target(getResourceFullPath());
+ final String message = "hello, world";
+ final String echo = t.path("message").request().put(Entity.text(message), String.class);
+ assertEquals(message, echo);
+ final String msg = t.path("message").request().get(String.class);
+ assertEquals(message, msg);
+ }
+}
diff --git a/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/SpringManagedServiceITCase.java b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/SpringManagedServiceITCase.java
new file mode 100644
index 0000000..633ceea
--- /dev/null
+++ b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/SpringManagedServiceITCase.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+
+import org.glassfish.jersey.server.ResourceConfig;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for Spring managed JAX-RS resources with @Service archetype.
+ *
+ * @author Konrad Garus (konrad.garus at gmail.com)
+ */
+public class SpringManagedServiceITCase extends ResourceTestBase {
+
+ @Override
+ protected ResourceConfig configure(final ResourceConfig rc) {
+ return rc.register(ServiceResource.class);
+ }
+
+ @Override
+ protected String getResourcePath() {
+ return "/spring/service";
+ }
+
+ @Test
+ public void testResourceScope() {
+ final WebTarget t = target(getResourceFullPath());
+ final String message = "hello, world";
+ final String echo = t.path("message").request().put(Entity.text(message), String.class);
+ assertEquals(message, echo);
+ final String msg = t.path("message").request().get(String.class);
+ assertEquals(message, msg);
+ }
+}
diff --git a/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/TestUtil.java b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/TestUtil.java
new file mode 100644
index 0000000..e4b4143
--- /dev/null
+++ b/tests/integration/spring4/src/test/java/org/glassfish/jersey/server/spring/test/TestUtil.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2013, 2018 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.server.spring.test;
+
+import javax.inject.Singleton;
+
+import org.glassfish.jersey.internal.inject.PerLookup;
+import org.glassfish.jersey.process.internal.RequestScoped;
+import org.glassfish.jersey.server.ResourceConfig;
+
+import org.glassfish.hk2.utilities.BuilderHelper;
+import org.glassfish.hk2.utilities.binding.AbstractBinder;
+
+class TestUtil {
+
+ public static ResourceConfig registerHK2Services(final ResourceConfig rc) {
+ rc
+ .register(new AbstractBinder() {
+ @Override
+ protected void configure() {
+ bind(BuilderHelper.link(HK2ServiceSingleton.class).in(Singleton.class).build());
+ }
+ })
+ .register(new AbstractBinder() {
+ @Override
+ protected void configure() {
+ bind(BuilderHelper.link(HK2ServiceRequestScoped.class).in(RequestScoped.class).build());
+ }
+ })
+ .register(new AbstractBinder() {
+ @Override
+ protected void configure() {
+ bind(BuilderHelper.link(HK2ServicePerLookup.class).in(PerLookup.class).build());
+ }
+ });
+ return rc;
+ }
+}
diff --git a/tests/integration/tracing-support/pom.xml b/tests/integration/tracing-support/pom.xml
new file mode 100644
index 0000000..82e08eb
--- /dev/null
+++ b/tests/integration/tracing-support/pom.xml
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2013, 2018 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
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.tests.integration</groupId>
+ <artifactId>project</artifactId>
+ <version>2.28-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>tracing-support</artifactId>
+ <packaging>war</packaging>
+ <name>jersey-tests-integration-tracing-support</name>
+
+ <description>Tracing support integration test</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+ <artifactId>jersey-test-framework-provider-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <configuration>
+ <systemPropertyVariables>
+ <!-- client side config works - failsafe plugin forks jvm -->
+ <java.util.logging.config.file>${project.build.testOutputDirectory}/logging.properties</java.util.logging.config.file>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ <configuration>
+ <connectors>
+ <connector>
+ <responseHeaderSize>16192</responseHeaderSize>
+ </connector>
+ </connectors>
+ <!-- server side config does not fork with jetty:run goal - it uses same jvm
+ use maven '-D' option instead:
+ mvn _goal_ -Djava.util.logging.config.file=target/test-classes/logging.properties
+ <systemProperties>
+ <systemProperty>
+ <name>java.util.logging.config.file</name>
+ <value>${project.build.testOutputDirectory}/logging.properties</value>
+ </systemProperty>
+ </systemProperties>
+ -->
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/AllTracingSupport.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/AllTracingSupport.java
new file mode 100644
index 0000000..f260a39
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/AllTracingSupport.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.server.TracingConfig;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@ApplicationPath("/ALL")
+public class AllTracingSupport extends TracingSupport {
+
+ public AllTracingSupport() {
+ super(TracingConfig.ALL);
+ }
+
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/AsyncResource.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/AsyncResource.java
new file mode 100644
index 0000000..338172c
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/AsyncResource.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.tracing;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.Suspended;
+
+/**
+* @author Libor Kramolis (libor.kramolis at oracle.com)
+*/
+@Path("/async")
+public class AsyncResource {
+
+ @Path("{name}")
+ @GET
+ public void get(@PathParam("name") String name, @Suspended final AsyncResponse asyncResponse) {
+ asyncResponse.resume(new Message(new StringBuffer(name).reverse().toString()));
+ }
+
+ @POST
+ public void post(Message post, @Suspended final AsyncResponse asyncResponse) {
+ asyncResponse.resume(new Message(new StringBuffer(post.getText()).reverse().toString()));
+ }
+
+ @Path("sub-resource-method")
+ @POST
+ public void postSub(Message post, @Suspended final AsyncResponse asyncResponse) {
+ asyncResponse.resume(new Message(new StringBuffer(post.getText()).reverse().toString()));
+ }
+
+ @Path("sub-resource-locator")
+ public AsyncSubResource getSubLoc() {
+ return new AsyncSubResource();
+ }
+
+ @Path("sub-resource-locator-null")
+ public AsyncSubResource getSubLocNull() {
+ return null;
+ }
+
+ @GET
+ @Path("runtime-exception")
+ public void getRuntimeException(@Suspended final AsyncResponse asyncResponse) {
+ asyncResponse.resume(new RuntimeException("Something does not work ..."));
+ }
+
+ @GET
+ @Path("mapped-exception")
+ public void getMappedException(@Suspended final AsyncResponse asyncResponse) {
+ asyncResponse.resume(new TestException("This could be client fault ..."));
+ }
+
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/AsyncSubResource.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/AsyncSubResource.java
new file mode 100644
index 0000000..9666448
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/AsyncSubResource.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2015, 2018 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.integration.tracing;
+
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.Suspended;
+
+/**
+* @author Libor Kramolis (libor.kramolis at oracle.com)
+*/
+@Path("/")
+public class AsyncSubResource {
+ @POST
+ public void post(Message post, @Suspended final AsyncResponse asyncResponse) {
+ asyncResponse.resume(new Message(new StringBuffer(post.getText()).reverse().toString()));
+ }
+
+ @Path("sub-resource-method")
+ @POST
+ public void postSub(Message post, @Suspended final AsyncResponse asyncResponse) {
+ asyncResponse.resume(new Message(new StringBuffer(post.getText()).reverse().toString()));
+ }
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/ContainerRequestFilter68.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/ContainerRequestFilter68.java
new file mode 100644
index 0000000..bbf688a
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/ContainerRequestFilter68.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import java.io.IOException;
+import javax.annotation.Priority;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Provider
+@Priority(68)
+public class ContainerRequestFilter68 implements ContainerRequestFilter {
+ @Override
+ public void filter(ContainerRequestContext requestContext) throws IOException {
+ //System.out.println("*** ContainerRequestFilter68.filter");
+ }
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/ContainerRequestFilterNoPriority.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/ContainerRequestFilterNoPriority.java
new file mode 100644
index 0000000..80c095c
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/ContainerRequestFilterNoPriority.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import java.io.IOException;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Provider
+public class ContainerRequestFilterNoPriority implements ContainerRequestFilter {
+ @Override
+ public void filter(ContainerRequestContext requestContext) throws IOException {
+ //System.out.println("*** ContainerRequestFilterNoPriority.filter");
+ }
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/ContainerResponseFilter5001.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/ContainerResponseFilter5001.java
new file mode 100644
index 0000000..f674354
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/ContainerResponseFilter5001.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import java.io.IOException;
+import javax.annotation.Priority;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Provider
+@Priority(5001)
+public class ContainerResponseFilter5001 implements ContainerResponseFilter {
+ @Override
+ public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
+ //System.out.println("*** ContainerResponseFilter5001.filter");
+ }
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/ContainerResponseFilterNoPriority.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/ContainerResponseFilterNoPriority.java
new file mode 100644
index 0000000..381da17
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/ContainerResponseFilterNoPriority.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import java.io.IOException;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Provider
+public class ContainerResponseFilterNoPriority implements ContainerResponseFilter {
+ @Override
+ public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
+ //System.out.println("*** ContainerResponseFilterNoPriority.filter");
+ }
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/Message.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/Message.java
new file mode 100644
index 0000000..b8f4f6a
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/Message.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class Message {
+
+ private String text;
+
+ public Message() {
+ }
+
+ public Message(String text) {
+ //System.out.println("*** Message: |" + text + "|");
+ this.text = text;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ Message message = (Message) o;
+
+ if (text != null ? !text.equals(message.text) : message.text != null) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return text != null ? text.hashCode() : 0;
+ }
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/MessageBodyReaderGeneric.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/MessageBodyReaderGeneric.java
new file mode 100644
index 0000000..4d93336
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/MessageBodyReaderGeneric.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Provider
+@Consumes("*/*")
+public class MessageBodyReaderGeneric implements MessageBodyReader<Message> {
+
+ @Override
+ public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+ return false;
+ }
+
+ @Override
+ public Message readFrom(Class<Message> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType,
+ MultivaluedMap<String, String> httpHeaders,
+ InputStream entityStream) throws IOException, WebApplicationException {
+ return null;
+ }
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/MessageBodyReaderTestFormat.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/MessageBodyReaderTestFormat.java
new file mode 100644
index 0000000..81d0941
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/MessageBodyReaderTestFormat.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.Provider;
+
+import org.glassfish.jersey.message.MessageUtils;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Provider
+@Consumes(Utils.APPLICATION_X_JERSEY_TEST)
+public class MessageBodyReaderTestFormat implements MessageBodyReader<Message> {
+
+ boolean serverSide = true;
+
+ public MessageBodyReaderTestFormat() {
+ }
+
+ public MessageBodyReaderTestFormat(final boolean serverSide) {
+ this.serverSide = serverSide;
+ }
+
+ @Override
+ public boolean isReadable(final Class<?> type, final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType) {
+ return type.isAssignableFrom(Message.class);
+ }
+
+ @Override
+ public Message readFrom(final Class<Message> type, final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType, final MultivaluedMap<String, String> httpHeaders,
+ final InputStream entityStream) throws IOException, WebApplicationException {
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(entityStream, MessageUtils.getCharset(mediaType)));
+
+ final String line = reader.readLine();
+ if (line == null || !line.startsWith(Utils.FORMAT_PREFIX) || !line.endsWith(Utils.FORMAT_SUFFIX)) {
+ throw new WebApplicationException(
+ new IllegalArgumentException("Input content '" + line + "' is not in a valid format!"));
+ }
+ final String text = line.substring(Utils.FORMAT_PREFIX.length(), line.length() - Utils.FORMAT_SUFFIX.length());
+
+ if (serverSide) {
+ Utils.throwException(text, this,
+ Utils.TestAction.MESSAGE_BODY_READER_THROW_WEB_APPLICATION,
+ Utils.TestAction.MESSAGE_BODY_READER_THROW_PROCESSING,
+ Utils.TestAction.MESSAGE_BODY_READER_THROW_ANY);
+ }
+
+ return new Message(text);
+ }
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/MessageBodyWriterGeneric.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/MessageBodyWriterGeneric.java
new file mode 100644
index 0000000..4e295ba
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/MessageBodyWriterGeneric.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Provider
+@Produces("*/*")
+public class MessageBodyWriterGeneric implements MessageBodyWriter<Message> {
+
+ @Override
+ public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+ return false;
+ }
+
+ @Override
+ public long getSize(Message message, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+ return -1;
+ }
+
+ @Override
+ public void writeTo(Message message,
+ Class<?> type,
+ Type genericType,
+ Annotation[] annotations,
+ MediaType mediaType,
+ MultivaluedMap<String, Object> httpHeaders,
+ OutputStream entityStream) throws IOException, WebApplicationException {
+ }
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/MessageBodyWriterTestFormat.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/MessageBodyWriterTestFormat.java
new file mode 100644
index 0000000..6983d18
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/MessageBodyWriterTestFormat.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+import org.glassfish.jersey.message.MessageUtils;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Provider
+@Produces(Utils.APPLICATION_X_JERSEY_TEST)
+public class MessageBodyWriterTestFormat implements MessageBodyWriter<Message> {
+
+ boolean serverSide = true;
+
+ public MessageBodyWriterTestFormat() {
+ }
+
+ public MessageBodyWriterTestFormat(final boolean serverSide) {
+ this.serverSide = serverSide;
+ }
+
+ @Override
+ public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType) {
+ return type.isAssignableFrom(Message.class);
+ }
+
+ @Override
+ public long getSize(final Message message, final Class<?> type, final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType) {
+ return -1;
+ }
+
+ @Override
+ public void writeTo(final Message message, final Class<?> type, final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders,
+ final OutputStream entityStream) throws IOException, WebApplicationException {
+ if (serverSide) {
+ Utils.throwException(message.getText(), this,
+ Utils.TestAction.MESSAGE_BODY_WRITER_THROW_WEB_APPLICATION,
+ Utils.TestAction.MESSAGE_BODY_WRITER_THROW_PROCESSING,
+ Utils.TestAction.MESSAGE_BODY_WRITER_THROW_ANY);
+ }
+
+ final OutputStreamWriter writer = new OutputStreamWriter(entityStream, MessageUtils.getCharset(mediaType));
+ writer.write(Utils.FORMAT_PREFIX);
+ writer.write(message.getText());
+ writer.write(Utils.FORMAT_SUFFIX);
+ writer.flush();
+ }
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/OnDemandTracingSupport.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/OnDemandTracingSupport.java
new file mode 100644
index 0000000..0a15268
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/OnDemandTracingSupport.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import javax.ws.rs.ApplicationPath;
+
+import org.glassfish.jersey.server.TracingConfig;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@ApplicationPath("/ON_DEMAND")
+public class OnDemandTracingSupport extends TracingSupport {
+
+ public OnDemandTracingSupport() {
+ super(TracingConfig.ON_DEMAND);
+ }
+
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/PreMatchingContainerRequestFilter23.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/PreMatchingContainerRequestFilter23.java
new file mode 100644
index 0000000..6cc32a9
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/PreMatchingContainerRequestFilter23.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import java.io.IOException;
+import javax.annotation.Priority;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.PreMatching;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Provider
+@PreMatching
+@Priority(23)
+public class PreMatchingContainerRequestFilter23 implements ContainerRequestFilter {
+ @Override
+ public void filter(ContainerRequestContext requestContext) throws IOException {
+ //System.out.println("*** PreMatchingContainerRequestFilter23.filter");
+ }
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/PreMatchingContainerRequestFilter42.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/PreMatchingContainerRequestFilter42.java
new file mode 100644
index 0000000..fa83983
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/PreMatchingContainerRequestFilter42.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import java.io.IOException;
+import javax.annotation.Priority;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.PreMatching;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Provider
+@PreMatching
+@Priority(42)
+public class PreMatchingContainerRequestFilter42 implements ContainerRequestFilter {
+ @Override
+ public void filter(ContainerRequestContext requestContext) throws IOException {
+ //System.out.println("*** PreMatchingContainerRequestFilter42.filter");
+ Utils.throwException(requestContext, this,
+ Utils.TestAction.PRE_MATCHING_REQUEST_FILTER_THROW_WEB_APPLICATION,
+ Utils.TestAction.PRE_MATCHING_REQUEST_FILTER_THROW_PROCESSING,
+ Utils.TestAction.PRE_MATCHING_REQUEST_FILTER_THROW_ANY);
+ }
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/ReaderInterceptor14.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/ReaderInterceptor14.java
new file mode 100644
index 0000000..e37971c
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/ReaderInterceptor14.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import java.io.IOException;
+import javax.annotation.Priority;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.ReaderInterceptor;
+import javax.ws.rs.ext.ReaderInterceptorContext;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Provider
+@Priority(14)
+public class ReaderInterceptor14 implements ReaderInterceptor {
+ @Override
+ public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
+ //System.out.println("*** ReaderInterceptor14.aroundReadFrom: BEFORE");
+ try {
+ Thread.sleep(42);
+ } catch (InterruptedException e) {
+ }
+ try {
+ return context.proceed();
+ } finally {
+ try {
+ Thread.sleep(42);
+ } catch (InterruptedException e) {
+ }
+ //System.out.println("*** ReaderInterceptor14.aroundReadFrom: AFTER");
+ }
+ }
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/ReaderInterceptor18.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/ReaderInterceptor18.java
new file mode 100644
index 0000000..3d3f444
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/ReaderInterceptor18.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import java.io.IOException;
+import javax.annotation.Priority;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.ReaderInterceptor;
+import javax.ws.rs.ext.ReaderInterceptorContext;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Provider
+@Priority(18)
+public class ReaderInterceptor18 implements ReaderInterceptor {
+ @Override
+ public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
+ //System.out.println("*** ReaderInterceptor18.aroundReadFrom: BEFORE");
+ try {
+ return context.proceed();
+ } finally {
+ //System.out.println("*** ReaderInterceptor18.aroundReadFrom: AFTER");
+ }
+ }
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/Resource.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/Resource.java
new file mode 100644
index 0000000..c13b57d
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/Resource.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
+/**
+* @author Libor Kramolis (libor.kramolis at oracle.com)
+*/
+@Path("/root")
+public class Resource {
+
+ @Path("{name}")
+ @GET
+ public Message get(@PathParam("name") String name) {
+ return new Message(new StringBuffer(name).reverse().toString());
+ }
+
+ @POST
+ public Message post(Message post) {
+ return new Message(new StringBuffer(post.getText()).reverse().toString());
+ }
+
+ @Path("sub-resource-method")
+ @POST
+ public Message postSub(Message post) {
+ return new Message(new StringBuffer(post.getText()).reverse().toString());
+ }
+
+ @Path("sub-resource-locator")
+ public SubResource getSubLoc() {
+ return new SubResource();
+ }
+
+ @Path("sub-resource-locator-null")
+ public SubResource getSubLocNull() {
+ return null;
+ }
+
+ @GET
+ @Path("runtime-exception")
+ public Message getRuntimeException() {
+ throw new RuntimeException("Something does not work ...");
+ }
+
+ @GET
+ @Path("mapped-exception")
+ public Message getMappedException() {
+ throw new TestException("This could be client fault ...");
+ }
+
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/SubResource.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/SubResource.java
new file mode 100644
index 0000000..b803c3e
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/SubResource.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+
+/**
+* @author Libor Kramolis (libor.kramolis at oracle.com)
+*/
+@Path("/")
+public class SubResource {
+ @POST
+ public Message post(Message post) {
+ return new Message(new StringBuffer(post.getText()).reverse().toString());
+ }
+
+ @Path("sub-resource-method")
+ @POST
+ public Message postSub(Message post) {
+ return new Message(new StringBuffer(post.getText()).reverse().toString());
+ }
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/TestException.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/TestException.java
new file mode 100644
index 0000000..26dccfd
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/TestException.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class TestException extends RuntimeException {
+
+ public TestException() {
+ super();
+ }
+
+ public TestException(String message) {
+ super(message);
+ }
+
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/TestExceptionMapper.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/TestExceptionMapper.java
new file mode 100644
index 0000000..04d6dec
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/TestExceptionMapper.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import javax.annotation.Priority;
+import javax.ws.rs.Priorities;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Priority(Priorities.USER)
+@Provider
+public class TestExceptionMapper implements ExceptionMapper<TestException> {
+
+ @Override
+ public Response toResponse(TestException throwable) {
+ return Response.status(501).build();
+ }
+
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/TestExtendedExceptionMapperGeneric.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/TestExtendedExceptionMapperGeneric.java
new file mode 100644
index 0000000..6a0cc9d
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/TestExtendedExceptionMapperGeneric.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import javax.ws.rs.Priorities;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+
+import javax.annotation.Priority;
+
+import org.glassfish.jersey.spi.ExtendedExceptionMapper;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Priority(Priorities.USER + 1)
+@Provider
+public class TestExtendedExceptionMapperGeneric implements ExtendedExceptionMapper<Exception> {
+
+ @Override
+ public Response toResponse(Exception throwable) {
+ return Response.status(500).build();
+ }
+
+ @Override
+ public boolean isMappable(Exception throwable) {
+ return !(throwable instanceof RuntimeException);
+ }
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/TestExtendedExceptionMapperRuntime.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/TestExtendedExceptionMapperRuntime.java
new file mode 100644
index 0000000..0161b37
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/TestExtendedExceptionMapperRuntime.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import javax.ws.rs.Priorities;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+
+import javax.annotation.Priority;
+
+import org.glassfish.jersey.spi.ExtendedExceptionMapper;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Priority(Priorities.USER + 2)
+@Provider
+public class TestExtendedExceptionMapperRuntime implements ExtendedExceptionMapper<Throwable> {
+
+ @Override
+ public Response toResponse(Throwable throwable) {
+ return Response.status(500).build();
+ }
+
+ @Override
+ public boolean isMappable(Throwable throwable) {
+ return (throwable instanceof RuntimeException) && !(throwable instanceof WebApplicationException);
+ }
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/TracingSupport.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/TracingSupport.java
new file mode 100644
index 0000000..fabb7a2
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/TracingSupport.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.ServerProperties;
+import org.glassfish.jersey.server.TracingConfig;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class TracingSupport extends ResourceConfig {
+
+ public TracingSupport(TracingConfig type) {
+ Utils.configure(this);
+ property(ServerProperties.TRACING, type.name());
+ }
+
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/Utils.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/Utils.java
new file mode 100644
index 0000000..aa9b45d
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/Utils.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import java.util.logging.Logger;
+
+import javax.ws.rs.ProcessingException;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.core.Configurable;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.logging.LoggingFeature;
+import org.glassfish.jersey.server.ResourceConfig;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public final class Utils {
+
+ public static final String HEADER_TRACING_PREFIX = "X-Jersey-Tracing-";
+
+ public static final String APPLICATION_X_JERSEY_TEST = "application/x-jersey-test";
+ public static final String FORMAT_PREFIX = "-=#[";
+ public static final String FORMAT_SUFFIX = "]#=-";
+ public static final String HEADER_TEST_ACTION = "test-action";
+
+ private Utils() {
+ }
+
+ public static void configure(ResourceConfig configurable) {
+ configurable.packages(Utils.class.getPackage().getName());
+// OR:
+// configure((Configurable)configurable);
+// configurable.register(PreMatchingContainerRequestFilter23.class);
+// configurable.register(PreMatchingContainerRequestFilter42.class);
+// configurable.register(ContainerRequestFilter68.class);
+// configurable.register(ContainerRequestFilterNoPriority.class);
+// configurable.register(ContainerResponseFilter5001.class);
+// configurable.register(ContainerResponseFilterNoPriority.class);
+// configurable.register(TestExceptionMapper.class);
+// configurable.register(TestExtendedExceptionMapperGeneric.class);
+// configurable.register(TestExtendedExceptionMapperRuntime.class);
+// configurable.register(Resource.class);
+// configurable.register(SubResource.class);
+ configurable.register(new LoggingFeature(Logger.getAnonymousLogger(), LoggingFeature.Verbosity.PAYLOAD_ANY));
+ }
+
+ public static void configure(ClientConfig configurable) {
+ configure((Configurable) configurable);
+ }
+
+ public static void configure(Configurable configurable) {
+ configurable.register(ReaderInterceptor14.class);
+ configurable.register(ReaderInterceptor18.class);
+ configurable.register(WriterInterceptor39.class);
+ configurable.register(WriterInterceptor45.class);
+ configurable.register(new MessageBodyReaderTestFormat(false));
+ configurable.register(MessageBodyReaderGeneric.class);
+ configurable.register(new MessageBodyWriterTestFormat(false));
+ configurable.register(MessageBodyWriterGeneric.class);
+ }
+
+ public static void throwException(final ContainerRequestContext requestContext,
+ final Object fromContext,
+ final TestAction throwWebApplicationException,
+ final TestAction throwProcessingException,
+ final TestAction throwAnyException) {
+ final Utils.TestAction testAction = Utils.getTestAction(requestContext);
+ throwExceptionImpl(testAction, fromContext, throwWebApplicationException, throwProcessingException, throwAnyException);
+ }
+
+ public static void throwException(final String testActionName,
+ final Object fromContext,
+ final TestAction throwWebApplicationException,
+ final TestAction throwProcessingException,
+ final TestAction throwAnyException) {
+ Utils.TestAction testAction;
+ try {
+ testAction = TestAction.valueOf(testActionName);
+ } catch (IllegalArgumentException ex) {
+ try {
+ testAction = TestAction.valueOf(new StringBuffer(testActionName).reverse().toString());
+ } catch (IllegalArgumentException ex2) {
+ testAction = null;
+ }
+ }
+ throwExceptionImpl(testAction, fromContext, throwWebApplicationException, throwProcessingException, throwAnyException);
+ }
+
+ private static void throwExceptionImpl(final Utils.TestAction testAction,
+ final Object fromContext,
+ final TestAction throwWebApplicationException,
+ final TestAction throwProcessingException,
+ final TestAction throwAnyException) {
+ final String message = "Test Exception from " + fromContext.getClass().getName();
+ if (testAction == null) {
+ // do nothing
+ } else if (testAction == throwWebApplicationException) {
+ throw new WebApplicationException(message);
+ } else if (testAction == throwProcessingException) {
+ throw new ProcessingException(message);
+ } else if (testAction == throwAnyException) {
+ throw new RuntimeException(message);
+ }
+ }
+
+ public static TestAction getTestAction(ContainerRequestContext requestContext) {
+ String testActionHeader = requestContext.getHeaderString(HEADER_TEST_ACTION);
+ TestAction testAction = null;
+ if (testActionHeader != null) {
+ testAction = TestAction.valueOf(testActionHeader);
+ }
+ return testAction;
+ }
+
+ public static enum TestAction {
+ PRE_MATCHING_REQUEST_FILTER_THROW_WEB_APPLICATION,
+ PRE_MATCHING_REQUEST_FILTER_THROW_PROCESSING,
+ PRE_MATCHING_REQUEST_FILTER_THROW_ANY,
+ MESSAGE_BODY_READER_THROW_WEB_APPLICATION,
+ MESSAGE_BODY_READER_THROW_PROCESSING,
+ MESSAGE_BODY_READER_THROW_ANY,
+ MESSAGE_BODY_WRITER_THROW_WEB_APPLICATION,
+ MESSAGE_BODY_WRITER_THROW_PROCESSING,
+ MESSAGE_BODY_WRITER_THROW_ANY;
+ //TODO add other *_THROW_* actions to throw exception from other stages
+ }
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/WriterInterceptor39.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/WriterInterceptor39.java
new file mode 100644
index 0000000..f6257db
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/WriterInterceptor39.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import java.io.IOException;
+import java.util.Date;
+import javax.annotation.Priority;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.WriterInterceptor;
+import javax.ws.rs.ext.WriterInterceptorContext;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Provider
+@Priority(39)
+public class WriterInterceptor39 implements WriterInterceptor {
+ @Override
+ public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
+ //System.out.println("*** WriterInterceptor39.aroundWriteTo: BEFORE");
+ try {
+ Thread.sleep(42);
+ } catch (InterruptedException e) {
+ }
+ context.getHeaders().putSingle(WriterInterceptor39.class.getSimpleName(), new Date());
+ context.proceed();
+ //System.out.println("*** WriterInterceptor39.aroundWriteTo: AFTER");
+ }
+}
diff --git a/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/WriterInterceptor45.java b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/WriterInterceptor45.java
new file mode 100644
index 0000000..a76f13f
--- /dev/null
+++ b/tests/integration/tracing-support/src/main/java/org/glassfish/jersey/tests/integration/tracing/WriterInterceptor45.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import java.io.IOException;
+import java.util.Date;
+import javax.annotation.Priority;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.WriterInterceptor;
+import javax.ws.rs.ext.WriterInterceptorContext;
+
+/**
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@Provider
+@Priority(45)
+public class WriterInterceptor45 implements WriterInterceptor {
+ @Override
+ public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
+ //System.out.println("*** WriterInterceptor45.aroundWriteTo: BEFORE");
+ context.getHeaders().putSingle(WriterInterceptor45.class.getSimpleName(), new Date());
+ context.proceed();
+ try {
+ Thread.sleep(42);
+ } catch (InterruptedException e) {
+ }
+ //System.out.println("*** WriterInterceptor45.aroundWriteTo: AFTER");
+ }
+}
diff --git a/tests/integration/tracing-support/src/test/java/org/glassfish/jersey/tests/integration/tracing/AllTracingSupportITCase.java b/tests/integration/tracing-support/src/test/java/org/glassfish/jersey/tests/integration/tracing/AllTracingSupportITCase.java
new file mode 100644
index 0000000..430789e
--- /dev/null
+++ b/tests/integration/tracing-support/src/test/java/org/glassfish/jersey/tests/integration/tracing/AllTracingSupportITCase.java
@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.TracingConfig;
+import org.glassfish.jersey.server.internal.ServerTraceEvent;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.TestProperties;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * 'ALL' tracing support test that is running in external Jetty container.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+@RunWith(Parameterized.class)
+public class AllTracingSupportITCase extends JerseyTest {
+
+ private final String resourcePath;
+
+ public AllTracingSupportITCase(String resourcePath) {
+ this.resourcePath = resourcePath;
+ }
+
+ @Parameterized.Parameters(name = "{index}: {0}")
+ public static List<Object[]> testData() {
+ return Arrays.asList(new Object[][] {
+ {"/root"},
+ {"/async"},
+ });
+ }
+
+ //
+ // JerseyTest
+ //
+
+ @Override
+ protected ResourceConfig configure() {
+ enable(TestProperties.LOG_TRAFFIC);
+ enable(TestProperties.DUMP_ENTITY);
+
+ return new AllTracingSupport();
+ }
+
+ @Override
+ protected void configureClient(ClientConfig clientConfig) {
+ Utils.configure(clientConfig);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ //
+ // tests
+ //
+
+ @Test
+ public void testGet() {
+ Invocation.Builder builder = resource(resourcePath).path("NAME").request();
+ Response response = builder.get();
+ assertXJerseyTrace(response, false);
+ assertEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void testRuntimeException() {
+ Invocation.Builder builder = resource(resourcePath).path("runtime-exception").request();
+
+ Response response = builder.get();
+ assertXJerseyTrace(response, true);
+ assertEquals(500, response.getStatus());
+ }
+
+ @Test
+ public void testMappedException() throws InterruptedException, IOException {
+ Invocation.Builder builder = resource(resourcePath).path("mapped-exception").request();
+
+ Response response = builder.get();
+ assertXJerseyTrace(response, true);
+ assertEquals(501, response.getStatus());
+ }
+
+ @Test
+ public void testGet405() {
+ Invocation.Builder builder = resource(resourcePath).request();
+
+ Response response = builder.get();
+ assertXJerseyTrace(response, false);
+ assertEquals(405, response.getStatus());
+ }
+
+ @Test
+ public void testPostSubResourceMethod() {
+ Invocation.Builder builder = resource(resourcePath).path("sub-resource-method").request();
+
+ Response response = builder.post(Entity.entity(new Message("POST"), Utils.APPLICATION_X_JERSEY_TEST));
+ assertXJerseyTrace(response, false);
+ assertEquals("TSOP", response.readEntity(Message.class).getText());
+ }
+
+ @Test
+ public void testPostSubResourceLocator() {
+ Invocation.Builder builder = resource(resourcePath).path("sub-resource-locator").request();
+
+ Response response = builder.post(Entity.entity(new Message("POST"), Utils.APPLICATION_X_JERSEY_TEST));
+ assertXJerseyTrace(response, false);
+ assertEquals("TSOP", response.readEntity(Message.class).getText());
+ }
+
+ @Test
+ public void testPostSubResourceLocatorNull() {
+ Invocation.Builder builder = resource(resourcePath).path("sub-resource-locator-null").request();
+
+ Response response = builder.post(Entity.entity(new Message("POST"), Utils.APPLICATION_X_JERSEY_TEST));
+ assertEquals(404, response.getStatus());
+ }
+
+ @Test
+ public void testPostSubResourceLocatorSubResourceMethod() {
+ Invocation.Builder builder = resource(resourcePath).path("sub-resource-locator").path("sub-resource-method").request();
+
+ Response response = builder.post(Entity.entity(new Message("POST"), Utils.APPLICATION_X_JERSEY_TEST));
+ assertXJerseyTrace(response, false);
+ assertEquals("TSOP", response.readEntity(Message.class).getText());
+ }
+
+ @Test
+ public void testTraceInnerException() {
+ // PRE_MATCHING_REQUEST_FILTER
+ testTraceInnerExceptionImpl(Utils.TestAction.PRE_MATCHING_REQUEST_FILTER_THROW_WEB_APPLICATION, 500, false);
+ testTraceInnerExceptionImpl(Utils.TestAction.PRE_MATCHING_REQUEST_FILTER_THROW_PROCESSING, 500, true);
+ testTraceInnerExceptionImpl(Utils.TestAction.PRE_MATCHING_REQUEST_FILTER_THROW_ANY, 500, true);
+ // MESSAGE_BODY_WRITER
+ testTraceInnerExceptionImpl(Utils.TestAction.MESSAGE_BODY_WRITER_THROW_WEB_APPLICATION, 500, false);
+ testTraceInnerExceptionImpl(Utils.TestAction.MESSAGE_BODY_WRITER_THROW_PROCESSING, 500, true);
+ testTraceInnerExceptionImpl(Utils.TestAction.MESSAGE_BODY_WRITER_THROW_ANY, 500, true);
+ // MESSAGE_BODY_READER
+ testTraceInnerExceptionImpl(Utils.TestAction.MESSAGE_BODY_READER_THROW_WEB_APPLICATION, 500, false);
+ testTraceInnerExceptionImpl(Utils.TestAction.MESSAGE_BODY_READER_THROW_PROCESSING, 500, true);
+ testTraceInnerExceptionImpl(Utils.TestAction.MESSAGE_BODY_READER_THROW_ANY, 500, true);
+ }
+
+ //
+ // utils
+ //
+
+ private void testTraceInnerExceptionImpl(Utils.TestAction testAction, int expectedStatus, boolean exceptionExpected) {
+ Invocation.Builder builder = resource(resourcePath).request();
+ builder.header(Utils.HEADER_TEST_ACTION, testAction);
+
+ Response response = builder.post(Entity.entity(new Message(testAction.name()), Utils.APPLICATION_X_JERSEY_TEST));
+ assertXJerseyTrace(response, exceptionExpected);
+ assertEquals(expectedStatus, response.getStatus());
+ }
+
+ private void assertXJerseyTrace(Response response, boolean exceptionExpected) {
+ int finished = 0;
+ int exceptionMapping = 0;
+
+ for (String k : response.getHeaders().keySet()) {
+ if (k.toLowerCase().startsWith(Utils.HEADER_TRACING_PREFIX.toLowerCase())) {
+ String value = response.getHeaderString(k);
+ if (value.startsWith(ServerTraceEvent.FINISHED.category())) {
+ finished++;
+ } else if (value.startsWith(ServerTraceEvent.EXCEPTION_MAPPING.category())) {
+ exceptionMapping++;
+ }
+ }
+ }
+ assertEquals("Just one FINISHED expected!", 1, finished);
+ if (exceptionExpected) {
+ assertEquals("EXCEPTION expected!", 1, exceptionMapping);
+ } else {
+ assertEquals("EXCEPTION NOT expected!", 0, exceptionMapping);
+ }
+ }
+
+ private WebTarget resource(String path) {
+ return target("/" + TracingConfig.ALL).path(path);
+ }
+
+}
diff --git a/tests/integration/tracing-support/src/test/java/org/glassfish/jersey/tests/integration/tracing/OnDemandTracingSupportITCase.java b/tests/integration/tracing-support/src/test/java/org/glassfish/jersey/tests/integration/tracing/OnDemandTracingSupportITCase.java
new file mode 100644
index 0000000..05ecceb
--- /dev/null
+++ b/tests/integration/tracing-support/src/test/java/org/glassfish/jersey/tests/integration/tracing/OnDemandTracingSupportITCase.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2013, 2018 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.integration.tracing;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.message.internal.TracingLogger;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.TracingConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.TestProperties;
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * 'ON_DEMAND' tracing support test that is running in external Jetty container.
+ *
+ * @author Libor Kramolis (libor.kramolis at oracle.com)
+ */
+public class OnDemandTracingSupportITCase extends JerseyTest {
+
+ //
+ // JerseyTest
+ //
+
+ @Override
+ protected ResourceConfig configure() {
+ enable(TestProperties.LOG_TRAFFIC);
+ enable(TestProperties.DUMP_ENTITY);
+
+ return new OnDemandTracingSupport();
+ }
+
+ @Override
+ protected void configureClient(ClientConfig clientConfig) {
+ Utils.configure(clientConfig);
+ }
+
+ @Override
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ return new ExternalTestContainerFactory();
+ }
+
+ //
+ // tests
+ //
+
+ @Test
+ public void testNoTracing() {
+ Invocation.Builder builder = resource("/root").request();
+ Response response = builder.post(Entity.entity(new Message("POST"), Utils.APPLICATION_X_JERSEY_TEST));
+ assertFalse(hasX_Jersey_Trace(response));
+ assertEquals("TSOP", response.readEntity(Message.class).getText());
+ }
+
+ @Test
+ public void testTraceAcceptEmpty() {
+ testTraceAccept("");
+ }
+
+ @Test
+ public void testTraceAcceptTrue() {
+ testTraceAccept("true");
+ }
+
+ @Test
+ public void testTraceAcceptWhatever() {
+ testTraceAccept("whatever");
+ }
+
+ private void testTraceAccept(String acceptValue) {
+ Invocation.Builder builder = resource("/root").request();
+ Response response = builder.header(TracingLogger.HEADER_ACCEPT, acceptValue)
+ .post(Entity.entity(new Message("POST"), Utils.APPLICATION_X_JERSEY_TEST));
+ assertTrue(hasX_Jersey_Trace(response));
+ assertEquals("TSOP", response.readEntity(Message.class).getText());
+ }
+
+ //
+ // utils
+ //
+
+ private boolean hasX_Jersey_Trace(Response response) {
+ for (String k : response.getHeaders().keySet()) {
+ if (k.toLowerCase().startsWith(Utils.HEADER_TRACING_PREFIX.toLowerCase())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private WebTarget resource(String path) {
+ return target("/" + TracingConfig.ON_DEMAND).path(path);
+ }
+
+}
diff --git a/tests/integration/tracing-support/src/test/resources/logging.properties b/tests/integration/tracing-support/src/test/resources/logging.properties
new file mode 100644
index 0000000..6ba7395
--- /dev/null
+++ b/tests/integration/tracing-support/src/test/resources/logging.properties
@@ -0,0 +1,25 @@
+#
+# Copyright (c) 2013, 2018 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
+#
+
+#All attributes details
+handlers=java.util.logging.ConsoleHandler
+java.util.logging.ConsoleHandler.level=FINEST
+java.util.logging.SimpleFormatter.format=%4$-7s [%3$s] %5$s%6$s%n
+
+#All log level details
+.level=INFO
+org.glassfish.jersey.level=CONFIG
+org.glassfish.jersey.tracing.level=FINEST