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 <mcbenne...@dnb.com> 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: cib...@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Reply via email to