您可以使用它来使用自定义HeaderFilterStrategy。关键是要配置它在restConfiguration()endpointProperties(..)是这样的:
public void configure() {
JndiRegistry registry = getContext().getRegistry(JndiRegistry.class);
registry.bind("filter", new HeaderFilter());
restConfiguration()
.host("localhost")
.endpointProperty("headerFilterStrategy","#filter")
.setPort("10000");
from("rest:get:hello")
.to("http://localhost:20000?bridgeEndpoint=true")
.setHeader("Cache-Control",constant("private, max-age=0,no-store"));
from("netty-http:http://localhost:20000")
.setBody(constant("ok"));
}
其中#filter只是虚拟实现这样的(你可以创建一个适合你的好需求的过滤器)
public class HeaderFilter implements HeaderFilterStrategy {
@Override
public boolean applyFilterToCamelHeaders(String arg0, Object arg1, Exchange arg2) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean applyFilterToExternalHeaders(String arg0, Object arg1, Exchange arg2) {
// TODO Auto-generated method stub
return false;
}
}
现在如果要是跑我的路线没有.endpointProperty( “headerFilterStrategy”, “#过滤器”)线我得到的输出力科本
$ curl -D - http://localhost:10000/hello
HTTP/1.1 200 OK
Accept: */*
breadcrumbId: ID-myhost-40508-1441899753215-0-1
User-Agent: curl/7.35.0
Content-Length: 2
Connection: keep-alive
ok
和与.endpointProperty( “headerFilterStrategy”, “#过滤器”)线输出这样
$ curl -D - http://localhost:10000/hello
HTTP/1.1 200 OK
Accept: */*
breadcrumbId: ID-myhost-56308-1441899833287-0-1
Cache-Control: private, max-age=0,no-store
CamelHttpMethod: GET
CamelHttpResponseCode: 200
CamelHttpUri: /hello
CamelHttpUrl: http://localhost:10000/hello
CamelNettyChannelHandlerContext: org.jboss.ne[email protected]1fac34b
CamelNettyLocalAddress: /127.0.0.1:10000
CamelNettyMessageEvent: [id: 0x93dfe147, /127.0.0.1:35302 => /127.0.0.1:10000] RECEIVED: DefaultHttpRequest(chunked: false) GET /hello HTTP/1.1 User-Agent: curl/7.35.0 Host: localhost:10000 Accept: */*
CamelNettyRemoteAddress: /127.0.0.1:35302
User-Agent: curl/7.35.0
Content-Length: 2
Connection: keep-alive
ok