Skip to content

Commit

Permalink
merge of the actual 2.x into the 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
senivam authored May 15, 2024
2 parents 8d2ae8a + 8cc19dd commit 47716d0
Show file tree
Hide file tree
Showing 14 changed files with 389 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -937,12 +937,12 @@ public void close() throws IOException {
}

@Override
public synchronized void mark(int readlimit) {
public void mark(int readlimit) {
in.mark(readlimit);
}

@Override
public synchronized void reset() throws IOException {
public void reset() throws IOException {
checkAborted();
in.reset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -941,12 +941,12 @@ public void close() throws IOException {
}

@Override
public synchronized void mark(int readlimit) {
public void mark(int readlimit) {
in.mark(readlimit);
}

@Override
public synchronized void reset() throws IOException {
public void reset() throws IOException {
checkAborted();
in.reset();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved.
*
* 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 @@ -496,7 +496,7 @@ private void decideTransferEncoding() throws ParseException {

if (contentLengths != null) {
try {
int bodyLength = Integer.parseInt(contentLengths.get(0));
long bodyLength = Long.parseLong(contentLengths.get(0));
if (bodyLength == 0) {
expectContent = false;
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved.
*
* 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 @@ -31,7 +31,7 @@ abstract class TransferEncodingParser {

abstract boolean parse(ByteBuffer input) throws ParseException;

static TransferEncodingParser createFixedLengthParser(AsynchronousBodyInputStream responseBody, int expectedLength) {
static TransferEncodingParser createFixedLengthParser(AsynchronousBodyInputStream responseBody, long expectedLength) {
return new FixedLengthEncodingParser(responseBody, expectedLength);
}

Expand All @@ -42,11 +42,11 @@ static TransferEncodingParser createChunkParser(AsynchronousBodyInputStream resp

private static class FixedLengthEncodingParser extends TransferEncodingParser {

private final int expectedLength;
private final long expectedLength;
private final AsynchronousBodyInputStream responseBody;
private volatile int consumedLength = 0;
private volatile long consumedLength = 0;

FixedLengthEncodingParser(AsynchronousBodyInputStream responseBody, int expectedLength) {
FixedLengthEncodingParser(AsynchronousBodyInputStream responseBody, long expectedLength) {
this.expectedLength = expectedLength;
this.responseBody = responseBody;
}
Expand Down
76 changes: 76 additions & 0 deletions docs/src/main/docbook/appendix-properties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2210,4 +2210,80 @@
</tgroup>
</table>
</section>
<section xml:id="appendix-properties-multipart">
<title>Multipart configuration properties</title>

<para>
List of multipart configuration properties that can be found in &jersey.media.multipart.MultiPartProperties; class.
</para>

<table>
<title>
List of multipart configuration properties settable in the
&jersey.media.multipart.MultiPartProperties.MULTI_PART_CONFIG_RESOURCE; configuration file.
</title>
<tgroup cols="3">
<thead>
<row>
<entry>Constant</entry>
<entry>Value</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>&jersey.media.multipart.MultiPartProperties.BUFFER_THRESHOLD;</entry>
<entry><literal>jersey.config.multipart.bufferThreshold</literal></entry>
<entry>
<para>
Name of the resource property for the threshold size (in bytes) above which a
body part entity will be buffered to disk instead of being held in memory.
</para>
<para>
The default value is &jersey.message.MessageProperties.IO_DEFAULT_BUFFER_SIZE;
</para>
</entry>
</row>
<row>
<entry>&jersey.media.multipart.MultiPartProperties.MAX_PARTS;</entry>
<entry><literal>jersey.config.multipart.maxParts</literal></entry>
<entry>
<para>
Limit the maximum number of parts the multipart entity can have. If the limit is over,
the error response status <literal>413 - REQUEST_ENTITY_TOO_LARGE</literal>
is returned.
</para>
<para>
By default, the number is unlimited.
</para>
</entry>
</row>
<row>
<entry>&jersey.media.multipart.MultiPartProperties.MULTI_PART_CONFIG_RESOURCE;</entry>
<entry><literal>jersey-multipart-config.properties</literal></entry>
<entry>
<para>
Name of a properties resource that (if found in the classpath
for this application) will be used to configure the settings returned
by our getter methods.
</para>
</entry>
</row>
<row>
<entry>&jersey.media.multipart.MultiPartProperties.TEMP_DIRECTORY;</entry>
<entry><literal>jersey.config.multipart.tempDir</literal></entry>
<entry>
<para>
Name of the resource property for the directory to store temporary files containing body parts
of multipart message that extends allowed memory threshold.
</para>
<para>
The default value is not set (will be taken from <literal>java.io.tmpdir</literal> system property).
</para>
</entry>
</row>
</tbody>
</tgroup>
</table>
</section>
</appendix>
7 changes: 6 additions & 1 deletion docs/src/main/docbook/jersey.ent
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,12 @@
<!ENTITY jersey.media.multipart.FormDataParam "<link xlink:href='&jersey.javadoc.uri.prefix;/media/multipart/FormDataParam.html'>@FormDataParam</link>" >
<!ENTITY jersey.media.multipart.MultiPart "<link xlink:href='&jersey.javadoc.uri.prefix;/media/multipart/MultiPart.html'>MultiPart</link>" >
<!ENTITY jersey.media.multipart.MultiPartFeature "<link xlink:href='&jersey.javadoc.uri.prefix;/media/multipart/MultiPartFeature.html'>MultiPartFeature</link>" >
<!ENTITY jersey.media.multipart.StreamDataBodyPart "<link xlink:href='&jersey.javadoc.uri.prefix;/media/multipart/file/StreamDataBodyPart.html'>StreamDataBodyPart</link>" >
<!ENTITY jersey.media.multipart.MultiPartProperties "<link xlink:href='&jersey.javadoc.uri.prefix;/media/multipart/MultiPartProperties.html'>MultiPartProperties</link>" >
<!ENTITY jersey.media.multipart.MultiPartProperties.BUFFER_THRESHOLD "<link xlink:href='&jersey.javadoc.uri.prefix;/media/multipart/MultiPartProperties.html#BUFFER_THRESHOLD'>MultiPartProperties.BUFFER_THRESHOLD</link>">
<!ENTITY jersey.media.multipart.MultiPartProperties.MAX_PARTS "<link xlink:href='&jersey.javadoc.uri.prefix;/media/multipart/MultiPartProperties.html#MAX_PARTS'>MultiPartProperties.MAX_PARTS</link>">
<!ENTITY jersey.media.multipart.MultiPartProperties.MULTI_PART_CONFIG_RESOURCE "<link xlink:href='&jersey.javadoc.uri.prefix;/media/multipart/MultiPartProperties.html#MULTI_PART_CONFIG_RESOURCE'>MultiPartProperties.MULTI_PART_CONFIG_RESOURCE</link>">
<!ENTITY jersey.media.multipart.MultiPartProperties.TEMP_DIRECTORY "<link xlink:href='&jersey.javadoc.uri.prefix;/media/multipart/MultiPartProperties.html#TEMP_DIRECTORY'>MultiPartProperties.TEMP_DIRECTORY</link>">
<!ENTITY jersey.media.multipart.StreamDataBodyPart "<link xlink:href='&jersey.javadoc.uri.prefix;/media/multipart/file/StreamDataBodyPart.html'>StreamDataBodyPart</link>">
<!ENTITY jersey.message.MessageBodyWorkers "<link xlink:href='&jersey.javadoc.uri.prefix;/message/MessageBodyWorkers.html'>MessageBodyWorkers</link>">
<!ENTITY jersey.message.MessageProperties "<link xlink:href='&jersey.javadoc.uri.prefix;/message/MessageProperties.html'>MessageProperties</link>">
<!ENTITY jersey.message.MessageProperties.DEFLATE_WITHOUT_ZLIB "<link xlink:href='&jersey.javadoc.uri.prefix;/message/MessageProperties.html#DEFLATE_WITHOUT_ZLIB'>MessageProperties.DEFLATE_WITHOUT_ZLIB</link>">
Expand Down
21 changes: 20 additions & 1 deletion docs/src/main/docbook/media.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" standalone="no"?>
<!--
Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved.
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 @@ -1878,5 +1878,24 @@ public String postForm(
</tip>
</section>
</section>
<section xml:id="multipart.configuration">
<title>Properties for configuring the Multipart</title>
<para>
There are multiple options that can be used when configuring
the multipart. See &jersey.media.multipart.MultiPartProperties; or <xref linkend="appendix-properties-multipart"/>
for the possibilities.
</para>
<para>
The options can set in a configuration file specified by the
&jersey.media.multipart.MultiPartProperties.MULTI_PART_CONFIG_RESOURCE; property.
That is the standard Java properties file.
</para>
<para>
Or the options can be set programmatically,
by registering <literal>ContextResolver&lt;MultiPartProperties&gt;</literal>. For instance:
</para>
<programlisting language="java">ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.register(new MultiPartProperties().bufferThreshold(65535).maxParts(2).resolver());</programlisting>
</section>
</section>
</chapter>
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, 2024 Oracle and/or its affiliates. All rights reserved.
*
* 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 All @@ -23,6 +23,7 @@
import jakarta.ws.rs.ext.ContextResolver;

import org.glassfish.jersey.internal.util.PropertiesClass;
import org.glassfish.jersey.message.internal.ReaderWriter;

/**
* Injectable JavaBean containing the configuration parameters for
Expand All @@ -38,20 +39,25 @@ public class MultiPartProperties {
/**
* Default threshold size for buffer.
*/
public static final int DEFAULT_BUFFER_THRESHOLD = 4096;
public static final int DEFAULT_BUFFER_THRESHOLD = ReaderWriter.BUFFER_SIZE;

/**
* <p>
* Name of a properties resource that (if found in the classpath
* for this application) will be used to configure the settings returned
* by our getter methods.
* </p>
* <p>
* The resource name is {@code jersey-multipart-config.properties}.
* </p>
*/
public static final String MULTI_PART_CONFIG_RESOURCE = "jersey-multipart-config.properties";

/**
* Name of the resource property for the threshold size (in bytes) above which a body part entity will be
* buffered to disk instead of being held in memory.
*
* The default value is {@value #DEFAULT_BUFFER_THRESHOLD}.
* The default value is {@link #DEFAULT_BUFFER_THRESHOLD}.
*/
public static final String BUFFER_THRESHOLD = "jersey.config.multipart.bufferThreshold";

Expand All @@ -60,9 +66,21 @@ public class MultiPartProperties {
*/
public static final int BUFFER_THRESHOLD_MEMORY_ONLY = -1;

/**
* <p>
* Limit the maximum number of parts the multipart entity can have. If the limit is over,
* the error response status {@link jakarta.ws.rs.core.Response.Status#REQUEST_ENTITY_TOO_LARGE} is returned.
* </p>
* <p>
* By default, the number is unlimited.
* </p>
* @since 2.44
*/
public static final String MAX_PARTS = "jersey.config.multipart.maxParts";

/**
* Name of the resource property for the directory to store temporary files containing body parts of multipart message that
* extends allowed memory threshold..
* extends allowed memory threshold.
*
* The default value is not set (will be taken from {@code java.io.tmpdir} system property).
*/
Expand All @@ -79,6 +97,11 @@ public class MultiPartProperties {
*/
private String tempDir = null;

/**
* Maximum number of entity parts allowed.
*/
private int maxParts = Integer.MAX_VALUE;

/**
* Load and customize (if necessary) the configuration values for the
* {@code jersey-multipart} injection binder.
Expand Down Expand Up @@ -113,6 +136,15 @@ public String getTempDir() {
return tempDir;
}

/**
* Return maximum number of entity parts allowed.
* @return maximum number of parts.
* @since 2.44
*/
public int getMaxParts() {
return maxParts;
}

/**
* Set the size (in bytes) of the entity of an incoming {@link BodyPart} before it will be buffered to disk.
*
Expand All @@ -138,6 +170,17 @@ public MultiPartProperties tempDir(final String path) {
return this;
}

/**
* Set the maximum number of received parts of a multipart entity.
* @param maxParts The maximum number of entity parts.
* @return {@code MultiPartProperties} instance.
* @since 2.44
*/
public MultiPartProperties maxParts(int maxParts) {
this.maxParts = maxParts;
return this;
}

/**
* Configure the values returned by this instance's getters based on
* the contents of a properties resource, if it exists on the classpath
Expand Down Expand Up @@ -169,6 +212,9 @@ private void configure() {
if (props.containsKey(TEMP_DIRECTORY)) {
this.tempDir = props.getProperty(TEMP_DIRECTORY);
}
if (props.contains(MAX_PARTS)) {
this.maxParts = Integer.parseInt(props.getProperty(MAX_PARTS));
}
} catch (final IOException e) {
throw new IllegalArgumentException(e);
} finally {
Expand Down
Loading

0 comments on commit 47716d0

Please sign in to comment.