Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-13794

netty4-http: headerFilterStrategy not properly taken into account

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Invalid
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: camel-netty4-http
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      I have this test with a custom header filter strategy:

      @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");
      }
      

      This test fails because:

      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"]]>
      

      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.

        Attachments

          Activity

            People

            • Assignee:
              acosentino Andrea Cosentino
              Reporter:
              lb Luca Burgazzoli
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: