Skip to content

Commit

Permalink
Merge pull request #4853 from senivam/3x_merget
Browse files Browse the repository at this point in the history
  • Loading branch information
senivam authored Sep 14, 2021
2 parents 5fc527c + ae05206 commit 7002144
Show file tree
Hide file tree
Showing 165 changed files with 13,564 additions and 164 deletions.
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, 2021 Oracle and/or its affiliates. All rights reserved.
*
* 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 @@ -42,6 +42,7 @@

import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -146,6 +147,14 @@ public void testOptions() {
cr.close();
}

@Test
public void testOptionsWithEntity() {
WebTarget r = getWebTarget();
Response response = r.request().build("OPTIONS", Entity.text("OPTIONS")).invoke();
assertEquals(200, response.getStatus());
response.close();
}

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

package org.glassfish.jersey.grizzly.connector;

import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.Application;
import jakarta.ws.rs.core.Response;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* Tests the Http methods.
*/
public class HttpMethodTest extends JerseyTest {

@Override
protected Application configure() {
return new ResourceConfig(HttpMethodResource.class);
}

protected Client createClient() {
ClientConfig cc = new ClientConfig();
cc.connectorProvider(new GrizzlyConnectorProvider());
return ClientBuilder.newClient(cc);
}

private WebTarget getWebTarget(final Client client) {
return client.target(getBaseUri()).path("test");
}

private WebTarget getWebTarget() {
return getWebTarget(createClient());
}

@Path("/test")
public static class HttpMethodResource {
@GET
public String get() {
return "GET";
}
}

@Test
public void testOptionsWithEntity() {
WebTarget r = getWebTarget();
Response response = r.request().build("OPTIONS", Entity.text("OPTIONS")).invoke();
assertEquals(200, response.getStatus());
response.close();
}

@Test
public void testGet() {
WebTarget r = getWebTarget();
assertEquals("GET", r.request().get(String.class));

Response cr = r.request().get();
assertTrue(cr.hasEntity());
cr.close();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved.
*
* 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 @@ -55,6 +55,8 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;

@RunWith(Parameterized.class)
public class BasicHelidonConnectorTest extends JerseyTest {

Expand Down Expand Up @@ -305,4 +307,11 @@ public void testOneClientsTwoReqestsAsync() throws ExecutionException, Interrupt
Assert.assertEquals("long", longResponse.readEntity(String.class));
}
}

@Test
public void testOptionsWithEntity() {
Response response = target("basic").path("get").request().build("OPTIONS", Entity.text("OPTIONS")).invoke();
assertEquals(200, response.getStatus());
response.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.jersey.jdk.connector;

import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.Application;
import jakarta.ws.rs.core.Response;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* Tests the Http methods.
*/
public class HttpMethodTest extends JerseyTest {

@Override
protected Application configure() {
return new ResourceConfig(HttpMethodResource.class);
}

protected Client createClient() {
ClientConfig cc = new ClientConfig();
cc.connectorProvider(new JdkConnectorProvider());
return ClientBuilder.newClient(cc);
}

private WebTarget getWebTarget(final Client client) {
return client.target(getBaseUri()).path("test");
}

private WebTarget getWebTarget() {
return getWebTarget(createClient());
}

@Path("/test")
public static class HttpMethodResource {
@GET
public String get() {
return "GET";
}
}

@Test
public void testOptionsWithEntity() {
WebTarget r = getWebTarget();
Response response = r.request().build("OPTIONS", Entity.text("OPTIONS")).invoke();
assertEquals(200, response.getStatus());
response.close();
}

@Test
public void testGet() {
WebTarget r = getWebTarget();
assertEquals("GET", r.request().get(String.class));

Response cr = r.request().get();
assertTrue(cr.hasEntity());
cr.close();
}
}
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, 2021 Oracle and/or its affiliates. All rights reserved.
*
* 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 @@ -143,4 +143,11 @@ public void testPatch() {
Response response = target(PATH).request().method("PATCH", Entity.entity("PATCH", MediaType.TEXT_PLAIN));
assertEquals("PATCH", response.readEntity(String.class));
}

@Test
public void testOptionsWithEntity() {
Response response = target(PATH).request().build("OPTIONS", Entity.text("OPTIONS")).invoke();
assertEquals(200, response.getStatus());
response.close();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021 Oracle and/or its affiliates. All rights reserved.
*
* 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 @@ -98,4 +98,11 @@ public void testDelete() {
Response response = target(PATH).request().delete();
assertEquals("DELETE", response.readEntity(String.class));
}

@Test
public void testOptionsWithEntity() {
Response response = target(PATH).request().build("OPTIONS", Entity.text("OPTIONS")).invoke();
assertEquals(200, response.getStatus());
response.close();
}
}
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, 2021 Oracle and/or its affiliates. All rights reserved.
*
* 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 @@ -250,7 +250,7 @@ private static void addServletWithDefaultConfiguration(final ServletContext cont
}

// make <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> without init params
// work the same as <servlet-name>javax.ws.rs.Application</servlet-name>
// work the same as <servlet-name>jakarta.ws.rs.Application</servlet-name>
for (ServletRegistration servletRegistration : context.getServletRegistrations().values()) {
if (isJerseyServlet(servletRegistration.getClassName())
&& servletRegistration != registration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private static Map<String, EntityPresence> initializeMap() {
map.put("DELETE", EntityPresence.MUST_BE_NULL);
map.put("GET", EntityPresence.MUST_BE_NULL);
map.put("HEAD", EntityPresence.MUST_BE_NULL);
map.put("OPTIONS", EntityPresence.MUST_BE_NULL);
map.put("OPTIONS", EntityPresence.OPTIONAL);
map.put("PATCH", EntityPresence.MUST_BE_PRESENT);
map.put("POST", EntityPresence.OPTIONAL); // we allow to post null instead of entity
map.put("PUT", EntityPresence.MUST_BE_PRESENT);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion core-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
<threadCount>1</threadCount>
<forkCount>1C</forkCount>
<reuseForks>true</reuseForks>
<systemPropertiesFile>${project.basedir}/../etc/jenkins/systemPropertiesFile</systemPropertiesFile>
<systemPropertiesFile>${project.basedir}/etc/systemPropertiesFile</systemPropertiesFile>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public class ClassReader {
*/
static final int EXPAND_ASM_INSNS = 256;

/** The maximum size of array to allocate. */
private static final int MAX_BUFFER_SIZE = 1024 * 1024;

/** The size of the temporary byte array used to read class input streams chunk by chunk. */
private static final int INPUT_STREAM_DATA_CHUNK_SIZE = 4096;

Expand Down Expand Up @@ -191,7 +194,7 @@ public ClassReader(
this.b = classFileBuffer;
// Check the class' major_version. This field is after the magic and minor_version fields, which
// use 4 and 2 bytes respectively.
if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V17) {
if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V18) {
throw new IllegalArgumentException(
"Unsupported class file major version " + readShort(classFileOffset + 6));
}
Expand Down Expand Up @@ -310,13 +313,19 @@ private static byte[] readStream(final InputStream inputStream, final boolean cl
if (inputStream == null) {
throw new IOException("Class not found");
}
int bufferSize = calculateBufferSize(inputStream);
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
byte[] data = new byte[INPUT_STREAM_DATA_CHUNK_SIZE];
byte[] data = new byte[bufferSize];
int bytesRead;
while ((bytesRead = inputStream.read(data, 0, data.length)) != -1) {
int readCount = 0;
while ((bytesRead = inputStream.read(data, 0, bufferSize)) != -1) {
outputStream.write(data, 0, bytesRead);
readCount++;
}
outputStream.flush();
if (readCount == 1) {
return data;
}
return outputStream.toByteArray();
} finally {
if (close) {
Expand All @@ -325,6 +334,19 @@ private static byte[] readStream(final InputStream inputStream, final boolean cl
}
}

private static int calculateBufferSize(final InputStream inputStream) throws IOException {
int expectedLength = inputStream.available();
/*
* Some implementations can return 0 while holding available data
* (e.g. new FileInputStream("/proc/a_file"))
* Also in some pathological cases a very small number might be returned,
* and in this case we use default size
*/
if (expectedLength < 256) {
return INPUT_STREAM_DATA_CHUNK_SIZE;
}
return Math.min(expectedLength, MAX_BUFFER_SIZE);
}
// -----------------------------------------------------------------------------------------------
// Accessors
// -----------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
/**
* A visitor to visit a Java class. The methods of this class must be called in the following order:
* {@code visit} [ {@code visitSource} ] [ {@code visitModule} ][ {@code visitNestHost} ][ {@code
* visitPermittedSubclass} ][ {@code visitOuterClass} ] ( {@code visitAnnotation} | {@code
* visitTypeAnnotation} | {@code visitAttribute} )* ( {@code visitNestMember} | {@code
* visitOuterClass} ] ( {@code visitAnnotation} | {@code visitTypeAnnotation} | {@code
* visitAttribute} )* ( {@code visitNestMember} | [ {@code * visitPermittedSubclass} ] | {@code
* visitInnerClass} | {@code visitRecordComponent} | {@code visitField} | {@code visitMethod} )*
* {@code visitEnd}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class ClassWriter extends ClassVisitor {

/**
* The access_flags field of the JVMS ClassFile structure. This field can contain ASM specific
* access flags, such as {@link Opcodes#ACC_DEPRECATED} or {}@link Opcodes#ACC_RECORD}, which are
* access flags, such as {@link Opcodes#ACC_DEPRECATED} or {@link Opcodes#ACC_RECORD}, which are
* removed when generating the ClassFile structure.
*/
private int accessFlags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ public interface Opcodes {
int V15 = 0 << 16 | 59;
int V16 = 0 << 16 | 60;
int V17 = 0 << 16 | 61;
int V18 = 0 << 16 | 62;

/**
* Version flag indicating that the class is using 'preview' features.
Expand Down
Loading

0 comments on commit 7002144

Please sign in to comment.