0

I'm using Quarkus 2.13 with Camel 3.18. I have rest endpoint set, which is working as expected:

restConfiguration()
   .component("platform-http")
   .skipBindingOnErrorCode(false)
   .bindingMode(RestBindingMode.json);

I did write ContainerResponseFilter to modify headers of outgoing response, but response is not handle via this filter:

@JBossLog
@Provider
public class CustomContainerResponseFilter implements ContainerResponseFilter {    

    @Override
    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
            throws IOException {

        responseContext.getHeaders().add("X-Some-Header", "Hello from Response Filter");
// I want to filter out disallowed-headers
    }
}

Filter is working fine with standar controller, but when using Camel Endpoint with platform-http, response is not handle via ContainerResponseFilter.

@Path("/hello")
public class HelloController {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String sayHello() {
        return "Hello, Quarkus!";
    }
}

Update:

My goal is to filter out disallowed-headers. For that I've create my list and just want to remove headers which are not on the list.

kingkong
  • 1,537
  • 6
  • 27
  • 48

1 Answers1

1

If you want to set a custom response header, then you can do it in your Camel route.

public class RestRoutes extends RouteBuilder {
    @Override
    public void configure() {
        rest("/rest")
                .get()
                .to("direct:myRoute");

        from("direct:myRoute")
                .setHeader("my-custom").constant("my-value");
    }
}

Alternatively, since platform-http builds on Vert.x Web, you could use quarkus-reactive-routes to intercept requests and add a custom header to the response.

@RouteFilter(100)
void myFilter(RoutingContext rc) {
    rc.response().putHeader("my-custom", "my-value");
    rc.next();
}

More information can be found here:

https://quarkus.io/guides/reactive-routes#intercepting-http-requests

James Netherton
  • 1,092
  • 1
  • 7
  • 9
  • James Netherton - Thanks that is helpful. As for first option, I have more rest routes defined + exceptions handling - I would prefer put my logic in one places and separet that from camel routes. As for second option - as I read in documentatio @RouteFilter works with Request - Intercepting HTTP requests. – kingkong Jul 24 '23 at 10:05