Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

update 3.1 branch with actual master #4976

Merged
merged 7 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ KineticJS, v4.7.1
* Copyright: Eric Rowell

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

org.osgi.core version 6.0.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -63,12 +63,15 @@ void close(ClientRequest clientRequest, HttpUriRequest request, CloseableHttpRes
* Strategy that aborts Apache HttpRequests for the case of Chunked Stream, closes the stream, and response next.
*/
class GracefulClosingStrategy implements ApacheConnectionClosingStrategy {
private static final String UNIX_PROTOCOL = "unix";

static final GracefulClosingStrategy INSTANCE = new GracefulClosingStrategy();

@Override
public void close(ClientRequest clientRequest, HttpUriRequest request, CloseableHttpResponse response, InputStream stream)
throws IOException {
if (response.getEntity() != null && response.getEntity().isChunked()) {
if (response.getEntity() != null && response.getEntity().isChunked()
&& !request.getURI().getScheme().equals(UNIX_PROTOCOL)) {
request.abort();
}
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -509,7 +509,7 @@ public ClientResponse apply(final ClientRequest clientRequest) throws Processing
final HttpEntity entity = response.getEntity();

if (entity != null) {
if (headers.get(HttpHeaders.CONTENT_LENGTH) == null) {
if (headers.get(HttpHeaders.CONTENT_LENGTH) == null && entity.getContentLength() >= 0) {
headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(entity.getContentLength()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -288,16 +288,8 @@ protected void service(final HttpServletRequest request, final HttpServletRespon
* We need to work around this and not use getPathInfo
* for the decodedPath.
*/
final String decodedBasePath = request.getContextPath() + servletPath + "/";

final String encodedBasePath = UriComponent.encode(decodedBasePath,
UriComponent.Type.PATH);

if (!decodedBasePath.equals(encodedBasePath)) {
setResponseForInvalidUri(response, new ProcessingException("The servlet context path and/or the "
+ "servlet path contain characters that are percent encoded"));
return;
}
final String encodedBasePath = UriComponent.contextualEncode(
request.getContextPath() + servletPath, UriComponent.Type.PATH) + "/";

final URI baseUri;
final URI requestUri;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.jersey.servlet.internal;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.glassfish.jersey.internal.util.collection.Value;
import org.glassfish.jersey.internal.util.collection.Values;
import org.glassfish.jersey.servlet.ServletContainer;
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.net.URI;

/**
* Context encoding test. See Jersey-4949.
*/
public class ContextPathEncodingTest {
private static final String PATH = "A%20B";
private static final String CONTEXT = "c%20ntext";

@Test
public void contextEncodingTest() throws ServletException, IOException {
// In jetty maven plugin, context is set by
//<configuration>
// <scan>10</scan>
// <webApp>
// <contextPath>/c ntext</contextPath>
// </webApp>
//</configuration>

//Servlet path is not encoded, context is encoded
final ServletRequestValues servletRequestValues = new ServletRequestValues(
"/" + CONTEXT,
"",
"/" + CONTEXT + "/" + PATH
);
final EncodingTestServletContainer testServletContainer = new EncodingTestServletContainer(
"/" + CONTEXT + "/",
"/" + CONTEXT + "/" + PATH
);
EncodingTestData testData = new EncodingTestData(servletRequestValues, testServletContainer);

testData.test();
}

@Test
public void servletPathEncodingTest() throws ServletException, IOException {
//Servlet path is not encoded, context is encoded
final ServletRequestValues servletRequestValues = new ServletRequestValues(
"/",
"A B",
"/" + PATH + "/" + PATH
);
final EncodingTestServletContainer testServletContainer = new EncodingTestServletContainer(
"/" + PATH + "/",
"/" + PATH + "/" + PATH
);
EncodingTestData testData = new EncodingTestData(servletRequestValues, testServletContainer);

testData.test();
}

static class EncodingTestData {
final ServletRequestValues servletRequestValues;
final EncodingTestServletContainer encodingTestServletContainer;
final HttpServletRequest httpServletRequest;

EncodingTestData(ServletRequestValues servletRequestValues, EncodingTestServletContainer encodingTestServletContainer) {
this.servletRequestValues = servletRequestValues;
this.encodingTestServletContainer = encodingTestServletContainer;
this.httpServletRequest = (HttpServletRequest) Proxy.newProxyInstance(getClass().getClassLoader(),
new Class[]{HttpServletRequest.class}, new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return servletRequestValues.handle(method.getName());
}
});
}

public void test() throws ServletException, IOException {
encodingTestServletContainer.service(httpServletRequest, (HttpServletResponse) null);
}

}

static class ServletRequestValues {
final String servletPath;
final String requestUri;
final String contextPath;

ServletRequestValues(String contextPath, String servletPath, String requestUri) {
this.servletPath = servletPath;
this.requestUri = requestUri;
this.contextPath = contextPath;
}

Object handle(String name) {
switch (name) {
case "getServletPath":
return servletPath;
case "getRequestURI":
return requestUri;
case "getRequestURL":
return new StringBuffer(requestUri);
case "getContextPath":
return contextPath;
default:
return null;
}
}
}

static class EncodingTestServletContainer extends ServletContainer {
final String baseUri;
final String requestUri;

EncodingTestServletContainer(String baseUri, String requestUri) {
this.baseUri = baseUri;
this.requestUri = requestUri;
}

@Override
public Value<Integer> service(URI baseUri, URI requestUri, HttpServletRequest request, HttpServletResponse response) {
Assert.assertEquals(this.baseUri, baseUri.toASCIIString());
Assert.assertEquals(this.requestUri, requestUri.toASCIIString());
return Values.of(0);
}

//Update visibility
public void service(final HttpServletRequest request, final HttpServletResponse response)
throws ServletException, IOException {
super.service(request, response);
}
};
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -285,6 +285,15 @@ private static Object getLegacyFallbackValue(Map<String, ?> properties, Map<Stri
* @return value converted to the specified class type.
*/
public static <T> T convertValue(Object value, Class<T> type) {

if (((type.equals(Integer.class)) || (type.equals(int.class))) && Number.class.isInstance(value)) {
final Integer number2Int = ((Number) value).intValue();
return (T) number2Int;
} else if (((type.equals(Long.class)) || (type.equals(long.class))) && Number.class.isInstance(value)) {
final Long number2Long = ((Number) value).longValue();
return (T) number2Long;
}

if (!type.isInstance(value)) {
// TODO: Move string value readers from server to common and utilize them here
final Constructor constructor = AccessController.doPrivileged(ReflectionHelper.getStringConstructorPA(type));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -173,4 +173,30 @@ public void testPropertyNameDeclination() {
assertEquals(myNonJerseyProperty, PropertiesHelper.getPropertyNameForRuntime(myNonJerseyProperty, null));
}

@Test
public void testconvertValue() {
Long lg = 10L;
long l = 10L;
Integer ig = 10;
int i = 10;

assertEquals(ig, PropertiesHelper.convertValue(i, Integer.class));
assertEquals(ig, PropertiesHelper.convertValue(ig, Integer.class));
assertEquals(ig, PropertiesHelper.convertValue(l, Integer.class));
assertEquals(ig, PropertiesHelper.convertValue(lg, Integer.class));
assertEquals(lg, PropertiesHelper.convertValue(i, Long.class));
assertEquals(lg, PropertiesHelper.convertValue(ig, Long.class));
assertEquals(lg, PropertiesHelper.convertValue(l, Long.class));
assertEquals(lg, PropertiesHelper.convertValue(lg, Long.class));
assertEquals(ig, PropertiesHelper.convertValue(i, int.class));
assertEquals(ig, PropertiesHelper.convertValue(ig, int.class));
assertEquals(ig, PropertiesHelper.convertValue(l, int.class));
assertEquals(ig, PropertiesHelper.convertValue(lg, int.class));
assertEquals(lg, PropertiesHelper.convertValue(i, long.class));
assertEquals(lg, PropertiesHelper.convertValue(ig, long.class));
assertEquals(lg, PropertiesHelper.convertValue(l, long.class));
assertEquals(lg, PropertiesHelper.convertValue(lg, long.class));

}

}
4 changes: 2 additions & 2 deletions core-server/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2010, 2022 Oracle and/or its affiliates. All rights reserved.

This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -56,7 +56,7 @@
</license>
<license>
<name>Modified BSD</name>
<url>http://asm.objectweb.org/license.html</url>
<url>https://asm.ow2.io/license.html</url>
<distribution>repo</distribution>
<comments>ASM @ jersey.repackaged.org.objectweb.asm</comments>
</license>
Expand Down
2 changes: 1 addition & 1 deletion core-server/src/main/resources/META-INF/NOTICE.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ org.glassfish.jersey.server.internal.monitoring.core
* Copyright 2010-2013 Coda Hale and Yammer, Inc.

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

W3.org documents
Expand Down
6 changes: 3 additions & 3 deletions docs/src/main/docbook/jersey.ent
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="iso-8859-1" ?>
<!--

Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2010, 2022 Oracle and/or its affiliates. All rights reserved.

This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -59,8 +59,8 @@
<!ENTITY jaxb.release.uri "https://eclipse-ee4j.github.io/jaxb-ri">
<!ENTITY jaxb.javadoc.uri "&jaxb.release.uri;/docs/api/jakarta.xml.bind">
<!ENTITY jaxrs.release.uri "https://github.com/eclipse-ee4j/jaxrs-api">
<!ENTITY jaxrs.javadoc.uri "https://eclipse-ee4j.github.io/jaxrs-api/apidocs/&jax-rs.version;/jakarta/ws/rs">
<!ENTITY jaxrs21.javadoc.uri "https://eclipse-ee4j.github.io/jaxrs-api/apidocs/&jax-rs21.version;/javax/ws/rs">
<!ENTITY jaxrs.javadoc.uri "https://jakartaee.github.io/rest/apidocs/&jax-rs.version;/jakarta/ws/rs">
<!ENTITY jaxrs21.javadoc.uri "https://jakartaee.github.io/rest/apidocs/&jax-rs21.version;/javax/ws/rs">
<!ENTITY jaxrs31.spec.uri "https://jakarta.ee/specifications/restful-ws/&jax-rs31.spec.version;/jakarta-restful-ws-spec-&jax-rs31.spec.version;.html">
<!ENTITY jsonb.javadoc.uri "https://javaee.github.io/javaee-spec/javadocs/javax/json/bind">
<!ENTITY jersey.documentation.uri "https://eclipse-ee4j.github.io/jersey.github.io">
Expand Down
2 changes: 1 addition & 1 deletion examples/NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ KineticJS, v4.7.1
* Copyright: Eric Rowell

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

org.osgi.core version 6.0.0
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
</license>
<license>
<name>Modified BSD</name>
<url>http://asm.objectweb.org/license.html</url>
<url>https://asm.ow2.io/license.html</url>
<distribution>repo</distribution>
<comments>ASM @ jersey.repackaged.org.objectweb.asm</comments>
</license>
Expand Down Expand Up @@ -462,7 +462,7 @@
All Rights Reserved. Use is subject to license terms.]]>
</bottom>
<links>
<link>https://eclipse-ee4j.github.io/jaxrs-api/apidocs/2.1.6/</link>
<link>https://jakartaee.github.io/rest/apidocs/2.1.6/</link>
<link>https://javaee.github.io/hk2/apidocs/</link>
</links>
<excludePackageNames>
Expand Down
Loading