cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r638158 - in /incubator/cxf/trunk: common/common/src/main/java/org/apache/cxf/common/util/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ rt/frontend/simple/src/main/java/...
Date Tue, 18 Mar 2008 00:39:27 GMT
Author: dkulp
Date: Mon Mar 17 17:39:25 2008
New Revision: 638158

URL: http://svn.apache.org/viewvc?rev=638158&view=rev
Log:
[CXF-1476] Exceptions in in/out params the used generics or multi-arrays

Modified:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/WrapperClassGenerator.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceConfiguration.java
    incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/AbstractServiceConfiguration.java
    incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstService.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java?rev=638158&r1=638157&r2=638158&view=diff
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java
(original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java
Mon Mar 17 17:39:25 2008
@@ -20,7 +20,10 @@
 package org.apache.cxf.common.util;
 
 import java.lang.reflect.Constructor;
+import java.lang.reflect.GenericArrayType;
 import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -89,6 +92,30 @@
             return "[" + getClassCode(cl.getComponentType());
         }
         return "L" + periodToSlashes(cl.getName()) + ";";
+    }
+    public static String getClassCode(Type type) {
+        if (type instanceof Class) {
+            return getClassCode((Class)type);
+        } else if (type instanceof GenericArrayType) {
+            GenericArrayType at = (GenericArrayType)type;
+            return "[" + getClassCode(at.getGenericComponentType());
+        } else if (type instanceof ParameterizedType) {
+            ParameterizedType pt = (ParameterizedType)type;
+            StringBuilder a = new StringBuilder(getClassCode(pt.getRawType()));
+            a.setLength(a.length() - 1);
+            a.append('<');
+            boolean first = true;
+            for (Type t : pt.getActualTypeArguments()) {
+                if (!first) {
+                    a.append(" ,");
+                }
+                first = false;
+                a.append(getClassCode(t));  
+            }
+            a.append(">;");
+            return a.toString();
+        }
+        return null;
     }
     
     

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/WrapperClassGenerator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/WrapperClassGenerator.java?rev=638158&r1=638157&r2=638158&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/WrapperClassGenerator.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/WrapperClassGenerator.java
Mon Mar 17 17:39:25 2008
@@ -21,7 +21,6 @@
 
 
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Array;
 import java.lang.reflect.GenericArrayType;
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
@@ -38,11 +37,13 @@
 import javax.xml.bind.annotation.XmlNsForm;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 import javax.xml.namespace.QName;
+import javax.xml.ws.Holder;
 
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.ASMHelper;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.JavaUtils;
+import org.apache.cxf.jaxb.JAXBUtils;
 import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
 import org.apache.cxf.service.model.InterfaceInfo;
 import org.apache.cxf.service.model.MessageInfo;
@@ -250,40 +251,79 @@
         if (obj != null) {
             clz = (Class)obj;
         }
-        Class genericTypeClass = null;
         Type genericType = (Type)mpi.getProperty(ReflectionServiceFactoryBean.GENERIC_TYPE);
+        if (genericType instanceof ParameterizedType) {
+            ParameterizedType tp = (ParameterizedType)genericType;
+            if (tp.getRawType() instanceof Class
+                && Holder.class.isAssignableFrom((Class)tp.getRawType())) {
+                genericType = tp.getActualTypeArguments()[0];
+            }
+        }
+        String classCode = getClassCode(clz);
+        String fieldDescriptor = null;
+        
         if (genericType instanceof ParameterizedType
-            && Collection.class.isAssignableFrom(clz)) {
+            && (Collection.class.isAssignableFrom(clz) || clz.isArray())) {
             ParameterizedType ptype = (ParameterizedType)genericType;
 
             Type[] types = ptype.getActualTypeArguments();
             // TODO: more complex Parameterized type
             if (types.length > 0) {
                 if (types[0] instanceof Class) {
-                    genericTypeClass = (Class)types[0];
+                    fieldDescriptor = getClassCode(genericType);
                 } else if (types[0] instanceof GenericArrayType) {
-                    genericTypeClass = (Class)((GenericArrayType)types[0]).getGenericComponentType();
-                    genericTypeClass = Array.newInstance(genericTypeClass, 0).getClass();
+                    fieldDescriptor = getClassCode(genericType);
+                } else if (types[0] instanceof ParameterizedType) {
+                    classCode = getClassCode(((ParameterizedType)types[0]).getRawType());
+                    fieldDescriptor = getClassCode(genericType);
                 }
             }
         }
-        String classCode = getClassCode(clz);
-
-        String filedDescriptor = null;
-        if (genericTypeClass != null
-            && Collection.class.isAssignableFrom(clz)) {
-            filedDescriptor = classCode.substring(0, classCode.lastIndexOf(";")) + "<"
-                              + getClassCode(genericTypeClass) + ">;";
-        }
         String fieldName = JavaUtils.isJavaKeyword(name) ? JavaUtils.makeNonJavaKeyword(name)
: name;
         
-        FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, fieldName, 
-                                        classCode, filedDescriptor, null);
+        FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE,
+                                        fieldName, 
+                                        classCode,
+                                        fieldDescriptor,
+                                        null);
+        
+        
         AnnotationVisitor av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlElement;",
true);
         av0.visit("name", name);
         av0.visitEnd();
 
         List<Annotation> jaxbAnnos = getJaxbAnnos(mpi);
+        addJAXBAnnotations(fv, jaxbAnnos);
+        fv.visitEnd();
+
+        String methodName = JAXBUtils.nameToIdentifier(name, JAXBUtils.IdentifierType.GETTER);
+        MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "()" + classCode,

+                                          fieldDescriptor == null ? null : "()" + fieldDescriptor,
+                                          null);
+        mv.visitCode();
+
+        mv.visitVarInsn(Opcodes.ALOAD, 0);
+        mv.visitFieldInsn(Opcodes.GETFIELD, classFileName, fieldName, classCode);
+        mv.visitInsn(org.objectweb.asm.Type.getType(classCode).getOpcode(Opcodes.IRETURN));
+        mv.visitMaxs(0, 0);
+        mv.visitEnd();
+        
+        methodName = JAXBUtils.nameToIdentifier(name, JAXBUtils.IdentifierType.SETTER);
+        mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "(" + classCode + ")V",
+                            fieldDescriptor == null ? null : "(" + fieldDescriptor + ")V",
null);
+        mv.visitCode();
+        mv.visitVarInsn(Opcodes.ALOAD, 0);
+        org.objectweb.asm.Type setType = org.objectweb.asm.Type.getType(classCode);
+        mv.visitVarInsn(setType.getOpcode(Opcodes.ILOAD), 1);
+        mv.visitFieldInsn(Opcodes.PUTFIELD, className, fieldName, classCode);       
+        mv.visitInsn(Opcodes.RETURN);
+        mv.visitMaxs(0, 0);
+        mv.visitEnd();
+
+    }
+     
+    private void addJAXBAnnotations(FieldVisitor fv, List<Annotation> jaxbAnnos) {
+        AnnotationVisitor av0;
         for (Annotation ann : jaxbAnnos) {
             if (ann instanceof XmlMimeType) {
                 av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlMimeType;", true);
@@ -306,32 +346,8 @@
                 av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlList;", true);
                 av0.visitEnd();
             }
-
         }
-
-        fv.visitEnd();
-
-        String methodName = StringUtils.capitalize(name);
-
-        MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "get" + methodName, "()" +
classCode, null,
-                                          null);
-        mv.visitCode();
-
-        mv.visitVarInsn(Opcodes.ALOAD, 0);
-        mv.visitFieldInsn(Opcodes.GETFIELD, classFileName, fieldName, classCode);
-        mv.visitInsn(org.objectweb.asm.Type.getType(classCode).getOpcode(Opcodes.IRETURN));
-        mv.visitMaxs(0, 0);
-        mv.visitEnd();
-        
-        mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "set" + methodName, "(" + classCode + ")V",
null, null);
-        mv.visitCode();
-        mv.visitVarInsn(Opcodes.ALOAD, 0);
-        org.objectweb.asm.Type setType = org.objectweb.asm.Type.getType(classCode);
-        mv.visitVarInsn(setType.getOpcode(Opcodes.ILOAD), 1);
-        mv.visitFieldInsn(Opcodes.PUTFIELD, className, fieldName, classCode);       
-        mv.visitInsn(Opcodes.RETURN);
-        mv.visitMaxs(0, 0);
-        mv.visitEnd();
-
     }
+    
+    
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceConfiguration.java?rev=638158&r1=638157&r2=638158&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceConfiguration.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceConfiguration.java
Mon Mar 17 17:39:25 2008
@@ -20,8 +20,6 @@
 package org.apache.cxf.jaxws.support;
 
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Array;
-import java.lang.reflect.GenericArrayType;
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
@@ -734,27 +732,13 @@
         return Holder.class.equals(cls);
     }
     
-    public Class<?> getHolderType(Class<?> cls, Type type) {
+    public Type getHolderType(Class<?> cls, Type type) {
         if (cls.equals(Holder.class) && type instanceof ParameterizedType) {
             ParameterizedType paramType = (ParameterizedType)type;
-            cls = getHolderClass(paramType);
+            return paramType.getActualTypeArguments()[0];
         }
 
         return cls;
     }   
     
-    private static Class getHolderClass(ParameterizedType paramType) {
-        Object rawType = paramType.getActualTypeArguments()[0];
-        Class rawClass;
-        if (rawType instanceof GenericArrayType) {
-            rawClass = (Class)((GenericArrayType)rawType).getGenericComponentType();
-            rawClass = Array.newInstance(rawClass, 0).getClass();
-        } else {
-            if (rawType instanceof ParameterizedType) {
-                rawType = (Class)((ParameterizedType)rawType).getRawType();
-            }
-            rawClass = (Class)rawType;
-        }
-        return rawClass;
-    }
 }

Modified: incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/AbstractServiceConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/AbstractServiceConfiguration.java?rev=638158&r1=638157&r2=638158&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/AbstractServiceConfiguration.java
(original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/AbstractServiceConfiguration.java
Mon Mar 17 17:39:25 2008
@@ -184,7 +184,7 @@
         return null;
     }
     
-    public Class<?> getHolderType(Class<?> cls, Type type) {
+    public Type getHolderType(Class<?> cls, Type type) {
         return null;
     }
 }

Modified: incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java?rev=638158&r1=638157&r2=638158&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
(original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
Mon Mar 17 17:39:25 2008
@@ -20,8 +20,11 @@
 package org.apache.cxf.service.factory;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Array;
 import java.lang.reflect.Field;
+import java.lang.reflect.GenericArrayType;
 import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Proxy;
 import java.lang.reflect.Type;
 import java.net.MalformedURLException;
@@ -1441,11 +1444,42 @@
         }
     }
 
+    private static Class createArrayClass(GenericArrayType atp) {
+        Type tp = ((GenericArrayType)atp).getGenericComponentType();
+        Class rawClass = null;
+        if (tp instanceof Class) {
+            rawClass = (Class)tp;
+        } else if (tp instanceof GenericArrayType) {
+            rawClass = createArrayClass((GenericArrayType)tp);
+        } else if (tp instanceof ParameterizedType) {
+            rawClass = (Class)((ParameterizedType)tp).getRawType();
+            if (List.class.isAssignableFrom(rawClass)) { 
+                rawClass = getClass((ParameterizedType)tp);
+                rawClass = Array.newInstance(rawClass, 0).getClass();
+            }
+        }
+        return Array.newInstance(rawClass, 0).getClass();
+    }
+    
+    private static Class getClass(Type paramType) {
+        Class rawClass = null;
+        if (paramType instanceof Class) {
+            rawClass = (Class)paramType;
+        } else if (paramType instanceof GenericArrayType) {
+            rawClass = createArrayClass((GenericArrayType)paramType);
+        } else if (paramType instanceof ParameterizedType) {
+            rawClass = (Class)((ParameterizedType)paramType).getRawType();
+        } 
+        return rawClass;
+    }
+    
+    
     protected void initializeParameter(MessagePartInfo part, Class rawClass, Type type) {
         if (isHolder(rawClass, type)) {
-            Class<?> c = getHolderType(rawClass, type);
+            Type c = getHolderType(rawClass, type);
             if (c != null) {
-                rawClass = c;
+                type = c;
+                rawClass = getClass(type);
             }
         }
         part.setProperty(GENERIC_TYPE, type);
@@ -1549,9 +1583,9 @@
         return false;
     }
     
-    public Class<?> getHolderType(Class<?> cls, Type type) {
+    public Type getHolderType(Class<?> cls, Type type) {
         for (AbstractServiceConfiguration c : serviceConfigurations) {
-            Class<?> b = c.getHolderType(cls, type);
+            Type b = c.getHolderType(cls, type);
             if (b != null) {
                 return b;
             }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java?rev=638158&r1=638157&r2=638158&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
Mon Mar 17 17:39:25 2008
@@ -351,7 +351,7 @@
             port.throwException(10);
             fail("Expected exception not found");
         } catch (ServiceTestFault ex) {
-            assertEquals(10, ex.getFaultInfo().getId());
+            assertEquals(10L, ex.getFaultInfo().getId());
         }
         // CXF-1131 testcase
         try {

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstService.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstService.java?rev=638158&r1=638157&r2=638158&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstService.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstService.java
Mon Mar 17 17:39:25 2008
@@ -81,6 +81,11 @@
     List<Foo> listObjectOutput();
 
     @WebMethod
+    boolean listObjectIn(@WebParam(mode = WebParam.Mode.INOUT)
+                         Holder<List<Foo[]>> foos);
+
+    
+    @WebMethod
     List<Foo[]> listObjectArrayOutput();
     
     @WebMethod

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java?rev=638158&r1=638157&r2=638158&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java
Mon Mar 17 17:39:25 2008
@@ -180,4 +180,8 @@
     public Bar createBar(String val) {
         return new BarImpl(val);
     }
+
+    public boolean listObjectIn(Holder<List<Foo[]>> foos) {
+        return false;
+    }
 }



Mime
View raw message