Max Max - 1 year ago 233
Java Question

Camel HTTP Endpoint: How to set URL-String to POST Parameter


  • Apache Tomcat 7

  • Spring 3.2.11.RELEASE

  • Apache Camel 2.14.1

  • Camel HTTP Endpoint (


At the moment I use following code to set POST-Parameters to the message body.
The camel HTTP-Component reads the parameters and sends it.

.setHeader(Exchange.HTTP_METHOD, constant(
.setHeader(Exchange.CONTENT_TYPE, constant("application/x-www-form-urlencoded; charset: UTF-8"))
.setHeader(Exchange.CONTENT_ENCODING, constant("UTF-8"))

The problem ist that some parameters are URLs itself.
So something like this should be send as POST-Request:


My question is how to send "http://www.
.com?urlparam1=value1&urlparam2=value2" as value of postparameter2.

Thanks in advance.



Max Max
Answer Source

As isim mentioned above, following works for me. The idea is to parse a given url fist and to encode it again afterwards. This avoids double encoding.


public static String getEncodedURL(String urlString) {
    final String encodedURL;
    try {
        String decodedURL = URLDecoder.decode(urlString, "UTF-8");
        URL url = new URL(decodedURL);
        URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
        final URL urlFromDecoding = uri.toURL();
        encodedURL = URLEncoder.encode(urlFromDecoding.toString(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
    } catch (MalformedURLException e) {
    } catch (URISyntaxException e) {
    return encodedURL;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download