You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ve...@apache.org on 2015/06/07 20:02:53 UTC
svn commit: r1684053 - in /axis/axis1/java/trunk: ./ axis-rt-core/
axis-rt-core/src/main/java/org/apache/axis/attachments/
axis-rt-core/src/test/java/org/ axis-rt-core/src/test/java/org/apache/
axis-rt-core/src/test/java/org/apache/axis/ axis-rt-core/s...
Author: veithen
Date: Sun Jun 7 18:02:52 2015
New Revision: 1684053
URL: http://svn.apache.org/r1684053
Log:
AXIS-2910: Ensure that DimeBodyPart closes all input streams it requests from DataSource instances.
Added:
axis/axis1/java/trunk/axis-rt-core/src/test/java/org/
axis/axis1/java/trunk/axis-rt-core/src/test/java/org/apache/
axis/axis1/java/trunk/axis-rt-core/src/test/java/org/apache/axis/
axis/axis1/java/trunk/axis-rt-core/src/test/java/org/apache/axis/attachments/
axis/axis1/java/trunk/axis-rt-core/src/test/java/org/apache/axis/attachments/TestDimeBodyPart.java (with props)
Modified:
axis/axis1/java/trunk/axis-rt-core/pom.xml
axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/attachments/DimeBodyPart.java
axis/axis1/java/trunk/pom.xml
axis/axis1/java/trunk/samples/mtomstub-sample/pom.xml
Modified: axis/axis1/java/trunk/axis-rt-core/pom.xml
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-rt-core/pom.xml?rev=1684053&r1=1684052&r2=1684053&view=diff
==============================================================================
--- axis/axis1/java/trunk/axis-rt-core/pom.xml (original)
+++ axis/axis1/java/trunk/axis-rt-core/pom.xml Sun Jun 7 18:02:52 2015
@@ -92,6 +92,11 @@
<version>2.0.6</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.ws.commons.axiom</groupId>
+ <artifactId>testutils</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<resources>
Modified: axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/attachments/DimeBodyPart.java
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/attachments/DimeBodyPart.java?rev=1684053&r1=1684052&r2=1684053&view=diff
==============================================================================
--- axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/attachments/DimeBodyPart.java (original)
+++ axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/attachments/DimeBodyPart.java Sun Jun 7 18:02:52 2015
@@ -322,48 +322,57 @@ public class DimeBodyPart {
BufferedInputStream in = new BufferedInputStream(dh.getInputStream());
- final int myChunkSize = dh.getChunkSize();
-
- byte[] buffer1 = new byte[myChunkSize];
- byte[] buffer2 = new byte[myChunkSize];
-
- int bytesRead1 = 0 , bytesRead2 = 0;
-
- bytesRead1 = in.read(buffer1);
-
- if(bytesRead1 < 0) {
- sendHeader(os, position, 0, ONLY_CHUNK);
- os.write(pad, 0, dimePadding(0));
- return;
- }
- byte chunkbyte = CHUNK;
- do {
- bytesRead2 = in.read(buffer2);
+ try {
+ final int myChunkSize = dh.getChunkSize();
+
+ byte[] buffer1 = new byte[myChunkSize];
+ byte[] buffer2 = new byte[myChunkSize];
- if(bytesRead2 < 0) {
- //last record...do not set the chunk bit.
- //buffer1 contains the last chunked record!!
-
- //Need to distinguish if this is the first
- //chunk to ensure the TYPE and ID are sent
- if ( chunkbyte == CHUNK ){
- chunkbyte = ONLY_CHUNK;
- } else {
- chunkbyte = LAST_CHUNK;
+ int bytesRead1 = 0 , bytesRead2 = 0;
+
+ bytesRead1 = in.read(buffer1);
+
+ if(bytesRead1 < 0) {
+ sendHeader(os, position, 0, ONLY_CHUNK);
+ os.write(pad, 0, dimePadding(0));
+ return;
+ }
+ byte chunkbyte = CHUNK;
+ do {
+ bytesRead2 = in.read(buffer2);
+
+ if(bytesRead2 < 0) {
+ //last record...do not set the chunk bit.
+ //buffer1 contains the last chunked record!!
+
+ //Need to distinguish if this is the first
+ //chunk to ensure the TYPE and ID are sent
+ if ( chunkbyte == CHUNK ){
+ chunkbyte = ONLY_CHUNK;
+ } else {
+ chunkbyte = LAST_CHUNK;
+ }
+ sendChunk(os, position, buffer1, 0, bytesRead1, chunkbyte);
+ break;
}
+
sendChunk(os, position, buffer1, 0, bytesRead1, chunkbyte);
- break;
+ //set chunk byte to next chunk flag to avoid
+ //sending TYPE and ID on subsequent chunks
+ chunkbyte = CHUNK_NEXT;
+ //now that we have written out buffer1, copy buffer2 into to buffer1
+ System.arraycopy(buffer2,0,buffer1,0,myChunkSize);
+ bytesRead1 = bytesRead2;
+
+ }while(bytesRead2 > 0);
+ } finally {
+ try {
+ in.close();
}
-
- sendChunk(os, position, buffer1, 0, bytesRead1, chunkbyte);
- //set chunk byte to next chunk flag to avoid
- //sending TYPE and ID on subsequent chunks
- chunkbyte = CHUNK_NEXT;
- //now that we have written out buffer1, copy buffer2 into to buffer1
- System.arraycopy(buffer2,0,buffer1,0,myChunkSize);
- bytesRead1 = bytesRead2;
-
- }while(bytesRead2 > 0);
+ catch (IOException e) {
+ // ignore
+ }
+ }
}
protected void sendChunk(java.io.OutputStream os,
Added: axis/axis1/java/trunk/axis-rt-core/src/test/java/org/apache/axis/attachments/TestDimeBodyPart.java
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-rt-core/src/test/java/org/apache/axis/attachments/TestDimeBodyPart.java?rev=1684053&view=auto
==============================================================================
--- axis/axis1/java/trunk/axis-rt-core/src/test/java/org/apache/axis/attachments/TestDimeBodyPart.java (added)
+++ axis/axis1/java/trunk/axis-rt-core/src/test/java/org/apache/axis/attachments/TestDimeBodyPart.java Sun Jun 7 18:02:52 2015
@@ -0,0 +1,34 @@
+/*
+ * 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.axis.attachments;
+
+import junit.framework.TestCase;
+
+import org.apache.axiom.testutils.activation.InstrumentedDataSource;
+import org.apache.axiom.testutils.activation.RandomDataSource;
+import org.apache.commons.io.output.NullOutputStream;
+
+public class TestDimeBodyPart extends TestCase {
+ public void testWriteToWithDynamicContentDataHandlerClosesInputStreams() throws Exception {
+ InstrumentedDataSource ds = new InstrumentedDataSource(new RandomDataSource(1000));
+ DimeBodyPart bp = new DimeBodyPart(new DynamicContentDataHandler(ds), "1234");
+ bp.write(new NullOutputStream(), (byte)0);
+ assertEquals(0, ds.getOpenStreamCount());
+ }
+}
Propchange: axis/axis1/java/trunk/axis-rt-core/src/test/java/org/apache/axis/attachments/TestDimeBodyPart.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: axis/axis1/java/trunk/pom.xml
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/pom.xml?rev=1684053&r1=1684052&r2=1684053&view=diff
==============================================================================
--- axis/axis1/java/trunk/pom.xml (original)
+++ axis/axis1/java/trunk/pom.xml Sun Jun 7 18:02:52 2015
@@ -126,8 +126,8 @@
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
- <artifactId>axiom-testutils</artifactId>
- <version>1.2.13</version>
+ <artifactId>testutils</artifactId>
+ <version>1.2.15-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
Modified: axis/axis1/java/trunk/samples/mtomstub-sample/pom.xml
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/samples/mtomstub-sample/pom.xml?rev=1684053&r1=1684052&r2=1684053&view=diff
==============================================================================
--- axis/axis1/java/trunk/samples/mtomstub-sample/pom.xml (original)
+++ axis/axis1/java/trunk/samples/mtomstub-sample/pom.xml Sun Jun 7 18:02:52 2015
@@ -56,7 +56,7 @@
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
- <artifactId>axiom-testutils</artifactId>
+ <artifactId>testutils</artifactId>
<scope>test</scope>
</dependency>
</dependencies>