3 Replies Latest reply on Dec 2, 2013 6:38 PM by Bill Robinson

    REST POST Method help - deploy job executeAgainstServers

      I'm trying to POST against this URI /id/SystemObject/Job/Patching%20Job/AixPatchingJob/ce8cc016-5d8d-4add-9e63-73180f1521b0/Operations/executeAgainstServers using PERL LWP.

       

      I'm attempting the example from BL Webservices document page 59-61.

      I'm having a hard time formatting the POST data for OperationArguments below

      name:servers

      type:/type/PropertySetClasses/SystemObject/Server

      uris: /id/SystemObject/Server/c3fdea41-527e-4ca9-9072-52378cafaff5

       

      Here's a snippet of my PERL code.

       

      my ( $name, $type, $uri );

      $name = "servers";

      $type = qq(/type/PropertySetClasses/SystemObject/Server);

      $uri = &get_server_uri;

      my $sess = &bl_login();  

      my $job_uri = &get_job_uri();

                 

      my $blhost = "https://test-bladelogic:9843";

      my $bl_url = "$blhost$job_uri/Operations/executeAgainstServers";

      my $browser = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 } , 'Conten-Type' => 'text/xml');

      $browser->default_header( 'SessionId' => "$sess" );  #pass sessionID to HTTP header

      $browser->header( 'Content-Type' => 'application/xml' );

      my $response = $browser->post ( "$bl_url" ,

                                                         [ 'name' => $name,

                                                          'type' => $type,

                                                           'uris' => $uri

                                                           ],

                                                          );           

      print $response->error_as_HTML unless $response->is_success;

      my $content = $response->decoded_content();

      print $content;

       

      I'm getting this error

      HTTP/1.1 200 OK

      Server: Apache-Coyote/1.1

      Content-Type: text/xml

      Transfer-Encoding: chunked

      Date: Mon, 28 Oct 2013 19:57:44 GMT

       

      <?xml version='1.0' encoding='UTF-8'?><RESTXMLResponse><ErrorResponse><Error>Unable to parse operation arguments : Input REST Request XML does not comply with the schema (line 1, column 1). Message: Content is not allowed in prolog.</Error></ErrorResponse></RESTXMLResponse>

        • 1. Re: REST POST Method help - deploy job executeAgainstServers
          Bill Robinson

          i'm using soap, not rest and this works..

           

          i'm not sure you can do 'executeAgainst' w/ rest.

           

          #!/usr/bin/perl -w

          use strict;

           

          use IO::Handle;

          use SOAP::Lite;

          use LWP::UserAgent;

          use MIME::Base64;

           

          print "BMC Web Services Tunnel\n";

          if( $#ARGV < 2)

          {

              die "Not enough arguments: expecting server login-name password";

          }

           

          my $server = shift @ARGV;

          my $username = shift @ARGV;

          my $password = shift @ARGV;

          my $role = shift @ARGV;

          BEGIN { $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0 }

           

          print "Per Web Services Client Test.  Server: ${server}, user=${username}\n";

          print "Name: $username\n";

           

          my $sessionId = login($username, $password, "SRP");

           

          my @returnValue;

          my $jobStatus = "NONE";

          @returnValue = assumeRole($role);

           

          @returnValue = executeCommandByParamList("DeployJob", "getDBKeyByGroupAndName","/Workspace/Test","deploy12");

          my $jobKey = $returnValue[0];

          print "JobKey: $jobKey\n";

           

          @returnValue = executeCommandByParamList("Job","executeAgainstServers",$jobKey,"blapp82-red5.demodrive.com,blprov01-82,red5-82");

          my $schId = $returnValue[0];

          print "Schedule Id: $schId\n";

           

          # login (username, password, authenticationMethod )

          sub login {

              my $username = shift @_;

              my $password = shift @_;

              my $authenticationMethod = shift @_;

           

              my $loginEndpoint = "https://${server}:9843/services/LoginService";

              my $loginSoapaction = "bladelogicNamespace:loginUsingUserCredential";

              my $loginMethod = "loginUsingUserCredential";

              my $loginNamespace = 'http://bladelogic.com/webservices/skeleton/login';

              my $loginService = SOAP::Lite->new(uri => $loginSoapaction, proxy => $loginEndpoint) ;

              my $loginResult;

           

              eval {

                  $loginResult = $loginService->call(

                  SOAP::Data->name($loginMethod)->attr( { xmlns => $loginNamespace } ),

                  SOAP::Data->name( userName => $username),

                  SOAP::Data->name( password => $password),

                  SOAP::Data->name( authenticationType => $authenticationMethod)

                  );

              };

              if ($@) {

                  print "SOAP exception during login: " . $@ . "\n";

                  return undef;

              }

           

              my $sessionId = 0;

           

              if ($loginResult->fault) {

                  printf "A fault (%s) occurred: %s\n",

                      $loginResult->faultcode, $loginResult->faultstring;

              } else {

                  $sessionId = $loginResult->valueof('//loginUsingUserCredentialResponse/returnSessionId');

              }

              return $sessionId;

          }

           

          sub assumeRole {

           

              my $role = shift @_;

           

              my $cmdEndpoint = "https://${server}:9843/services/AssumeRoleService";

              my $cmdSoapaction = "bladelogicNamespace:assumeRole";

              my $cmdMethod = "assumeRole";

              my $cmdNamespace = "http://bladelogic.com/webservices/skeleton/assumerole";

              my $cmdService = SOAP::Lite->new(uri => $cmdSoapaction, proxy => $cmdEndpoint) ;

           

             my @headers =

                  (SOAP::Header->name("sessionId")->value($sessionId)->uri("http://bladelogic.com/webservices/framework/xsd")->prefix("ns1"));

           

              my $cmdResponse;

              eval {

                  $cmdResponse = $cmdService->call(

                  SOAP::Data->name($cmdMethod)->attr( { 'xmlns:ns1' => $cmdNamespace } )->prefix('ns1'),

                  SOAP::Data->name(roleName => $role)->prefix('ns1'),

                  @headers

                  );

              };

          }

           

          sub executeCommandByParamList {

           

              my $nameSpace = shift @_;

              my $commandName = shift @_;

              my @commandArgs = @_;

           

              my $cmdEndpoint = "https://${server}:9843/services/CLITunnelService";

              my $cmdSoapaction = "bladelogicNamespace:executeCommandByParamList";

              my $cmdMethod = "executeCommandByParamList";

              my $cmdNamespace = "http://bladelogic.com/webservices/skeleton/clitunnel";

              my $cmdService = SOAP::Lite->new(uri => $cmdSoapaction, proxy => $cmdEndpoint) ;

           

              # Session header

              my @headers =

                  (SOAP::Header->name("sessionId")->value($sessionId)->uri("http://bladelogic.com/webservices/framework/xsd")->prefix("ns1"));

           

              my $cmdResponse;

              eval {

                  my @argumentList;

                  my $commandArg;

                  push @argumentList,  SOAP::Data->name($cmdMethod)->attr( { 'xmlns:ns6' => $cmdNamespace} )->prefix('ns6');

                  push @argumentList,  SOAP::Data->name(nameSpace => $nameSpace)->prefix('ns6');

                  push @argumentList,  SOAP::Data->name(commandName => $commandName)->prefix('ns6');

                  foreach $commandArg (@commandArgs) {

                     push @argumentList, SOAP::Data->name(commandArguments => $commandArg)->prefix('ns6');

                  }

                  push @argumentList, @headers;

                  $cmdResponse = $cmdService->call(@argumentList);

              };

              if ($@) {

                  print "SOAP exception during $cmdSoapaction $nameSpace $commandName: " . $@ . "\n";

                  return undef;

              }

           

              if ($cmdResponse->fault) {

                  printf "A fault (%s) occurred: %s\n",

                      $cmdResponse->faultcode, $cmdResponse->faultstring;

              } else {

                  @returnValue = $cmdResponse->valueof('//executeCommandByParamListResponse/return/returnValue');

              }

          }

          • 2. Re: REST POST Method help - deploy job executeAgainstServers

            Thanks Bill for the PERL code.  I actually downloaded your deploy job examples before I opened this disccussion.  I was trying to get some pointers from your PERL code for REST command arguments.

            Can you please confirm if "executeAgainstServers" doesnt work in REST.  That command was used as an example for deploying jobs using REST in the webservices pdf page 60

             

            Also, do you know if  there is an example XML format that I can refer to when performing a POST deploy job.  In other REST clients that I've written in PERL, I would slurp an XML file update the contents and then POST the updated XML to the application.

             

            Thanks,

            Ray

            • 3. Re: REST POST Method help - deploy job executeAgainstServers
              Bill Robinson

              I don't think the executeAgainst works in rest.  i'd look at using soapui and loading up the wsdl to get the proper xml format for each request.