1

I am using Mule and Mule Expression Language to retrieve values form a properties file and change the contents of a connector address based on those values.

Example: It would read test1 and test2 from the file and store in the variables ${user} and ${pw}. It would then use http://${user}:${pw}@testurl.com as the address for the connector.

Does Mule automatically escape strings when being used in an address? I would assume it doesn't and just uses the exact string provided. Is there a built in method in MEL that can be used to escape strings.

My concern is that the ${user} could contain a character that is required to be escaped to be interpreted literally, therefore causing an issue with the final url.

My solution if it can't be escaped would be to restrict the valid characters for those 2 parameters and I would like to avoid this.

Grice
  • 1,345
  • 11
  • 24
  • Could you pls provide the full url you need to pass .. we will get an Idea then what value you required to pass in ${user} – Anirban Sen Chowdhary Oct 22 '14 at 15:00
  • I specified the url in the example. `http://${user}:${pw}@testurl.com`. It would become `http://test:test1@testurl.com` when values are added. – Grice Oct 22 '14 at 15:06
  • It works fine if it reads from properties file .. what's the issue you are facing ?? – Anirban Sen Chowdhary Oct 22 '14 at 16:02
  • @AnirbanSenChowdhary I'm not having an issue, I just wanted to to understand if mule automatically escapes characters with special meaning when used in a url, such as `=` becoming `%3D` I understand that in most cases where special characters are not involved it will work fine. – Grice Oct 22 '14 at 16:10
  • @AnirbanSenChowdhary An example could be if `${pw}` was `!@//::!ds=d3*&??` or any number of other characters with unique meaning. – Grice Oct 22 '14 at 16:12

1 Answers1

2

MEL allows you to use standard Java method invocation so you could use any Java utility to URL encode the string such as URLEncoder - http://docs.oracle.com/javase/7/docs/api/java/net/URLEncoder.html

For example:

#[java.net.URLEncoder.encode('${user}','UTF-8')]
Ryan Carter
  • 11,441
  • 2
  • 20
  • 27