I did this by creating my own DataSource object too. Maybe if there is
a ByteArrayDataSource I didn't need to! On the other hand, coding a DS
of your own would help if you had a really big data set.... because
you might be able to avoid holding it all in memory at once.
public class MyDataSource implements javax.activation.DataSource {
public String getContentType() {
return "image/jpeg";
}
public InputStream getInputStream() throws IOException {
ByteArrayInputStream bais = new
ByteArrayInputStream(data);
return bais;
}
public String getName() {
return "test.jpg";
}
public OutputStream getOutputStream() throws IOException {
throw new UnsupportedOperationException();
}
}
On 9/29/06, Betsy Frey <[EMAIL PROTECTED]> wrote:
One does not have to use an ImageDataSource or FileDataSource. You can code
your own DataSource, implementing javax.activation.DataSource.
When receiving MTOM data, one gets a DataHandler from the OMText element, and
one can get the input stream from that:
OMText data = (OMText) child.getFirstOMChild();
DataHandler dh = (DataHandler) data.getDataHandler();
InputStream istream = dh.getDataSource().getInputStream();
An intermediate file may still be created. This is because, when transferring
binary data using MTOM, there is the issue that a very large amount of data
could cause an OutOfMemoryError, without storing it on disk as it is being
received. One controls this by these configuration settings:
<parameter name="cacheAttachments" locked="false">true</parameter>
<parameter name="attachmentDIR" locked="false">temp directory</parameter>
<parameter name="sizeThreshold" locked="false">4000</parameter>
Betsy
________________________________________
From: scott ken [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 28, 2006 7:53 PM
To: [email protected]
Subject: Re: about Axis2's binary attachment
Usually we will have an InputStream object. But I didn't make it work. I tried
using a byte array as input.
you can easily convert an InputStream to a byte array. After that, use
ByteArrayDataSource.
// Build OMText to hold binary data
byte[] binaryBytes = ...;
ByteArrayDataSource dataSource = new ByteArrayDataSource(binaryBytes );
DataHandler expectedDH = new DataHandler(dataSource);
OMText textData = omFactory.createOMText(expectedDH, true);
On 9/28/06, sam wang <[EMAIL PROTECTED]> wrote:
Hi, there,
I have a question about transferring binary attachment through Axis2. I want to
transfer binary
attachment from server side to client side. My question is that if I can attach
any kind of binary
data? from Axis2's api, I see there are only two datasource: file and image.
theoritically, Axis2
can transfer any kind of object because we can first serialize any object to
disk, save it as a
file, and then construct file datasource to attach into soap as binary
attachment. but it will not
be efficient. so my question is that if there is a way to attach the object
(for example,
CachedRowSet) to soap directly and return to client, instead of saving as file
first. if it can,
could anyone give me a java snippet?
thank you very much!
Sam
__________________________________________________
Do You Yahoo!?
Tired of spam?Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. Any unauthorized review, use, disclosure or distribution is
prohibited. If you are not the intended recipient, please contact the sender by
reply e-mail and destroy all copies of the original message.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
Paul Fremantle
VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
http://bloglines.com/blog/paulfremantle
[EMAIL PROTECTED]
"Oxygenating the Web Service Platform", www.wso2.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]