Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 94b873fdf -> 4e2cf99e1


[CXF-7279] Addressing the generic type leak


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/4e2cf99e
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/4e2cf99e
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/4e2cf99e

Branch: refs/heads/3.1.x-fixes
Commit: 4e2cf99e1589d94319a54f7f07f7655e4e545480
Parents: 94b873f
Author: Sergey Beryozkin <[email protected]>
Authored: Tue Mar 14 16:08:08 2017 +0000
Committer: Sergey Beryozkin <[email protected]>
Committed: Tue Mar 14 16:34:56 2017 +0000

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/utils/InjectionUtils.java  | 24 ++++++++-----
 .../org/apache/cxf/systest/jaxrs/Document.java  | 38 ++++++++++++++++++++
 .../cxf/systest/jaxrs/DocumentResource.java     | 35 ++++++++++++++++++
 .../cxf/systest/jaxrs/DocumentResourceImpl.java | 33 +++++++++++++++++
 .../jaxrs/JAXRSClientServerSpringBookTest.java  |  8 +++++
 .../src/test/resources/jaxrs/WEB-INF/beans.xml  |  8 +++++
 6 files changed, 137 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/4e2cf99e/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
----------------------------------------------------------------------
diff --git 
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
 
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
index 68e4933..2f63997 100644
--- 
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
+++ 
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
@@ -1445,15 +1445,21 @@ public final class InjectionUtils {
        
         if (type instanceof TypeVariable) {
             type = InjectionUtils.getSuperType(serviceCls, 
(TypeVariable<?>)type);
-        } else if (type instanceof ParameterizedType
-            && ((ParameterizedType)type).getActualTypeArguments()[0] 
instanceof TypeVariable
-            && isSupportedCollectionOrArray(getRawType(type))) {
-            TypeVariable<?> typeVar = 
(TypeVariable<?>)((ParameterizedType)type).getActualTypeArguments()[0];
-            Type theType = InjectionUtils.getSuperType(serviceCls, typeVar);
-            Class<?> cls = theType instanceof Class 
-                ? (Class<?>)theType : InjectionUtils.getActualType(theType, 0);
-            type = new ParameterizedCollectionType(cls);
-        } 
+        } else if (type instanceof ParameterizedType) {
+            ParameterizedType pt = (ParameterizedType)type;
+            if (pt.getActualTypeArguments()[0] instanceof TypeVariable
+                && isSupportedCollectionOrArray(getRawType(pt))) {
+                TypeVariable<?> typeVar = 
(TypeVariable<?>)pt.getActualTypeArguments()[0];
+                Type theType = InjectionUtils.getSuperType(serviceCls, 
typeVar);
+                if (theType instanceof Class) {
+                    type = new ParameterizedCollectionType((Class<?>)theType);
+                } else {
+                    type = processGenericTypeIfNeeded(serviceCls, paramCls, 
theType);
+                    type = new ParameterizedCollectionType(getRawType(type));
+                }
+            }
+        }
+            
         if (type == null || type == Object.class) {
             type = paramCls;
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/4e2cf99e/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Document.java
----------------------------------------------------------------------
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Document.java 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Document.java
new file mode 100644
index 0000000..3331ec6
--- /dev/null
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Document.java
@@ -0,0 +1,38 @@
+/**
+ * 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;
+
+public class Document<T> {
+    private T t;
+
+    public Document() {
+        
+    }
+    public Document(T t) {
+        this.t = t;
+    }
+    
+    public T getT() {
+        return t;
+    }
+
+    public void setT(T t) {
+        this.t = t;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/4e2cf99e/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/DocumentResource.java
----------------------------------------------------------------------
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/DocumentResource.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/DocumentResource.java
new file mode 100644
index 0000000..195710b
--- /dev/null
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/DocumentResource.java
@@ -0,0 +1,35 @@
+/**
+ * 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.Set;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+
+@Path("resource")
+public interface DocumentResource<ID, T extends Document<ID>> {
+    @Path("{id}")
+    @GET
+    @Produces("application/json")
+    Set<T> getDocuments(@PathParam("id") ID id);
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/4e2cf99e/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/DocumentResourceImpl.java
----------------------------------------------------------------------
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/DocumentResourceImpl.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/DocumentResourceImpl.java
new file mode 100644
index 0000000..a606171
--- /dev/null
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/DocumentResourceImpl.java
@@ -0,0 +1,33 @@
+/**
+ * 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.Collections;
+import java.util.Set;
+
+public class DocumentResourceImpl implements DocumentResource<String, 
Document<String>> {
+
+    @Override
+    public Set<Document<String>> getDocuments(String id) {
+        Document<String> d = new Document<String>(id);
+        return Collections.singleton(d);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/4e2cf99e/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
----------------------------------------------------------------------
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
index ddaf103..ab4bb1c 100644
--- 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
@@ -92,6 +92,14 @@ public class JAXRSClientServerSpringBookTest extends 
AbstractBusClientServerTest
     }
     
     @Test
+    public void testGetDocuments() throws Exception {
+        String baseAddress = "http://localhost:"; + PORT + 
"/the/thedocs/resource/doc";
+        WebClient wc = WebClient.create(baseAddress);
+        Response r = wc.accept("application/json").get();
+        assertEquals("[{\"t\":\"doc\"}]", r.readEntity(String.class));
+    }
+
+    @Test
     public void testGetBookWebEx() throws Exception {
         final String address = "http://localhost:"; + PORT + 
"/the/thebooks/bookstore/books/webex"; 
         doTestGetBookWebEx(address);

http://git-wip-us.apache.org/repos/asf/cxf/blob/4e2cf99e/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml 
b/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml
index b4f5d5b..f2b8935 100644
--- a/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml
+++ b/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml
@@ -233,6 +233,14 @@
             <entry key="depthInnerElementCountThreshold" value="2"/>
         </jaxrs:properties>
     </jaxrs:server>
+    <jaxrs:server id="thedocs" address="/thedocs">
+        <jaxrs:serviceBeans>
+            <bean class="org.apache.cxf.systest.jaxrs.DocumentResourceImpl"/>
+        </jaxrs:serviceBeans>
+        <jaxrs:providers>
+            <bean 
class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
+        </jaxrs:providers>
+    </jaxrs:server>
     <bean id="jaxbProviderForTypes" 
class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
         <property name="unmarshallAsJaxbElement" value="true"/>
         <property name="schemaLocations" ref="theSchemaLocations"/>

Reply via email to