You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2005/03/15 22:42:02 UTC
cvs commit: ws-axis/java/src/org/apache/axis/attachments DynamicContentDataHandler.java DimeBodyPart.java
dims 2005/03/15 13:42:02
Modified: java/src/org/apache/axis/attachments DimeBodyPart.java
Added: java/src/org/apache/axis/attachments
DynamicContentDataHandler.java
Log:
Fix for AXIS-1872 - Allow for streaming of DIME attachments
from Marc Dumontier
URL: http://issues.apache.org/jira/browse/AXIS-1872
Example in bug report:
DynamicContentDataHandler datahandler = null;
URL url = new URL("http",host,port,QUERY_STRING);
URLDataSource dataSource = new URLDataSource(url);
datahandler = new DynamicContentDataHandler(dataSource);
datahandler.setChunkSize(10 * 1024 * 1024);
Revision Changes Path
1.25 +59 -7 ws-axis/java/src/org/apache/axis/attachments/DimeBodyPart.java
Index: DimeBodyPart.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/attachments/DimeBodyPart.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- DimeBodyPart.java 16 Mar 2004 22:55:02 -0000 1.24
+++ DimeBodyPart.java 15 Mar 2005 21:42:02 -0000 1.25
@@ -27,8 +27,9 @@
import javax.activation.DataHandler;
import javax.activation.DataSource;
-import java.util.StringTokenizer;
+import java.io.BufferedInputStream;
import java.io.IOException;
+import java.util.StringTokenizer;
/**
@@ -220,10 +221,12 @@
Messages.getMessage("attach.dimeMaxChunkSize0", "" + maxchunk));
if (maxchunk > MAX_DWORD) throw new IllegalArgumentException(
Messages.getMessage("attach.dimeMaxChunkSize1", "" + maxchunk));
- if (data instanceof byte[]) send(os, position, (byte[]) data,
- maxchunk);
- if (data instanceof DataHandler) send(os, position,
- (DataHandler) data, maxchunk);
+ if (data instanceof byte[])
+ send(os, position, (byte[]) data, maxchunk);
+ else if (data instanceof DynamicContentDataHandler)
+ send(os, position, (DynamicContentDataHandler) data, maxchunk);
+ else if (data instanceof DataHandler)
+ send(os, position, (DataHandler) data, maxchunk);
}
/**
@@ -265,7 +268,6 @@
void send(java.io.OutputStream os, byte position, DataHandler dh,
final long maxchunk) throws java.io.IOException {
-// START FIX: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=17001
java.io.InputStream in = null;
try {
byte chunknext = 0;
@@ -298,7 +300,57 @@
}
}
}
-// END FIX: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=17001
+ }
+
+ /**
+ * Special case for dynamically generated content.
+ * maxchunk is currently ignored since the default is 2GB.
+ * The chunk size is retrieved from the DynamicContentDataHandler
+ *
+ * @param os
+ * @param position
+ * @param dh
+ * @param maxchunk
+ * @throws java.io.IOException
+ */
+ void send(java.io.OutputStream os, byte position, DynamicContentDataHandler dh,
+ final long maxchunk)
+ throws java.io.IOException {
+
+ 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;
+ byte chunknext = 0;
+
+ bytesRead1 = in.read(buffer1);
+
+ if(bytesRead1 < 0) {
+ //no data all.should we be sending an empty dime record?
+ throw new IOException("No data found to send in DIME message");
+ }
+
+ do {
+ bytesRead2 = in.read(buffer2);
+
+ if(bytesRead2 < 0) {
+ //last record...do not set the chunk bit.
+ //buffer1 contains the last chunked record!
+ sendChunk(os, position, buffer1, 0, bytesRead1, (byte)0);
+ break;
+ }
+
+ sendChunk(os, position, buffer1, 0, bytesRead1, (byte)CHUNK);
+
+ //now that we have written out buffer1, copy buffer2 into to buffer1
+ System.arraycopy(buffer2,0,buffer1,0,myChunkSize);
+ bytesRead1 = bytesRead2;
+
+ }while(bytesRead2 > 0);
}
protected void sendChunk(java.io.OutputStream os,
1.1 ws-axis/java/src/org/apache/axis/attachments/DynamicContentDataHandler.java
Index: DynamicContentDataHandler.java
===================================================================
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed 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 java.net.URL;
import javax.activation.DataHandler;
import javax.activation.DataSource;
/**
* To be used with writing out DIME Attachments.
*
* AXIS will use DIME record chunking.
*
* @author Marc Dumontier (mrdumont@blueprint.org)
*
*/
public class DynamicContentDataHandler extends DataHandler {
int chunkSize = 1*1024*1024;
/**
* @param arg0
*/
public DynamicContentDataHandler(DataSource arg0) {
super(arg0);
}
/**
* @param arg0
* @param arg1
*/
public DynamicContentDataHandler(Object arg0, String arg1) {
super(arg0, arg1);
}
/**
* @param arg0
*/
public DynamicContentDataHandler(URL arg0) {
super(arg0);
}
/**
* Get the DIME record chunk size
* @return The value
*/
public int getChunkSize() {
return chunkSize;
}
/**
* Set the DIME record chunk size
* @param chunkSize The value.
*/
public void setChunkSize(int chunkSize) {
this.chunkSize = chunkSize;
}
}