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 "Andreas Veithen (JIRA)" <ax...@ws.apache.org> on 2009/02/02 09:45:59 UTC

[jira] Moved: (AXIS-2773) file size content length java patch to MimeUtils.java

     [ https://issues.apache.org/jira/browse/AXIS-2773?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andreas Veithen moved AXIS2-4227 to AXIS-2773:
----------------------------------------------

          Component/s:     (was: client-api)
                       Basic Architecture
    Affects Version/s:     (was: 1.4)
                       1.4
                  Key: AXIS-2773  (was: AXIS2-4227)
              Project: Axis  (was: Axis 2.0 (Axis2))

> file size content length java patch to MimeUtils.java
> -----------------------------------------------------
>
>                 Key: AXIS-2773
>                 URL: https://issues.apache.org/jira/browse/AXIS-2773
>             Project: Axis
>          Issue Type: Improvement
>          Components: Basic Architecture
>    Affects Versions: 1.4
>            Reporter: Simon Massey
>            Priority: Minor
>
> We are decoding streams of XML using Java to extract the documents and
> are then using Axis to send the extracted documents onwards to a 3rd
> party DotNet system. We found that Axis was trying to look for the file
> data on disk to determine the content length of the document data. This
> was failing as the data is not on disk. We did not want to flush the
> data to a temporary disk file. We have patched the Axis code to resolve
> this issue. The included below our patch to MimeUtils.java checks whether the
> DataHandler implements a new interface ContentLength. If it does it uses
> the method on that interface to determine the size of the content else
> it uses the existing logic. I have also included below our client class
> VirtualFileDataSource that extends FileDataSource and implements
> ContentLength that we pass to Axis. 
> Here is a snippet of code that shows how we send data via axis using
> the patched code: 
> public String putDocument(final String uniqueName, final Integer
> version,
> 			final String contentType, final InputStream dataStream, int length)
> 			throws RemoteException {
> 		Service service = new Service();
> 		Call call = null;
> 		try {
> 			call = (Call) service.createCall();
> 		} catch (ServiceException e) {
> 			logger.error("Could not create axis.client.Service.", e);
> 		}
> 		call.setTargetEndpointAddress(endPointUrl);
> 		call
> 				.setOperationName(new QName(
> 						"http://x.y.co.uk/SomeIntegration/DocumentUpload",
> 						"PutDoc"));
> 		call.addParameter("DocumentId", Constants.XSD_STRING,
> 				javax.xml.rpc.ParameterMode.IN);
> 		call.addParameter("DocumentReference", Constants.XSD_STRING,
> 				javax.xml.rpc.ParameterMode.IN);
> 		call.addParameter("DocumentVersion", Constants.XSD_STRING,
> 				javax.xml.rpc.ParameterMode.IN);
> 		call.setReturnType(org.apache.axis.Constants.XSD_STRING);
> 		// Create the virtual file data source for the in-memory InputStream 
> 		DataHandler dhSource = new DataHandler(new VirtualFileDataSource(
> 				uniqueName, contentType, dataStream, length));
> 		QName qnameAttachment = new QName("urn:EchoAttachmentsService",
> 				"DataHandler");
> 		call.registerTypeMapping(
> 				dhSource.getClass(), // Add serializer for attachment.
> 				qnameAttachment, JAFDataHandlerSerializerFactory.class,
> 				JAFDataHandlerDeserializerFactory.class);
> 		call.addParameter("source", qnameAttachment, ParameterMode.IN);
> 		String ret = (String) call.invoke(new Object[] { null, uniqueName,
> 				version, dhSource });
>  
> 		...
> }
> >>> VirtualFileDataSource.java <<<
> import java.io.File;
> import java.io.IOException;
> import java.io.InputStream;
> import java.io.OutputStream;
> import javax.activation.FileDataSource;
> import javax.activation.FileTypeMap;
> import org.apache.axis.attachments.ContentLength;
> /**
>  * This class defines a read-only FileDataDataSource that can be used to 
>  * wrap in-memory document data that is not on disk that we would like to 
>  * post via Apache Axis. The class implements org.apache.axis.attachments.ContentLength
>  * which Apache can use to determine the length of the docuement data without
>  * attempting to look for the data on disk. 
>  *   
>  * @author smasse01
>  */
> public class VirtualFileDataSource extends FileDataSource implements ContentLength 
> {
> 	private String name = null;
> 	private String contentType = null;
> 	private InputStream inputStream = null;
> 	private int length = -1;
> 	
> 	public VirtualFileDataSource(String name, String contentType, InputStream inputStream, int length ) {
> 		super("");
> 		this.name = name;
> 		this.contentType = contentType;
> 		this.inputStream = inputStream;
> 		this.length = length;
> 	}
> 	@Override
> 	public String getContentType() {
> 		return this.contentType;
> 	}
> 	@Override
> 	public File getFile() {
> 		throw new AssertionError("operation not supported");
> 	}
> 	@Override
> 	public InputStream getInputStream() throws IOException {
> 		return this.inputStream;
> 	}
> 	@Override
> 	public String getName() {
> 		return this.name;
> 	}
> 	@Override
> 	public OutputStream getOutputStream() throws IOException {
> 		throw new AssertionError("operation not supported");
> 	}
> 	@Override
> 	public void setFileTypeMap(FileTypeMap map) {
> 		throw new AssertionError("operation not supported");
> 	}
> 	public int getContentLength() {
> 		return this.length;
> 	}
> }
> >>> ContentLength.java <<<
> package org.apache.axis.attachments;
> public interface ContentLength {
> 	public int getContentLength();
> }
> >>> MimeUtils.java.patch <<<
> Index: src/org/apache/axis/attachments/MimeUtils.java
> ===================================================================
> --- src/org/apache/axis/attachments/MimeUtils.java	(revision 738865)
> +++ src/org/apache/axis/attachments/MimeUtils.java	(working copy)
> @@ -93,9 +93,12 @@
>              javax.activation.DataHandler dh = bp.getDataHandler();
>              javax.activation.DataSource ds = dh.getDataSource();
>  
> +            if( ds instanceof ContentLength ){
> +            	dataSize = ((ContentLength)ds).getContentLength();
> +            }
>              // Do files our selfs since this is costly to read in. Ask the file system.
>              // This is 90% of the use of attachments.
> -            if (ds instanceof javax.activation.FileDataSource) {
> +            else if (ds instanceof javax.activation.FileDataSource) {
>                  javax.activation.FileDataSource fdh =
>                          (javax.activation.FileDataSource) ds;
>                  java.io.File df = fdh.getFile();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.