cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r788752 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/ rt/frontend/jaxrs/src/mai...
Date Fri, 26 Jun 2009 16:14:56 GMT
Author: sergeyb
Date: Fri Jun 26 16:14:55 2009
New Revision: 788752

URL: http://svn.apache.org/viewvc?rev=788752&view=rev
Log:
JAXRS : starting with WADL testing

Added:
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Book.java  
(with props)
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Chapter.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Orders.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java?rev=788752&r1=788751&r2=788752&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
Fri Jun 26 16:14:55 2009
@@ -26,8 +26,10 @@
 
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.cxf.jaxrs.model.wadl.WadlGenerator;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.message.Message;
 
@@ -69,6 +71,7 @@
         MultivaluedMap<String, String> queries = u.getQueryParameters();
         handleTypeQuery(m, queries);
         handleMethod(m, queries, new HttpHeadersImpl(m));
+        checkMetadataRequest(m);
         return new UriInfoImpl(m, null).getPath();
     }
     
@@ -145,4 +148,24 @@
         .put(HttpHeaders.ACCEPT, Collections.singletonList(acceptValue));
     }
     
+    /*
+     * TODO : looks like QueryHandler is well suited for the purpose of serving
+     * wadl/wsdl2 root requests with URIs which can not be used for selecting
+     * ClassResourceInfo which is where RequestFilters invoked after the resource class
+     * has been selected are handy. Consider implementing this method as part of the QueryHandler,
+     * we will need to save the list of ClassResourceInfos on the EndpointInfo though
+     */
+    public void checkMetadataRequest(Message m) {
+        String query = (String)m.get(Message.QUERY_STRING);
+        if (query != null && query.contains(WadlGenerator.WADL_QUERY)) {
+            String requestURI = (String)m.get(Message.REQUEST_URI);
+            String baseAddress = HttpUtils.getBaseAddress(m);
+            if (baseAddress.equals(requestURI)) {
+                Response r = new WadlGenerator().handleRequest(m, null);
+                if (r != null) {
+                    m.getExchange().put(Response.class, r);
+                }
+            }
+        }
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java?rev=788752&r1=788751&r2=788752&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
Fri Jun 26 16:14:55 2009
@@ -86,6 +86,9 @@
         RequestPreprocessor rp = ProviderFactory.getInstance(message).getRequestPreprocessor();
         if (rp != null) {
             rp.preprocess(message, new UriInfoImpl(message, null));
+            if (message.getExchange().get(Response.class) != null) {
+                return;
+            }
         }
         
         String requestContentType = (String)message.get(Message.CONTENT_TYPE);
@@ -143,7 +146,7 @@
                 try {                
                     ori = JAXRSUtils.findTargetMethod(resource, 
                         values.getFirst(URITemplate.FINAL_MATCH_GROUP), httpMethod, values,

-                        requestContentType, acceptContentTypes);
+                        requestContentType, acceptContentTypes, false);
                     message.getExchange().put(OperationResourceInfo.class, ori);
                 } catch (WebApplicationException ex) {
                     operChecked = true;

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=788752&r1=788751&r2=788752&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Fri Jun 26 16:14:55 2009
@@ -37,6 +37,7 @@
 import javax.xml.transform.sax.SAXResult;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.jaxrs.JAXRSServiceImpl;
 import org.apache.cxf.jaxrs.ext.RequestHandler;
 import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
 import org.apache.cxf.jaxrs.impl.UriInfoImpl;
@@ -48,6 +49,7 @@
 import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.service.Service;
 import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.staxutils.StreamWriterContentHandler;
 
@@ -79,11 +81,19 @@
         sbMain.append("<application xmlns=\"").append(WADL_NS).append("\">");
         StringBuilder sbGrammars = new StringBuilder();
         sbGrammars.append("<grammars>");
+        
         StringBuilder sbResources = new StringBuilder();
         sbResources.append("<resources base=\"").append(ui.getBaseUri().toString()).append("\">");
-        handleResource(sbResources, resource, resource.getURITemplate().getValue(),
-                       resource.getURITemplate().getVariables());
+        
+        List<ClassResourceInfo> cris = getResourcesList(m, resource);
+        for (ClassResourceInfo cri : cris) {
+            handleResource(sbResources, cri, cri.getURITemplate().getValue(),
+                           cri.getURITemplate().getVariables());
+        }
         sbResources.append("</resources>");
+        
+        
+        
         sbGrammars.append("</grammars>");
         sbMain.append(sbGrammars.toString());
         sbMain.append(sbResources.toString());
@@ -276,5 +286,9 @@
         return opsWithSamePath;
     }
     
+    public List<ClassResourceInfo> getResourcesList(Message m, ClassResourceInfo cri)
{
+        return cri != null ? Collections.singletonList(cri)
+               : ((JAXRSServiceImpl)m.getExchange().get(Service.class)).getClassResourceInfos();
+    }
     
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=788752&r1=788751&r2=788752&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Fri
Jun 26 16:14:55 2009
@@ -240,6 +240,17 @@
                                                          MultivaluedMap<String, String>
values, 
                                                          String requestContentType, 
                                                          List<MediaType> acceptContentTypes)
{
+        return JAXRSUtils.findTargetMethod(resource, path, httpMethod, values, requestContentType,

+                                           acceptContentTypes, true);
+    }
+    
+    public static OperationResourceInfo findTargetMethod(ClassResourceInfo resource, 
+                                                         String path,
+                                                         String httpMethod, 
+                                                         MultivaluedMap<String, String>
values, 
+                                                         String requestContentType, 
+                                                         List<MediaType> acceptContentTypes,
+                                                         boolean logNow) {
         SortedMap<OperationResourceInfo, MultivaluedMap<String, String>> candidateList
= 
             new TreeMap<OperationResourceInfo, MultivaluedMap<String, String>>(
                 new OperationResourceInfoComparator());
@@ -306,7 +317,7 @@
                                                    path,
                                                    requestType.toString(),
                                                    convertTypesToString(acceptContentTypes));
-        if (!"OPTIONS".equalsIgnoreCase(httpMethod)) {
+        if (!"OPTIONS".equalsIgnoreCase(httpMethod) && logNow) {
             LOG.warning(errorMsg.toString());
         }
         ResponseBuilder rb = createResponseBuilder(resource, status, methodMatched == 0);

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Book.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Book.java?rev=788752&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Book.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Book.java Fri
Jun 26 16:14:55 2009
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.model.wadl;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
+public class Book {
+
+    private int id;
+    public Book(int id) {
+        this.id = id;
+    }
+    
+    @GET
+    @Path("/book")
+    public int getId() {
+        return id;
+    }
+    
+    @Path("/chapter/{cid}")
+    public Chapter getChapter(@PathParam("cid") int cid) {
+        return new Chapter(cid);
+    }
+
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Book.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Book.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java?rev=788752&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
Fri Jun 26 16:14:55 2009
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.model.wadl;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.CookieParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.MatrixParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+
+@Path("/bookstore/{id}")
+@Consumes("application/xml, application/json")
+@Produces("application/xml, application/json")
+public class BookStore {
+
+    @GET 
+    @Produces("text/plain")
+    public String getName() {
+        return "store";
+    }
+    
+    @POST
+    @Path("books/{bookid}")
+    public Book addBook(@PathParam("id") int id,
+                        @PathParam("bookid") int bookId,
+                        @MatrixParam("mid") int matrixId,
+                        @HeaderParam("hid") int headerId,
+                        @CookieParam("cid") int cookieId,
+                        @Context HttpHeaders headers,
+                        Book b) {
+        return new Book(1);
+    }
+    
+    @Path("booksubresource")
+    public Book getBook() {
+        return new Book(1);
+    }
+    
+    
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Chapter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Chapter.java?rev=788752&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Chapter.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Chapter.java
Fri Jun 26 16:14:55 2009
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.model.wadl;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+public class Chapter {
+
+    private int id;
+    public Chapter(int id) {
+        this.id = id;
+    }
+    
+    @GET
+    @Path("/id")
+    public int getId() {
+        return id;
+    }
+    
+    
+
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Chapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Chapter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Orders.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Orders.java?rev=788752&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Orders.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Orders.java
Fri Jun 26 16:14:55 2009
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.model.wadl;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+@Path("/orders")
+public class Orders {
+
+    @GET
+    @Produces("text/plain")
+    public int getNumberOfOrders() {
+        return 100;
+    }
+    
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Orders.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/Orders.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java?rev=788752&r1=788751&r2=788752&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Fri Jun 26 16:14:55 2009
@@ -18,15 +18,25 @@
  */
 package org.apache.cxf.jaxrs.model.wadl;
 
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Response;
 
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.jaxrs.JAXRSServiceImpl;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
-import org.apache.cxf.jaxrs.resources.BookStore;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.service.Service;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.servlet.ServletDestination;
 import org.easymock.classextension.EasyMock;
@@ -53,16 +63,23 @@
     }
     
     @Test
-    public void testWadl() throws Exception {
+    public void testSingleRootResource() throws Exception {
         WadlGenerator wg = new WadlGenerator();
-        Message m = mockMessage("http://localhost:8080/baz", "/bar", WadlGenerator.WADL_QUERY);
         ClassResourceInfo cri = 
             ResourceUtils.createClassResourceInfo(BookStore.class, BookStore.class, true,
true);
+        Message m = mockMessage("http://localhost:8080/baz", "/bar", WadlGenerator.WADL_QUERY,
null);
+        
         Response r = wg.handleRequest(m, cri);
+        checkResponse(r);
+        List<Element> els = getWadlResourcesInfo("http://localhost:8080/baz", 1, r.getEntity().toString());
+        checkBookStoreInfo(els.get(0));
+        
+    }
+    
+    private void checkResponse(Response r) throws Exception {
         assertNotNull(r);
         assertEquals(WadlGenerator.WADL_TYPE.toString(),
                      r.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE));
-//        System.out.println(r.getEntity().toString());
 //        File f = new File("test.xml");
 //        f.delete();
 //        f.createNewFile();
@@ -73,18 +90,61 @@
 //        fos.close();
     }
     
-    private Message mockMessage(String baseAddress, String pathInfo, String query) {
+    @Test
+    public void testMultipleRootResources() throws Exception {
+        WadlGenerator wg = new WadlGenerator();
+        ClassResourceInfo cri1 = 
+            ResourceUtils.createClassResourceInfo(BookStore.class, BookStore.class, true,
true);
+        ClassResourceInfo cri2 = 
+            ResourceUtils.createClassResourceInfo(Orders.class, Orders.class, true, true);
+        List<ClassResourceInfo> cris = new ArrayList<ClassResourceInfo>();
+        cris.add(cri1);
+        cris.add(cri2);
+        Message m = mockMessage("http://localhost:8080/baz", "/bar", WadlGenerator.WADL_QUERY,
cris);
+        Response r = wg.handleRequest(m, null);
+        checkResponse(r);
+        List<Element> els = getWadlResourcesInfo("http://localhost:8080/baz", 2, r.getEntity().toString());
+        checkBookStoreInfo(els.get(0));
+        Element orderResource = els.get(1);
+        assertEquals("/orders", orderResource.getAttribute("path"));
+    }
+
+    private void checkBookStoreInfo(Element resource) {
+        assertEquals("/bookstore/{id}", resource.getAttribute("path"));
+    }
+    
+    private List<Element> getWadlResourcesInfo(String baseURI, int size, String value)
throws Exception {
+        Document doc = DOMUtils.readXml(new StringReader(value));
+        Element root = doc.getDocumentElement();
+        assertEquals("http://research.sun.com/wadl/2006/10", root.getNamespaceURI());
+        assertEquals("application", root.getLocalName());
+        List<Element> resourcesEls = DOMUtils.getChildrenWithName(root, 
+                                            "http://research.sun.com/wadl/2006/10", "resources");
+        assertEquals(1, resourcesEls.size());
+        Element resourcesEl =  resourcesEls.get(0);
+        assertEquals(baseURI, resourcesEl.getAttribute("base"));
+        List<Element> resourceEls = 
+            DOMUtils.getChildrenWithName(resourcesEl, 
+                                                "http://research.sun.com/wadl/2006/10", "resource");
+        assertEquals(size, resourceEls.size());
+        return resourceEls;
+    }
+    
+    
+    private Message mockMessage(String baseAddress, String pathInfo, String query,
+                                List<ClassResourceInfo> cris) {
         Message m = new MessageImpl();
-        control.reset();
-        Exchange e = control.createMock(Exchange.class);
+        Exchange e = new ExchangeImpl();
+        e.put(Service.class, new JAXRSServiceImpl(cris));
+        
         m.setExchange(e);
+        control.reset();
         ServletDestination d = control.createMock(ServletDestination.class);
-        e.getDestination();
-        EasyMock.expectLastCall().andReturn(d).anyTimes();
         EndpointInfo epr = new EndpointInfo(); 
         epr.setAddress(baseAddress);
         d.getEndpointInfo();
         EasyMock.expectLastCall().andReturn(epr).anyTimes();
+        e.setDestination(d);
         m.put(Message.REQUEST_URI, pathInfo);
         m.put(Message.QUERY_STRING, query);
         m.put(Message.HTTP_REQUEST_METHOD, "GET");

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java?rev=788752&r1=788751&r2=788752&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
Fri Jun 26 16:14:55 2009
@@ -22,13 +22,20 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.net.HttpURLConnection;
 import java.net.Socket;
 import java.net.URL;
 import java.net.URLConnection;
+import java.util.List;
 
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 
 import org.junit.BeforeClass;
@@ -43,6 +50,57 @@
     }
     
     @Test
+    public void testMultipleRootsWadl() throws Exception {
+        List<Element> resourceEls = getWadlResourcesInfo("http://localhost:9080/webapp/",
+                                                         "http://localhost:9080/webapp/",
2);
+        String path1 = resourceEls.get(0).getAttribute("path");
+        int bookStoreInd = path1.contains("/bookstore") ? 0 : 1;
+        int petStoreInd = bookStoreInd == 0 ? 1 : 0;
+        checkBookStoreInfo(resourceEls.get(bookStoreInd));
+        checkPetStoreInfo(resourceEls.get(petStoreInd));
+    }
+    
+    @Test
+    public void testBookStoreWadl() throws Exception {
+        List<Element> resourceEls = getWadlResourcesInfo("http://localhost:9080/webapp/",
+                                                         "http://localhost:9080/webapp/bookstore",
1);
+        checkBookStoreInfo(resourceEls.get(0));
+    }
+    
+    @Test
+    public void testPetStoreWadl() throws Exception {
+        List<Element> resourceEls = getWadlResourcesInfo("http://localhost:9080/webapp/",
+                                                         "http://localhost:9080/webapp/petstore",
1);
+        checkPetStoreInfo(resourceEls.get(0));
+    }
+ 
+    private void checkBookStoreInfo(Element resource) {
+        assertEquals("/bookstore", resource.getAttribute("path"));
+    }
+    
+    private void checkPetStoreInfo(Element resource) {
+        assertEquals("/petstore/", resource.getAttribute("path"));
+    }
+    
+    private List<Element> getWadlResourcesInfo(String baseURI, String requestURI, int
size) throws Exception {
+        WebClient client = WebClient.create(requestURI + "?_wadl&_type=xml");
+        Document doc = DOMUtils.readXml(new InputStreamReader(client.get(InputStream.class),
"UTF-8"));
+        Element root = doc.getDocumentElement();
+        assertEquals("http://research.sun.com/wadl/2006/10", root.getNamespaceURI());
+        assertEquals("application", root.getLocalName());
+        List<Element> resourcesEls = DOMUtils.getChildrenWithName(root, 
+                                            "http://research.sun.com/wadl/2006/10", "resources");
+        assertEquals(1, resourcesEls.size());
+        Element resourcesEl =  resourcesEls.get(0);
+        assertEquals(baseURI, resourcesEl.getAttribute("base"));
+        List<Element> resourceEls = 
+            DOMUtils.getChildrenWithName(resourcesEl, 
+                                                "http://research.sun.com/wadl/2006/10", "resource");
+        assertEquals(size, resourceEls.size());
+        return resourceEls;
+    }
+    
+    @Test
     public void testGetBook123() throws Exception {
         
         String endpointAddress =



Mime
View raw message