英文:
Why ContainerResponseFilter dosen't work with Camel Rest component?
问题
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.
英文:
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.
答案1
得分: 1
如果您想设置自定义响应头,您可以在Camel路由中执行以下操作:
public class RestRoutes extends RouteBuilder {
@Override
public void configure() {
rest("/rest")
.get()
.to("direct:myRoute");
from("direct:myRoute")
.setHeader("my-custom").constant("my-value");
}
}
或者,由于platform-http
基于Vert.x Web构建,您可以使用quarkus-reactive-routes
来拦截请求并向响应添加自定义头。
@RouteFilter(100)
void myFilter(RoutingContext rc) {
rc.response().putHeader("my-custom", "my-value");
rc.next();
}
更多信息可以在这里找到:
https://quarkus.io/guides/reactive-routes#intercepting-http-requests
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论