-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properly implement priority of ContainerResponseFilter #44237
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...resteasy/reactive/server/vertx/test/simple/MultipleResponseFiltersWithPrioritiesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package org.jboss.resteasy.reactive.server.vertx.test.simple; | ||
|
||
import static io.restassured.RestAssured.*; | ||
import static io.restassured.RestAssured.when; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import java.io.IOException; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.container.ContainerRequestContext; | ||
import jakarta.ws.rs.container.ContainerResponseContext; | ||
import jakarta.ws.rs.container.ContainerResponseFilter; | ||
import jakarta.ws.rs.ext.Provider; | ||
|
||
import org.jboss.resteasy.reactive.server.vertx.test.CookiesSetInFilterTest; | ||
import org.jboss.resteasy.reactive.server.vertx.test.framework.ResteasyReactiveUnitTest; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.restassured.http.Headers; | ||
|
||
public class MultipleResponseFiltersWithPrioritiesTest { | ||
|
||
@RegisterExtension | ||
static ResteasyReactiveUnitTest test = new ResteasyReactiveUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(CookiesSetInFilterTest.TestResource.class, CookiesSetInFilterTest.Filters.class)); | ||
|
||
@Test | ||
void requestDoesNotContainCookie() { | ||
when().get("/test") | ||
.then() | ||
.statusCode(200) | ||
.body(is("foo")); | ||
} | ||
|
||
@Test | ||
void test() { | ||
Headers headers = get("/hello") | ||
.then() | ||
.statusCode(200) | ||
.extract().headers(); | ||
assertThat(headers.getValues("filter-response")).containsOnly("max-default-0-minPlus1-min"); | ||
} | ||
|
||
@Path("hello") | ||
public static class TestResource { | ||
|
||
@GET | ||
public String get() { | ||
return "hello"; | ||
} | ||
} | ||
|
||
@Provider | ||
@Priority(Integer.MAX_VALUE) | ||
public static class FilterMax implements ContainerResponseFilter { | ||
|
||
@Override | ||
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) | ||
throws IOException { | ||
responseContext.getHeaders().putSingle("filter-response", "max"); | ||
} | ||
|
||
} | ||
|
||
@Provider | ||
public static class FilterDefault implements ContainerResponseFilter { | ||
|
||
@Override | ||
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) | ||
throws IOException { | ||
String previousFilterHeaderValue = (String) responseContext.getHeaders().getFirst("filter-response"); | ||
responseContext.getHeaders().putSingle("filter-response", previousFilterHeaderValue + "-default"); | ||
} | ||
|
||
} | ||
|
||
@Provider | ||
@Priority(0) | ||
public static class Filter0 implements ContainerResponseFilter { | ||
|
||
@Override | ||
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) | ||
throws IOException { | ||
String previousFilterHeaderValue = (String) responseContext.getHeaders().getFirst("filter-response"); | ||
responseContext.getHeaders().putSingle("filter-response", previousFilterHeaderValue + "-0"); | ||
} | ||
|
||
} | ||
|
||
@Provider | ||
@Priority(Integer.MIN_VALUE + 1) | ||
public static class FilterMinPlus1 implements ContainerResponseFilter { | ||
|
||
@Override | ||
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) | ||
throws IOException { | ||
String previousFilterHeaderValue = (String) responseContext.getHeaders().getFirst("filter-response"); | ||
responseContext.getHeaders().putSingle("filter-response", previousFilterHeaderValue + "-minPlus1"); | ||
} | ||
|
||
} | ||
|
||
@Provider | ||
@Priority(Integer.MIN_VALUE) | ||
public static class FilterMin implements ContainerResponseFilter { | ||
|
||
@Override | ||
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) | ||
throws IOException { | ||
String previousFilterHeaderValue = (String) responseContext.getHeaders().getFirst("filter-response"); | ||
responseContext.getHeaders().putSingle("filter-response", previousFilterHeaderValue + "-min"); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified with
Collections.reversedOrder(INSTANCE)
or by invoking it in the callerThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually like this idiom here because it follows the same principle as in the rest of RESTEasy Reactive codebase