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 Rick Rineholt <ri...@us.ibm.com> on 2001/11/04 20:28:53 UTC

Attachment support.

I have been successful in sending a SOAP attachment with the modified files
attached in
zip file expand in the "current" Axis code base.  If this code can't be
used out right, I'm hopeful
 that portions of it might be used in facilitating this functionality.
WARNING, it was work in progress.

To build it:
Unzip in the current Axis code base.
Add activiation.jar and mailapi.jar to your classpath.
  (Without these it should still build and functional tests run, but
attachments won't work).
It 'should', complete all the functional test.

If you'd like to test it:
You need to add the following service to your Axis server deployment.
--------------------------------------------------
 <service name="MD5Service">
  <provider type="java:org.apache.axis.handlers.MD5AttachHandler">
   <handler:provider type
="java:org.apache.axis.handlers.MD5AttachHandler"/>
  </provider>
 </service>
--------------------------------------------------
Start your HTTPServer  (I only tested with TC 4.0)
Make sure your server also has activiation.jar and mailapi.jar too

Then in the  java\test\md5attach directory run the test.cmd
  - you may need to edit this command to change the url to your http
server.

WARNING WARNING.
You will have in your temp directory files left over
that need to be deleted, they are named axis***axis
(remember work that is in progress)
WARNING WARNING.

What should  happen?  Well, if you just run "test.cmd", it should
 record the current time, creates a soap envelope that reference the
attachment which is
the test.cmd file itself and sends to the server.  The MD5AttachHandler,
gets the SOAP
envelope  finds the element that has the reference to the attachment.  With
this it gets
the attachment from the attachments object and then the actual JAF
datahandler.
It then records the time and calculates the difference. It then does an MD5
signature.
It then sends back the time differences and the MD5 signature in an element
data.
The MD5AttachTest then displays the time it took to send (assuming sender
and receiver
have reasonably synched clocks).  It then does an MD5 signature on the
local file and
compares them.  Hopefully they are the same.

You can use TcpTunnelGui to see it being sent. (Ah, do't try this with a
50m file)

Warning I was really only using this as a workhorse to validate the code.
Its not pretty for a demo or sample.
Also I was pointed to by someone to use the put.java as a base and maybe I
misunderstood, because
it seem that the Service Client interface there is "deprecated" :-(
  As an aside,  I ran in to the a dilemma with attachments. I needed a
Message object to create an
  attachment in it.  Then I was able to get the SOAP part and from there
modify the DOM elements
to reference my attachment.
 But then I could not find a way to update the envelope in the SOAP part
since it seems this DOM is only
 a copy.  I broke what again "I" perceived has the stalemate by adding to
the SOAPPart a "setSOAPEnvelope".
 I feel I must have missed something since I would think this would be a
very common thing to do. Note,
 I have seen code that after it updates the envelope it creates a new
message, but then my attachments
 wouldn't be associated with the new message any more.   Would like to hear
how it should be done.

What it does:
The sending side is pretty easy it just uses the mailapi.jar to format the
data.  The difference
  over SOAP 2x is that it read all data in memory to determine the content
length.  Won't work for
  a .5G file.   What I did was two things: first I fixed it so that the
only encoding type I send
is 8bit for the SOAP part.  Anything else I send with an encoding type as
"binary".  SOAP 2.x
use of the mail api reads it in memory which the mail api then determined
if it was safe to
be sent as "mail"  for most binary data this meant encoding it to Base64 or
encoded printable.
Another over head SOAP 2.x had..  Anything other than mail is 8 bit safe
and this is not necessary.  By not using
these encodings I can directly calculate the content length. So nothing is
ever read in to
memory.
For SOAP 2.x on the receiving side, all the attachments were read in
memory.  What this code
does is manages the stream itself.  If and only if the stream is
multipart-related it creates a filtered
stream for the rest of the SOAP engine (i.e. it only perceives to "see" the
SOAP data stream). Note
that if this is not a multi-part stream the SOAP engine gets the actual
stream.  It then filters out all attachments.
For small attachments the data is kept in memory.  Once a limit is hit all
the data of the attachment is sent
to disk.  What is the limit?  It gets sets for each attachments and "could"
be made in some way to differentiate
by mime type or if possible the actual service or parameter.

The good news:
-------------------
Is that "I" (and if you try it, hopefully you) been able to send BIG files.
I have tested
routinely with zip files that are 60M and only take a minute or two to
send.  I have tested once with
a .5 G and that completed too in the proportional time.  Remember, for big
files, if your sending and receiving
on the same machine you won't get as good of a performance since your
reading and writing (caching)
at the same time (i.e. competing for disk space).
While there is some buffer to make it efficient for finding mime
boundaries,  the SOAP content,
is not read entirely in memory.  Potentially attachments that are received
before the SOAP content
are cached.  Attachments, following the SOAP content are read in when they
are referenced.

The bad news:
---------------------
"This was work under progress"
Admitting, it is still rough with tons of to-dos.
It's only there for handlers and not filtered to the higher level RPC
level.
File caching needs to clean up after itself.
On the received side there needs to be support for receiving encoding types
 "Base64" and "quoted printable" for a future mail transport and for
servers that
 insist on sending these encodings on 8bit safe protocols.
I only enabled it for the HTTP server and not any of the other servers in
Axis.
Code to make  the attachments available  to the Java RPC layer
Handling refernces to Content-Location as well.
Code to remove attachments from the message.
There are many more....

Again, I hope this can  help in getting attachment  support in
Axis.  If this, or something comparable gets into Axis
soon, I'd be willing to lend a hand in tackling  issues that will help
complete this feature in Axis.
(See attached file: axisattach.zip)(See attached file: activation.jar)(See
attached file: mailapi.jar)

Rick Rineholt

rineholt@us.ibm.com

Re: Attachment support.

Posted by Rob Jellinghaus <ro...@unrealities.com>.
At 03:36 AM 11/5/2001 -0500, Glen Daniels wrote:
>* I'm wondering if there isn't a somewhat nicer way to isolate the stuff
>that relies on activation/mail.  The AttachmentsImpl pattern here seems a
>little clunky... the MessageWithAttachments subclass idea might actually be
>a bit more attractive.... what was the reasoning against that again?

This was my doing.  Here's the relevant explanation, from an earlier thread with James.  Did you miss this at the time?

Incidentally, looks to me like Rick's been voted in as committer :-)  What next?

Cheers!
Rob


Return-Path: <ax...@xml.apache.org>
Delivered-To: robj@unrealities.com
Mailing-List: contact axis-dev-help@xml.apache.org; run by ezmlm
Reply-To: axis-dev@xml.apache.org
list-help: <ma...@xml.apache.org>
list-unsubscribe: <ma...@xml.apache.org>
list-post: <ma...@xml.apache.org>
Delivered-To: mailing list axis-dev@xml.apache.org
X-Sender: robj@unrealities.com
Date: Fri, 26 Oct 2001 17:31:28 -0700
To: axis-dev@xml.apache.org,axis-dev@xml.apache.org
From: Rob Jellinghaus <ro...@unrealities.com>
Subject: Re: SOAP Attachment
X-Spam-Rating: daedalus.apache.org 1.6.2 500/1000/N

At 10:43 PM 10/23/2001 -0700, James M Snell wrote:
>Well... I'm not sure with the current Message API, but with the changes 
>that I have in mind (not yet finalized or completely thought out), each 
>service will use a specific Message factory class for creating messages. 
>If the service supports or requires messages with attachments, then all 
>messages created by that services message factory will be an instance of 
>MessageWithAttachments.  If the service does not support messages with 
>attachments, then all messages created will be instances of Message. 

I think that this is the wrong way to break out attachment functionality.  Organizing subclasses this way could lead to an explosion of subclasses (Message, SOAPMessage, MessageWithAttachments, SOAPMessageWithAttachments...).

My upcoming pass on the message API (see my last email) will break out attachment-specific functionality into an "attachments object" which can be part (or not) of any Message.

Likewise, for SOAP versus other message formats (XML-RPC?), I think that rather than defining multiple subclasses of Message, we should instead define multiple classes of Envelope.  I agree with you that org.apache.axis.SOAPEnvelope seems wrong -- it's too high-level a dependency on SOAP.  org.apache.axis.message.soap.SOAPEnvelope (or even org.apache.axis.soap.SOAPEnvelope) would be better, I think.  Of course, then there would need to be org.apache.axis.Envelope as an actual class, which doesn't exist either.

To sum up, I would rather have 
	public Envelope Message.getAsEnvelope()
and
	public Object Message.getAttachments()

So to get the attachments from any message, whether it is a SOAP message or not, you just do "myAttachments = (MessageAttachments)myMessage.getAttachments();"

Does this make sense?  In a nutshell: don't parameterize Message by subclassing, parameterize it with contained objects.

Cheers!
Rob






Re: Attachment support.

Posted by Glen Daniels <gd...@macromedia.com>.
Hi Rick!

A few comments from a brief glance at the code:

* Woo hoo! :)  Thanks for working on this.

* Formatting - please stick with the Axis coding conventions (4 space
indents, no tabs, 80 col lines)

* I'm wondering if there isn't a somewhat nicer way to isolate the stuff
that relies on activation/mail.  The AttachmentsImpl pattern here seems a
little clunky... the MessageWithAttachments subclass idea might actually be
a bit more attractive.... what was the reasoning against that again?

* We won't need to worry about checking for cids vs. URLs in this code -
that'll happen when we resolve HREFs in the
DeserializationContext/Deserializer code - by the time we're calling
getPartByReference(), we already know it's a MIME ref.  (in looking at that
code, I note that the DeserializationContext's mapping of IDs -> IDResolvers
needs some revamping - rather than explicitly registering each ID, we should
be passing the HREF string to a resolver supplier and returning the
LocalResolver if it starts with "#", a MIMEResolver if it starts with
"cid:", etc...)

--Glen

----- Original Message -----
From: "Rick Rineholt" <ri...@us.ibm.com>
To: <ax...@xml.apache.org>
Sent: Sunday, November 04, 2001 2:28 PM
Subject: Attachment support.


> I have been successful in sending a SOAP attachment with the modified
files
> attached in
> zip file expand in the "current" Axis code base.  If this code can't be
> used out right, I'm hopeful
>  that portions of it might be used in facilitating this functionality.
> WARNING, it was work in progress.
>
> To build it:
> Unzip in the current Axis code base.
> Add activiation.jar and mailapi.jar to your classpath.
>   (Without these it should still build and functional tests run, but
> attachments won't work).
> It 'should', complete all the functional test.
>
> If you'd like to test it:
> You need to add the following service to your Axis server deployment.
> --------------------------------------------------
>  <service name="MD5Service">
>   <provider type="java:org.apache.axis.handlers.MD5AttachHandler">
>    <handler:provider type
> ="java:org.apache.axis.handlers.MD5AttachHandler"/>
>   </provider>
>  </service>
> --------------------------------------------------
> Start your HTTPServer  (I only tested with TC 4.0)
> Make sure your server also has activiation.jar and mailapi.jar too
>
> Then in the  java\test\md5attach directory run the test.cmd
>   - you may need to edit this command to change the url to your http
> server.
>
> WARNING WARNING.
> You will have in your temp directory files left over
> that need to be deleted, they are named axis***axis
> (remember work that is in progress)
> WARNING WARNING.
>
> What should  happen?  Well, if you just run "test.cmd", it should
>  record the current time, creates a soap envelope that reference the
> attachment which is
> the test.cmd file itself and sends to the server.  The MD5AttachHandler,
> gets the SOAP
> envelope  finds the element that has the reference to the attachment.
With
> this it gets
> the attachment from the attachments object and then the actual JAF
> datahandler.
> It then records the time and calculates the difference. It then does an
MD5
> signature.
> It then sends back the time differences and the MD5 signature in an
element
> data.
> The MD5AttachTest then displays the time it took to send (assuming sender
> and receiver
> have reasonably synched clocks).  It then does an MD5 signature on the
> local file and
> compares them.  Hopefully they are the same.
>
> You can use TcpTunnelGui to see it being sent. (Ah, do't try this with a
> 50m file)
>
> Warning I was really only using this as a workhorse to validate the code.
> Its not pretty for a demo or sample.
> Also I was pointed to by someone to use the put.java as a base and maybe I
> misunderstood, because
> it seem that the Service Client interface there is "deprecated" :-(
>   As an aside,  I ran in to the a dilemma with attachments. I needed a
> Message object to create an
>   attachment in it.  Then I was able to get the SOAP part and from there
> modify the DOM elements
> to reference my attachment.
>  But then I could not find a way to update the envelope in the SOAP part
> since it seems this DOM is only
>  a copy.  I broke what again "I" perceived has the stalemate by adding to
> the SOAPPart a "setSOAPEnvelope".
>  I feel I must have missed something since I would think this would be a
> very common thing to do. Note,
>  I have seen code that after it updates the envelope it creates a new
> message, but then my attachments
>  wouldn't be associated with the new message any more.   Would like to
hear
> how it should be done.
>
> What it does:
> The sending side is pretty easy it just uses the mailapi.jar to format the
> data.  The difference
>   over SOAP 2x is that it read all data in memory to determine the content
> length.  Won't work for
>   a .5G file.   What I did was two things: first I fixed it so that the
> only encoding type I send
> is 8bit for the SOAP part.  Anything else I send with an encoding type as
> "binary".  SOAP 2.x
> use of the mail api reads it in memory which the mail api then determined
> if it was safe to
> be sent as "mail"  for most binary data this meant encoding it to Base64
or
> encoded printable.
> Another over head SOAP 2.x had..  Anything other than mail is 8 bit safe
> and this is not necessary.  By not using
> these encodings I can directly calculate the content length. So nothing is
> ever read in to
> memory.
> For SOAP 2.x on the receiving side, all the attachments were read in
> memory.  What this code
> does is manages the stream itself.  If and only if the stream is
> multipart-related it creates a filtered
> stream for the rest of the SOAP engine (i.e. it only perceives to "see"
the
> SOAP data stream). Note
> that if this is not a multi-part stream the SOAP engine gets the actual
> stream.  It then filters out all attachments.
> For small attachments the data is kept in memory.  Once a limit is hit all
> the data of the attachment is sent
> to disk.  What is the limit?  It gets sets for each attachments and
"could"
> be made in some way to differentiate
> by mime type or if possible the actual service or parameter.
>
> The good news:
> -------------------
> Is that "I" (and if you try it, hopefully you) been able to send BIG
files.
> I have tested
> routinely with zip files that are 60M and only take a minute or two to
> send.  I have tested once with
> a .5 G and that completed too in the proportional time.  Remember, for big
> files, if your sending and receiving
> on the same machine you won't get as good of a performance since your
> reading and writing (caching)
> at the same time (i.e. competing for disk space).
> While there is some buffer to make it efficient for finding mime
> boundaries,  the SOAP content,
> is not read entirely in memory.  Potentially attachments that are received
> before the SOAP content
> are cached.  Attachments, following the SOAP content are read in when they
> are referenced.
>
> The bad news:
> ---------------------
> "This was work under progress"
> Admitting, it is still rough with tons of to-dos.
> It's only there for handlers and not filtered to the higher level RPC
> level.
> File caching needs to clean up after itself.
> On the received side there needs to be support for receiving encoding
types
>  "Base64" and "quoted printable" for a future mail transport and for
> servers that
>  insist on sending these encodings on 8bit safe protocols.
> I only enabled it for the HTTP server and not any of the other servers in
> Axis.
> Code to make  the attachments available  to the Java RPC layer
> Handling refernces to Content-Location as well.
> Code to remove attachments from the message.
> There are many more....
>
> Again, I hope this can  help in getting attachment  support in
> Axis.  If this, or something comparable gets into Axis
> soon, I'd be willing to lend a hand in tackling  issues that will help
> complete this feature in Axis.
> (See attached file: axisattach.zip)(See attached file: activation.jar)(See
> attached file: mailapi.jar)
>
> Rick Rineholt
>
> rineholt@us.ibm.com
>
>