mangusbrother
mangusbrother

Reputation: 4156

ServerResponseFilter not being applied to GET

I have a Quarkus application with the following filters definition:


@ApplicationScoped
@Slf4j
public class Filters {


// some @Inject parameters i'm using

  @ServerRequestFilter(preMatching = true)
  public void requestLoggingFilter(ContainerRequestContext requestContext) {
    log.info("Recv: [{}] {}, {}", requestContext.getHeaderString("myHeader"), requestContext.getMethod(), requestContext.getUriInfo().getRequestUri());
  }



  @ServerResponseFilter
  public void responseBasicHeaderFilter(ContainerResponseContext responseContext) {
    responseContext.getHeaders().putSingle("myHeader, "myValue");
  }

  @ServerResponseFilter
  public void responseLoggingFilter(ContainerResponseContext responseContext) {
    log.info("Sent: [{}] {} {}", responseContext.getHeaderString("myHeader"), , responseContext.getStatusInfo(), responseContext.getEntity());
  }
}

And I have two tests: Test Class config:

@QuarkusTest
public class MyTest {
...
}

Test A:

  final Response response = given()
        .post(BASE_URL)
        .then()
        .extract().response();
    assertEquals(200, response.getStatusCode(), () -> "Got: " + response.prettyPrint());
    assertEquals("myValue", response.getHeader("myHeader"));

  final Response response2 = given()
        .get(BASE_URL)
        .then()
        .extract().response();
    assertEquals(200, response2.getStatusCode(), () -> "Got: " + response2.prettyPrint());
    assertEquals("myValue", response2.getHeader("myHeader"));

Test B:

  final Response response = given()
        .post(BASE_URL)
        .then()
        .extract().response();
    assertEquals(200, response.getStatusCode(), () -> "Got: " + response.prettyPrint());
    assertEquals("myValue", response.getHeader("myHeader"));

If i run Test B on it's own, it passes.

If i run Test A however the last assertion fails (the header value is not there).

The @ServerResponseFilter seem to not be called beyond the first time, however @ServerRequestFilter seem to be fine.

I have tested the api manually and can confirm the same behaviour. Calling the GET request first will also have the same behaviour.

I have verified that the response generated by my Controller (pojo) is generated successfully.

What could be preventing it from being rerun?

Upvotes: 0

Views: 607

Answers (1)

mangusbrother
mangusbrother

Reputation: 4156

Turns out it wasn't related to GET vs POST

my GET method was returning a Multi . I converted this to Uni> and it worked.

From the documentation i found this snippet

Reactive developers may wonder why we can't return a stream of fruits directly. It tends to eb a bad idea with a database....

The keyword being we can't so I imagine this is not supported functionality

Upvotes: 1

Related Questions