cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r727800 - in /cxf/branches/2.1.x-fixes: ./ 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:31:35 GMT
Author: dkulp
Date: Thu Dec 18 11:31:34 2008
New Revision: 727800

URL: http://svn.apache.org/viewvc?rev=727800&view=rev
Log:
Merged revisions 727792 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r727792 | dkulp | 2008-12-18 14:10:58 -0500 (Thu, 18 Dec 2008) | 3 lines
  
  Fix issues with primitive arrays when used in exceptions
  Fix redirect case sensitivity
........

Modified:
    cxf/branches/2.1.x-fixes/   (props changed)
    cxf/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
    cxf/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
    cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
    cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
    cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ComplexException.java
    cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java

Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 18 11:31:34 2008
@@ -1 +1 @@
-/cxf/trunk:686333-686363,686764,686820,687096,687194,687363,687387,687463,687543,687722,687798,687814,687817,687891,687910,687914,688086,688102,688133,688596,688735,688870,689572,689596,689855,689924,690067,690289,691246,691271,691295,691338,691355,691488,691602,691646,691706,691728,692116,692157,692310,692466,692499,693653,693819,694179,694263,694417,694716,694744,694747,694795,694869,694981,694987,694993,695041,695096,695396,695484,695537,695552,695561,695619,695684,695835,695840,695868,695935,695977,696016,696094,696433,696720,697085,697868,698128,699289,700261,700507,700602,700981,701316,701783,701830,701862,702187,702205-702248,702267,702547,702561,702580,702602,702609,702616,702653,702656,702957,703191,703239,703309,703501,703513,703548,704584,704937,704997,705150,705235,705274,705340,705446,705548,705614,705692,705708,706482,706631,706675,706900,706909,707034,707089,707100,707902,708035,708044,708074,708410,708417,708550,708554,709353-709354,709425,710076,710150,71015
 4,711193,711388,711410,711490,711635,711949,711975,712194,712198,712238,712272,712299,712312,712670,712893,713082,713095-713096,713099,713584,713597,713737,713804,713899,714167-714168,714245,714255,717937-717961,718281-718448,718565,718620,718640,718665,718970,719017,719210,719215-719218,719222-719273,719305,719327-719680,720053,720119-720218,720238,720293-720316,720497,721221,721241,721501,722117,722129,722412,722988,723024,723338,723378,723716-723791,724333-724372,724433-724438,724449,724481,724485,724668,724780,724782,724785,724793,724795,724940,725071,725316,725332,725335,725348,725364,725418,725425-725426,725455,725506,725554,725562,725651,725671,725688,725754,725773,725799,725839,726342,726524,726631,726634,726637,726639,726692,726724,726769,726992,727096,727445,727521,727568,727692,727754
+/cxf/trunk:686333-686363,686764,686820,687096,687194,687363,687387,687463,687543,687722,687798,687814,687817,687891,687910,687914,688086,688102,688133,688596,688735,688870,689572,689596,689855,689924,690067,690289,691246,691271,691295,691338,691355,691488,691602,691646,691706,691728,692116,692157,692310,692466,692499,693653,693819,694179,694263,694417,694716,694744,694747,694795,694869,694981,694987,694993,695041,695096,695396,695484,695537,695552,695561,695619,695684,695835,695840,695868,695935,695977,696016,696094,696433,696720,697085,697868,698128,699289,700261,700507,700602,700981,701316,701783,701830,701862,702187,702205-702248,702267,702547,702561,702580,702602,702609,702616,702653,702656,702957,703191,703239,703309,703501,703513,703548,704584,704937,704997,705150,705235,705274,705340,705446,705548,705614,705692,705708,706482,706631,706675,706900,706909,707034,707089,707100,707902,708035,708044,708074,708410,708417,708550,708554,709353-709354,709425,710076,710150,71015
 4,711193,711388,711410,711490,711635,711949,711975,712194,712198,712238,712272,712299,712312,712670,712893,713082,713095-713096,713099,713584,713597,713737,713804,713899,714167-714168,714245,714255,717937-717961,718281-718448,718565,718620,718640,718665,718970,719017,719210,719215-719218,719222-719273,719305,719327-719680,720053,720119-720218,720238,720293-720316,720497,721221,721241,721501,722117,722129,722412,722988,723024,723338,723378,723716-723791,724333-724372,724433-724438,724449,724481,724485,724668,724780,724782,724785,724793,724795,724940,725071,725316,725332,725335,725348,725364,725418,725425-725426,725455,725506,725554,725562,725651,725671,725688,725754,725773,725799,725839,726342,726524,726631,726634,726637,726639,726692,726724,726769,726992,727096,727445,727521,727568,727692,727754,727792

Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java?rev=727800&r1=727799&r2=727800&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
Thu Dec 18 11:31:34 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/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java?rev=727800&r1=727799&r2=727800&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
Thu Dec 18 11:31:34 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/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?rev=727800&r1=727799&r2=727800&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
Thu Dec 18 11:31:34 2008
@@ -1670,9 +1670,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/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java?rev=727800&r1=727799&r2=727800&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
(original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
Thu Dec 18 11:31:34 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/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ComplexException.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ComplexException.java?rev=727800&r1=727799&r2=727800&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ComplexException.java
(original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/ComplexException.java
Thu Dec 18 11:31:34 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/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java?rev=727800&r1=727799&r2=727800&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java
(original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java
Thu Dec 18 11:31:34 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