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 Archit Shah <as...@redhat.com> on 2005/07/15 19:24:27 UTC
use of DataHandler in JavaUtils.convert
The convert method of org.apache.axis.utils.JavaUtils relies on the
getContent method of javax.activation.DataHandler to get an InputStream
for the data, twice doing the following:
in = (InputStream)handler.getContent();
instead of:
in = handler.getInputStream();
Calling getContent and casting to InputStream is not guaranteed to work.
The Javadoc for the getContent method (see [1]) specifies "If no
DataContentHandler can be found for the the type of this data, the
DataHandler returns an InputStream for the data." Therefore, the cast
can fail if a DataContentHandler is installed. I ran into this situation
using the GNU javamail implementation [2], which has a
DataContentHandler for the MIME type application/octet-stream. This
DataContentHandler causes, for certain data, the getContent method to
return a byte array instead of an InputStream. In particular, I
encountered a ClassCastException in the JUnit tests
test.wsdl.interop4.groupG.mime.rpc.MimeRPCInteropTestCase#test2MimeRPCSoapPortEchoAttachments
and
test.wsdl.interop4.groupG.dime.rpc.DimeRPCInteropTestCase#test2DimeRPCSoapPortEchoAttachments.
Casting the return value of getContent is also done in another context.
JavaUtils and SourceDataHandlerDeserializer both do:
StreamSource ss = new StreamSource(new StringReader(
(String) dh.getContent()));
when the following would suffice:
StreamSource ss = new StreamSource(dh.getInputStream());
Replacing the calls to getContent with calls to getInputStream in these
four locations (3 in JavaUtils and 1 in SourceDataHandlerDeserializer)
will make Axis more robust to changes in the underlying javamail
implementations. A patch is attached. The patch produces no regressions
in the Axis tests when run with the Sun javamail implementation and
fixes two test failures encountered when using Axis with the GNU
javamail implementation
-- Archit Shah
Links
1. http://java.sun.com/j2ee/1.4/docs/api/javax/activation/DataHandler.html
2. http://www.gnu.org/software/classpathx/javamail/