cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7279] Addressing the generic type leak
Date Tue, 14 Mar 2017 16:08:22 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 792443729 -> d0821bce5


[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/d0821bce
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/d0821bce
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/d0821bce

Branch: refs/heads/master
Commit: d0821bce5faa119c882a9000dbe03a124df5b033
Parents: 7924437
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Tue Mar 14 16:08:08 2017 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Tue Mar 14 16:08:08 2017 +0000

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/utils/InjectionUtils.java  | 22 +++++++-----
 .../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, 136 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/d0821bce/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 042b378..0c4e8e3 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
@@ -1494,15 +1494,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/d0821bce/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/d0821bce/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/d0821bce/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/d0821bce/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 647fb3f..a5a3c82 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
@@ -90,6 +90,14 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest
         Book book = wc.replaceHeader("Accept", "application/xml").query("id", 1L).get(Book.class);
         assertEquals("CXF", book.getName());
     }
+    
+    @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 {

http://git-wip-us.apache.org/repos/asf/cxf/blob/d0821bce/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 bfd097a..49dc91a 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"/>


Mime
View raw message