cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r727792 - in /cxf/trunk: rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/ rt/transports/http/src/main/java/org/apache/cxf/transport/http/ systests/src/test/java/org/apache/cxf/systest/jaxws/
Date Thu, 18 Dec 2008 19:10:58 GMT
Author: dkulp
Date: Thu Dec 18 11:10:58 2008
New Revision: 727792

URL: http://svn.apache.org/viewvc?rev=727792&view=rev
Log:
Fix issues with primitive arrays when used in exceptions
Fix redirect case sensitivity

Modified:
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ComplexException.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java?rev=727792&r1=727791&r2=727792&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
(original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
Thu Dec 18 11:10:58 2008
@@ -130,24 +130,10 @@
                     } else if (part.getMessageInfo().getOperation().isUnwrapped()
                                && (mObj.getClass().isArray() || mObj instanceof List)
                                && el.getMaxOccurs() != 1) {
-                        // Have to handle this ourselves.... which really
-                        // sucks.... but what can we do?
-                        Object objArray;
-                        if (mObj instanceof List) {
-                            List l = (List)mObj;
-                            objArray = l.toArray(new Object[l.size()]);
-                            cls = null;
-                        } else {
-                            objArray = mObj;
-                            cls = objArray.getClass().getComponentType();
-                        }
-                        int len = Array.getLength(objArray);
-                        for (int x = 0; x < len; x++) {
-                            Object o = Array.get(objArray, x);
-                            writeObject(marshaller, source, 
-                                        new JAXBElement(elName, cls == null ? o.getClass()
: cls,
-                                                                   o));
-                        }
+                        writeArrayObject(marshaller, 
+                                         source,
+                                         elName,
+                                         mObj);
                     } else {
                         writeObject(marshaller, source, new JAXBElement(elName, cls, mObj));
                     }
@@ -275,7 +261,12 @@
                 if (JAXBContextInitializer.isFieldAccepted(f, accessType)) {
                     QName fname = new QName(namespace, f.getName());
                     f.setAccessible(true);
-                    writeObject(marshaller, writer, new JAXBElement(fname, String.class,
f.get(elValue)));
+                    if (JAXBSchemaInitializer.isArray(f.getGenericType())) {
+                        writeArrayObject(marshaller, writer, fname, f.get(elValue));    
                   
+                    } else {
+                        writeObject(marshaller, writer, new JAXBElement(fname, String.class,

+                                                                        f.get(elValue)));
+                    }
                 }
             }
             for (Method m : cls.getMethods()) {
@@ -284,7 +275,12 @@
                     String name = m.getName().substring(idx);
                     name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
                     QName mname = new QName(namespace, name);
-                    writeObject(marshaller, writer, new JAXBElement(mname, String.class,
m.invoke(elValue)));
+                    if (JAXBSchemaInitializer.isArray(m.getGenericReturnType())) {
+                        writeArrayObject(marshaller, writer, mname, m.invoke(elValue));
+                    } else {
+                        writeObject(marshaller, writer, new JAXBElement(mname, String.class,

+                                                                        m.invoke(elValue)));
+                    }
                 }
             }
 
@@ -295,6 +291,31 @@
         }
     }
 
+    @SuppressWarnings("unchecked")
+    private static void writeArrayObject(Marshaller marshaller, 
+                                         Object source,
+                                         QName mname,
+                                         Object mObj) throws Fault, JAXBException {
+        // Have to handle this ourselves.... which really
+        // sucks.... but what can we do?
+        Object objArray;
+        Class cls = null;
+        if (mObj instanceof List) {
+            List<?> l = (List)mObj;
+            objArray = l.toArray(new Object[l.size()]);
+            cls = null;
+        } else {
+            objArray = mObj;
+            cls = objArray.getClass().getComponentType();
+        }
+        int len = Array.getLength(objArray);
+        for (int x = 0; x < len; x++) {
+            Object o = Array.get(objArray, x);
+            writeObject(marshaller, source, 
+                        new JAXBElement(mname, cls == null ? o.getClass() : cls, o));
+        }        
+    }
+
     public static Exception unmarshallException(Unmarshaller u, 
                                                 Object source,
                                                 MessagePartInfo part) {
@@ -339,9 +360,32 @@
                 QName q = reader.getName();
                 try {
                     Field f = cls.getField(q.getLocalPart());
+                    Type type = f.getGenericType();
                     if (JAXBContextInitializer.isFieldAccepted(f, accessType)) {
                         f.setAccessible(true);
-                        f.set(obj, u.unmarshal(reader, f.getType()));
+                        if (JAXBSchemaInitializer.isArray(type)) {
+                            Class<?> compType = JAXBSchemaInitializer
+                                .getArrayComponentType(type);
+                            List<Object> ret = unmarshallArray(u, reader,
+                                                               q,
+                                                               compType,
+                                                               createList(type));
+                            Object o = ret;
+                            if (!isList(type)) {
+                                if (compType.isPrimitive()) {
+                                    o = java.lang.reflect.Array.newInstance(compType, ret.size());
+                                    for (int x = 0; x < ret.size(); x++) {
+                                        Array.set(o, x, ret.get(x));
+                                    }
+                                } else {
+                                    o = ret.toArray((Object[])Array.newInstance(compType,
ret.size()));
+                                }
+                            }
+
+                            f.set(obj, o);
+                        } else {
+                            f.set(obj, u.unmarshal(reader, f.getType()));
+                        }
                     }
                 } catch (NoSuchFieldException ex) {
                     String s = Character.toUpperCase(q.getLocalPart().charAt(0))
@@ -352,9 +396,32 @@
                     } catch (NoSuchMethodException mex) {
                         m = cls.getMethod("is" + s);
                     }
+                    Type type = m.getGenericReturnType();
                     Method m2 = cls.getMethod("set" + s, m.getReturnType());
-                    Object o = getElementValue(u.unmarshal(reader, m.getReturnType()));
-                    m2.invoke(obj, o);
+                    if (JAXBSchemaInitializer.isArray(type)) {
+                        Class<?> compType = JAXBSchemaInitializer
+                            .getArrayComponentType(type);
+                        List<Object> ret = unmarshallArray(u, reader,
+                                                           q,
+                                                           compType,
+                                                           createList(type));
+                        Object o = ret;
+                        if (!isList(type)) {
+                            if (compType.isPrimitive()) {
+                                o = java.lang.reflect.Array.newInstance(compType, ret.size());
+                                for (int x = 0; x < ret.size(); x++) {
+                                    Array.set(o, x, ret.get(x));
+                                }
+                            } else {
+                                o = ret.toArray((Object[])Array.newInstance(compType, ret.size()));
+                            }
+                        }
+
+                        m2.invoke(obj, o);
+                    } else {
+                        Object o = getElementValue(u.unmarshal(reader, m.getReturnType()));
+                        m2.invoke(obj, o);
+                    }
                 }
             }
             return (Exception)obj;
@@ -464,6 +531,9 @@
 
     private static List<Object> createList(MessagePartInfo part) {
         Type genericType = (Type)part.getProperty("generic.type");
+        return createList(genericType); 
+    }
+    private static List<Object> createList(Type genericType) {
         if (genericType instanceof ParameterizedType) {
             Type tp2 = ((ParameterizedType)genericType).getRawType();
             if (tp2 instanceof Class) {
@@ -477,10 +547,15 @@
                 }
             }
         }
-
         return new ArrayList<Object>();
     }
 
+    private static boolean isList(Type cls) {
+        if (cls instanceof ParameterizedType) {
+            return true;
+        }
+        return false;
+    }
     private static boolean isList(MessagePartInfo part) {
         if (part.getTypeClass().isArray() && !part.getTypeClass().getComponentType().isPrimitive())
{
             // && Collection.class.isAssignableFrom(part.getTypeClass())) {

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java?rev=727792&r1=727791&r2=727792&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
(original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
Thu Dec 18 11:10:58 2008
@@ -20,7 +20,9 @@
 package org.apache.cxf.jaxb;
 
 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.Type;
@@ -74,6 +76,45 @@
         this.qualifiedSchemas = q;
     }
 
+    static Class<?> getArrayComponentType(Type cls) {
+        if (cls instanceof Class) {
+            if (((Class)cls).isArray()) {
+                return ((Class)cls).getComponentType();
+            } else {
+                return (Class)cls;
+            }
+        } else if (cls instanceof ParameterizedType) {
+            for (Type t2 : ((ParameterizedType)cls).getActualTypeArguments()) {
+                return getArrayComponentType(t2);
+            }
+        } else if (cls instanceof GenericArrayType) {
+            GenericArrayType gt = (GenericArrayType)cls;
+            Class ct = (Class) gt.getGenericComponentType();
+            return Array.newInstance(ct, 0).getClass();
+        }
+        return null;
+    }
+    public JAXBBeanInfo getBeanInfo(Type cls) {
+        if (cls instanceof Class) {
+            if (((Class)cls).isArray()) {
+                return getBeanInfo(((Class)cls).getComponentType());
+            } else {
+                return getBeanInfo((Class)cls);
+            }
+        } else if (cls instanceof ParameterizedType) {
+            for (Type t2 : ((ParameterizedType)cls).getActualTypeArguments()) {
+                return getBeanInfo(t2);
+            }
+        } else if (cls instanceof GenericArrayType) {
+            GenericArrayType gt = (GenericArrayType)cls;
+            Class ct = (Class) gt.getGenericComponentType();
+            ct = Array.newInstance(ct, 0).getClass();
+
+            return getBeanInfo(ct);
+        }
+        
+        return null;
+    }
     public JAXBBeanInfo getBeanInfo(Class<?> cls) {
         return getBeanInfo(context, cls);
     }
@@ -452,35 +493,54 @@
         for (Field f : cls.getDeclaredFields()) {
             if (JAXBContextInitializer.isFieldAccepted(f, accessType)) {
                 //map field
-                JAXBBeanInfo beanInfo = getBeanInfo(f.getType());
+                Type type = f.getGenericType();
+                JAXBBeanInfo beanInfo = getBeanInfo(type);
                 if (beanInfo != null) {
-                    addElement(seq, beanInfo, new QName(namespace, f.getName()));
+                    addElement(seq, beanInfo, new QName(namespace, f.getName()), isArray(type));
                 }                
             }
         }
         for (Method m : cls.getMethods()) {
             if (JAXBContextInitializer.isMethodAccepted(m, accessType)) {
                 //map field
-                JAXBBeanInfo beanInfo = getBeanInfo(m.getReturnType());
+                Type type = m.getGenericReturnType();
+                JAXBBeanInfo beanInfo = getBeanInfo(type);
                 if (beanInfo != null) {
                     int idx = m.getName().startsWith("get") ? 3 : 2;
                     String name = m.getName().substring(idx);
                     name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
-                    addElement(seq, beanInfo, new QName(namespace, name));
+                    addElement(seq, beanInfo, new QName(namespace, name), isArray(type));
                 }                
             }
         }
         part.setProperty(JAXBDataBinding.class.getName() + ".CUSTOM_EXCEPTION", Boolean.TRUE);
     }
     
-    public void addElement(XmlSchemaSequence seq, JAXBBeanInfo beanInfo, QName name) {  
 
+    static boolean isArray(Type cls) {
+        if (cls instanceof Class) {
+            return ((Class)cls).isArray();
+        } else if (cls instanceof ParameterizedType) {
+            return true;
+        } else if (cls instanceof GenericArrayType) {
+            return true;
+        }
+        return false;
+    }
+
+    public void addElement(XmlSchemaSequence seq, JAXBBeanInfo beanInfo,
+                           QName name, boolean isArray) {    
         XmlSchemaElement el = new XmlSchemaElement();
         el.setName(name.getLocalPart());
         XmlSchemaTools.setElementQName(el, name);
 
-        el.setMinOccurs(1);
-        el.setMaxOccurs(1);
-        el.setNillable(true);
+        if (isArray) {
+            el.setMinOccurs(0);
+            el.setMaxOccurs(Long.MAX_VALUE);
+        } else {
+            el.setMinOccurs(1);
+            el.setMaxOccurs(1);
+            el.setNillable(true);
+        }
 
         if (beanInfo.isElement()) {
             QName ename = new QName(beanInfo.getElementNamespaceURI(null), 

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?rev=727792&r1=727791&r2=727792&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
Thu Dec 18 11:10:58 2008
@@ -1673,9 +1673,14 @@
     private String extractLocation(
             Map<String, List<String>> headers
     ) {
-        List<String> locs = headers.get("Location");
-        if (locs != null && locs.size() > 0) {
-            return locs.get(0);
+        
+        for (Map.Entry<String, List<String>> head : headers.entrySet()) {
+            if ("Location".equalsIgnoreCase(head.getKey())) {
+                List<String> locs = head.getValue();
+                if (locs != null && locs.size() > 0) {
+                    return locs.get(0);
+                }                
+            }
         }
         return null;
     }

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java?rev=727792&r1=727791&r2=727792&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
Thu Dec 18 11:10:58 2008
@@ -390,6 +390,7 @@
             fail("Expected exception not found");
         } catch (ComplexException ex) {
             assertEquals("Throw user fault -3", ex.getMessage());
+            assertEquals(3, ex.getInts().length);
         }          
         try {
             port.throwException(-3);

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ComplexException.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ComplexException.java?rev=727792&r1=727791&r2=727792&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ComplexException.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ComplexException.java Thu
Dec 18 11:10:58 2008
@@ -27,6 +27,7 @@
 
     private String reason;
     private MyBean[] beans;
+    private int[] ints;
     
     public ComplexException(String msg) {
         super(msg);
@@ -47,6 +48,13 @@
     public void setBeans(MyBean[] beans) {
         this.beans = beans;
     }
+    public int[] getInts() {
+        return ints;
+    }
+
+    public void setInts(int[] ints) {
+        this.ints = ints;
+    }
     
     
     @XmlAccessorType(XmlAccessType.PROPERTY)

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java?rev=727792&r1=727791&r2=727792&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java
Thu Dec 18 11:10:58 2008
@@ -173,6 +173,7 @@
             ComplexException.MyBean bean = new ComplexException.MyBean();
             bean.setName("Marco");
             ex.setBeans(new ComplexException.MyBean[] {bean});
+            ex.setInts(new int[] {1, 2, 3});
             throw ex;
         }
         default:



Mime
View raw message