FAQ
I have a very simple use-case that seems to highlight a bug in Camel's URI
handling code. It's very easy to demonstrate, the following code shows the
problem:

String query = URLEncoder.encode("D & B", "UTF-8");
String endpoint = "https4://www.google.com/?" + query;
Exchange response = producerTemplate().send(endpoint, new
DefaultExchange(context));

The result back from the Google search is only performed on 'D', and not the
full 'D & B' search term we specified.

I thought this problem might have been resolved by CAMEL-4857, since that is
a code change in the same area of the code, but downloading and building
Camel TRUNK doesn't fix this simple problem at all, nor can I see any way it
can fix the above problem (so I think this is a separate bug completely).

The real problem seems to be located in the following line from the method
'normalizeUri(String uri)' in the class 'URISupport.java':

Line 349 (in trunk): Map<String, Object> parameters =
URISupport.parseParameters(u);

Within the 'parseParameters()' method, the first line calls
'uri.getQuery()', but this decodes the query string, which results in my
encoded query string above (which is passed into this method correctly as
'?q=D+%26+B') being decoded to '?q=D+&+B', which is then subsequently parsed
(in the 'parseQuery(query)' line at 178) as having multiple query params
('q=D+' and '+B') when in fact it really only has one ('q=D+%20+B').

I was hoping to make a simple code change to this code (i.e. simply changing
the above 'uri.getQuery()' call to be 'uri.getRawQuery()' but my trunk
version fails with a test failure when I run 'mvn clean install' on the
'camel-core' POM, see below:

Failed tests:

testPollFileAndShouldBeDeletedAtThirdPoll(org.apache.camel.component.file.From
FilePollThirdTimeOkTest): mock://result Body of message: 0. Expected: <Hello
Wor
ld this file will be deleted> but was: <null>

Tests run: 4322, Failures: 1, Errors: 0, Skipped: 1

Any guidance would be very welcome...



--
View this message in context: http://camel.465427.n5.nabble.com/Ampersand-in-URI-query-parameter-not-working-CAMEL-4857-doesn-t-fix-tp5720914.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Search Discussions

  • Donald Whytock at Oct 11, 2012 at 3:11 pm
    Just a thought...Since it's being decoded, did you try double-encoding?

    String query = URLEncoder.encode(URLEncoder.encode("D & B", "UTF-8"), "UTF-8");
    On Thu, Oct 11, 2012 at 10:40 AM, pmcb55 wrote:
    I have a very simple use-case that seems to highlight a bug in Camel's URI
    handling code. It's very easy to demonstrate, the following code shows the
    problem:

    String query = URLEncoder.encode("D & B", "UTF-8");
    String endpoint = "https4://www.google.com/?" + query;
    Exchange response = producerTemplate().send(endpoint, new
    DefaultExchange(context));

    The result back from the Google search is only performed on 'D', and not the
    full 'D & B' search term we specified.

    I thought this problem might have been resolved by CAMEL-4857, since that is
    a code change in the same area of the code, but downloading and building
    Camel TRUNK doesn't fix this simple problem at all, nor can I see any way it
    can fix the above problem (so I think this is a separate bug completely).

    The real problem seems to be located in the following line from the method
    'normalizeUri(String uri)' in the class 'URISupport.java':

    Line 349 (in trunk): Map<String, Object> parameters =
    URISupport.parseParameters(u);

    Within the 'parseParameters()' method, the first line calls
    'uri.getQuery()', but this decodes the query string, which results in my
    encoded query string above (which is passed into this method correctly as
    '?q=D+%26+B') being decoded to '?q=D+&+B', which is then subsequently parsed
    (in the 'parseQuery(query)' line at 178) as having multiple query params
    ('q=D+' and '+B') when in fact it really only has one ('q=D+%20+B').

    I was hoping to make a simple code change to this code (i.e. simply changing
    the above 'uri.getQuery()' call to be 'uri.getRawQuery()' but my trunk
    version fails with a test failure when I run 'mvn clean install' on the
    'camel-core' POM, see below:

    Failed tests:

    testPollFileAndShouldBeDeletedAtThirdPoll(org.apache.camel.component.file.From
    FilePollThirdTimeOkTest): mock://result Body of message: 0. Expected: <Hello
    Wor
    ld this file will be deleted> but was: <null>

    Tests run: 4322, Failures: 1, Errors: 0, Skipped: 1

    Any guidance would be very welcome...



    --
    View this message in context: http://camel.465427.n5.nabble.com/Ampersand-in-URI-query-parameter-not-working-CAMEL-4857-doesn-t-fix-tp5720914.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Pmcb55 at Oct 12, 2012 at 1:58 pm
    Hi Donald - you're a GENIUS, that worked!!

    I would never have thought of that solution, but it certainly gets us over
    our problem. I would certainly think this gotcha should be reflected on the
    Camel documentation though, just as a warning note...

    Many thanks,

    Pat.




    --
    View this message in context: http://camel.465427.n5.nabble.com/Ampersand-in-URI-query-parameter-not-working-CAMEL-4857-doesn-t-fix-tp5720914p5720960.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Hadrian Zbarcea at Oct 11, 2012 at 3:30 pm
    I will try to take a look at your example later today. The double
    encoding issue was there from the beginning of camel. Due to the limited
    number of components at the time, we didn't see the edge cases very
    well, and later on we only worked around the once we encountered.
    Realistically, a proper fix will only come in 3.0.

    Cheers,
    Hadrian
    On 10/11/2012 10:40 AM, pmcb55 wrote:
    I have a very simple use-case that seems to highlight a bug in Camel's URI
    handling code. It's very easy to demonstrate, the following code shows the
    problem:

    String query = URLEncoder.encode("D & B", "UTF-8");
    String endpoint = "https4://www.google.com/?" + query;
    Exchange response = producerTemplate().send(endpoint, new
    DefaultExchange(context));

    The result back from the Google search is only performed on 'D', and not the
    full 'D & B' search term we specified.

    I thought this problem might have been resolved by CAMEL-4857, since that is
    a code change in the same area of the code, but downloading and building
    Camel TRUNK doesn't fix this simple problem at all, nor can I see any way it
    can fix the above problem (so I think this is a separate bug completely).

    The real problem seems to be located in the following line from the method
    'normalizeUri(String uri)' in the class 'URISupport.java':

    Line 349 (in trunk): Map<String, Object> parameters =
    URISupport.parseParameters(u);

    Within the 'parseParameters()' method, the first line calls
    'uri.getQuery()', but this decodes the query string, which results in my
    encoded query string above (which is passed into this method correctly as
    '?q=D+%26+B') being decoded to '?q=D+&+B', which is then subsequently parsed
    (in the 'parseQuery(query)' line at 178) as having multiple query params
    ('q=D+' and '+B') when in fact it really only has one ('q=D+%20+B').

    I was hoping to make a simple code change to this code (i.e. simply changing
    the above 'uri.getQuery()' call to be 'uri.getRawQuery()' but my trunk
    version fails with a test failure when I run 'mvn clean install' on the
    'camel-core' POM, see below:

    Failed tests:

    testPollFileAndShouldBeDeletedAtThirdPoll(org.apache.camel.component.file.From
    FilePollThirdTimeOkTest): mock://result Body of message: 0. Expected: <Hello
    Wor
    ld this file will be deleted> but was: <null>

    Tests run: 4322, Failures: 1, Errors: 0, Skipped: 1

    Any guidance would be very welcome...



    --
    View this message in context: http://camel.465427.n5.nabble.com/Ampersand-in-URI-query-parameter-not-working-CAMEL-4857-doesn-t-fix-tp5720914.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Pmcb55 at Oct 12, 2012 at 12:58 am
    Hi Hadrian,

    Thanks for the response (the activity and responsiveness of this group
    continues to really impress me!).

    But it's a bit of a concern that correct handling of something as
    fundamental as URI's needs a major overhaul and a version 3.0 release to get
    'right' !

    This is a real problem for our project though, so I'd definitely appreciate
    a quick (but safe!) workaround for this edge-case (by the way, I'm sure
    you'll appreciate that it's not such an edge-case for us, given that our
    company name is 'D&B' :) !!!).

    Thanks again for any help you might be able to offer,

    Pat.




    --
    View this message in context: http://camel.465427.n5.nabble.com/Ampersand-in-URI-query-parameter-not-working-CAMEL-4857-doesn-t-fix-tp5720914p5720925.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Claus Ibsen at Oct 13, 2012 at 9:10 am
    Hi

    What Camel version are you using?

    You can pass in the query "as is" using a header with the key
    Exchange.HTTP_QUERY. Then no encoding is needed.
    Then the endpoint is just "https4://www.google.com".
    And the key has the query you want to use.



    On Thu, Oct 11, 2012 at 4:40 PM, pmcb55 wrote:
    I have a very simple use-case that seems to highlight a bug in Camel's URI
    handling code. It's very easy to demonstrate, the following code shows the
    problem:

    String query = URLEncoder.encode("D & B", "UTF-8");
    String endpoint = "https4://www.google.com/?" + query;
    Exchange response = producerTemplate().send(endpoint, new
    DefaultExchange(context));

    The result back from the Google search is only performed on 'D', and not the
    full 'D & B' search term we specified.

    I thought this problem might have been resolved by CAMEL-4857, since that is
    a code change in the same area of the code, but downloading and building
    Camel TRUNK doesn't fix this simple problem at all, nor can I see any way it
    can fix the above problem (so I think this is a separate bug completely).

    The real problem seems to be located in the following line from the method
    'normalizeUri(String uri)' in the class 'URISupport.java':

    Line 349 (in trunk): Map<String, Object> parameters =
    URISupport.parseParameters(u);

    Within the 'parseParameters()' method, the first line calls
    'uri.getQuery()', but this decodes the query string, which results in my
    encoded query string above (which is passed into this method correctly as
    '?q=D+%26+B') being decoded to '?q=D+&+B', which is then subsequently parsed
    (in the 'parseQuery(query)' line at 178) as having multiple query params
    ('q=D+' and '+B') when in fact it really only has one ('q=D+%20+B').

    I was hoping to make a simple code change to this code (i.e. simply changing
    the above 'uri.getQuery()' call to be 'uri.getRawQuery()' but my trunk
    version fails with a test failure when I run 'mvn clean install' on the
    'camel-core' POM, see below:

    Failed tests:

    testPollFileAndShouldBeDeletedAtThirdPoll(org.apache.camel.component.file.From
    FilePollThirdTimeOkTest): mock://result Body of message: 0. Expected: <Hello
    Wor
    ld this file will be deleted> but was: <null>

    Tests run: 4322, Failures: 1, Errors: 0, Skipped: 1

    Any guidance would be very welcome...



    --
    View this message in context: http://camel.465427.n5.nabble.com/Ampersand-in-URI-query-parameter-not-working-CAMEL-4857-doesn-t-fix-tp5720914.html
    Sent from the Camel - Users mailing list archive at Nabble.com.


    --
    Claus Ibsen
    -----------------
    Red Hat, Inc.
    FuseSource is now part of Red Hat
    Email: cibsen@redhat.com
    Web: http://fusesource.com
    Twitter: davsclaus
    Blog: http://davsclaus.com
    Author of Camel in Action: http://www.manning.com/ibsen
  • Pmcb55 at Oct 15, 2012 at 3:17 am
    Hi Claus,

    I'm using the latest released Camel version (2.10.0), but also tried with
    the trunk version too.

    I don't think your suggestion would work for me, as I need to create a
    recipient list, with each recipient having different query parameters, so I
    need to encode those query params into each recipient URI (as just single
    URI strings) - and so setting the HTTP_QUERY on the entire exchange doesn't
    seem appropriate.

    Anyways, I got around the problem by double-encoded (as suggested by
    Donald).

    I did play around with your suggestion a little (which works), but it's
    still not the most intuitive (note I have to encode just the query part, and
    not the '?q=' part, of the HTTP_QUERY string):

    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setHeader(Exchange.HTTP_QUERY, "q=" +
    URLEncoder.encode("D & Bolly", "UTF-8"));
    Exchange response =
    CamelWrapper.getProducerTemplate().send("https4://www.google.com",
    exchange);

    It's certainly an interesting use-case though, thanks for all the feedback
    guys...!



    --
    View this message in context: http://camel.465427.n5.nabble.com/Ampersand-in-URI-query-parameter-not-working-CAMEL-4857-doesn-t-fix-tp5720914p5721035.html
    Sent from the Camel - Users mailing list archive at Nabble.com.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriescamel
postedOct 11, '12 at 2:44p
activeOct 15, '12 at 3:17a
posts7
users4
websitecamel.apache.org

People

Translate

site design / logo © 2021 Grokbase