Skip to content

Commit 9ad9f62

Browse files
authored
update 3.1 branch with actual master
2 parents 494fe2e + b94b9d4 commit 9ad9f62

File tree

18 files changed

+459
-28
lines changed

18 files changed

+459
-28
lines changed

NOTICE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ KineticJS, v4.7.1
9696
* Copyright: Eric Rowell
9797

9898
org.objectweb.asm Version 9.0
99-
* License: Modified BSD (http://asm.objectweb.org/license.html)
99+
* License: Modified BSD (https://asm.ow2.io/license.html)
100100
* Copyright (c) 2000-2011 INRIA, France Telecom. All rights reserved.
101101

102102
org.osgi.core version 6.0.0

connectors/apache-connector/src/main/java/org/glassfish/jersey/apache/connector/ApacheConnectionClosingStrategy.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -63,12 +63,15 @@ void close(ClientRequest clientRequest, HttpUriRequest request, CloseableHttpRes
6363
* Strategy that aborts Apache HttpRequests for the case of Chunked Stream, closes the stream, and response next.
6464
*/
6565
class GracefulClosingStrategy implements ApacheConnectionClosingStrategy {
66+
private static final String UNIX_PROTOCOL = "unix";
67+
6668
static final GracefulClosingStrategy INSTANCE = new GracefulClosingStrategy();
6769

6870
@Override
6971
public void close(ClientRequest clientRequest, HttpUriRequest request, CloseableHttpResponse response, InputStream stream)
7072
throws IOException {
71-
if (response.getEntity() != null && response.getEntity().isChunked()) {
73+
if (response.getEntity() != null && response.getEntity().isChunked()
74+
&& !request.getURI().getScheme().equals(UNIX_PROTOCOL)) {
7275
request.abort();
7376
}
7477
try {

connectors/apache-connector/src/main/java/org/glassfish/jersey/apache/connector/ApacheConnector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2022 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -509,7 +509,7 @@ public ClientResponse apply(final ClientRequest clientRequest) throws Processing
509509
final HttpEntity entity = response.getEntity();
510510

511511
if (entity != null) {
512-
if (headers.get(HttpHeaders.CONTENT_LENGTH) == null) {
512+
if (headers.get(HttpHeaders.CONTENT_LENGTH) == null && entity.getContentLength() >= 0) {
513513
headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(entity.getContentLength()));
514514
}
515515

containers/jersey-servlet-core/src/main/java/org/glassfish/jersey/servlet/ServletContainer.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2022 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -288,16 +288,8 @@ protected void service(final HttpServletRequest request, final HttpServletRespon
288288
* We need to work around this and not use getPathInfo
289289
* for the decodedPath.
290290
*/
291-
final String decodedBasePath = request.getContextPath() + servletPath + "/";
292-
293-
final String encodedBasePath = UriComponent.encode(decodedBasePath,
294-
UriComponent.Type.PATH);
295-
296-
if (!decodedBasePath.equals(encodedBasePath)) {
297-
setResponseForInvalidUri(response, new ProcessingException("The servlet context path and/or the "
298-
+ "servlet path contain characters that are percent encoded"));
299-
return;
300-
}
291+
final String encodedBasePath = UriComponent.contextualEncode(
292+
request.getContextPath() + servletPath, UriComponent.Type.PATH) + "/";
301293

302294
final URI baseUri;
303295
final URI requestUri;
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
* Copyright (c) 2022 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.servlet.internal;
18+
19+
import jakarta.servlet.ServletException;
20+
import jakarta.servlet.http.HttpServletRequest;
21+
import jakarta.servlet.http.HttpServletResponse;
22+
import org.glassfish.jersey.internal.util.collection.Value;
23+
import org.glassfish.jersey.internal.util.collection.Values;
24+
import org.glassfish.jersey.servlet.ServletContainer;
25+
import org.junit.Assert;
26+
import org.junit.Test;
27+
28+
import java.io.IOException;
29+
import java.lang.reflect.InvocationHandler;
30+
import java.lang.reflect.Method;
31+
import java.lang.reflect.Proxy;
32+
import java.net.URI;
33+
34+
/**
35+
* Context encoding test. See Jersey-4949.
36+
*/
37+
public class ContextPathEncodingTest {
38+
private static final String PATH = "A%20B";
39+
private static final String CONTEXT = "c%20ntext";
40+
41+
@Test
42+
public void contextEncodingTest() throws ServletException, IOException {
43+
// In jetty maven plugin, context is set by
44+
//<configuration>
45+
// <scan>10</scan>
46+
// <webApp>
47+
// <contextPath>/c ntext</contextPath>
48+
// </webApp>
49+
//</configuration>
50+
51+
//Servlet path is not encoded, context is encoded
52+
final ServletRequestValues servletRequestValues = new ServletRequestValues(
53+
"/" + CONTEXT,
54+
"",
55+
"/" + CONTEXT + "/" + PATH
56+
);
57+
final EncodingTestServletContainer testServletContainer = new EncodingTestServletContainer(
58+
"/" + CONTEXT + "/",
59+
"/" + CONTEXT + "/" + PATH
60+
);
61+
EncodingTestData testData = new EncodingTestData(servletRequestValues, testServletContainer);
62+
63+
testData.test();
64+
}
65+
66+
@Test
67+
public void servletPathEncodingTest() throws ServletException, IOException {
68+
//Servlet path is not encoded, context is encoded
69+
final ServletRequestValues servletRequestValues = new ServletRequestValues(
70+
"/",
71+
"A B",
72+
"/" + PATH + "/" + PATH
73+
);
74+
final EncodingTestServletContainer testServletContainer = new EncodingTestServletContainer(
75+
"/" + PATH + "/",
76+
"/" + PATH + "/" + PATH
77+
);
78+
EncodingTestData testData = new EncodingTestData(servletRequestValues, testServletContainer);
79+
80+
testData.test();
81+
}
82+
83+
static class EncodingTestData {
84+
final ServletRequestValues servletRequestValues;
85+
final EncodingTestServletContainer encodingTestServletContainer;
86+
final HttpServletRequest httpServletRequest;
87+
88+
EncodingTestData(ServletRequestValues servletRequestValues, EncodingTestServletContainer encodingTestServletContainer) {
89+
this.servletRequestValues = servletRequestValues;
90+
this.encodingTestServletContainer = encodingTestServletContainer;
91+
this.httpServletRequest = (HttpServletRequest) Proxy.newProxyInstance(getClass().getClassLoader(),
92+
new Class[]{HttpServletRequest.class}, new InvocationHandler() {
93+
@Override
94+
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
95+
return servletRequestValues.handle(method.getName());
96+
}
97+
});
98+
}
99+
100+
public void test() throws ServletException, IOException {
101+
encodingTestServletContainer.service(httpServletRequest, (HttpServletResponse) null);
102+
}
103+
104+
}
105+
106+
static class ServletRequestValues {
107+
final String servletPath;
108+
final String requestUri;
109+
final String contextPath;
110+
111+
ServletRequestValues(String contextPath, String servletPath, String requestUri) {
112+
this.servletPath = servletPath;
113+
this.requestUri = requestUri;
114+
this.contextPath = contextPath;
115+
}
116+
117+
Object handle(String name) {
118+
switch (name) {
119+
case "getServletPath":
120+
return servletPath;
121+
case "getRequestURI":
122+
return requestUri;
123+
case "getRequestURL":
124+
return new StringBuffer(requestUri);
125+
case "getContextPath":
126+
return contextPath;
127+
default:
128+
return null;
129+
}
130+
}
131+
}
132+
133+
static class EncodingTestServletContainer extends ServletContainer {
134+
final String baseUri;
135+
final String requestUri;
136+
137+
EncodingTestServletContainer(String baseUri, String requestUri) {
138+
this.baseUri = baseUri;
139+
this.requestUri = requestUri;
140+
}
141+
142+
@Override
143+
public Value<Integer> service(URI baseUri, URI requestUri, HttpServletRequest request, HttpServletResponse response) {
144+
Assert.assertEquals(this.baseUri, baseUri.toASCIIString());
145+
Assert.assertEquals(this.requestUri, requestUri.toASCIIString());
146+
return Values.of(0);
147+
}
148+
149+
//Update visibility
150+
public void service(final HttpServletRequest request, final HttpServletResponse response)
151+
throws ServletException, IOException {
152+
super.service(request, response);
153+
}
154+
};
155+
}

core-common/src/main/java/org/glassfish/jersey/internal/util/PropertiesHelper.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2022 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -285,6 +285,15 @@ private static Object getLegacyFallbackValue(Map<String, ?> properties, Map<Stri
285285
* @return value converted to the specified class type.
286286
*/
287287
public static <T> T convertValue(Object value, Class<T> type) {
288+
289+
if (((type.equals(Integer.class)) || (type.equals(int.class))) && Number.class.isInstance(value)) {
290+
final Integer number2Int = ((Number) value).intValue();
291+
return (T) number2Int;
292+
} else if (((type.equals(Long.class)) || (type.equals(long.class))) && Number.class.isInstance(value)) {
293+
final Long number2Long = ((Number) value).longValue();
294+
return (T) number2Long;
295+
}
296+
288297
if (!type.isInstance(value)) {
289298
// TODO: Move string value readers from server to common and utilize them here
290299
final Constructor constructor = AccessController.doPrivileged(ReflectionHelper.getStringConstructorPA(type));

core-common/src/test/java/org/glassfish/jersey/internal/util/PropertiesHelperTest.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -173,4 +173,30 @@ public void testPropertyNameDeclination() {
173173
assertEquals(myNonJerseyProperty, PropertiesHelper.getPropertyNameForRuntime(myNonJerseyProperty, null));
174174
}
175175

176+
@Test
177+
public void testconvertValue() {
178+
Long lg = 10L;
179+
long l = 10L;
180+
Integer ig = 10;
181+
int i = 10;
182+
183+
assertEquals(ig, PropertiesHelper.convertValue(i, Integer.class));
184+
assertEquals(ig, PropertiesHelper.convertValue(ig, Integer.class));
185+
assertEquals(ig, PropertiesHelper.convertValue(l, Integer.class));
186+
assertEquals(ig, PropertiesHelper.convertValue(lg, Integer.class));
187+
assertEquals(lg, PropertiesHelper.convertValue(i, Long.class));
188+
assertEquals(lg, PropertiesHelper.convertValue(ig, Long.class));
189+
assertEquals(lg, PropertiesHelper.convertValue(l, Long.class));
190+
assertEquals(lg, PropertiesHelper.convertValue(lg, Long.class));
191+
assertEquals(ig, PropertiesHelper.convertValue(i, int.class));
192+
assertEquals(ig, PropertiesHelper.convertValue(ig, int.class));
193+
assertEquals(ig, PropertiesHelper.convertValue(l, int.class));
194+
assertEquals(ig, PropertiesHelper.convertValue(lg, int.class));
195+
assertEquals(lg, PropertiesHelper.convertValue(i, long.class));
196+
assertEquals(lg, PropertiesHelper.convertValue(ig, long.class));
197+
assertEquals(lg, PropertiesHelper.convertValue(l, long.class));
198+
assertEquals(lg, PropertiesHelper.convertValue(lg, long.class));
199+
200+
}
201+
176202
}

core-server/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved.
4+
Copyright (c) 2010, 2022 Oracle and/or its affiliates. All rights reserved.
55
66
This program and the accompanying materials are made available under the
77
terms of the Eclipse Public License v. 2.0, which is available at
@@ -56,7 +56,7 @@
5656
</license>
5757
<license>
5858
<name>Modified BSD</name>
59-
<url>http://asm.objectweb.org/license.html</url>
59+
<url>https://asm.ow2.io/license.html</url>
6060
<distribution>repo</distribution>
6161
<comments>ASM @ jersey.repackaged.org.objectweb.asm</comments>
6262
</license>

core-server/src/main/resources/META-INF/NOTICE.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ org.glassfish.jersey.server.internal.monitoring.core
3737
* Copyright 2010-2013 Coda Hale and Yammer, Inc.
3838

3939
org.objectweb.asm Version 9.0
40-
* License: Modified BSD (http://asm.objectweb.org/license.html)
40+
* License: Modified BSD (https://asm.ow2.io/license.html)
4141
* Copyright: (c) 2000-2011 INRIA, France Telecom. All rights reserved.
4242

4343
W3.org documents

docs/src/main/docbook/jersey.ent

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="iso-8859-1" ?>
22
<!--
33
4-
Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved.
4+
Copyright (c) 2010, 2022 Oracle and/or its affiliates. All rights reserved.
55
66
This program and the accompanying materials are made available under the
77
terms of the Eclipse Public License v. 2.0, which is available at
@@ -59,8 +59,8 @@
5959
<!ENTITY jaxb.release.uri "https://eclipse-ee4j.github.io/jaxb-ri">
6060
<!ENTITY jaxb.javadoc.uri "&jaxb.release.uri;/docs/api/jakarta.xml.bind">
6161
<!ENTITY jaxrs.release.uri "https://github.com/eclipse-ee4j/jaxrs-api">
62-
<!ENTITY jaxrs.javadoc.uri "https://eclipse-ee4j.github.io/jaxrs-api/apidocs/&jax-rs.version;/jakarta/ws/rs">
63-
<!ENTITY jaxrs21.javadoc.uri "https://eclipse-ee4j.github.io/jaxrs-api/apidocs/&jax-rs21.version;/javax/ws/rs">
62+
<!ENTITY jaxrs.javadoc.uri "https://jakartaee.github.io/rest/apidocs/&jax-rs.version;/jakarta/ws/rs">
63+
<!ENTITY jaxrs21.javadoc.uri "https://jakartaee.github.io/rest/apidocs/&jax-rs21.version;/javax/ws/rs">
6464
<!ENTITY jaxrs31.spec.uri "https://jakarta.ee/specifications/restful-ws/&jax-rs31.spec.version;/jakarta-restful-ws-spec-&jax-rs31.spec.version;.html">
6565
<!ENTITY jsonb.javadoc.uri "https://javaee.github.io/javaee-spec/javadocs/javax/json/bind">
6666
<!ENTITY jersey.documentation.uri "https://eclipse-ee4j.github.io/jersey.github.io">

0 commit comments

Comments
 (0)