axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From si...@60hertz.com
Subject file size content length java patch to MimeUtils.java
Date Fri, 30 Jan 2009 10:36:42 GMT

Hi, 

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 attached 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 attached 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
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 });
 
		...
}

rgds,

Simon

Mime
View raw message