axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Hess" <gh...@wrappedapps.com>
Subject RE: Using ManagedMemoryDataSource?
Date Thu, 08 Jul 2004 13:49:31 GMT
Thanks Dhanush,
 
I have implemented my Server side receiving attachments as you have
outlined except I don't get the content(InputStream) directly from the
AttachmentPart, I first get the
AttachmentPart.getDataHandler().getInputStream() and is working fine. In
this case the Axis implementation is using MMDS. 
 
The problem I am having is reusing the MMDS in my code. For instance I
am fetching a large amount of data from a DB, I used to pass it around
as a byte[] but new requirements specify that the data will be quite
large 50M+ and instead of having that data reside totally in
memory(ouch!) I would like to use the MMDS and allow it to save a temp
file if needed and then I can just pass the MMDS around and eventually
use it to add attachments to my SOAP responses.  Currently I created a
ByteArrayDataSource to construct my DataHandlers to add attachments. Now
I want to use MMDS but am experiencing the issues noted.
 
Can I reuse this class in my own code to optimize the passing of large
data, how to do it, it seems straight forward but I must be missing
something?
 
This is what I am doing:
 
//Set Attachment type
MessageContext msgContext = MessageContext.getCurrentContext();
Message msg = msgContext.getResponseMessage();
msg.getAttachmentsImpl().setSendType(Attachments.SEND_TYPE_DIME);       
            
//Get large amount of data from DAO
//The data is a dump from a db and may be text or a binary(Depending on
DBMS used) so I choose to use "application/octet-stream" as the
//ContentType to handle all scenarios and the caller will know what to
expect.
InputStream is=  dao.getDBDump("id");
                        
//Prepare the attachment
//Use MMDS instead of ByteArrayDataSource for memory optimization
ManagedMemoryDataSource mmds = new ManagedMemoryDataSource(is,
ManagedMemoryDataSource.MAX_MEMORY_DISK_CACHED,
"application/octet-stream");      
DataHandler cdh = new DataHandler(mmds);
org.apache.axis.attachments.AttachmentPart cap = new
org.apache.axis.attachments.AttachmentPart(cdh);
msg.addAttachmentPart(cap); 
 
Any help is much appreciated.
 
Cheers,
 
Greg
 

Greg Hess

Software Engineer

Wrapped Apps Corporation

275 Michael Cowpland Dr.

Suite 201

Ottawa, Ontario

K2M 2G2

Tel: (613) 591 -7552 ext 230

Fax: (613) 591-0523

1 (877) 388-6742

www.wrappedapps.com

 <http://www.wrappedapps.com> 
 
-----Original Message-----
From: Dhanush Gopinath [mailto:dhanush@mahindrabt.com] 
Sent: Wednesday, July 07, 2004 12:11 AM
To: axis-user@ws.apache.org
Subject: Re: Using ManagedMemoryDataSource?
 
Hi Greg,
 
If ur attachment content is of Content-Type "application/octet-stream"
then the  AttachmentPart.getContent() method  will return an object of
Instream which is an Inner Class of ManagedMemoryDataSource.  and this
class extends java.io.InputStream.  (Reference Axis 1.1 Source)
 
So if you type cast the return of  AttachmentPart.getContent()  with an
InputStream it works fine and you will be able to save the file (Refer
Code below).
    
    AttachmentPart attachment =
(AttachmentPart)enumAttachment.nextElement();
    
    if
((attachment.getContentType()).equals("application/octet-stream"))
    {          
       InputStream is = (InputStream)attachment.getContent();     
     int filSize= attachment.getSize();     
     System.out.println("Got Size "+filSize);          
     byte [] byteArray= new byte[filSize];   
     System.out.println("Got byte array");          
     int ch = is.read(byteArray,0,filSize);
     System.out.println("Read to Byte Array");          
     System.out.println("Creating FOS");   
     FileOutputStream fosOct = new
FileOutputStream("D:\\mime_ws\\attachs\\"+enumFile.nextElement());

     System.out.println("Created FOS");          
     System.out.println("Writing the Byte Array to File");          
     fosOct.write(byteArray);
     System.out.println("Wrote to file ");
     fosOct.close();       
    } 
 
The above code works fine for me on Axis 1.1 
Hope this helps you. If you are so particular of MMDS then I havent used
it. I have tested a 10 MB file sucessfuly.
 
Cheers 
 
Dhanush Gopinath 
Software Engineer 
Mahindra British Telecom Ltd 
+91-020-4018100 Ext:-1218
  _____  

"Fate, it seems, is not without a sense of irony" - Morpheus , The
Matrix 
----- Original Message ----- 
From: Greg Hess <mailto:ghess@wrappedapps.com>  
To: axis-user@ws.apache.org 
Sent: Wednesday, July 07, 2004 12:11 AM
Subject: Using ManagedMemoryDataSource?
 
Hi All,
 
I am presently using the "manual method" for adding and receiving
attachments for my web service. Some of my attachments are quite large
and I would like to use the ManagedMemoryDataSource to optimize my
implementation. 
 
In testing when I construct a new instance of ManagedMemoryDataSource to
use with my attachments I pass it an InputStream to read from and manage
appropriately(either save to file or mem) but when I obtain an
InputStream from the MMDS instance it has 0 bytes available. 
 
 
InputStream is = dao.getData();
//is has data to read
 
ManagedMemoryDataSource mmds = new ManagedMemoryDataSource(is,
ManagedMemoryDataSource.MAX_MEMORY_DISK_CACHED,
"application/octet-stream");
 
is= mmds.getInputStream();
//is has no data to read?????
 
Does anyone know how to use this class?
 
Many thanks,
 

Greg Hess

Software Engineer

Wrapped Apps Corporation

275 Michael Cowpland Dr.

Suite 201

Ottawa, Ontario

K2M 2G2

Tel: (613) 591 -7552 ext 230

Fax: (613) 591-0523

1 (877) 388-6742

www.wrappedapps.com

 <http://www.wrappedapps.com> 
 
********************************************************* Disclaimer:
This message (including any attachments) contains confidential
information intended for a specific individual and purpose, and is
protected by law. If you are not the intended recipient, you should
delete this message and are hereby notified that any disclosure,
copying, or distribution of this message, or the taking of any action
based on it, is strictly prohibited.
********************************************************* Visit us at
http://www.mahindrabt.com 	

Mime
View raw message