From 44eed3917fb6b32f081698d75632b9209c2cacca Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Sun, 9 Aug 2009 22:41:55 +0000 Subject: [PATCH] Issue 76: properly address UTF encoding of paths git-svn-id: http://jclouds.googlecode.com/svn/trunk@1843 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../rest/JaxrsAnnotationProcessor.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/jclouds/rest/JaxrsAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/JaxrsAnnotationProcessor.java index f28850ee46..30a35d403f 100644 --- a/core/src/main/java/org/jclouds/rest/JaxrsAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/JaxrsAnnotationProcessor.java @@ -532,21 +532,24 @@ public class JaxrsAnnotationProcessor { for (Entry> entry : indexToPathParam.entrySet()) { for (Annotation key : entry.getValue()) { Set extractors = indexToParamExtractor.get(entry.getKey()); - + String paramKey = ((PathParam) key).value(); + String paramValue; if (extractors != null && extractors.size() > 0) { ParamParser extractor = (ParamParser) extractors.iterator().next(); - pathParamValues.put(((PathParam) key).value(), injector.getInstance( - extractor.value()).apply(args[entry.getKey()])); + paramValue = injector.getInstance(extractor.value()).apply(args[entry.getKey()]); } else { - String paramKey = ((PathParam) key).value(); - String paramValue = URLEncoder.encode(args[entry.getKey()].toString(), "UTF-8"); - for (char c : skipEncode) { - String value = Character.toString(c); - String encoded = URLEncoder.encode(value, "UTF-8"); - paramValue = paramValue.replaceAll(encoded, value); - } - pathParamValues.put(paramKey, paramValue); + paramValue = args[entry.getKey()].toString(); } + paramValue = URLEncoder.encode(paramValue, "UTF-8"); + // Web browsers do not always handle '+' characters well, use the well-supported + // '%20' instead. + paramValue = paramValue.replaceAll("\\+", "%20"); + for (char c : skipEncode) { + String value = Character.toString(c); + String encoded = URLEncoder.encode(value, "UTF-8"); + paramValue = paramValue.replaceAll(encoded, value); + } + pathParamValues.put(paramKey, paramValue); } } return pathParamValues;