Perl SOAP :: Lite, problems mounting complex request

0

I'm trying to consume an API using Perl + SOAP :: Lite, for simple requests I can consume the API and get the result, however I need to make a more complex request to access a given API service and I'm having problems.

Below is the code I'm working on:

SwiftApiFuncions.pm

package SwiftApiFuncions;

use SOAP::Lite ; #+trace => "debug"
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;

use Data::Dumper;

sub new {
  my ( $Type, %Param ) = @_;

  # allocate new hash for object
  my $Self = {};
  bless( $Self, $Type );

 return $Self;
}

sub getSwiftApiResult {

  my ( $Type, %Param ) = @_;

  my $username = $Param{username};
  my $password = $Param{password};
  my $function = $Param{function};

  if($function eq 'getProjectDetails'){
  $projectId = returnProjectIdFromName($username, $password, $function);
  }elsif($function eq 'getCardListForProjectInput'){
    $projectId = returnCardListFromProjectDetail($username, $password, 
    $function, $projectName);
  }elsif($function eq 'addCard'){
    $projectId = createCardOnProjectName($username, $password, $function,
    $projectName);
 }

  return $projectId;
}

sub getHeader {

  my ( $SoapClient, $username, $password, $function ) = @_;

  my $serializer = $SoapClient->serializer();
  $serializer->register_ns("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "wsse" );
$serializer->register_ns("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "wsu" );
$serializer->envprefix("SOAP-ENV");

my $Security = SOAP::Header->name("Security")->prefix("wsse")
->attr({"SOAP-ENV:mustUnderstand" => 1});

my $UsernameToken = SOAP::Header
->name("UsernameToken" =>
  \SOAP::Header->value(SOAP::Header->name("Username")->prefix("wsse")   
->value($username)->type(""),
         SOAP::Header->name("Password")->prefix("wsse")->value($password) 
->type("")
         ->attr({"Type"=>"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"})))
        ->prefix("wsse");

$Security->value(\$UsernameToken);

return $Security;

}

sub returnProjectIdFromName {

my ( $username, $password ) = @_;

my $SoapClient = SOAP::Lite
->uri('https://login.swift-kanban.com/axis2/services/ProjectService?wsdl')
->proxy('https://login.swift-kanban.com/axis2/services/ProjectService')
->autotype(0);

my $Security = getHeader($SoapClient, $username, $password);
my $beamlineName = SOAP::Data->name('getProjectDetails')->type("")->attr({"SOAP-ENV"});
my $runName = SOAP::Data->name("userLoginId")->value($username)->type("");
my $xml = $SoapClient->getProject($Security, $beamlineName, $runName);
$projectName = $xml->dataof('//getProjectResponse/Projects/Project/')->attr->{'ns:projectName'};
$projectId = $xml->dataof('//getProjectResponse/Projects/Project/')->attr->{'ns:projectId'};
$uniqueId = $xml->dataof('//getProjectResponse/Projects/Project/')->attr->{'ns:UniqueId'};

return  $projectId;

}

sub returnCardListFromProjectDetail {

my ($username, $password, $function, $projectName ) = @_;

my $SoapClient = SOAP::Lite
->uri('https://login.swift-kanban.com/axis2/services/MetadataService?wsdl')
->proxy('https://login.swift-kanban.com/axis2/services/MetadataService')
->autotype(0);

my $Security = getHeader($SoapClient, $username, $password);

$projectId = returnProjectIdFromName($username, $password);

my $beamlineName = SOAP::Data->name('getCardListForProjectInput')->type("")->attr({"SOAP-ENV"});
my $runName = SOAP::Data->name("projectId")->value($projectId)->type("");
my $runParam = SOAP::Data->name("userLoginId")->value($username)->type("");

my $xml = $SoapClient->getCardListForProject($Security, $beamlineName, ($runName,$runParam))->body;
#$projectName = $xml->dataof('//getProjectResponse/Projects/Project/')->attr->{'ns:projectName'};
#$projectId = $xml->dataof('//getProjectResponse/Projects/Project/')->attr->{'ns:projectId'};
#$uniqueId = $xml->dataof('//getProjectResponse/Projects/Project/')->attr->{'ns:UniqueId'};

return  Dumper($xml);

}

sub createCardOnProjectName {

my ($username, $password, $function, $projectName ) = @_;

my $SoapClient = SOAP::Lite
->uri('https://login.swift-kanban.com/axis2/services/KanbanCardService?wsdl')
->proxy('https://login.swift-kanban.com/axis2/services/KanbanCardService')
->autotype(0);

my $Security = getHeader($SoapClient, $username, $password);

$projectId = returnProjectIdFromName($username, $password);
$cardType = returnProjectIdFromName($username, $password);

my $beamlineName = SOAP::Data->name('addCardDetails')->type("")->attr({"SOAP-ENV"})->value({
\SOAP::Data->name(projectId => $projectId)->type("")->value('projectId'),
SOAP::Data->name(cardType => $cardType)->type("")->value('projectId'),
SOAP::Data->name(userLoginId => '[email protected]'),
SOAP::Data->name('mode')->type(""),
SOAP::Data->name('fields')->type("")->value({
SOAP::Data->name('field')->type("")->attr("name" )->value('teste de criacao'),
SOAP::Data->name('field')->type("")->attr("cardSize")->value('M'),
SOAP::Data->name('field')->type("")->attr("classOfService")->value('Expedite'),
SOAP::Data->name('field')->type("")->attr("Category")->value('PM'),
SOAP::Data->name('field')->type("")->attr( "currentOwner")->value($username)})});

my $xml = $SoapClient->addCard($Security, $beamlineName)->body;
#$projectName = $xml->dataof('//getProjectResponse/Projects/Project/')->attr->{'ns:projectName'};
#$projectId = $xml->dataof('//getProjectResponse/Projects/Project/')->attr->{'ns:projectId'};
#$uniqueId = $xml->dataof('//getProjectResponse/Projects/Project/')->attr->{'ns:UniqueId'};

return Dumper($xml);

}
1;

index.pl

use strict;
use warnings;
use diagnostics;
use SwiftApiFuncions;
use Data::Dumper;

my $username = "USUARIO";
my $password = "********";

my $index = SwiftApiFuncions->new();

my $result = $index->getSwiftApiResult (
    username => $username,
    password => $password,
    function => 'addCard'
);

print $result;

When I run index.pl I always get an error of type:

  

Element 'SOAP: Data = HASH (0x2f04c64)' can not be allowed in valid XML   message

    
asked by anonymous 17.09.2018 / 14:08

0 answers