Hi, The attached patch changes SimpleTypeMapper.isDataHandler so that it no longer returns true for java.lang.Object. The effect of this change is that if a method has a parameter of type java.lang.Object, the method will be passed an OMNode containing the contents of the parameter element instead of a javax.activation.DataHandler. This is a significant improvement since the javax.activation.DataHandler conversion assumes that the element contains base 64 encoded binary data, but OMNode can represent anything. This is also consistent with java2wsdl, which maps java.lang.Object to xs:anyType, which means that the element is allowed to have any content, not just base64binary.
Ideally, I would like to deserialize the object for the xs:anyType parameter based on the xsi:type attribute, if present. That could be accomplished by changing BeanUtil, or it can be done in the web service implementation itself. Either way, this change must be applied first to get rid of the destructive conversion to javax.activation.DataHandler. In addition to the change to SimpleTypeMapper, the patch contains tests for SimpleTypeMapper and BeanUtil, a change to pom.xml so that the BeanUtil test gets run at build time, and a fix for a problem in CoverterUtilTest exposed by the change to pom.xml. Is this patch acceptable, or is there something I should do differently? Regards, Pétur Runólfsson Betware The content of this e-mail, together with any of its attachments, is for the exclusive and confidential use of the named addressee(s) and it may contain legally privileged and confidential information and/or copyrighted material. Any other distribution, use or reproduction without the sender's prior consent is unauthorized and strictly prohibited. If you have by coincidence, mistake or without specific authorization received this e-mail in error, please notify the sender by e-mail immediately, uphold strict confidentiality and neither read, copy, transfer, disseminate, disclose nor otherwise make use of its content in any way and delete the material from your computer. The content of the e-mail and its attachments is the liability of the individual sender, if it does not relate to the affairs of Betware. Betware does not assume any civil or criminal liability should the e-mail or it´s attachments be virus infected.
Index: test/org/apache/axis2/databinding/utils/BeanUtilTest.java =================================================================== --- test/org/apache/axis2/databinding/utils/BeanUtilTest.java (revision 0) +++ test/org/apache/axis2/databinding/utils/BeanUtilTest.java (revision 0) @@ -0,0 +1,134 @@ +/* + * 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.axis2.databinding.utils; + +import org.apache.axiom.om.*; +import org.apache.axis2.engine.DefaultObjectSupplier; +import org.apache.axis2.engine.ObjectSupplier; + +import junit.framework.TestCase; + +import javax.activation.DataHandler; +import javax.xml.namespace.QName; + +import java.util.List; + + +public class BeanUtilTest extends TestCase { + + public class ComplexType { + private String child; + + public void setChild(String child) { + this.child = child; + } + + public String getChild() { + return child; + } + } + + private ObjectSupplier objectSupplier; + + private OMFactory omFactory; + private OMElement omElement; + private OMNamespace xsiNamespace; + + @Override + protected void setUp() throws Exception { + objectSupplier = new DefaultObjectSupplier(); + + omFactory = OMAbstractFactory.getOMFactory(); + xsiNamespace = omFactory.createOMNamespace(Constants.XSI_NAMESPACE, "xsi"); + omElement = omFactory.createOMElement(new QName("hello")); + } + + public void testProcessObjectAsSimpleType() throws Exception { + omElement.setText("World"); + + Object result = BeanUtil.processObject(omElement, String.class, new MultirefHelper(omElement), false, objectSupplier); + assertTrue(result instanceof String); + assertEquals("World", result); + } + + public void testProcessObjectAsOmElement() throws Exception { + omElement.setText("World"); + + Object result = BeanUtil.processObject(omElement, OMElement.class, new MultirefHelper(omElement), false, objectSupplier); + assertTrue(result instanceof OMElement); + assertEquals(omElement, result); + } + + public void testProcessObjectAsNull() throws Exception { + OMAttribute nilAttribute = omFactory.createOMAttribute("nil", xsiNamespace, "true"); + omElement.addAttribute(nilAttribute); + + Object result = BeanUtil.processObject(omElement, String.class, new MultirefHelper(omElement), false, objectSupplier); + assertNull(result); + } + + public void testProcessObjectAsByteArray() throws Exception { + omElement.setText("Word"); + + Object result = BeanUtil.processObject(omElement, byte.class, new MultirefHelper(omElement), true, objectSupplier); + assertTrue(result instanceof byte[]); + assertEquals(3, ((byte[]) result).length); + } + + public void testProcessObjectAsList() throws Exception { + OMElement child = omFactory.createOMElement(new QName("child"), omElement); + child.setText("World"); + + Object result = BeanUtil.processObject(omElement, List.class, new MultirefHelper(omElement), false, objectSupplier); + assertTrue(result instanceof List); + assertEquals(1, ((List) result).size()); + } + + public void testProcessObjectAsDataHandler() throws Exception { + omElement.setText("Word"); + + Object result = BeanUtil.processObject(omElement, DataHandler.class, new MultirefHelper(omElement), false, objectSupplier); + assertTrue(result instanceof DataHandler); + } + + public void testProcessObjectAsComplexType() throws Exception { + OMElement child = omFactory.createOMElement(new QName("child"), omElement); + child.setText("World"); + + Object result = BeanUtil.processObject(omElement, ComplexType.class, new MultirefHelper(omElement), false, objectSupplier); + assertTrue(result instanceof ComplexType); + assertEquals("World", ((ComplexType) result).getChild()); + } + + public void testProcessObjectAsObject() throws Exception { + omElement.declareNamespace(omFactory.createOMNamespace(Constants.XSD_NAMESPACE, "xs")); + + omElement.setText("World"); + omElement.addAttribute(createTypeAttribute("xs:string")); + + Object result = BeanUtil.processObject(omElement, Object.class, new MultirefHelper(omElement), false, objectSupplier); + assertTrue(result instanceof OMText); + assertEquals("World", ((OMText) result).getText()); + } + + private OMAttribute createTypeAttribute(String value) { + return omFactory.createOMAttribute("type", xsiNamespace, value); + } +} Property changes on: test/org/apache/axis2/databinding/utils/BeanUtilTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Index: test/org/apache/axis2/databinding/utils/ConverterUtilTest.java =================================================================== --- test/org/apache/axis2/databinding/utils/ConverterUtilTest.java (revision 783297) +++ test/org/apache/axis2/databinding/utils/ConverterUtilTest.java (working copy) @@ -157,11 +157,15 @@ System.out.println("calendar ==> " + simpleDateFormat.format(date)); System.out.println("calendar ==> " + ConverterUtil.convertToString(date)); + } + + public void testConvertCalendarToString() { + TimeZone timeZone = TimeZone.getTimeZone("Australia/Perth"); Calendar c = Calendar.getInstance(timeZone); c.clear(); c.set(2008, Calendar.JANUARY, 1); - TestCase.assertTrue(ConverterUtil.convertToString(c).endsWith("+08:00")); + TestCase.assertTrue(ConverterUtil.convertToString(c).endsWith("+09:00")); } Index: test/org/apache/axis2/databinding/typemapping/SimpleTypeMapperTest.java =================================================================== --- test/org/apache/axis2/databinding/typemapping/SimpleTypeMapperTest.java (revision 0) +++ test/org/apache/axis2/databinding/typemapping/SimpleTypeMapperTest.java (revision 0) @@ -0,0 +1,39 @@ +/* + * 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.axis2.databinding.typemapping; + +import junit.framework.TestCase; + +import javax.activation.DataHandler; + +import java.awt.datatransfer.Transferable; + +public class SimpleTypeMapperTest extends TestCase { + + public void testDataHandlerTypes() { + assertTrue(SimpleTypeMapper.isDataHandler(DataHandler.class)); + assertTrue(SimpleTypeMapper.isDataHandler(Transferable.class)); + } + + public void testNonDataHandlerTypes() { + assertFalse(SimpleTypeMapper.isDataHandler(Object.class)); + } + +} Property changes on: test/org/apache/axis2/databinding/typemapping/SimpleTypeMapperTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Index: src/org/apache/axis2/databinding/typemapping/SimpleTypeMapper.java =================================================================== --- src/org/apache/axis2/databinding/typemapping/SimpleTypeMapper.java (revision 783297) +++ src/org/apache/axis2/databinding/typemapping/SimpleTypeMapper.java (working copy) @@ -204,7 +204,7 @@ } public static boolean isDataHandler(Class obj) { - return obj.isAssignableFrom(DataHandler.class); + return obj.isAssignableFrom(DataHandler.class) && !obj.equals(Object.class); } public static boolean isHashSet(Class obj) { Index: pom.xml =================================================================== --- pom.xml (revision 783297) +++ pom.xml (working copy) @@ -105,7 +105,6 @@ <skip>false</skip> <excludes> <exclude>**/*Abstract*.java</exclude> - <exclude>**/*Util*.java</exclude> <exclude>**/*PhaseResolvingTest.java</exclude> </excludes> <includes>
