Permalink
Browse files

Improve Path/PathParam URI robusness

  • Loading branch information...
jfarcand committed Jun 15, 2011
1 parent f9ade2d commit ee04f6dcb8fac9683320e8a6bd32b8c8bab68f8a
Showing with 11 additions and 5 deletions.
  1. +11 −5 restsimple-client/src/main/java/org/sonatype/restsimple/client/WebProxy.java
@@ -223,7 +223,12 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
final Path atClass = clazz.getAnnotation(Path.class);
if (atClass != null) {
- rawUrl.append(atClass.value());
+ String s = atClass.value();
+ if (rawUrl.toString().endsWith("/") ){
+ rawUrl.append(s.startsWith("/") ? s.substring(1) : s);
+ } else {
+ rawUrl.append(s.startsWith("/") ? s : "/" + s);
+ }
} else {
final Path atDeclaringClass = method.getDeclaringClass().getAnnotation(Path.class);
if (atDeclaringClass != null) {
@@ -233,11 +238,12 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
final Path atMethod = method.getAnnotation(Path.class);
if (atMethod != null) {
- String value = atMethod.value();
- if (rawUrl.toString().endsWith( "/" ) && value.startsWith( "/" )) {
- value = value.substring( 1 );
+ String s = atMethod.value();
+ if (rawUrl.toString().endsWith("/") ){
+ rawUrl.append(s.startsWith("/") ? s.substring(1) : s);
+ } else {
+ rawUrl.append(s.startsWith("/") ? s : "/" + s);
}
- rawUrl.append(value);
}
if (rawUrl.toString().trim().length() == 0) {

0 comments on commit ee04f6d

Please sign in to comment.