Loading ...
Sorry, an error occurred while loading the content.

Re: MIME attachments and SOAP Lite 0.68 / Apache 2.2.2

Expand Messages
  • techrg99
    Hey Ger, Well, I figured out a work-around. I am just sending all the stuff I need as arguments to the SOAP call. I ve given up on MIME-attachments with
    Message 1 of 6 , Aug 2, 2006
    • 0 Attachment
      Hey Ger,

      Well, I figured out a work-around. I am just sending all the stuff I
      need as arguments to the SOAP call. I've given up on MIME-attachments
      with SOAP::Lite 0.68/Apache 2.2.2 for now. I realized, I can very
      easily send up (or down) a complex Hash including binary file
      contents... So, why even use MIME attachments? What does it buy me?
      Here is an example of sending several binary files up to the server
      using MIME::Base64, and MD5 checksums... Returning files from the
      Server to the Client should be just as straight-forward.

      ---------------------------------------------
      Client-Side Code
      ---------------------------------------------
      use strict;
      use Digest::MD5 qw(md5_base64);
      use MIME::Base64;
      use SOAP::Lite +trace => qw(debug);
      #use SOAP::Lite;
      use File::Basename;
      use Data::Dumper;

      my @files = ('picture.gif', '/tmp/J7SLS8daSH');
      my $file_data = {};
      my $buf;
      my $b64data;
      my $checksum;

      foreach (@files) {
      $b64data = '';
      open FILE, $_;
      binmode FILE;
      $checksum = Digest::MD5->new->addfile(*FILE)->b64digest;
      close FILE;

      open FILE, $_;
      binmode FILE;

      while (read(FILE, $buf, 60*57)) {
      $b64data .= encode_base64($buf);
      }

      close FILE;

      push @{$file_data->{-files}}, {
      -name => basename ($_),
      -checksum => $checksum,
      -data => $b64data,
      };
      }

      my $soap = SOAP::Lite
      -> uri('http://myserver:8010/FILE_TEST')
      -> proxy('http://myserver:8010/server');

      if ($soap) {
      my $call = $soap->call(send_file => $file_data);

      if ($call) {
      my $return_data = $call->result;
      print Dumper $return_data;
      }
      else {
      print "Call failed\n";
      }
      }
      else {
      "SOAP creation failed\n";
      }



      ---------------------------------------------
      Server-Side Code
      ---------------------------------------------
      package FILE_TEST;

      use strict;

      use SOAP::Lite;
      use Data::Dumper;
      use MIME::Base64;
      use Digest::MD5 qw(md5_base64);



      sub send_file {
      my ($self, $file_data) = @_;
      my $return_data;
      my $checksum;

      my $dir = "/tmp/".time();

      mkdir ($dir);

      foreach my $file (@{$file_data->{-files}}) {
      open FILE, "> $dir/$file->{-name}";
      binmode FILE;

      print FILE decode_base64($file->{-data});
      close FILE;

      open FILE, qq($dir/$file->{-name});
      binmode FILE;
      $checksum = Digest::MD5->new->addfile(*FILE)->b64digest;
      close FILE;

      push @{$return_data->{-files}}, {
      -name => $file->{-name},
      -local_checksum => $file->{-checksum},
      -server_checksum => $checksum,
      };

      }

      return $return_data;
      }



      ---------------------------------------------
      Client-Side Output
      ---------------------------------------------
      $VAR1 = {
      '-files' => [
      {
      '-name' => 'movie.gif',
      '-server_checksum'=> '5q0k/WEaNi8Or7oNWdqwcg',
      '-local_checksum' => '5q0k/WEaNi8Or7oNWdqwcg'
      },
      {
      '-name' => 'J7SLS8daSH',
      '-server_checksum'=> 'HkFgablI9qGvCVq8aatM4g',
      '-local_checksum' => 'HkFgablI9qGvCVq8aatM4g'
      }
      ]
      };


      Yeah! Checksums match... good deal!

      I've tested this with a fairly large file - 13 MB Perl distro
      stable.tar.gz... and it worked fine.

      Good Luck! Let me know if you make any discoveries on the
      MIME-attachment front. But, like I said, I am not going to bother
      with them. This does everyhting I need, and gives me more flexability.

      See ya,
      Steve


      --- In soaplite@yahoogroups.com, Ger Apeldoorn <g.apeldoorn@...> wrote:
      >
      > Hi,
      >
      > I'm trying to get the server to respond with an attachment.
      >
      > The example @majordojo simply does not work (for me).
      >
      > Error:
      > --------------------%<------------------------
      > SOAP::Serializer::envelope: Server Can't call method "parts" on
      unblessed
      > reference at ./Server.cgi line 110.
      > --------------------%<------------------------
      >
      > Code:
      > --------------------%<------------------------
      > my $self = shift;
      > my $envelope = pop;
      >
      > foreach my $part (@{$envelope->parts}) { #line 110
      > print STDERR "Attachment found! (".ref($$part).")\n";
      > }
      > --------------------%<------------------------
      >
      > Any help/tips GREATLY appreciated!
      >
      > BTW: It's not only attachments I have to receive. I also have got
      some values
      > that I need to retrieve. How can I get them out of the envelope?
      >
      > I read here (http://www.majordojo.com/soapmime/soapmime_and_so.php)
      that
      > SOAP::MIME and SOAP::Lite merged in 2003. Is this perhaps the cause
      that the
      > examples are not working?
      >
      > Many thanks,
      > Ger.
      >
      > Op dinsdag 1 augustus 2006 16:47, schreef techrg99:
      > > Hey Ger,
      > >
      > > Yes. I am using the sample code.
      > >
      > > Try changning your client-side SOAP code so that you see the SOAP
      > > debugging stuff...
      > >
      > > use SOAP::Lite +trace => qw(debug);
      > >
      > > You will still get the 500 error, but you will be able to see exactly
      > > what SOAP is doing, or trying to do :-)
      > >
      > > Steve
      > >
      > > --- In soaplite@yahoogroups.com, Ger Apeldoorn <g.apeldoorn@> wrote:
      > > > Hi Steve,
      > > >
      > > > Have you seen this one?
      > > >
      > > > http://www.majordojo.com/SOAP-MIME/samples/
      > > >
      > > > I'm currently trying to do something like you described, but I'm
      > >
      > > still at
      > >
      > > > the "INTERNAL SERVER ERROR" stage... :S
      > > >
      > > > Ger.
      > > >
      > > > Op dinsdag 1 augustus 2006 01:01, schreef u:
      > > > > Hi all,
      > > > >
      > > > > I have the following server configuration:
      > > > > Apache 2.2.2 (w/ mod_perl), SOAP::Lite 0.68, and Expat 2.0.0
      > > > >
      > > > > I am trying to send a MIME::Entity attachment from a client perl
      > > > > script to the SOAP server. (Both of which are on the same
      machine for
      > > > > now).
      > > > >
      > > > > I've tried a lot of the MIME::Entity build options, and
      SOAP::Lite
      > > > > options. But, it seems when ever I use the parts() option to
      attach
      > > > > my MIME::Entities to my soap call, the call fails with the
      following
      > > > > error message:
      > > > >
      > > > > --
      > > > > <faultcode>soap:Client</faultcode><faultstring>Application failed
      > > > > during request deserialization:
      > > > > syntax error at line 1, column 0, byte 0 at
      > >
      > >
      /usr/local/perl/lib/site_perl/5.8.8/i686-linux-thread-multi/XML/Parser.pm
      > >
      > > > > line 187
      > > > > </faultstring>
      > > > > --
      > > > >
      > > > > Has anyone successfully sent a MIME attachment from a perl
      client to
      > > > > an Apache/SOAP Server? I have not found any recent examples out
      > >
      > > there.
      > >
      > > > > Thanks,
      > > > >
      > > > > Steve
      > > >
      > > > --
      > > > ARGOSS: your partner for atmospheric, marine & coastal information
      > > > P O Box 61
      > > > 8325ZH Vollenhove The Netherlands
      > > > tel +31-527-242299 fax +31-527-242016
      > > > Web http://www.argoss.nl
      > > >
      > > > Confidentiality Notice & Disclaimer
      > > > The contents of this e-mail and any attachments are intended only
      > >
      > > for the
      > >
      > > > use of the e-mail addressee(s) shown. If you are not that person, or
      > >
      > > one of
      > >
      > > > those persons, you are not allowed to take any action based upon it
      > >
      > > or to
      > >
      > > > copy it, forward, distribute or disclose the contents of it and you
      > >
      > > should
      > >
      > > > please delete it from your system.
      > > >
      > > > ARGOSS Holding BV and its subsidiaries do not accept any liability
      > >
      > > for any
      > >
      > > > errors or omissions in the context of this e-mail or its attachments
      > >
      > > which
      > >
      > > > arise as a result of Internet transmission, nor accept liability for
      > > > statements which are those of the author and not clearly made on
      > >
      > > behalf of
      > >
      > > > ARGOSS.
      >
      > --
      > ARGOSS: your partner for atmospheric, marine & coastal information
      > P O Box 61
      > 8325ZH Vollenhove The Netherlands
      > tel +31-527-242299 fax +31-527-242016
      > Web http://www.argoss.nl
      >
      > Confidentiality Notice & Disclaimer
      > The contents of this e-mail and any attachments are intended only
      for the
      > use of the e-mail addressee(s) shown. If you are not that person, or
      one of
      > those persons, you are not allowed to take any action based upon it
      or to
      > copy it, forward, distribute or disclose the contents of it and you
      should
      > please delete it from your system.
      >
      > ARGOSS Holding BV and its subsidiaries do not accept any liability
      for any
      > errors or omissions in the context of this e-mail or its attachments
      which
      > arise as a result of Internet transmission, nor accept liability for
      > statements which are those of the author and not clearly made on
      behalf of
      > ARGOSS.
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.