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

camel-http - HTTP broken followRedirection

    XMLWordPrintableJSON

Details

    • Unknown

    Description

      Look like in 3.20.0 broken functionallity for disable follow redirections (HTTP 300-399 statuses) by set automatic-retries-disabled. Now need also set RedirectHandlingDisabled

       

      Here simple example:

      import org.apache.camel.CamelContext;
      import org.apache.camel.Exchange;
      import org.apache.camel.builder.RouteBuilder;
      import org.apache.camel.component.http.HttpComponent;
      import org.apache.camel.impl.DefaultCamelContext;
      
      import static org.apache.camel.builder.endpoint.StaticEndpointBuilders.http;
      
      class Scratch {
          public static void main(String[] args) throws Exception {
              //1
              CamelContext context1 = createContext(8080);
              var httpComponent1 = context1.getComponent("http", HttpComponent.class);
              httpComponent1.setFollowRedirects(false);
              context1.start();
      
              var response1 = context1.createProducerTemplate().requestBody("direct:http", "");
              //Redirect to Apache Camel Page without any errors
              System.out.println(response1);
      
      
              //2
              CamelContext context2 = createContext(8081);
              var httpComponent2 = context2.getComponent("http", HttpComponent.class);
              httpComponent2.setFollowRedirects(false);
              httpComponent2.setAutomaticRetriesDisabled(true);
              context2.start();
              var response2 = context2.createProducerTemplate().requestBody("direct:http", "");
              //Redirect to Apache Camel Page without any errors
              System.out.println(response2);
      
              //3
              CamelContext context3 = createContext(8082);
              var httpComponent3 = context3.getComponent("http", HttpComponent.class);
              httpComponent3.setFollowRedirects(false);
              httpComponent3.setAutomaticRetriesDisabled(true);
              httpComponent3.setRedirectHandlingDisabled(true);
              context3.start();
              var response3 = context3.createProducerTemplate().requestBody("direct:http", "");
              //work as expected - error throws
              System.out.println(response3);
      
          }
      
          private static CamelContext createContext(int port) throws Exception {
              CamelContext context = new DefaultCamelContext();
              context.addRoutes(new RouteBuilder() {
                  @Override
                  public void configure() {
                      restConfiguration().component("jetty").host("localhost").port(port);
                      rest().get("test303").to("direct:addLocation");
                      from("direct:addLocation")
                              .setHeader("Location", constant("https://camel.apache.org"))
                              .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(303));
      
                      from("direct:http")
                              .setHeader(Exchange.HTTP_METHOD, constant("GET"))
                              .to(http("localhost:" + port + "/test303")
                                      .bridgeEndpoint(true)
                                      .throwExceptionOnFailure(true)
                                      .advanced()
                                      .okStatusCodeRange("200-299"))
                              .convertBodyTo(String.class);
                  }
              });
              return context;
          }
      } 

       

      • In version 3.11.1 exaption throws on 2 step with setAutomaticRetriesDisabled  (for run it - need remove setFollowRedirects)
      • In version 3.20.0 exaption throws  only on 3 step.

       

      Please fix it or add description of this new behavior to your documentaions.

      Also I don't understan how to use option camel.component.http.follow-redirects because seems it does not works as expected "Whether to the HTTP request should follow redirects."

      Attachments

        Issue Links

          Activity

            People

              davsclaus Claus Ibsen
              akvel Valeriy Ak
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: