Skip to content

Commit b64d9a0

Browse files
Changes
- Removed old workaround/cast for NIO buffers in Java 1.8; doesn't work anymore with Jetty and newer Java versions. - Added ws_upload_buffer_size to configuration that is used by new upload logic. - NanoHTTPD BEETROOT 2.3.6
1 parent a17e734 commit b64d9a0

File tree

10 files changed

+53
-23
lines changed

10 files changed

+53
-23
lines changed

cfg/beetroot.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ ws_cache_size=2
332332
#
333333
ws_file_cache_size=200
334334

335+
#
336+
# Upload buffer size in kBytes.
337+
#
338+
ws_upload_buffer_size=16
339+
335340
#
336341
# Response buffer size in kBytes.
337342
#

cfg/beetroot_dist.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ ws_cache_size=2
332332
#
333333
ws_file_cache_size=200
334334

335+
#
336+
# Upload buffer size in kBytes.
337+
#
338+
ws_upload_buffer_size=16
339+
335340
#
336341
# Response buffer size in kBytes.
337342
#

cfg/beetroot_test.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ ws_cache_size=1
332332
#
333333
ws_file_cache_size=200
334334

335+
#
336+
# Upload buffer size in kBytes.
337+
#
338+
ws_upload_buffer_size=16
339+
335340
#
336341
# Response buffer size in kBytes.
337342
#

db/h2/db/test/beetroot.mv.db

16 KB
Binary file not shown.

doc/running.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ The following web containers are supported.
6363
$ java -jar $JETTY_HOME/start.jar --add-modules=server,http,ee11-deploy
6464
```
6565

66-
Make sure the environment variable `JETTY_HOME` is set; it should point to the `jetty-home-12.x.x` directory. Also, set the environment variable `JETTY_BASE` to point to the base directory you created.
66+
Make sure the environment variable `JETTY_HOME` is set; it should point to the `jetty-home-12.x.x` directory. Also, set the environment variable `JETTY_BASE` to point to the base directory you created.
6767

6868
3. For proper [Log4j 2 logging](https://logging.apache.org/log4j/2.12.x/index.html) via [SLF4J](https://www.slf4j.org/), you unfortunately need to provide your own `log4j2.xml` file. Jetty does not automatically read Log4j2 configurations from standard locations within the web archive. Therefore, create this file in your base directory at `resources/log4j2.xml`:
6969

@@ -123,6 +123,8 @@ The following web containers are supported.
123123

124124
6. Place `beetroot-jetty.war` into the `webapps/` folder of your Jetty base directory. Start Jetty, then open your browser and navigate `http://localhost:8080/beetroot`.
125125

126+
**Note**: Keep in mind that Jetty, by default, extracts the WAR into a temporary directory. When the server is restarted, this directory is deleted and a new one is created. Therefore, you cannot apply patches in this default mode, nor will any data stored inside the internal H2 database persist. If you require a persistent deployment, you must configure Jetty to run the application in exploded WAR mode.
127+
126128
For further instructions, see: [Jetty 12.1 Operations Guide](https://jetty.org/docs/jetty/12.1/operations-guide/begin/index.html).
127129

128130
### Oracle WebLogic

etc/pom/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<version.maven.surefire.plugin>3.5.4</version.maven.surefire.plugin>
2929

3030
<version.autumo.beetroot>3.2.0</version.autumo.beetroot>
31-
<version.nanohttpd>BEETROOT-2.3.5</version.nanohttpd>
31+
<version.nanohttpd>BEETROOT-2.3.6</version.nanohttpd>
3232
<version.hikaricp>7.0.2</version.hikaricp>
3333
<version.jcolor>5.5.1</version.jcolor>
3434
<version.angus.activation>2.0.3</version.angus.activation>
Binary file not shown.

lib/repo/org/nanohttpd/nanohttpd/BEETROOT-2.3.5/nanohttpd-BEETROOT-2.3.5.jar renamed to lib/repo/org/nanohttpd/nanohttpd/BEETROOT-2.3.6/nanohttpd-BEETROOT-2.3.6.jar

53.3 KB
Binary file not shown.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<version.maven.resources.plugin>3.4.0</version.maven.resources.plugin>
5353
<version.maven.surefire.plugin>3.5.4</version.maven.surefire.plugin>
5454

55-
<version.nanohttpd>BEETROOT-2.3.5</version.nanohttpd>
55+
<version.nanohttpd>BEETROOT-2.3.6</version.nanohttpd>
5656
<version.hikaricp>7.0.2</version.hikaricp>
5757
<version.jcolor>5.5.1</version.jcolor>
5858
<version.angus.activation>2.0.3</version.angus.activation>

src/main/java/ch/autumo/beetroot/BeetRootHTTPSession.java

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package ch.autumo.beetroot;
1919

20+
import java.io.ByteArrayOutputStream;
2021
import java.io.IOException;
2122
import java.io.InputStream;
2223
import java.io.OutputStream;
@@ -32,10 +33,6 @@
3233
import java.util.Locale;
3334
import java.util.Map;
3435

35-
import jakarta.servlet.http.HttpServletRequest;
36-
import jakarta.servlet.http.HttpServletResponse;
37-
import jakarta.servlet.http.Part;
38-
3936
import org.nanohttpd.protocols.http.HTTPSession;
4037
import org.nanohttpd.protocols.http.NanoHTTPD;
4138
import org.nanohttpd.protocols.http.NanoHTTPD.ResponseException;
@@ -50,6 +47,9 @@
5047
import org.slf4j.LoggerFactory;
5148

5249
import ch.autumo.beetroot.handler.ErrorHandler;
50+
import jakarta.servlet.http.HttpServletRequest;
51+
import jakarta.servlet.http.HttpServletResponse;
52+
import jakarta.servlet.http.Part;
5353

5454
/**
5555
* BeetRoot HTTP session.
@@ -60,12 +60,18 @@ public class BeetRootHTTPSession extends HTTPSession {
6060

6161
static {
6262

63-
int kBytes = BeetRootConfigurationManager.getInstance().getInt("ws_response_buffer_size");
63+
int kBytes = BeetRootConfigurationManager.getInstance().getInt("ws_upload_buffer_size");
6464
if (kBytes == -1) {
65-
LOG.warn("Using 16 kBytes for response buffer size.");
65+
LOG.warn("Using 16 kBytes for upload buffer size.");
6666
kBytes = 16;
6767
}
68+
UPLOAD_BUFFER_SIZE = kBytes * 1024;
6869

70+
kBytes = BeetRootConfigurationManager.getInstance().getInt("ws_response_buffer_size");
71+
if (kBytes == -1) {
72+
LOG.warn("Using 16 kBytes for response buffer size.");
73+
kBytes = 16;
74+
}
6975
RESPONSE_BUFFER_SIZE = kBytes * 1024;
7076
System.setProperty("ch.autumo.beetroot.respDownBufSizeKB", "" + kBytes);
7177

@@ -74,15 +80,18 @@ public class BeetRootHTTPSession extends HTTPSession {
7480
LOG.warn("Using 8 kBytes for response download buffer size.");
7581
kBytesDown = 8;
7682
}
77-
7883
RESPONSE_DOWNLOAD_BUFFER_SIZE = kBytesDown * 1024;
84+
7985
}
8086

81-
// buffer size
82-
public static final long RESPONSE_BUFFER_SIZE;
87+
// Upload buffer size.
88+
public static final int UPLOAD_BUFFER_SIZE;
8389

84-
// download buffer size
85-
public static final long RESPONSE_DOWNLOAD_BUFFER_SIZE;
90+
// Response buffer size.
91+
public static final int RESPONSE_BUFFER_SIZE;
92+
93+
// Download response buffer size.
94+
public static final int RESPONSE_DOWNLOAD_BUFFER_SIZE;
8695

8796
private String externalSessionId;
8897

@@ -170,7 +179,7 @@ public void executeForServlet(BeetRootService beetRootService, HttpServletReques
170179
if (downHeaderVal != null) {
171180
response.setContentType(r.getMimeType());
172181
response.setHeader("Content-disposition", downHeaderVal);
173-
final byte[] buffer = new byte[Long.valueOf(RESPONSE_BUFFER_SIZE).intValue()];
182+
final byte[] buffer = new byte[RESPONSE_BUFFER_SIZE];
174183
int numBytesRead;
175184
while ((numBytesRead = r.getData().read(buffer)) > 0) {
176185
response.getOutputStream().write(buffer, 0, numBytesRead);
@@ -278,14 +287,18 @@ public void parseBodyForServlet(Map<String, String> files, HttpServletRequest re
278287
if (partName.startsWith("MAX") || partName.startsWith("_"))
279288
continue LOOP;
280289

281-
int size = (int) part.getSize();
282-
InputStream inputStream = part.getInputStream();
283-
byte[] bytes = new byte[inputStream.available()];
284-
inputStream.read(bytes);
285-
286-
ByteBuffer fbuf = ByteBuffer.wrap(bytes, 0, bytes.length);
287-
final String path = saveTmpFile(fbuf, 0, size, part.getSubmittedFileName());
288-
files.put(partName, path);
290+
final InputStream inputStream = part.getInputStream();
291+
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
292+
byte[] buffer = new byte[UPLOAD_BUFFER_SIZE];
293+
int read;
294+
while ((read = inputStream.read(buffer)) != -1) {
295+
baos.write(buffer, 0, read);
296+
}
297+
byte[] bytes = baos.toByteArray();
298+
299+
final ByteBuffer fbuf = ByteBuffer.wrap(bytes, 0, bytes.length);
300+
final String path = saveTmpFile(fbuf, 0, bytes.length, part.getSubmittedFileName());
301+
files.put(partName, path);
289302

290303
List<String> values = super.parms.get(partName);
291304
if (values == null) {

0 commit comments

Comments
 (0)