You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2013/09/22 19:22:57 UTC
svn commit: r1525392 - in /cxf/trunk/rt/frontend/jaxrs/src:
main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
Author: sergeyb
Date: Sun Sep 22 17:22:56 2013
New Revision: 1525392
URL: http://svn.apache.org/r1525392
Log:
Reverting the earlier change to UriBuilder path method accepting Class and method name, cloning resolved vars info too
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java?rev=1525392&r1=1525391&r2=1525392&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java Sun Sep 22 17:22:56 2013
@@ -425,11 +425,16 @@ public class UriBuilderImpl extends UriB
builder.schemeSpecificPart = schemeSpecificPart;
builder.leadingSlash = leadingSlash;
builder.originalPathEmpty = originalPathEmpty;
+ builder.resolvedEncodedTemplates =
+ resolvedEncodedTemplates == null ? null : new HashMap<String, Object>(resolvedEncodedTemplates);
+ builder.resolvedTemplates =
+ resolvedTemplates == null ? null : new HashMap<String, Object>(resolvedTemplates);
+ builder.resolvedTemplatesPathEnc =
+ resolvedTemplatesPathEnc == null ? null : new HashMap<String, Object>(resolvedTemplatesPathEnc);
return builder;
}
-
// CHECKSTYLE:ON
-
+
@Override
public UriBuilder fragment(String theFragment) throws IllegalArgumentException {
this.fragment = theFragment;
@@ -469,15 +474,24 @@ public class UriBuilderImpl extends UriB
if (method == null) {
throw new IllegalArgumentException("method is null");
}
+ Path foundAnn = null;
for (Method meth : resource.getMethods()) {
if (meth.getName().equals(method)) {
Path ann = meth.getAnnotation(Path.class);
- String path = ann == null ? "" : ann.value();
- return path(resource).path(path);
+ if (foundAnn != null && ann != null) {
+ throw new IllegalArgumentException("Multiple Path annotations for '" + method
+ + "' overloaded method");
+ }
+ foundAnn = ann;
}
}
- throw new IllegalArgumentException("No Path annotation for '" + method + "' method");
+ if (foundAnn == null) {
+ throw new IllegalArgumentException("No Path annotation for '" + method + "' method");
+ }
+ // path(String) decomposes multi-segment path when necessary
+ return path(foundAnn.value());
}
+
@Override
public UriBuilder path(Method method) throws IllegalArgumentException {
Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java?rev=1525392&r1=1525391&r2=1525392&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java Sun Sep 22 17:22:56 2013
@@ -25,7 +25,11 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import org.apache.cxf.jaxrs.resources.Book;
@@ -784,7 +788,8 @@ public class UriBuilderImplTest extends
@Test
public void testAddPathClassMethod() throws Exception {
URI uri = new URI("http://foo/");
- URI newUri = new UriBuilderImpl().uri(uri).path(BookStore.class, "updateBook").path("bar").build();
+ URI newUri = new UriBuilderImpl().uri(uri).path(BookStore.class)
+ .path(BookStore.class, "updateBook").path("bar").build();
assertEquals("URI is not built correctly", new URI("http://foo/bookstore/books/bar"), newUri);
}
@@ -1562,5 +1567,34 @@ public class UriBuilderImplTest extends
assertEquals(expected, uri.toString());
}
+ @Test
+ public void testFromMethod() {
+ URI uri = UriBuilder.fromMethod(TestPath.class, "headSub").build();
+ assertEquals(uri.toString(), "/sub");
+ }
+ @Path(value = "/TestPath")
+ public static class TestPath {
+
+ @GET
+ public Response getPlain() {
+ return Response.ok().build();
+ }
+
+ @Path(value = "/sub")
+ public Response headSub() {
+ return Response.ok().build();
+ }
+
+ @Path(value = "sub1")
+ public Response test1() {
+ return Response.ok().build();
+ }
+
+ @Path(value = "/sub2")
+ public Response test1(@QueryParam("testName") String test) {
+ return Response.ok(test).build();
+ }
+
+ }
}