Author: sergeyb
Date: Tue Jul 10 16:57:30 2012
New Revision: 1359782
URL: http://svn.apache.org/viewvc?rev=1359782&view=rev
Log:
[CXF-4415] Support for basic hierarchical queries
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1359782&r1=1359781&r2=1359782&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Tue Jul 10 16:57:30 2012
@@ -101,6 +101,7 @@ public final class InjectionUtils {
private static final String HTTP_SERVLET_RESPONSE_CLASS_NAME =
"javax.servlet.http.HttpServletResponse";
private static final String PARAM_HANDLERS_FIRST =
"check.parameter.handlers.first";
+ private static final String IGNORE_MATRIX_PARAMETERS =
"ignore.matrix.parameters";
private InjectionUtils() {
@@ -289,12 +290,12 @@ public final class InjectionUtils {
if (value == null) {
return null;
}
-
if (pType == ParameterType.PATH) {
if (PathSegment.class.isAssignableFrom(pClass)) {
return pClass.cast(new PathSegmentImpl(value, decoded));
- } else {
- value = new PathSegmentImpl(value, false).getPath();
+ } else if (!MessageUtils.isTrue(
+
message.getContextualProperty(IGNORE_MATRIX_PARAMETERS))) {
+ value = new PathSegmentImpl(value, false).getPath();
}
}
Modified:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1359782&r1=1359781&r2=1359782&view=diff
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
(original)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
Tue Jul 10 16:57:30 2012
@@ -559,6 +559,43 @@ public class BookStore {
return found.get(0);
}
+ @GET
+ @Path("/books/{search}/chapter/{chapter}")
+ @Produces("application/xml")
+ public Chapter getChapterFromSelectedBook(@Context SearchContext
searchContext,
+ @PathParam("search") String
expression,
+ @PathParam("chapter") int
chapter) {
+
+ SearchCondition<Book> sc = searchContext.getCondition(expression,
Book.class);
+ if (sc == null) {
+ throw new WebApplicationException(404);
+ }
+ List<Book> found = sc.findAll(books.values());
+ if (found.size() != 1) {
+ throw new WebApplicationException(404);
+ }
+ Book selectedBook = found.get(0);
+
+ return selectedBook.getChapter(chapter);
+ }
+
+ @GET
+ @Path("/books({search})/chapter")
+ @Produces("application/xml")
+ public Chapter getIntroChapterFromSelectedBook(@Context SearchContext
searchContext,
+ @PathParam("search") String
expression) {
+
+ return getChapterFromSelectedBook(searchContext, expression, 1);
+ }
+
+ @GET
+ @Path("/books[{search}]/chapter")
+ @Produces("application/xml")
+ public Chapter getIntroChapterFromSelectedBook2(@Context SearchContext
searchContext,
+ @PathParam("search") String
expression) {
+
+ return getChapterFromSelectedBook(searchContext, expression, 1);
+ }
@GET
@Path("/books/text/xml/{bookId}")
Modified:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1359782&r1=1359781&r2=1359782&view=diff
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Tue Jul 10 16:57:30 2012
@@ -72,11 +72,44 @@ public class JAXRSClientServerBookTest e
public static void startServers() throws Exception {
AbstractResourceInfo.clearAllMaps();
assertTrue("server did not launch correctly",
- launchServer(BookServer.class, true));
+ launchServer(BookServer.class));
createStaticBus();
}
@Test
+ public void testGetChapterFromSelectedBook() {
+ String address = "http://localhost:" + PORT +
"/bookstore/books/id=le=123/chapter/1";
+ doTestGetChapterFromSelectedBook(address);
+ }
+
+ @Test
+ public void testGetIntroChapterFromSelectedBook() {
+ String address = "http://localhost:" + PORT +
"/bookstore/books(id=le=123)/chapter";
+ doTestGetChapterFromSelectedBook(address);
+ }
+
+ @Test
+ public void testGetIntroChapterFromSelectedBook2() {
+ String address = "http://localhost:" + PORT + "/bookstore/";
+ WebClient wc = WebClient.create(address);
+ wc.path("books[id=le=123]");
+ wc.path("chapter");
+ wc.accept("application/xml");
+ Chapter chapter = wc.get(Chapter.class);
+ assertEquals("chapter 1", chapter.getTitle());
+ }
+
+ private void doTestGetChapterFromSelectedBook(String address) {
+
+ WebClient wc =
+ WebClient.create(address);
+
WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000);
+ wc.accept("application/xml");
+ Chapter chapter = wc.get(Chapter.class);
+ assertEquals("chapter 1", chapter.getTitle());
+ }
+
+ @Test
public void testWithComplexPath() {
WebClient wc =
WebClient.create("http://localhost:" + PORT +
"/bookstore/allCharsButA-B/:@!$&'()*+,;=-._~");