Author: dkulp Date: Fri Jun 29 14:53:54 2012 New Revision: 1355421 URL: http://svn.apache.org/viewvc?rev=1355421&view=rev Log: Merged revisions 1355400 via git cherry-pick from https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes
........ r1355400 | ay | 2012-06-29 10:15:53 -0400 (Fri, 29 Jun 2012) | 9 lines Merged revisions 1355396 via svn merge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1355396 | ay | 2012-06-29 16:09:21 +0200 (Fri, 29 Jun 2012) | 1 line [CXF-4401] XMLStreamDataReader not closing the original input stream ........ ........ Added: cxf/branches/2.5.x-fixes/rt/core/src/test/java/org/apache/cxf/databinding/ cxf/branches/2.5.x-fixes/rt/core/src/test/java/org/apache/cxf/databinding/source/ cxf/branches/2.5.x-fixes/rt/core/src/test/java/org/apache/cxf/databinding/source/XMLStreamDataReaderTest.java (with props) Modified: cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java Modified: cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java?rev=1355421&r1=1355420&r2=1355421&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java (original) +++ cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/XMLStreamDataReader.java Fri Jun 29 14:53:54 2012 @@ -183,6 +183,19 @@ public class XMLStreamDataReader impleme } return b; } + + public void close() throws XMLStreamException { + try { + super.close(); + } catch (XMLStreamException e) { + //ignore + } + try { + ins.close(); + } catch (IOException e) { + //ignore + } + } }; } return input; Added: cxf/branches/2.5.x-fixes/rt/core/src/test/java/org/apache/cxf/databinding/source/XMLStreamDataReaderTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/core/src/test/java/org/apache/cxf/databinding/source/XMLStreamDataReaderTest.java?rev=1355421&view=auto ============================================================================== --- cxf/branches/2.5.x-fixes/rt/core/src/test/java/org/apache/cxf/databinding/source/XMLStreamDataReaderTest.java (added) +++ cxf/branches/2.5.x-fixes/rt/core/src/test/java/org/apache/cxf/databinding/source/XMLStreamDataReaderTest.java Fri Jun 29 14:53:54 2012 @@ -0,0 +1,83 @@ +/** + * 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.databinding.source; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; + +import org.apache.cxf.message.Message; +import org.apache.cxf.message.MessageImpl; +import org.apache.cxf.staxutils.StaxUtils; + +import org.junit.Assert; +import org.junit.Test; + +/** + * + */ +public class XMLStreamDataReaderTest extends Assert { + private static final byte[] DUMMY_DATA = "<ns:dummy xmlns:ns='http://www.apache.org/cxf'/>".getBytes(); + + @Test + public void testCloseOriginalInputStream() throws Exception { + XMLStreamDataReader reader = new XMLStreamDataReader(); + Message msg = new MessageImpl(); + TestInputStream in1 = new TestInputStream(DUMMY_DATA); + TestInputStream in2 = new TestInputStream(DUMMY_DATA); + + msg.setContent(InputStream.class, in1); + + reader.setProperty(Message.class.getName(), msg); + + Object obj = reader.read(new QName("http://www.apache.org/cxf", "dummy"), + StaxUtils.createXMLStreamReader(in2), XMLStreamReader.class); + + assertTrue(obj instanceof XMLStreamReader); + + assertFalse(in1.isClosed()); + assertFalse(in2.isClosed()); + ((XMLStreamReader)obj).close(); + + assertTrue(in2.isClosed()); + assertTrue(in1.isClosed()); + } + + private static class TestInputStream extends ByteArrayInputStream { + private boolean closed; + + public TestInputStream(byte[] buf) { + super(buf); + } + + @Override + public void close() throws IOException { + closed = true; + super.close(); + } + + public boolean isClosed() { + return closed; + } + } +} Propchange: cxf/branches/2.5.x-fixes/rt/core/src/test/java/org/apache/cxf/databinding/source/XMLStreamDataReaderTest.java ------------------------------------------------------------------------------ svn:executable = *
