You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Robert Herold <he...@cotagesoft.com> on 2002/05/21 02:22:07 UTC

beta2 attachments bug?

In Beta2, the attachment handling reads the attachment input stream twice!
While this works OK for files, it will not work for data sources that are
true streams.  It also seems inefficient.

I found this out because I want to send some data as an attachment.  I tried
out the attachments sample, and it worked.  Then I replaced the
FileDataSource with my own DataSource, which always handed back the same
InputStream in getInputStream().  Peeking at the traffic with TCPMon, no
data was transmitted in the attachment part (because the stream was
exhausted by being read already).

Whittling it down to a simple String datasource and changing
getInputStream() to always hand back a new stream (and the debug message)
revealed what was going on:

  private class XStringDataSource implements DataSource {
      private String str = null;
	// private InputStream is = null;

      public XStringDataSource(String s) {
	  this.str = s;
        //this.is = (InputStream) new ByteArrayInputStream(str.getBytes());
      }

      public String getContentType() {
        return "application/octet-stream";
      }

      public InputStream getInputStream() {
        System.out.println("in getInputStream");
        // return is;
        return (InputStream) new ByteArrayInputStream(str.getBytes());
      }

      public String getName() {
        return "My String InputStream Data Source";
      }

      public OutputStream getOutputStream() throws IOException {
        throw new IOException("OutputStream not supported");
      }
    }

and in the code that sends the attachments:

  DataHandler dhSource = new DataHandler( new XStringDataSource( "Rufus T.
Firefly" ));

Is it the correct behavior for Axis to ask for and read the input stream
twice?

-- bob

----------
Robert Herold
Cotagesoft, Inc.