Page 1 of 1

perl & soap to create a document

PostPosted:Tue Nov 11, 2008 12:26 pm
by justroll
hi

i\'m trying to use perl to create a document in openkm; although my knowledge to OOP is limited i wrote the following (which is working UNTIL the creation part)
Code: Select all
#!/usr/bin/perl

use strict;
use SOAP::Lite;
use Data::Dumper;
use MIME::Base64 qw(en_base64);
#   local($/) = undef;  # slurp
#   print en_base64(<STDIN>);
use Document;

use SOAP::Lite +trace => qw (debug);
my $resp;

my $PartnersWS = SOAP::Lite->service(\'http://localhost:8080/OpenKM/OKMAuth?wsdl\');
my $token = $PartnersWS->login(\'admin\',\'admin\');

print \"---\";
my $buff=\"\";my $buf;
   open(FILE, \"/var/log/wtmp\") or die \"$!\";
my $doc = new Document(\'/okm:root/testfolder/wtmp.txt2\',\'admin\');
my $file=$PartnersWS1->create($token,$doc,$buff);
my $res = $PartnersWS->logout($token);
---
Document.pm looks like
Code: Select all
#!/usr/bin/perl 

package Document;

sub new
{
    my $class = shift;
    my $self = {
        path => shift,
        author  => shift,
    };
    bless $self, $class;
    return $self;
}
sub setPath {
    my ( $self, $path ) = @_;
    $self->{path} = $path if defined($path);
    return $self->{path};
}

sub getPath {
    my( $self ) = @_;
    return $self->{path};
}
1;
--

Point is when sending the soap. .nothing comes in the soap call

look ..
Code: Select all
Dumper($doc)

$VAR1 = bless( {
                 \'author\' => \'admin\',
                 \'path\' => \'/okm:root/testfolder/wtmp.txt2\'
               }, \'Document\' );
----
actual soap call
Code: Select all
SOAP::Transport::HTTP::Client::send_receive: POST http://127.0.0.1:8080/OpenKM/OKMDocument HTTP/1.1
Accept: text/xml
Accept: multipart/*
Accept: application/soap
Content-Length: 6755
Content-Type: text/xml; charset=utf-8
SOAPAction: \"\"

<?xml version=\"1.0\" encoding=\"UTF-8\"?><soap:Envelope soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:tns=\"http://endpoint.ws.openkm.git.es/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body><tns:create><arg0 xsi:type=\"xsd:string\">1129287567495677636285-19554898471</arg0>[color=#FF0000]<arg1 xsi:nil=\"true\" xsi:type=\"tns:document\" />[/color]<arg2 xsi:type=\"xsd:base64Binary\">QlFBQUFHcGVBQUF....</arg2></tns:create></soap:Body></soap:Envelope>
can anyone please help me ?

Re:perl & soap to create a document

PostPosted:Fri Nov 14, 2008 9:11 am
by pavila
SOAP:Lite seems to have some problems with complex types and WSDL. Read this article for more info: Complex SOAP::Lite requests - my rules for SOAP::Sanity!. I\'m not a Perl expert so I can\'t help you. Tell me if you find a solution, please.

Re:perl & soap to create a document

PostPosted:Wed Dec 02, 2009 2:41 pm
by nicolaijorgensen
Hi!

I\'ve tried every possible idea with SOAP::Lite and I just can\'t get anything working with complex structs like tns:folder.

In stead I\'ve managed to get the Folder create function working in perl. It\'s not pretty but it\'s worth sharing IMHO

EDIT: Sorry, but I can\'t copy/paste my script. I get an error \"invalid access\" when I try. Have tried Quote and Code tags without luck...
EDIT2: I\'ve posted the code to my website here:
http://www.pvr.dk/openkm.html

To use, call like this with a valid login TOKEN:
script.pl \"http://localhost:8080/OpenKM/OKMFolder\" TOKEN \"/okm:root/FolderToCreate\"

/Nicolai