Skip to content

Commit

Permalink
Prevent creation of the Response object for ContainerResponseContext
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Jan 22, 2025
1 parent 32144de commit d99c1a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import java.nio.file.Path;
import java.nio.file.Paths;

import jakarta.ws.rs.container.ContainerResponseContext;
import jakarta.ws.rs.core.HttpHeaders;

import org.hamcrest.Matchers;
import org.jboss.resteasy.reactive.FilePart;
import org.jboss.resteasy.reactive.PathPart;
import org.jboss.resteasy.reactive.server.ServerResponseFilter;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand All @@ -30,7 +32,7 @@ public class FileTestCase {
@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(FileResource.class, WithWriterInterceptor.class, WriterInterceptor.class));
.addClasses(FileResource.class, WithWriterInterceptor.class, WriterInterceptor.class, Filters.class));

@Test
public void testFiles() throws Exception {
Expand Down Expand Up @@ -168,4 +170,14 @@ public void testChecks() throws IOException {
} catch (IllegalArgumentException x) {
}
}

public static class Filters {

@ServerResponseFilter
public void responseHeaders(ContainerResponseContext responseContext) {
// make sure the use of these methods does not change the response code
responseContext.hasEntity();
responseContext.getEntity();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ public Builder getLinkBuilder(String relation) {

@Override
public boolean hasEntity() {
return response().hasEntity();
return context.getResult() != null;
}

@Override
public Object getEntity() {
return response().getEntity();
return context.getResult();
}

@Override
Expand Down

0 comments on commit d99c1a9

Please sign in to comment.