[Xml-compile] Extracting received MTOMs using XML::Compile::XOP

Christopher Taranto christopher at tokpela.com
Wed May 14 21:04:16 GMT 2014


Hi,



I have been using XML::Compile::SOAP to interface with several webservices
using XOP and have been able to upload with no issues.



But now I am having some problems extracting the returned XOP document(s).



Could anyone please point me to an example of extracting MTOM attachments
using XML::Compile::SOAP?



I've been successful in doing it by using trace with a different webservice
but I am using a new webservice and my method is not working.



The actual script is too long to include and requires authorization – so I
am only including how I am making the call here:



use XML::Compile::WSDL11;      # use WSDL version 1.1

use XML::Compile::SOAP11;      # use SOAP version 1.1

use XML::Compile::SOAP12;      # use SOAP version 1.2

use XML::Compile::Transport::SOAPHTTP;

use XML::Compile::XOP;



my $xml_compile  = XML::Compile::WSDL11->new($primary_wsdl, schema_dirs =>
\@schema_dirs)

                                  || die "[Error] UNABLE TO CREATE
XML::Compile::WSDL11 OBJECT";



my $ua  = LWP::UserAgent->new();



$ua->ssl_opts(verify_hostname => 0, keep_alive => 1);

$ua->cookie_jar( {file => $jar_file, autosave => 1, ignore_discard => 1 });



my $trans = XML::Compile::Transport::SOAPHTTP->new(user_agent => $ua, soap
=> 'SOAP11');



my $call = $xml_compile->compileClient($operation_name, port =>
$service_port, trans => $trans);



my %get_request_params   = (%data);

my $request_params             = get_request_params(%get_request_params);



my @request_params            = (parameters => $request_params);

my ($answer, $trace)              = $call->(@request_params);



Which results in a successful call:



ANSWER: $VAR1 = {

          'parameters' => {

                          'Result' => {

                  'SignedDocument' => {


                      'InitialContentEncoding' => 'MIME',

                                                      'DocumentFormat' =>
'OTHER',

                                                      'Data' => bless(
do{\(my $o = 63420456)}, 'XML::LibXML::Element' ),


                      'ImplicitSignatureInfo' => {


                              'SignatureFormat' => 'PKCS7',


                              'AuditCategory' => 'CADESA'

                                                      }

                                                 }

                                            }

                               },

                    '{http://www.trustweaver.com/trustarchive}RequestId' =>
bless( do{\(my $o = 63419928)}, 'XML::LibXML::Element' )

          };



And how I have been extracting MTOM objects in another webservice:



# get all of the MTOM data objects and index by the content id from the
header

my @received_files;



my $req = $trace->request;   # HTTP message which was sent

my $res = $trace->response;  # HTTP message received



my @parts = $res->parts;



foreach (@parts) {



     my $part = $_;



      my $headers  = $part->headers;



       if ($headers->header('Content-Type')              eq
'application/octet-stream' &&

           $headers->header('Content-Transfer-Encoding') eq 'binary' ) {



            my %file;



            my $cid = $headers->header('Content-ID');

            $cid  =~ s/^<//;

            $cid  =~ s/>$//;



            my $xop  = XML::Compile::XOP::Include->new(bytes =>
$part->content, cid => $cid);



            $file{cid}  = $cid;

            $file{xop}          = $xop;

            $file{filename}     = $filename;



            push(@received_files, \%file);



        }



}



foreach (@received_files) {



    my $file            = $_;



    my $cid             = $file->{cid};

    my $xop             = $file->{xop};



    my $filename        = $file->{filename};



    my $target_filepath = "$target_directory/$filename";



    if ($xop->write($target_filepath)) {



        print "WROTE FILE [$filename] TO [$target_filepath]\n";



    } else {



        print "[Error] UNABLE TO WRITE FILE [$filename] TO
[$target_filepath]\n";



    }



}



And I am also getting the XOP lose message:



  warning: loosing received XOPs



But I cannot seem to get the extraction done correctly.



Any help or pointers is greatly appreciated.



Thank you!



Christopher Taranto
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/xml-compile/attachments/20140514/1325c184/attachment.htm>


More information about the Xml-compile mailing list