Luca Burgazzoli created CAMEL-13794:
---------------------------------------

             Summary: netty4-http: headerFilterStrategy not properly taken into 
account
                 Key: CAMEL-13794
                 URL: https://issues.apache.org/jira/browse/CAMEL-13794
             Project: Camel
          Issue Type: Bug
          Components: camel-netty4-http
            Reporter: Luca Burgazzoli


I have this test with a custom header filter strategy:

{code}
@Test
void testCustomHeadersFilter() throws Exception {
    final int port = AvailablePortFinder.getNextAvailable();
    final CamelContext context = new DefaultCamelContext()

    DefaultHeaderFilterStrategy hfs = new DefaultHeaderFilterStrategy();
    hfs.setOutFilterPattern("(?i)(My)[\\.|a-z|A-z|0-9]*");
    hfs.setInFilterPattern("(?i)(My)[\\.|a-z|A-z|0-9]*");

    context.getRegistry().bind("myFilterStrategy", hfs);

    //NettyHttpComponent c = context.getComponent("netty4-http", 
NettyHttpComponent.class);
    //c.setHeaderFilterStrategy(hfs);

    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:source")
                .setHeader("CamelHeader")
                    .constant("CamelHeaderValue")
                .setHeader("MyHeader")
                    .constant("MyHeaderValue")
                
.toF("netty4-http:http://localhost:%d?headerFilterStrategy=#myFilterStrategy";, 
port)
                .to("mock:source");

            fromF("netty4-http:http://localhost:%d";, port)
                .setBody().constant("test");
        }
    });

    context.start();

    MockEndpoint mock = context.getEndpoint("mock:source", MockEndpoint.class);
    mock.expectedMessageCount(1);

    context.createProducerTemplate().sendBody("direct:source", "test");

    mock.assertIsSatisfied();

    
assertThat(mock.getExchanges().get(0).getMessage().getHeaders()).doesNotContainKey("MyHeader");
    
assertThat(mock.getExchanges().get(0).getMessage().getHeaders()).containsEntry("CamelHeader",
 "CamelHeaderValue");
}
{code}

This test fails because:

{code}
java.lang.AssertionError: 
Expecting:
 <{"CamelHttpResponseCode"=200, "CamelHttpResponseText"="OK", 
"connection"="keep-alive", "content-length"="4"}>
to contain:
 <[MapEntry[key="CamelHeader", value="CamelHeaderValue"]]>
but could not find:
 <[MapEntry[key="CamelHeader", value="CamelHeaderValue"]]>
{code}

which is strange as:
- CamelHeader is supposed to be present
- MyHeader is not present 

so it seems that the default netty filter is also used. 

If the header filter strategy is applied on component level, then the test 
succeed.



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to