Return-Path: Delivered-To: apmail-ws-axis-user-archive@www.apache.org Received: (qmail 57524 invoked from network); 9 Jul 2007 17:58:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 9 Jul 2007 17:58:15 -0000 Received: (qmail 57916 invoked by uid 500); 9 Jul 2007 17:58:10 -0000 Delivered-To: apmail-ws-axis-user-archive@ws.apache.org Received: (qmail 57193 invoked by uid 500); 9 Jul 2007 17:58:06 -0000 Mailing-List: contact axis-user-help@ws.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-user@ws.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-user@ws.apache.org Received: (qmail 57182 invoked by uid 99); 9 Jul 2007 17:58:06 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Jul 2007 10:58:06 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [216.23.136.231] (HELO mailhost.van.redback.com) (216.23.136.231) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Jul 2007 10:58:03 -0700 Received: from [127.0.0.1] (dhcp-36-235.van.redback.com [172.19.36.235]) by mailhost.van.redback.com (Postfix) with ESMTP id A74F383319 for ; Mon, 9 Jul 2007 10:57:41 -0700 (PDT) Message-ID: <46927714.4010804@redback.com> Date: Mon, 09 Jul 2007 10:57:40 -0700 From: Alex Dickinson User-Agent: Thunderbird 2.0.0.4 (Windows/20070604) MIME-Version: 1.0 To: axis-user@ws.apache.org Subject: Re: Streaming Soap with Attachments References: <0E17FD072E9875498207C91A391661A937F030@SRV-EXCHBE01.thecamelsnose.com> <19e0530f0707041135n337772c0w5f75125ba1978868@mail.gmail.com> <468BFDCE.3090107@redback.com> <0E17FD072E9875498207C91A391661A937F049@SRV-EXCHBE01.thecamelsnose.com> <468D1689.8090600@redback.com> <0E17FD072E9875498207C91A391661A937F081@SRV-EXCHBE01.thecamelsnose.com> In-Reply-To: <0E17FD072E9875498207C91A391661A937F081@SRV-EXCHBE01.thecamelsnose.com> X-Enigmail-Version: 0.95.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org I am quite surprised that your DataSource in conjunction with a custom DataHandler didn't work. The code that you provided for the DataSource doesn't use a PipedStream, so I don't see where this is introduced. I have a DataSource that uses an NIO Pipe to feed data to a DataHandler, and it works without a problem: DataHandler dh = new MyDataHandler(new MyDataSource()); MessageContext inMsgCtx = MessageContext.getCurrentMessageContext(); OperationContext opCtx = inMsgCtx.getOperationContext(); MessageContext inMsgCtx = opCtx.getMessageContext( WSDLConstants.MESSAGE_LABEL_OUT_VALUE); outCtx.addAttachment(dh); class MyDataHandler extends DataHandler { public EventDataHandler(DataSource ds) { super(ds); } public void writeTo(OutputStream os) throws IOException { InputStream is = null; byte data[] = new byte[8 * 1024]; int bytes_read; is = dataSource.getInputStream(); try { while ((bytes_read = is.read(data)) > 0) { os.write(data, 0, bytes_read); os.flush(); } } finally { is.close(); is = null; } } } } class MyDataSource implements DataSource { private final Pipe _pipe; public MyDataSource(Pipe pipe) { _pipe = pipe; } /** * @see javax.activation.DataSource#getInputStream() */ public InputStream getInputStream() { return Channels.newInputStream(_pipe.source()); } public OutputStream getOutputStream() throws IOException { return Channels.newOutputStream(_pipe.sink()); } /** * @see javax.activation.DataSource#getContentType() */ public String getContentType() { return "application/octect-stream"; } /** * @see javax.activation.DataSource#getName() */ public String getName() { return "blah...."; } } Peter Makoi wrote: > Hi Alex > Thanks again for your efforts > I have tried to the override the writeTo() method as you have advised > and it didn't work, farther more I have tried to investigate whether if > the problem might be with getInputStream() in DataHandler calss and it > turned out to be using a PipedInput/OutputStream that has a circular > buffer into which incoming data is placed. I wonder if this buffering > might be the cause of the delay! > > > > -----Original Message----- > From: Alex Dickinson [mailto:alexd@redback.com] > Sent: Thursday, July 05, 2007 6:04 PM > To: axis-user@ws.apache.org > Subject: Re: Streaming Soap with Attachments > > Override the writeTo of DataHandler to overcome the caching used by the > BufferedOutputStreams (Note that this is the same code as the original > implementation of DataHandler.writeTo, but it will flush after each > write): > > public void writeTo(OutputStream os) throws IOException > { > // for the DataSource case > if (dataSource != null) > { > InputStream is = null; > byte data[] = new byte[8 * 1024]; > int bytes_read; > > is = dataSource.getInputStream(); > > try > { > while ((bytes_read = is.read(data)) > 0) > { > os.write(data, 0, bytes_read); > os.flush(); > } > } > finally > { > is.close(); > is = null; > } > } > else > { // for the Object case > DataContentHandler dch = getDataContentHandler(); > dch.writeTo(object, objectMimeType, os); > } > } > > > Peter Makoi wrote: >> Thaks a lot Alex >> Is it possible that you provide an example code because I have already >> tried to write a custom DataSource class and it is not working as I >> expected >> below is the code >> >> public javax.activation.DataHandler[] returnStreamingByteArray(final > int >> timeout) { >> DataHandler ret = new DataHandler(new DataSource() { >> private long start = System.currentTimeMillis(); >> private long end = start + timeout; >> >> public String getContentType() { >> return "text/plain"; >> } >> >> public InputStream getInputStream() throws IOException { >> return new InputStream() { >> public int read() throws IOException { >> try { >> Thread.sleep(10); >> } catch (InterruptedException e) { >> //ignore this exception >> } >> if (System.currentTimeMillis() > end) { >> return -1; >> } else { >> return (int)(Math.random() * 256); >> } >> } >> }; >> } >> >> public String getName() { >> return ""; >> } >> >> public OutputStream getOutputStream() throws IOException { >> return null; >> } >> >> >> }); >> return new DataHandler[]{ret}; >> } >> >> >> -----Original Message----- >> From: Alex Dickinson [mailto:alexd@redback.com] >> Sent: Wednesday, July 04, 2007 10:07 PM >> To: axis-user@ws.apache.org >> Subject: Re: Streaming Soap with Attachments >> >> The delay is due to the default behaviour of writeObject() in >> javax.activation.DataHandler. The stream that gets passed to it is >> buffered, which will have to fill up before the bytes are sent over > the >> socket's stream. >> >> Also the ByteArrayDataSource requires that the DataSource be fully >> written to before it can be read from. >> >> I had to do something similar. I had small amounts of data that had to >> be sent over a long period of time. I ended up having to write a > custom >> DataSource that made data available to the InputStream as soon as it > was >> available, and to implement a custom DataHandler to would flush the >> output in writeObject when ever it wrote data. >> >> Hope that helps, >> Alex >> >> >> >> Davanum Srinivas wrote: >>> Axis1 or Axis2? Can you post some code of what you tried? >>> >>> thanks, >>> dims >>> >>> On 7/4/07, Peter Makoi wrote: >>>> >>>> >>>> Does soap with attachments using MIME multipart support streaming? >>>> >>>> I have goggled around trying to find out if there is a possibility > of >>>> doing >>>> that but i end up getting some old postings and documentations that >>>> suggest >>>> that SwA does not support streaming >>>> >>>> I have also tried to simulate streaming a considerably large amount >> of >>>> data >>>> by sending it as a data handler and then use the streaming > capability >>>> of the >>>> activation framework to stream the data into an output stream >>>> >>>> But what I got is an overhead equivalent to the time spend to >> transmit >>>> the >>>> whole file to the client before the streaming begins(my conclusion >> was >>>> that >>>> the data is received in a one-go and because of it's large size it >> take's >>>> the processor sometime to allocate some memory space to save it >> before >>>> the >>>> streaming even begins).... Does anyone have any explanation? Thanks >> in >>>> advance >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org >> For additional commands, e-mail: axis-user-help@ws.apache.org >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org >> For additional commands, e-mail: axis-user-help@ws.apache.org >> >> >> > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org > For additional commands, e-mail: axis-user-help@ws.apache.org > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org > For additional commands, e-mail: axis-user-help@ws.apache.org > > > --------------------------------------------------------------------- To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org For additional commands, e-mail: axis-user-help@ws.apache.org