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

Question about sending and receiving multiple attachments

Expand Messages
  • tutailitama
    Hi! I wrote these examples, using SOAP::Lite 0.67: SOAP server must receive attachments and save them into a file. ############### SERVER BEGIN #!/usr/bin/perl
    Message 1 of 1 , Jan 30, 2006
    • 0 Attachment
      Hi!
      I wrote these examples, using SOAP::Lite 0.67:

      SOAP server must receive attachments and save them into a file.
      ############### SERVER BEGIN
      #!/usr/bin/perl -w
      use SOAP::Lite +trace => ['all'];
      use SOAP::Transport::HTTP;
      $SIG{PIPE} = $SIG{INT} = 'IGNORE';
      my $server_addr = '192.168.1.1';
      my $server_port = 8090;
      SOAP::Transport::HTTP::Daemon
      -> new(LocalAddr => $server_addr, LocalPort => $server_port, Reuse => 1)
      -> dispatch_with({'http://192.168.1.1:8090'=>'Delivery'})
      -> dispatch_to('Delivery')
      -> handle;
      BEGIN {
      package Delivery;
      use SOAP::Lite;
      use MIME::Entity;
      use strict;
      use vars qw(@ISA);
      @ISA = qw(SOAP::Server::Parameters);

      sub MyMethod {
      my $self = shift;
      my $envelope = pop;
      open FILE, ">att.txt";
      foreach my $part (@{$envelope->parts}) {
      print STDERR "soaplite: attachment found! (".ref($part).")\n";
      print STDERR "soaplite: contents => ".$part->stringify."\n";
      print FILE $part->stringify;
      }
      close FILE;
      print STDERR "envelope is of type: " . ref($envelope) . "\n";
      return 1,SOAP::Data->name(Param1 => '54321')->type(''),2;
      }
      1;

      }
      ############### SERVER END

      SOAP client must send request with a multiple MIME attachments
      ############### CLIENT BEGIN
      #!/usr/bin/perl
      use SOAP::Lite +trace => ['all'];
      use MIME::Entity;
      my $att1 = "AAAA";
      my $att2 = "plain.txt";
      my $ent = build MIME::Entity
      Type => "multipart/related; start=\"<$att1>\"",
      Id => "<xxid>"
      ;
      $ent->attach(
      Type => "text/plain",
      Id => "<$att1>",
      Encoding => "7bit",
      Path => "./attachments/$att1",
      Filename => "$att1",
      Disposition => "attachment"
      );
      $ent->attach(
      Type => "text/plain",
      Id => "<$att2>",
      Encoding => "7bit",
      Path => "./attachments/$att2",
      Filename => "$att2",
      Disposition => "attachment"
      );
      $HOST = "http://192.168.1.1:8090";
      my $search = SOAP::Lite
      ->packager(SOAP::Packager::MIME->new)
      ->parts([$ent])
      ->proxy($HOST)
      ->readable(1)
      ->on_action( sub { return '""';} )
      ->envprefix('env')
      ;
      my $method = SOAP::Data->name('MyMethod')->uri($HOST);
      my @params = (
      SOAP::Data->name(Param1 => '12345')->type(''),
      SOAP::Data->name(Subject => 'ssuubbjjeecctt')->type(''),
      SOAP::Data->name(Content)->attr({'href' => "cid:xxid"})->type(''),
      );
      my $results = $search->call($method => @params);

      ######### RESULTS

      1;
      ############### CLIENT END

      There is something strange.

      1. I must add start = <...> parameter into the MIME header manually,
      because I receive the message "Unresolved (wrong?) href (xxid) in
      element 'Content'" when this parameter is missing.

      2. When I insert semicolon into this string after start parameter, like:
      Type => "multipart/related; start=\"<$att1>\";"
      boundaries are not displayed correctly, double semicolon in MIME
      header exists: start="<AAAA>";;
      and server cannot see attachments
      ############### CLIENT'S DEBUG OUTPUT BEGIN
      SOAP::Transport::new: ()
      SOAP::Serializer::new: ()
      SOAP::Deserializer::new: ()
      SOAP::Parser::new: ()
      SOAP::Lite::new: ()
      SOAP::Transport::HTTP::Client::new: ()
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Lite::call: ()
      SOAP::Serializer::envelope: ()
      SOAP::Serializer::envelope: SOAP::Data=HASH(0x1db02bc)
      SOAP::Data=HASH(0x1ef8f84) SOAP::Data=HASH(0x1f05748)
      SOAP::Data=HASH(0x1f057d8)
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Transport::HTTP::Client::send_receive: HTTP::Request=HASH(0x1ef8e7c)
      SOAP::Transport::HTTP::Client::send_receive: POST
      http://192.168.1.1:8090 HTTP/1.1
      Accept: text/xml
      Accept: multipart/*
      Accept: application/soap
      Content-Length: 1434
      Content-Type: Multipart/Related; type="text/xml";
      start="<main_envelope>"; boundary="----------=_1138623103-3420-1";
      charset=utf-8
      SOAPAction: ""

      This is a multi-part message in MIME format...

      ------------=_1138623103-3420-1
      Content-Type: text/xml
      Content-Disposition: inline
      Content-Location: /main_envelope
      Content-ID: <main_envelope>

      <?xml version="1.0" encoding="UTF-8"?>
      <env:Envelope
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <env:Body>
      <namesp1:MyMethod xmlns:namesp1="http://192.168.1.1:8090">
      <Param1>12345</Param1>

      <Subject>ssuubbjjeecctt</Subject>

      <Content href="cid:xxid" />
      </namesp1:MyMethod>
      </env:Body>
      </env:Envelope>

      ------------=_1138623103-3420-1
      Content-Type: multipart/related;
      start="<AAAA>";;
      boundary="----------=_1138623102-3420-0"
      Content-Transfer-Encoding: binary
      Content-ID: <xxid>
      MIME-Version: 1.0
      X-Mailer: MIME-tools 6.106 (Entity 6.106)

      This is a multi-part message in MIME format...

      --
      Content-Type: text/plain; name="AAAA"
      Content-Disposition: attachment; filename="AAAA"
      Content-Transfer-Encoding: 7bit
      Content-ID: <AAAA>

      123
      --
      Content-Type: text/plain; name="plain.txt"
      Content-Disposition: attachment; filename="plain.txt"
      Content-Transfer-Encoding: 7bit
      Content-ID: <plain.txt>

      456
      ----

      ------------=_1138623103-3420-1--
      SOAP::Transport::HTTP::Client::send_receive:
      HTTP::Response=HASH(0x208d024)
      SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 200 OK
      Date: Mon, 30 Jan 2006 12:11:43 GMT
      Server: libwww-perl-daemon/1.35
      Content-Length: 549
      Content-Type: text/xml; charset=utf-8
      Client-Date: Mon, 30 Jan 2006 12:11:43 GMT
      Client-Peer: 192.168.1.1:8090
      Client-Response-Num: 1
      SOAPServer: SOAP::Lite/Perl/0.67

      <?xml version="1.0" encoding="UTF-8"?><soap:Envelope
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:soapenc="http://schemas.xml
      soap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s
      oap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><MyMethodResponse
      xmlns="http://192.168.1.1:8090"><s-gensym15 xsi:type="xsd:int"
      >1</s-gensym15><Param1>54321</Param1><s-gensym18
      xsi:type="xsd:int">2</s-gensym18></MyMethodResponse></soap:Body></soap:Envelope>
      SOAP::Deserializer::deserialize: ()
      SOAP::Parser::decode: ()
      SOAP::SOM::new: ()
      SOAP::Lite::DESTROY: ()
      SOAP::Deserializer::DESTROY: ()
      SOAP::Parser::DESTROY: ()
      SOAP::Transport::DESTROY: ()
      SOAP::Transport::HTTP::Client::DESTROY: ()
      SOAP::SOM::DESTROY: ()
      SOAP::Serializer::DESTROY: ()
      SOAP::Data::DESTROY: ()
      SOAP::Data::DESTROY: ()
      SOAP::Data::DESTROY: ()
      SOAP::Data::DESTROY: ()
      SOAP::Data::DESTROY: ()
      SOAP::Data::DESTROY: ()
      SOAP::Data::DESTROY: ()
      SOAP::Data::DESTROY: ()
      ############### CLIENT'S DEBUG OUTPUT END
      ############### SERVER'S DEBUG OUTPUT BEGIN
      SOAP::Transport::new: ()
      SOAP::Serializer::new: ()
      SOAP::Deserializer::new: ()
      SOAP::Parser::new: ()
      SOAP::Server::new: ()
      SOAP::Transport::HTTP::Server::new: ()
      SOAP::Transport::HTTP::Daemon::new: ()
      Use of uninitialized value in string eq at
      D:/Perl/site/lib/SOAP/Transport/HTTP.pm line 316.
      SOAP::Server::handle: ()
      SOAP::Deserializer::deserialize: ()
      Use of uninitialized value in concatenation (.) or string at
      D:/Perl/site/lib/MIME/Parser.pm line 1910.
      SOAP::Parser::decode: ()
      SOAP::SOM::new: ()
      SOAP::Data::new: ()
      SOAP::Data::DESTROY: ()
      (eval): 12345 ssuubbjjeecctt This is a multi-part message in MIME
      format...

      --
      Content-Type: text/plain; name="AAAA"
      Content-Disposition: attachment; filename="AAAA"
      Content-Transfer-Encoding: 7bit
      Content-ID: <AAAA>

      123
      --
      Content-Type: text/plain; name="plain.txt"
      Content-Disposition: attachment; filename="plain.txt"
      Content-Transfer-Encoding: 7bit
      Content-ID: <plain.txt>

      456
      ----
      soaplite: attachment found! (MIME::Entity)
      soaplite: contents => Content-Type: multipart/related;
      start="<AAAA>";;
      boundary="----------=_1138623408-2900-0"
      Content-Transfer-Encoding: binary
      Content-ID: <xxid>
      MIME-Version: 1.0
      X-Mailer: MIME-tools 6.106 (Entity 6.106)

      This is a multi-part message in MIME format...

      ----

      envelope is of type: SOAP::SOM
      SOAP::Data::new: ()
      SOAP::Server::handle: 1 SOAP::Data=HASH(0x21f3004) 2
      SOAP::Serializer::envelope: ()
      SOAP::Serializer::envelope: MyMethodResponse 1
      SOAP::Data=HASH(0x21f3004) 2
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::SOM::DESTROY: ()
      ############### SERVER'S DEBUG OUTPUT END

      2. When I not insert semicolon into this string after start parameter,
      like:
      Type => "multipart/related; start=\"<$att1>\"", I receive the message
      "Unresolved (wrong?) href (xxid) in element 'Content'" when this
      parameter is missing, but boundaries seems ok.

      What I do wrong?

      Thanks.
    Your message has been successfully submitted and would be delivered to recipients shortly.