You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2007/05/17 23:44:15 UTC

svn commit: r539128 - in /incubator/cxf/trunk: common/common/src/main/java/org/apache/cxf/jaxb/ common/common/src/test/java/org/apache/cxf/jaxb/ rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/

Author: dkulp
Date: Thu May 17 14:44:14 2007
New Revision: 539128

URL: http://svn.apache.org/viewvc?view=rev&rev=539128
Log:
[CXF-660] Fix for NPE in getWrapper for booleans
Fix issue with headers always being echoed back to clients

Added:
    incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/jaxb/WrapperHelperTest.java   (with props)
Modified:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/WrapperHelper.java
    incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapHeaderInterceptor.java

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/WrapperHelper.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/WrapperHelper.java?view=diff&rev=539128&r1=539127&r2=539128
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/WrapperHelper.java (original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/WrapperHelper.java Thu May 17 14:44:14 2007
@@ -191,8 +191,9 @@
             
             elField = getElField(partName, wrapperType);
                 
-            if (!Collection.class.isAssignableFrom(elField.getType())
-                && !elField.getType().isArray()) {
+            if (elField == null
+                || (!Collection.class.isAssignableFrom(elField.getType())
+                && !elField.getType().isArray())) {
     
                 try {
                     method = wrapperType.getClass().getMethod(accessor.replaceFirst("get", "is"),
@@ -239,11 +240,8 @@
     }
 
     private static Field getElField(String partName, Object wrapperType) {
-        String fieldName = partName;
+        String fieldName = JAXBUtils.nameToIdentifier(partName, JAXBUtils.IdentifierType.VARIABLE);
         Field elField = null;
-        if (JAXBUtils.isJavaKeyword(partName)) {
-            fieldName = JAXBUtils.nameToIdentifier(partName, JAXBUtils.IdentifierType.VARIABLE);
-        }
         for (Field field : wrapperType.getClass().getDeclaredFields()) {
             if (field.getName().equals(fieldName)) {
                 elField = field;

Added: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/jaxb/WrapperHelperTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/jaxb/WrapperHelperTest.java?view=auto&rev=539128
==============================================================================
--- incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/jaxb/WrapperHelperTest.java (added)
+++ incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/jaxb/WrapperHelperTest.java Thu May 17 14:44:14 2007
@@ -0,0 +1,114 @@
+/**
+ * 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.jaxb;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class WrapperHelperTest extends Assert {
+
+
+    @Test
+    public void getBooleanTypeWrappedPart() throws Exception {
+        SetIsOK ok = new SetIsOK();
+        ok.setParameter3(new boolean[] {true, false});
+        Object object = WrapperHelper.getWrappedPart("Parameter1", ok, "boolean");
+        assertTrue(object instanceof Boolean);
+        object = WrapperHelper.getWrappedPart("Parameter3", ok, "boolean");
+        assertTrue(object instanceof boolean[]);
+        assertTrue(((boolean[])object)[0]);
+        assertFalse(((boolean[])object)[1]);
+        
+        WrapperHelper.setWrappedPart("Parameter1", ok, true);
+        assertTrue(ok.isParameter1());
+        WrapperHelper.setWrappedPart("Parameter3", ok, new boolean[] {false, true});
+        assertTrue(ok.getParameter3()[1]);
+        assertFalse(ok.getParameter3()[0]);        
+    }
+
+
+    @XmlAccessorType(XmlAccessType.FIELD)
+    @XmlType(name = "", propOrder = { "parameter1", "parameter2", "parameter3" })
+    @XmlRootElement(name = "setIsOK")
+    class SetIsOK {
+
+        @XmlElement(name = "Parameter1")
+        protected boolean parameter1;
+        @XmlElement(name = "Parameter2")
+        protected int parameter2;
+        @XmlElement(name = "Parameter3")
+        protected boolean parameter3[];
+
+        /**
+         * Gets the value of the parameter1 property.
+         * 
+         */
+        public boolean isParameter1() {
+            return parameter1;
+        }
+
+        /**
+         * Sets the value of the parameter1 property.
+         * 
+         */
+        public void setParameter1(boolean value) {
+            this.parameter1 = value;
+        }
+
+        /**
+         * Gets the value of the parameter2 property.
+         * 
+         */
+        public int getParameter2() {
+            return parameter2;
+        }
+
+        /**
+         * Sets the value of the parameter2 property.
+         * 
+         */
+        public void setParameter2(int value) {
+            this.parameter2 = value;
+        }
+        
+        
+        /**
+         * Gets the value of the parameter2 property.
+         * 
+         */
+        public boolean[] getParameter3() {
+            return parameter3;
+        }
+
+        /**
+         * Sets the value of the parameter2 property.
+         * 
+         */
+        public void setParameter3(boolean value[]) {
+            this.parameter3 = value;
+        }
+    }
+}
+

Propchange: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/jaxb/WrapperHelperTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/jaxb/WrapperHelperTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapHeaderInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapHeaderInterceptor.java?view=diff&rev=539128&r1=539127&r2=539128
==============================================================================
--- incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapHeaderInterceptor.java (original)
+++ incubator/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapHeaderInterceptor.java Thu May 17 14:44:14 2007
@@ -86,6 +86,8 @@
             int idx = mpi.getIndex();
             Object object = null;
             if (param != null) {
+                message.getHeaders().remove(param);
+                
                 if (param.getDataBinding() == null) {
                     Node source = (Node)param.getObject();
                     object = getNodeDataReader(message).read(mpi, source);