I want to send a URI as the value of a query/matrix parameter. Before I can append it to an existing URI, I need to encode it according to RFC 2396. For example, given the input:
http://google.com/resource?key=value1 & value2
I expect the output:
http%3a%2f%2fgoogle.com%2fresource%3fkey%3dvalue1%2520%26%2520value2
Neither java.net.URLEncoder
nor java.net.URI
will generate the right output. URLEncoder
is meant for HTML form encoding which is not the same as RFC 2396. URI
has no mechanism for encoding a single value at a time so it has no way of knowing that value1 and value2 are part of the same key.