Fix regression on LoggingFeature's max entity size (#5007)
diff --git a/core-common/src/main/java/org/glassfish/jersey/logging/LoggingInterceptor.java b/core-common/src/main/java/org/glassfish/jersey/logging/LoggingInterceptor.java
index 601d6b2..fd1791b 100644
--- a/core-common/src/main/java/org/glassfish/jersey/logging/LoggingInterceptor.java
+++ b/core-common/src/main/java/org/glassfish/jersey/logging/LoggingInterceptor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, 2021 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 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
@@ -305,7 +305,7 @@
if ((off | len | ba.length - (len + off) | off + len) < 0) {
throw new IndexOutOfBoundsException();
}
- if ((baos.size() + len) <= maxEntitySize) {
+ if (baos.size() <= maxEntitySize) {
baos.write(ba, off, len);
}
out.write(ba, off, len);
diff --git a/tests/e2e/src/test/java/org/glassfish/jersey/tests/e2e/common/LoggingFeatureTest.java b/tests/e2e/src/test/java/org/glassfish/jersey/tests/e2e/common/LoggingFeatureTest.java
index b85b8df..3f3522e 100644
--- a/tests/e2e/src/test/java/org/glassfish/jersey/tests/e2e/common/LoggingFeatureTest.java
+++ b/tests/e2e/src/test/java/org/glassfish/jersey/tests/e2e/common/LoggingFeatureTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2021 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
@@ -284,6 +284,23 @@
assertThat(record.getMessage(), containsString(SEPARATOR));
}
+ @Test
+ public void testLoggingFeatureMaxEntitySize() {
+ final Response response = target("/text")
+ .register(LoggingFeature.class)
+ .property(LoggingFeature.LOGGING_FEATURE_LOGGER_NAME, LOGGER_NAME)
+ .property(LoggingFeature.LOGGING_FEATURE_MAX_ENTITY_SIZE, 1)
+ .request()
+ .post(Entity.text(ENTITY));
+
+ // Correct response status.
+ assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
+ // Check logs for trimmedEntity.
+ String trimmedEntity = ENTITY.charAt(0) + "...more...";
+ List<LogRecord> logRecords = getLoggedRecords();
+ assertThat(getLoggingFilterRequestLogRecord(logRecords).getMessage(), containsString(trimmedEntity));
+ assertThat(getLoggingFilterResponseLogRecord(logRecords).getMessage(), containsString(trimmedEntity));
+ }
}
/**