cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r707089 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ systests/src/test/java/org/apache/cxf/sys...
Date Wed, 22 Oct 2008 14:30:42 GMT
Author: sergeyb
Date: Wed Oct 22 07:30:41 2008
New Revision: 707089

URL: http://svn.apache.org/viewvc?rev=707089&view=rev
Log:
JAXRS: fix for CXF-1882

Added:
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerInfo.java   (with
props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.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/Customer.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java?rev=707089&r1=707088&r2=707089&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
Wed Oct 22 07:30:41 2008
@@ -38,6 +38,7 @@
 import javax.ws.rs.PathParam;
 import javax.ws.rs.ProduceMime;
 import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.SecurityContext;
@@ -104,6 +105,20 @@
         return PARAM_ANNOTATION_CLASSES.contains(annotationClass);
     }
     
+    public static boolean isMethodParamAnnotationClass(Class<?> annotationClass) {

+        return PARAM_ANNOTATION_CLASSES.contains(annotationClass)
+               || Context.class == annotationClass;
+    }
+    
+    public static boolean isMethodParamAnnotations(Annotation[] paramAnnotations) {
+        for (Annotation a : paramAnnotations) {
+            if (AnnotationUtils.isMethodParamAnnotationClass(a.annotationType())) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
     public static boolean isMethodAnnotation(Annotation a) { 
         return METHOD_ANNOTATION_CLASSES.contains(a.annotationType())
                || a.annotationType() == HttpMethod.class;
@@ -141,19 +156,16 @@
         if (m == null) {
             return m;
         }
+        
         for (Annotation a : m.getAnnotations()) {
             if (AnnotationUtils.isMethodAnnotation(a)) {
                 return m;
             }        
         }
-        for (Annotation[] paramAnnotations : m.getParameterAnnotations()) {
-            for (Annotation a : paramAnnotations) {
-                if (AnnotationUtils.isParamAnnotationClass(a.annotationType())) {
-                    return m;
-                } 
-            }
-        }
         
+        if (isMethodParamAnnotations(m.getAnnotations())) {
+            return m;
+        }
         
         Class<?> superC = m.getDeclaringClass().getSuperclass();
         if (superC != null) {

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=707089&r1=707088&r2=707089&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 Wed
Oct 22 07:30:41 2008
@@ -345,8 +345,8 @@
 
         String path = (String)message.get(JAXRSInInterceptor.RELATIVE_PATH);
         
-        if (parameterAnns == null || parameterAnns.length == 0) {
-            // we can't really limit it to just PUT and POST
+        if (parameterAnns == null 
+            || !AnnotationUtils.isMethodParamAnnotations(parameterAnns)) {
             
             String contentType = (String)message.get(Message.CONTENT_TYPE);
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java?rev=707089&r1=707088&r2=707089&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java Wed Oct 22
07:30:41 2008
@@ -42,7 +42,7 @@
 
 import org.apache.cxf.jaxrs.impl.PathSegmentImpl;
 
-public class Customer {
+public class Customer implements CustomerInfo {
     
     @XmlRootElement(name = "CustomerBean")
     public static class CustomerBean {
@@ -107,6 +107,9 @@
         uriInfo = ui;
     }
     
+    public void setUriInfoContext(UriInfo ui) {
+    }
+    
     @Context
     public void setServletContext(ServletContext sc) {
         servletContext3 = sc;

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerInfo.java?rev=707089&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerInfo.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerInfo.java Wed Oct
22 07:30:41 2008
@@ -0,0 +1,27 @@
+/**
+ * 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;
+
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+public interface CustomerInfo {
+    void setUriInfoContext(@Context UriInfo uriInfo); 
+}

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

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

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=707089&r1=707088&r2=707089&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Wed Oct 22 07:30:41 2008
@@ -612,6 +612,27 @@
     }
     
     @Test
+    public void testHttpContextParametersFromInterface() throws Exception {
+        
+        ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
+        Method methodToInvoke = 
+            Customer.class.getMethod("setUriInfoContext", 
+                                     new Class[]{UriInfo.class});
+        OperationResourceInfo ori = 
+            new OperationResourceInfo(methodToInvoke, cri);
+        ori.setHttpMethod("GET");
+        ori.setAnnotatedMethod(AnnotationUtils.getAnnotatedMethod(methodToInvoke));
+        
+        
+        Message m = new MessageImpl();
+        
+        List<Object> params = 
+            JAXRSUtils.processParameters(ori, new MetadataMap<String, String>(), m);
+        assertEquals("1 parameters expected", 1, params.size());
+        assertSame(UriInfoImpl.class, params.get(0).getClass());
+    }
+    
+    @Test
     public void testServletContextParameters() throws Exception {
         
         ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java?rev=707089&r1=707088&r2=707089&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java
Wed Oct 22 07:30:41 2008
@@ -23,8 +23,10 @@
 import javax.jws.WebParam;
 import javax.jws.WebService;
 import javax.ws.rs.GET;
+import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
+import javax.ws.rs.ProduceMime;
 
 @WebService
 @Path("/bookstore")
@@ -35,4 +37,9 @@
     @Path("/{id}")
     Book getBook(@PathParam("id") @WebParam(name = "id") Long id);
 
+    @WebMethod
+    @POST
+    @Path("/books")
+    @ProduceMime("application/xml")
+    Book addBook(@WebParam(name = "book") Book book);
 }

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java?rev=707089&r1=707088&r2=707089&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java
Wed Oct 22 07:30:41 2008
@@ -36,7 +36,13 @@
     public Book getBook(Long id) {
         return books.get(id);
     }
-
+    
+    public Book addBook(Book book) {
+        book.setId(124);
+        books.put(book.getId(), book);
+        return books.get(book.getId());
+    }
+    
     private void init() {
         Book book = new Book();
         book.setId(new Long(123));

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java?rev=707089&r1=707088&r2=707089&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java
Wed Oct 22 07:30:41 2008
@@ -19,12 +19,17 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import java.io.File;
 import java.io.InputStream;
 import java.net.URL;
 import java.net.URLConnection;
 
 import javax.xml.namespace.QName;
 
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.FileRequestEntity;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
@@ -50,6 +55,33 @@
     }
     
     @Test
+    public void testAddGetBookRest() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:9092/rest/bookstore/books";
+        
+        File input = new File(getClass().getResource("resources/add_book.txt").toURI());
        
+        PostMethod post = new PostMethod(endpointAddress);
+        post.setRequestHeader("Content-Type", "application/xml");
+        RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
+        post.setRequestEntity(entity);
+        HttpClient httpclient = new HttpClient();
+        
+        try {
+            int result = httpclient.executeMethod(post);
+            assertEquals(200, result);
+            
+            InputStream expected = getClass().getResourceAsStream("resources/expected_add_book.txt");
+            
+            assertEquals(getStringFromInputStream(expected), post.getResponseBodyAsString());
+        } finally {
+            // Release current connection to the connection pool once you are done
+            post.releaseConnection();
+        }
+                
+    }
+    
+    @Test
     public void testGetBookSoap() throws Exception {
         String wsdlAddress =
             "http://localhost:9092/soap/bookservice?wsdl"; 



Mime
View raw message