Skip to content

Commit

Permalink
Fix regression on LoggingFeature's max entity size (eclipse-ee4j#5007)
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomsantos committed Mar 18, 2022
1 parent 9bb2e8d commit 8a4ee71
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
@@ -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
Expand Down Expand Up @@ -305,7 +305,7 @@ public void write(byte[] ba, int off, int len) throws IOException {
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);
Expand Down
@@ -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
Expand Down Expand Up @@ -284,6 +284,23 @@ public void testLoggingFeatureBuilderProperty() {
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));
}
}

/**
Expand Down

0 comments on commit 8a4ee71

Please sign in to comment.