Skip to content

Commit 75898f4

Browse files
jbescossenivam
authored andcommitted
Bug 31362657 - USING JSPS WITH JERSEY 2.X DROP HEADERS IN 14.1.1
Signed-off-by: Jorge Bescos Gascon <[email protected]>
1 parent a05f5fb commit 75898f4

File tree

8 files changed

+350
-0
lines changed

8 files changed

+350
-0
lines changed

tests/integration/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
<module>servlet-2.5-mvc-1</module>
108108
<module>servlet-2.5-mvc-2</module>
109109
<module>servlet-2.5-mvc-3</module>
110+
<module>servlet-2.5-mvc-4</module>
110111
<module>servlet-2.5-reload</module>
111112
<module>servlet-3-async</module>
112113
<module>servlet-3-chunked-io</module>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
5+
6+
This program and the accompanying materials are made available under the
7+
terms of the Eclipse Public License v. 2.0, which is available at
8+
http://www.eclipse.org/legal/epl-2.0.
9+
10+
This Source Code may also be made available under the following Secondary
11+
Licenses when the conditions for such availability set forth in the
12+
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
13+
version 2 with the GNU Classpath Exception, which is available at
14+
https://www.gnu.org/software/classpath/license.html.
15+
16+
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
17+
18+
-->
19+
20+
<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">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<parent>
24+
<groupId>org.glassfish.jersey.tests.integration</groupId>
25+
<artifactId>project</artifactId>
26+
<version>2.32.0-SNAPSHOT</version>
27+
</parent>
28+
29+
<artifactId>servlet-2.5-mvc-4</artifactId>
30+
<packaging>war</packaging>
31+
<name>jersey-tests-integration-servlet-2.5-mvc-4</name>
32+
33+
<description>Servlet integration test - servlet-2.5-mvc-4 - filter - MVC - jersey.config.servlet.JspTemplatesBasePath</description>
34+
35+
<dependencies>
36+
<dependency>
37+
<groupId>org.glassfish.jersey.containers</groupId>
38+
<artifactId>jersey-container-servlet-core</artifactId>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.glassfish.jersey.ext</groupId>
42+
<artifactId>jersey-mvc</artifactId>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.glassfish.jersey.ext</groupId>
46+
<artifactId>jersey-mvc-jsp</artifactId>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>javax.servlet</groupId>
51+
<artifactId>servlet-api</artifactId>
52+
<version>${servlet2.version}</version>
53+
</dependency>
54+
55+
<dependency>
56+
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
57+
<artifactId>jersey-test-framework-provider-external</artifactId>
58+
<scope>test</scope>
59+
</dependency>
60+
</dependencies>
61+
62+
<build>
63+
<plugins>
64+
<plugin>
65+
<groupId>org.apache.maven.plugins</groupId>
66+
<artifactId>maven-compiler-plugin</artifactId>
67+
</plugin>
68+
<plugin>
69+
<groupId>org.apache.maven.plugins</groupId>
70+
<artifactId>maven-failsafe-plugin</artifactId>
71+
</plugin>
72+
<plugin>
73+
<groupId>org.eclipse.jetty</groupId>
74+
<artifactId>jetty-maven-plugin</artifactId>
75+
</plugin>
76+
</plugins>
77+
</build>
78+
79+
<profiles>
80+
<profile>
81+
<id>jdk11+</id>
82+
<activation>
83+
<jdk>[11,)</jdk>
84+
</activation>
85+
<dependencies>
86+
<dependency>
87+
<groupId>jakarta.xml.bind</groupId>
88+
<artifactId>jakarta.xml.bind-api</artifactId>
89+
</dependency>
90+
<dependency>
91+
<groupId>com.sun.xml.bind</groupId>
92+
<artifactId>jaxb-osgi</artifactId>
93+
</dependency>
94+
</dependencies>
95+
</profile>
96+
</profiles>
97+
98+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
package org.glassfish.jersey.tests.integration.servlet_25_mvc_4;
18+
19+
import org.glassfish.jersey.message.GZipEncoder;
20+
import org.glassfish.jersey.server.ResourceConfig;
21+
import org.glassfish.jersey.server.filter.EncodingFilter;
22+
import org.glassfish.jersey.server.mvc.jsp.JspMvcFeature;
23+
import org.glassfish.jersey.tests.integration.servlet_25_mvc_4.resource.ExampleResource;
24+
25+
public class MyApplication extends ResourceConfig {
26+
27+
public MyApplication() {
28+
property("jersey.config.server.mvc.templateBasePath.jsp", "/WEB-INF/jsp");
29+
property("jersey.config.servlet.filter.forwardOn404", "true");
30+
property("jersey.config.servlet.filter.staticContentRegex", "/WEB-INF/.*\\.jsp");
31+
packages(ExampleResource.class.getPackage().getName());
32+
EncodingFilter.enableFor(this, new Class[] {GZipEncoder.class});
33+
register(JspMvcFeature.class);
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
package org.glassfish.jersey.tests.integration.servlet_25_mvc_4.resource;
18+
19+
import javax.ws.rs.GET;
20+
import javax.ws.rs.Path;
21+
import javax.ws.rs.PathParam;
22+
import javax.ws.rs.Produces;
23+
24+
import org.glassfish.jersey.server.mvc.Viewable;
25+
26+
@Path("/{client}")
27+
public class ExampleResource {
28+
29+
@GET
30+
@Path("html")
31+
@Produces({ "text/html" })
32+
public Viewable displayMain(@PathParam("client") String inClientId) {
33+
return new Viewable("/main");
34+
}
35+
36+
@GET
37+
@Path("string")
38+
@Produces({ "text/html" })
39+
public String string(@PathParam("client") String inClientId) {
40+
return "string string string string string string";
41+
}
42+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<%--
2+
3+
Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
4+
5+
This program and the accompanying materials are made available under the
6+
terms of the Eclipse Public License v. 2.0, which is available at
7+
http://www.eclipse.org/legal/epl-2.0.
8+
9+
This Source Code may also be made available under the following Secondary
10+
Licenses when the conditions for such availability set forth in the
11+
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
12+
version 2 with the GNU Classpath Exception, which is available at
13+
https://www.gnu.org/software/classpath/license.html.
14+
15+
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16+
17+
--%>
18+
19+
<html>
20+
<head>
21+
<meta charset="utf-8">
22+
<title>Test</title>
23+
24+
</head>
25+
<body>
26+
find this string
27+
</body>
28+
</html>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
5+
6+
This program and the accompanying materials are made available under the
7+
terms of the Eclipse Public License v. 2.0, which is available at
8+
http://www.eclipse.org/legal/epl-2.0.
9+
10+
This Source Code may also be made available under the following Secondary
11+
Licenses when the conditions for such availability set forth in the
12+
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
13+
version 2 with the GNU Classpath Exception, which is available at
14+
https://www.gnu.org/software/classpath/license.html.
15+
16+
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
17+
18+
-->
19+
20+
<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">
21+
<filter>
22+
<filter-name>org.glassfish.jersey.tests.integration.servlet_25_mvc_4.MyApplication</filter-name>
23+
<filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
24+
<init-param>
25+
<param-name>javax.ws.rs.Application</param-name>
26+
<param-value>org.glassfish.jersey.tests.integration.servlet_25_mvc_4.MyApplication</param-value>
27+
</init-param>
28+
</filter>
29+
<filter-mapping>
30+
<filter-name>org.glassfish.jersey.tests.integration.servlet_25_mvc_4.MyApplication</filter-name>
31+
<url-pattern>/*</url-pattern>
32+
</filter-mapping>
33+
</web-app>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
package org.glassfish.jersey.tests.integration.servlet_25_mvc_4;
18+
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertFalse;
21+
22+
import javax.ws.rs.core.Response;
23+
24+
import org.glassfish.jersey.message.GZipEncoder;
25+
import org.junit.Test;
26+
27+
public class GzipITCase extends TestSupport {
28+
29+
@Test
30+
public void testString() throws Exception {
31+
Response response = target("/client/string").register(GZipEncoder.class)
32+
.request("text/html").acceptEncoding("gzip").get();
33+
String resp = response.readEntity(String.class);
34+
assertResponseContains(resp, "string string string string string string");
35+
assertEquals("gzip", response.getHeaderString("Content-Encoding"));
36+
}
37+
38+
@Test
39+
public void testJsp() throws Exception {
40+
Response response = target("/client/html").register(GZipEncoder.class)
41+
.request("text/html", "application/xhtml+xml", "application/xml;q=0.9", "*/*;q=0.8").acceptEncoding("gzip")
42+
.get();
43+
String resp = response.readEntity(String.class);
44+
assertHtmlResponse(resp);
45+
assertResponseContains(resp, "find this string");
46+
assertEquals("gzip", response.getHeaderString("Content-Encoding"));
47+
}
48+
49+
@Test
50+
public void testJspNotDecoded() throws Exception {
51+
Response response = target("/client/html")
52+
.request("text/html", "application/xhtml+xml", "application/xml;q=0.9", "*/*;q=0.8").acceptEncoding("gzip")
53+
.get();
54+
String resp = response.readEntity(String.class);
55+
assertFalse(resp.contains("find this string"));
56+
assertEquals("gzip", response.getHeaderString("Content-Encoding"));
57+
}
58+
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
package org.glassfish.jersey.tests.integration.servlet_25_mvc_4;
18+
19+
import javax.ws.rs.core.Application;
20+
21+
import org.glassfish.jersey.test.JerseyTest;
22+
import org.glassfish.jersey.test.TestProperties;
23+
import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
24+
import org.glassfish.jersey.test.spi.TestContainerException;
25+
import org.glassfish.jersey.test.spi.TestContainerFactory;
26+
27+
import static org.junit.Assert.assertNotNull;
28+
import static org.junit.Assert.assertTrue;
29+
30+
public abstract class TestSupport extends JerseyTest {
31+
32+
@Override
33+
protected Application configure() {
34+
enable(TestProperties.LOG_TRAFFIC);
35+
enable(TestProperties.DUMP_ENTITY);
36+
return new MyApplication();
37+
}
38+
39+
@Override
40+
protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
41+
return new ExternalTestContainerFactory();
42+
}
43+
44+
protected void assertHtmlResponse(final String response) {
45+
assertNotNull("No text returned!", response);
46+
47+
assertResponseContains(response, "<html>");
48+
assertResponseContains(response, "</html>");
49+
}
50+
51+
protected void assertResponseContains(final String response, final String text) {
52+
assertTrue("Response should contain " + text + " but was: " + response, response.contains(text));
53+
}
54+
}

0 commit comments

Comments
 (0)