From 07db37f530aa9450874f2e96b31505ab3e39e622 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Wed, 1 Sep 2021 11:32:03 +0300 Subject: [PATCH] Fix @NoCache without fields handling in RESTEasy Reactive Fixes: #19822 --- .../test/cache/NoCacheOnMethodsTest.java | 40 +++++++++++++------ .../scanning/CacheControlScanner.java | 10 ++--- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/cache/NoCacheOnMethodsTest.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/cache/NoCacheOnMethodsTest.java index 00662d7c38287..1925a3855d852 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/cache/NoCacheOnMethodsTest.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/cache/NoCacheOnMethodsTest.java @@ -30,37 +30,53 @@ public JavaArchive get() { }); @Test - public void testWith() { - RestAssured.get("/test/with") + public void testWithFields() { + RestAssured.get("/test/withFields") .then() .statusCode(200) - .body(equalTo("with")) + .body(equalTo("withFields")) .header("Cache-Control", "no-cache=\"f1\", no-cache=\"f2\""); } @Test - public void testWithout() { - RestAssured.get("/test/without") + public void testWithoutFields() { + RestAssured.get("/test/withoutFields") .then() .statusCode(200) - .body(equalTo("without")) + .body(equalTo("withoutFields")) + .header("Cache-Control", "no-cache"); + } + + @Test + public void testWithoutAnnotation() { + RestAssured.get("/test/withoutAnnotation") + .then() + .statusCode(200) + .body(equalTo("withoutAnnotation")) .header("Cache-Control", nullValue()); } @Path("test") public static class ResourceWithNoCache { - @Path("with") + @Path("withFields") @GET @NoCache(fields = { "f1", "f2" }) - public String with() { - return "with"; + public String withFields() { + return "withFields"; + } + + @Path("withoutFields") + @GET + @NoCache + public String withoutFields() { + return "withoutFields"; } - @Path("without") + @Path("withoutAnnotation") @GET - public String without() { - return "without"; + public String withoutAnnotation() { + return "withoutAnnotation"; } } } diff --git a/independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/scanning/CacheControlScanner.java b/independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/scanning/CacheControlScanner.java index 5b5ef46790639..6464523f41e22 100644 --- a/independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/scanning/CacheControlScanner.java +++ b/independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/scanning/CacheControlScanner.java @@ -61,18 +61,18 @@ private ExtendedCacheControl noCacheToCacheControl(AnnotationInstance noCacheIns if (noCacheInstance == null) { return null; } + ExtendedCacheControl cacheControl = new ExtendedCacheControl(); + cacheControl.setNoCache(true); + cacheControl.setNoTransform(false); AnnotationValue fieldsValue = noCacheInstance.value("fields"); if (fieldsValue != null) { String[] fields = fieldsValue.asStringArray(); if ((fields != null) && (fields.length > 0)) { - ExtendedCacheControl cacheControl = new ExtendedCacheControl(); - cacheControl.setNoCache(true); - cacheControl.setNoTransform(false); cacheControl.getNoCacheFields().addAll(Arrays.asList(fields)); - return cacheControl; + } } - return null; + return cacheControl; } private ExtendedCacheControl cacheToCacheControl(AnnotationInstance cacheInstance) {