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

Cannot use square brackets in HTTP parameters

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 3.12.0
    • 3.14.1, 3.15.0
    • camel-core
    • None
    • Unknown

    Description

      It was reported on mailing list, there is some problem when trying to use square brackets as part of the URI params. I've run some expertiment with the RAW() function, but this is only applied to the value parameter, not the variable name (ie, param=RAW(value)).

      As a reproducer, we may run this route (ie, via Camel K):

      // camel-k: language=java
      
      import org.apache.camel.builder.RouteBuilder;
      import org.apache.camel.model.rest.RestParamType;
      import org.apache.camel.Exchange;
      
      public class Test extends RouteBuilder {
        @Override
        public void configure() throws Exception {
            rest()
                .get("/hello")
                .param().name("test[bogus]").type(RestParamType.query).defaultValue("false").description("Just for testing").endParam()
                .to("direct:hello");
      
            from("direct:hello")
                .setHeader(Exchange.CONTENT_TYPE, constant("text/plain"))
                .setBody().simple("${headers.test[bogus]}");
      
            // Write your routes here, for example:
            from("timer:java?period=3000")
              .to("http://localhost:8080/hello?test[bogus]=true")
              .log("${body}");
        }
      }
      

      It will end up with error:

      [1] Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: http://localhost:8080/hello?test%5Bbogus%5D=true due to: Error binding property (test[bogus]=true) with name: test[bogus] on bean: http://localhost:8080/hello?test%5Bbogus%5D=true with value: true
      [1]     at org.apache.camel.impl.engine.AbstractCamelContext.doGetEndpoint(AbstractCamelContext.java:963)
      [1]     at org.apache.camel.impl.engine.AbstractCamelContext.getEndpoint(AbstractCamelContext.java:845)
      [1]     at org.apache.camel.support.CamelContextHelper.resolveEndpoint(CamelContextHelper.java:123)
      [1]     at org.apache.camel.reifier.SendReifier.resolveEndpoint(SendReifier.java:43)
      [1]     at org.apache.camel.reifier.SendReifier.createProcessor(SendReifier.java:36)
      [1]     at org.apache.camel.reifier.ProcessorReifier.makeProcessor(ProcessorReifier.java:838)
      [1]     at org.apache.camel.reifier.ProcessorReifier.addRoutes(ProcessorReifier.java:579)
      [1]     at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:236)
      [1]     ... 31 more
      [1] Caused by: org.apache.camel.PropertyBindingException: Error binding property (test[bogus]=true) with name: test[bogus] on bean: http://localhost:8080/hello?test%5Bbogus%5D=true with value: true
      [1]     at org.apache.camel.support.PropertyBindingSupport.doSetPropertyValue(PropertyBindingSupport.java:476)
      [1]     at org.apache.camel.support.PropertyBindingSupport.doBuildPropertyOgnlPath(PropertyBindingSupport.java:326)
      [1]     at org.apache.camel.support.PropertyBindingSupport.doBindProperties(PropertyBindingSupport.java:210)
      [1]     at org.apache.camel.support.PropertyBindingSupport.access$100(PropertyBindingSupport.java:88)
      [1]     at org.apache.camel.support.PropertyBindingSupport$Builder.bind(PropertyBindingSupport.java:1789)
      [1]     at org.apache.camel.support.DefaultEndpoint.setProperties(DefaultEndpoint.java:413)
      [1]     at org.apache.camel.support.DefaultEndpoint.configureProperties(DefaultEndpoint.java:388)
      [1]     at org.apache.camel.support.DefaultComponent.setProperties(DefaultComponent.java:425)
      [1]     at org.apache.camel.component.http.HttpComponent.createEndpoint(HttpComponent.java:377)
      [1]     at org.apache.camel.support.DefaultComponent.createEndpoint(DefaultComponent.java:171)
      [1]     at org.apache.camel.impl.engine.AbstractCamelContext.doGetEndpoint(AbstractCamelContext.java:929)
      [1]     ... 38 more
      [1] Caused by: java.lang.IllegalArgumentException: Cannot set property: test[bogus] as a Map because target bean has no setter method for the Map
      [1]     at org.apache.camel.support.PropertyBindingSupport.setPropertyCollectionViaReflection(PropertyBindingSupport.java:523)
      [1]     at org.apache.camel.support.PropertyBindingSupport.doSetPropertyValue(PropertyBindingSupport.java:453)
      [1]     ... 48 more
      

      Trying to apply the RAW() function on the parameter (ie, ?RAW(test[bogus])=true) does not convert the parameter, but create a new one called RAW(test[bogus])

      Attachments

        Activity

          People

            davsclaus Claus Ibsen
            squakez Pasquale Congiusti
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: