I am using graph API of Facebook and I call it through camel framework. My query has non ASCII characters (e.g. küçük). I am getting the following exception:-
Cause:
org.apache.commons.httpclient.URIException: Invalid query
at org.apache.commons.httpclient.URI.parseUriReference(URI.java:2049)
at org.apache.commons.httpclient.URI.<init>(URI.java:147)
at org.apache.commons.httpclient.HttpMethodBase.getURI
at org.apache.commons.httpclient.HttpClient.executeMethod
at org.apache.commons.httpclient.HttpClient.executeMethod
at org.apache.camel.component.http.HttpProducer.executeMethod
at org.apache.camel.component.http.HttpProducer.process
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:122)
Does camel support non ASCII characters in URI? If not, what other things can be done?
example URL: https://graph.facebook.com/?ids=http://www.example.com/küçük
When generating a URL, only ASCII symbols are allowed to be used. An example of a non-ASCII character is the Ñ. The URL can't contain any non-ASCII character or even a space.
For instance, the "#" character needs to be encoded because it has a special meaning of that of an html anchor. The <space> character needs to be encoded because it is not a valid URL character. Also, some characters, such as "~" might not transport properly across the internet.
It is sometimes called URL encoding. The encoding consists of substitution: A '%' followed by the hexadecimal representation of the ASCII value of the replace character. Special characters needing encoding are: ':' , '/' , '?' , '#' , '[' , ']' , '@' , '!'
"URL encoding replaces non ASCII characters with a "%" followed by hexadecimal digits." (more info here)
You could try this:
URL url = new URL(uri.toASCIIString());
or maybe
String xstr = URLEncoder.encode("维", "utf-8");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With