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

Perl->Soap server respond with attachments

Expand Messages
  • Ger Apeldoorn
    Hi, I ve got some problems with sending attachments with SOAP::Lite. I m trying to make a soap server respond with an attachments which I want to collect on
    Message 1 of 2 , Jun 20, 2006
    • 0 Attachment
      Hi,

      I've got some problems with sending attachments with SOAP::Lite.

      I'm trying to make a soap server respond with an attachments which I want to
      collect on the client side. The other way around, it works.

      I've looked at dozens of domentation pages and examples, but I cannot get it
      to work. Even copy/pasted examples just dont work.

      I'm using Ubuntu 6.06 LTS.

      I've enabled debugging in client and server, and can see the soap
      communication that is received. The attachment is not present in the received
      data. The MIME object is made in Server.cgi, but never sent.

      Any help is greatly appreciated!

      Ger Apeldoorn

      Client.cgi:
      --------------------%<------------------------
      #!/usr/bin/perl -w
      #use strict;
      use warnings;
      use SOAP::Lite +trace => [debug];
      use MIME::Entity;

      my $soap = SOAP::Lite
      ->packager(SOAP::Packager::MIME->new)
      ->uri('http://localhost/ArgossGateway')
      ->proxy('http://127.0.0.1:18001');
      #->proxy('http://localhost/SOAPresearch/Server.cgi');
      my $som = $soap->give_attachment();

      #print "Result: ", $som->result;

      foreach my $part (@{$som->parts}) {
      print $part->stringify;
      }
      --------------------%<------------------------

      Server.cgi
      --------------------%<------------------------
      #!/usr/bin/perl -w
      #use strict;
      use warnings;
      use SOAP::Transport::HTTP;
      use MIME::Entity;
      use SOAP::Lite +trace;
      use MIME::Tools;

      my $daemon = SOAP::Transport::HTTP::Daemon
      ->new(LocalAddr => 'localhost', LocalPort => '18001')
      ->dispatch_to('ArgossGateway')
      ->handle( );
      BEGIN{
      package ArgossGateway;

      use vars qw(@ISA);
      @ISA = qw(SOAP::Server::Parameters);

      sub new
      {
      my $class = shift;
      my $self = {};
      bless ($self, $class);
      }

      sub give_attachment
      {
      MIME::Tools->debugging(1);
      my $self = shift;
      my $envelope = pop;
      use MIME::Entity;
      my $ent = build MIME::Entity
      Id => "<1234>",
      Type => "text/plain",
      Path => "attachment.txt",
      Filename => "attachment.txt",
      Disposition => "attachment";

      foreach my $part (@{$ent->parts}) {
      print "Attachment found! (".ref($part).")\n";
      }

      return SOAP::Data->name("foo" => "------------------"), $ent;
      }
      }
      --------------------%<------------------------

      Client-side debugging:
      --------------------%<------------------------
      $ ./Client.cgi
      Unquoted string "debug" may clash with future reserved word at ./Client.cgi
      line 4.
      SOAP::Transport::HTTP::Client::send_receive: POST http://127.0.0.1:18001
      HTTP/1.1
      Accept: text/xml
      Accept: multipart/*
      Accept: application/soap
      Content-Length: 440
      Content-Type: text/xml; charset=utf-8
      SOAPAction: "http://localhost/ArgossGateway#give_attachment"

      <?xml version="1.0" encoding="UTF-8"?><soap:Envelope
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><give_attachment
      xmlns="http://localhost/ArgossGateway"
      xsi:nil="true" /></soap:Body></soap:Envelope>
      SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 200 OK
      Date: Mon, 19 Jun 2006 10:47:23 GMT
      Server: libwww-perl-daemon/1.36
      Content-Length: 508
      Content-Type: text/xml; charset=utf-8
      Client-Date: Mon, 19 Jun 2006 10:47:23 GMT
      Client-Peer: 127.0.0.1:18001
      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.xmlsoap.org/soap/encoding/"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><give_attachmentResponse
      xmlns="http://localhost/ArgossGateway"><foo
      xsi:type="xsd:string">------------------</foo></give_attachmentResponse></soap:Body></soap:Envelope>
      --------------------%<------------------------
    • gapeldoorn
      Hi, I ve got some problems with sending attachments with SOAP::Lite. I m trying to make a soap server respond with an attachments which I want to collect on
      Message 2 of 2 , Jun 20, 2006
      • 0 Attachment
        Hi,

        I've got some problems with sending attachments with SOAP::Lite.

        I'm trying to make a soap server respond with an attachments which I
        want to
        collect on the client side. The other way around, it works.

        I've looked at dozens of domentation pages and examples, but I cannot
        get it
        to work. Even copy/pasted examples just dont work.

        I'm using Ubuntu 6.06 LTS.

        I've enabled debugging in client and server, and can see the soap
        communication that is received. The attachment is not present in the
        received
        data. The MIME object is made in Server.cgi, but never sent.

        Any help is greatly appreciated!

        Ger Apeldoorn

        PS: Yesterday, I tried to send this same mail to
        soaplite@yahoogroups.com, but I never got it. I hope you didnt get it
        3 times. If so, sorry about that!

        Client.cgi:
        --------------------%<------------------------
        #!/usr/bin/perl -w
        #use strict;
        use warnings;
        use SOAP::Lite +trace => [debug];
        use MIME::Entity;

        my $soap = SOAP::Lite
        ->packager(SOAP::Packager::MIME->new)
        ->uri('http://localhost/ArgossGateway')
        ->proxy('http://127.0.0.1:18001');
        #->proxy('http://localhost/SOAPresearch/Server.cgi');
        my $som = $soap->give_attachment();

        #print "Result: ", $som->result;

        foreach my $part (@{$som->parts}) {
        print $part->stringify;
        }
        --------------------%<------------------------

        Server.cgi
        --------------------%<------------------------
        #!/usr/bin/perl -w
        #use strict;
        use warnings;
        use SOAP::Transport::HTTP;
        use MIME::Entity;
        use SOAP::Lite +trace;
        use MIME::Tools;

        my $daemon = SOAP::Transport::HTTP::Daemon
        ->new(LocalAddr => 'localhost', LocalPort => '18001')
        ->dispatch_to('ArgossGateway')
        ->handle( );
        BEGIN{
        package ArgossGateway;

        use vars qw(@ISA);
        @ISA = qw(SOAP::Server::Parameters);

        sub new
        {
        my $class = shift;
        my $self = {};
        bless ($self, $class);
        }

        sub give_attachment
        {
        MIME::Tools->debugging(1);
        my $self = shift;
        my $envelope = pop;
        use MIME::Entity;
        my $ent = build MIME::Entity
        Id => "<1234>",
        Type => "text/plain",
        Path => "attachment.txt",
        Filename => "attachment.txt",
        Disposition => "attachment";

        foreach my $part (@{$ent->parts}) {
        print "Attachment found! (".ref($part).")\n";
        }

        return SOAP::Data->name("foo" => "------------------"), $ent;
        }
        }
        --------------------%<------------------------

        Client-side debugging:
        --------------------%<------------------------
        $ ./Client.cgi
        Unquoted string "debug" may clash with future reserved word at
        ./Client.cgi
        line 4.
        SOAP::Transport::HTTP::Client::send_receive: POST http://127.0.0.1:18001
        HTTP/1.1
        Accept: text/xml
        Accept: multipart/*
        Accept: application/soap
        Content-Length: 440
        Content-Type: text/xml; charset=utf-8
        SOAPAction: "http://localhost/ArgossGateway#give_attachment"

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

        xmlns="http://localhost/ArgossGateway"
        xsi:nil="true" /></soap:Body></soap:Envelope>
        SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 200 OK
        Date: Mon, 19 Jun 2006 10:47:23 GMT
        Server: libwww-perl-daemon/1.36
        Content-Length: 508
        Content-Type: text/xml; charset=utf-8
        Client-Date: Mon, 19 Jun 2006 10:47:23 GMT
        Client-Peer: 127.0.0.1:18001
        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.xmlsoap.org/soap/encoding/"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><give_attachmentResponse

        xmlns="http://localhost/ArgossGateway"><foo
        xsi:type="xsd:string">------------------</foo></give_attachmentResponse></soap:Body></soap:Envelope>
        --------------------%<------------------------
      Your message has been successfully submitted and would be delivered to recipients shortly.