cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1501756 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Wed, 10 Jul 2013 13:12:01 GMT
Author: sergeyb
Date: Wed Jul 10 13:12:01 2013
New Revision: 1501756

URL: http://svn.apache.org/r1501756
Log:
[CXF-5108] Ignoring Maps with complex values and better support for Maps with simple values
when dealing with parameter extensions

Added:
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookBean.java   (with
props)
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/BookSubresource.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresourceImpl.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.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=1501756&r1=1501755&r2=1501756&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
Wed Jul 10 13:12:01 2013
@@ -621,23 +621,41 @@ public final class InjectionUtils {
                                         ParameterType pathParam, Message message) {
     // CHECKSTYLE:ON
         ParameterizedType paramType = (ParameterizedType) genericType;
-        ParameterizedType valueParamType = (ParameterizedType) InjectionUtils
-                                   .getType(paramType.getActualTypeArguments(), 1);
-        Class<?> valueType = (Class<?>) InjectionUtils.getType(valueParamType
-                           .getActualTypeArguments(), 0);
-
-        MultivaluedMap<String, Object> theValues = new MetadataMap<String, Object>();
-           
-        Set<Map.Entry<String, List<String>>> processedValuesEntrySet =
processedValues.entrySet();
-        for (Map.Entry<String, List<String>> processedValuesEntry : processedValuesEntrySet)
{
-            List<String> valuesList = processedValuesEntry.getValue();
-            for (String value : valuesList) {
-                Object o = InjectionUtils.handleParameter(value,
-                                   decoded, valueType, paramAnns, pathParam, message);
-                theValues.add(processedValuesEntry.getKey(), o);
+        Class<?> keyType = (Class<?>)paramType.getActualTypeArguments()[0];
+        Type secondType = InjectionUtils.getType(paramType.getActualTypeArguments(), 1);
+        
+        if (secondType instanceof ParameterizedType) {
+            MultivaluedMap<Object, Object> theValues = new MetadataMap<Object, Object>();
+            ParameterizedType valueParamType = (ParameterizedType) secondType;
+            Class<?> valueType = (Class<?>) InjectionUtils.getType(valueParamType
+                               .getActualTypeArguments(), 0);
+    
+            for (Map.Entry<String, List<String>> processedValuesEntry : processedValues.entrySet())
{
+                List<String> valuesList = processedValuesEntry.getValue();
+                for (String value : valuesList) {
+                    Object o = InjectionUtils.handleParameter(value,
+                                       decoded, valueType, paramAnns, pathParam, message);
+                    theValues.add(convertStringToPrimitive(processedValuesEntry.getKey(),
keyType), o);
+                }
+            }
+            return theValues;
+        } else {
+            Map<Object, Object> theValues = new HashMap<Object, Object>();
+            Class<?> valueType = 
+                (Class<?>) InjectionUtils.getType(paramType.getActualTypeArguments(),
1);
+            for (Map.Entry<String, List<String>> processedValuesEntry : processedValues.entrySet())
{
+                List<String> valuesList = processedValuesEntry.getValue();
+                for (String value : valuesList) {
+                    Object o = InjectionUtils.handleParameter(value,
+                                       decoded, valueType, paramAnns, pathParam, message);
+                    theValues.put(
+                        convertStringToPrimitive(processedValuesEntry.getKey(), keyType),

+                        o);
+                }
             }
+            return theValues;
         }
-        return theValues;
+        
     }    
 
     
@@ -648,19 +666,25 @@ public final class InjectionUtils {
             if (paramType.getActualTypeArguments().length == 2) {
                 Class<?> firstType = getRawType(getType(paramType.getActualTypeArguments(),
0));
                 Type secondType = getType(paramType.getActualTypeArguments(), 1);
-                if (secondType instanceof ParameterizedType) {
-                    Class<?> secondRawType = getRawType(secondType);
-                    if (String.class == firstType && List.class.isAssignableFrom(secondRawType))
{
-                        Class<?> listtype = getRawType(
-                            getType(((ParameterizedType)secondType).getActualTypeArguments(),
0));
-                        return InjectionUtils.isPrimitive(listtype);
-                    }
-                }
+                Class<?> secondRawType = getRawType(secondType);
+                
+                return InjectionUtils.isPrimitive(firstType) 
+                    && (InjectionUtils.isPrimitive(secondRawType)
+                        || allowedMapListValue(secondRawType, secondType));
             } 
         }
         return false;
     }
     
+    private static boolean allowedMapListValue(Class<?> cls, Type type) {
+        if (List.class.isAssignableFrom(cls)) {
+            Class<?> listtype = getRawType(
+                getType(((ParameterizedType)type).getActualTypeArguments(), 0));
+            return InjectionUtils.isPrimitive(listtype);
+        }
+        return false;
+    }
+    
     private static List<MultivaluedMap<String, String>> processValues(Class<?>
type, Type genericType,
                                         MultivaluedMap<String, String> values,
                                         boolean isbean) {
@@ -1097,6 +1121,14 @@ public final class InjectionUtils {
                         theValues = CastUtils.cast((List<?>)value);
                     }
                     values.put(propertyName, theValues);
+                } else if (Map.class.isAssignableFrom(value.getClass())) {
+                    if (isSupportedMap(m.getGenericReturnType())) {
+                        Map<Object, Object> map = CastUtils.cast((Map<?, ?>)value);
+                        for (Map.Entry<Object, Object> entry : map.entrySet()) {
+                            values.add(propertyName + "." + entry.getKey().toString(), 
+                                       entry.getValue().toString());
+                        }
+                    }
                 } else {
                     fillInValuesFromBean(value, propertyName, values);
                 }

Added: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookBean.java?rev=1501756&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookBean.java (added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookBean.java Wed
Jul 10 13:12:01 2013
@@ -0,0 +1,135 @@
+/**
+ * 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.systest.jaxrs;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.xml.bind.annotation.XmlRootElement;
+
+
+@XmlRootElement(name = "Book")
+public class BookBean {
+    private String name;
+    private long id;
+    private Map<Long, Chapter> chapters = new HashMap<Long, Chapter>();
+    private Map<Long, String> comments = new HashMap<Long, String>();
+    
+    public BookBean() {
+        init();
+        //System.out.println("----chapters: " + chapters.size());
+    }
+    
+    public BookBean(String name, long id) {
+        this.name = name;
+        this.id = id;
+    }
+    
+    public void setName(String n) {
+        name = n;
+    }
+
+    public String getName() {
+        return name;
+    }
+    
+    public void setId(long i) {
+        id = i;
+    }
+    public long getId() {
+        return id;
+    }
+    
+    @PUT
+    public void cloneState(BookBean book) {
+        id = book.getId();
+        name = book.getName();
+    }
+    
+    @GET
+    public BookBean retrieveState() {
+        return this;
+    }
+    
+    @GET
+    @Path("chapters/{chapterid}/")    
+    @Produces("application/xml;charset=ISO-8859-1")
+    public Chapter getChapter(@PathParam("chapterid")int chapterid) {
+        return chapters.get(new Long(chapterid));
+    }
+    
+    @GET
+    @Path("chapters/acceptencoding/{chapterid}/")    
+    @Produces("application/xml")
+    public Chapter getChapterAcceptEncoding(@PathParam("chapterid")int chapterid) {
+        return chapters.get(new Long(chapterid));
+    }
+
+    @GET
+    @Path("chapters/badencoding/{chapterid}/")    
+    @Produces("application/xml;charset=UTF-48")
+    public Chapter getChapterBadEncoding(@PathParam("chapterid")int chapterid) {
+        return chapters.get(new Long(chapterid));
+    }
+    
+    @Path("chapters/sub/{chapterid}/")    
+    public Chapter getSubChapter(@PathParam("chapterid")int chapterid) {
+        return chapters.get(new Long(chapterid));
+    }
+    
+    @Path("chaptersobject/sub/{chapterid}/")    
+    public Object getSubChapterObject(@PathParam("chapterid")int chapterid) {
+        return getSubChapter(chapterid);
+    }
+    
+    
+    final void init() {
+        Chapter c1 = new Chapter();
+        c1.setId(1);
+        c1.setTitle("chapter 1");
+        chapters.put(c1.getId(), c1);
+        Chapter c2 = new Chapter();
+        c2.setId(2);
+        c2.setTitle("chapter 2");
+        chapters.put(c2.getId(), c2);
+    }
+
+    public Map<Long, Chapter> getChapters() {
+        return chapters;
+    }
+
+    public void setChapters(Map<Long, Chapter> chapters) {
+        this.chapters = chapters;
+    }
+
+    public Map<Long, String> getComments() {
+        return comments;
+    }
+
+    public void setComments(Map<Long, String> comments) {
+        this.comments = comments;
+    }
+
+}

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookBean.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresource.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresource.java?rev=1501756&r1=1501755&r2=1501756&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresource.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresource.java
Wed Jul 10 13:12:01 2013
@@ -94,7 +94,7 @@ public interface BookSubresource {
     @GET
     @Path("/thebook5")
     @Produces("application/xml")
-    Book getTheBookQueryBean(@QueryParam("") Book book) throws BookNotFoundFault;
+    BookBean getTheBookQueryBean(@QueryParam("") BookBean book) throws BookNotFoundFault;
     
 }
 

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresourceImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresourceImpl.java?rev=1501756&r1=1501755&r2=1501756&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresourceImpl.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresourceImpl.java
Wed Jul 10 13:12:01 2013
@@ -20,6 +20,7 @@
 package org.apache.cxf.systest.jaxrs;
 
 import java.util.List;
+import java.util.Map;
 
 import javax.ws.rs.core.UriInfo;
 
@@ -111,8 +112,15 @@ public class BookSubresourceImpl impleme
         return new Book(name, bookid);
     }
 
-    public Book getTheBookQueryBean(Book book) throws BookNotFoundFault {
-        return book;
+    public BookBean getTheBookQueryBean(BookBean book) throws BookNotFoundFault {
+        Map<Long, String> comments = book.getComments();
+        String comment1 = comments.get(1L);
+        String comment2 = comments.get(2L);
+        if ("Good".equals(comment1) && "Good".equals(comment2)) {
+            return book;
+        } else {
+            return null;
+        }
     }
 
 }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=1501756&r1=1501755&r2=1501756&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
Wed Jul 10 13:12:01 2013
@@ -548,8 +548,10 @@ public class JAXRSSoapBookTest extends A
                                                               BookStoreJaxrsJaxws.class);
         WebClient.getConfig(proxy).getOutInterceptors().add(new LoggingOutInterceptor());
         BookSubresource bs = proxy.getBookSubresource("139");
-        Book bean = new Book("CXF Rocks", 139L);
-        Book b = bs.getTheBookQueryBean(bean);
+        BookBean bean = new BookBean("CXF Rocks", 139L);
+        bean.getComments().put(1L, "Good");
+        bean.getComments().put(2L, "Good");
+        BookBean b = bs.getTheBookQueryBean(bean);
         assertEquals(139, b.getId());
         assertEquals("CXF Rocks", b.getName());
     }



Mime
View raw message