Posts

Showing posts with the label soap::lite

3 ways to disable auto typing in SOAP::Lite client

Often SOAP::Lite will try to autotype a parameter in a request and it does it wrongly (or correctly) causing the SOAP server to fail badly (for so many reasons). SOAP::Lite provides three ways to disable this typing. Two of the ways work at the client object level and the other does it at the SOAP::Data object level. Client Level The following options disable autotyping for all data items in a request: autotype method. After creating a SOAP::Lite client you can disable autotyping by $soapclient->autotype(0) . Example: my $soap = SOAP::Lite->uri($xmlns)->proxy($proxy) ->on_action( sub {"$action?type=$reqname&ns=$xmlns"} ); $soap->autotype(0); Overriding the typelookup method. You can override the typelookup to run undef/false/etc. Example: sub typelookup { return undef; } Data object SOAP::Data object provide a type method. This allows manually typing of the object. When this is set to an empty string no type is set nor is it autotyped by serializer. No...

Adding http request/response logging to SOAP::Lite

Sometimes I just want to save the xml versions of the SOAP requests and responses (generally to share with someone else). The SOAP::Lite perldoc page points to using SOAP::Trace . It has lots of good stuff but its a bit heavy. And in my case, I'm trying to figure out how to log response and requests over http so the following will hopefully help simplify my next search. :) here is my approach, first the code (all good things start in code :) : package SOAP::HTTP::Logging; use warnings; use strict; use Exporter; our @EXPORT = qw( enable_logging disable_logging soap_log_file log_message ); our $logfile; our $logboth = 0; our $log_request = 0; our $log_response = 0; # setup global options sub enable_logging { $log_request = $log_response = 1; } sub disable_logging { $log_request = $log_response = 0; } sub soap_log_file { $logfile = shift if @_; return $logfile; } # logging sub sub log_message { my $in = shift; # SOAP::Lite pushes in the object its called on # only log ...

SOAP::Lite and Test::MockModule

Intro As part of a project to convert an existing SOAP client library over to a new version of calls, I found that I needed a way to test potential faults and new data formats without requiring live calls. After I built it for the new stuff, I used it to test existing calls and errors as well. This code was running live for several years before I needed to change it for the new version, this inspired me to be very careful and invest in testing. On a side note, I found plenty of bugs just creating the test suite in the existing code that had been there for years. Creating the Test Suite To create the test suite, I needed to pretend to get SOAP server responses. I turned to Test::MockModule to step in and provide hooks to return them. I found that mocking these responses were pretty straightforward once I figured out how to use the SOAP::Lite deserializer. (like most things, its easy once you know how) The following outlines what I did to create the suite, well at least the process of u...