Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non ascii characters in URL param in camel

Tags:

apache-camel

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
like image 212
Pallavi Goliwale Avatar asked Apr 01 '15 13:04

Pallavi Goliwale


People also ask

Can a URL contain non ascii characters?

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.

Can we pass special characters in URL?

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.

Which characters need URL encoding?

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: ':' , '/' , '?' , '#' , '[' , ']' , '@' , '!'


1 Answers

"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");
like image 56
djb Avatar answered Sep 18 '22 22:09

djb