简体   繁体   中英

Need Perl SOAP::Transport::HTTP::CGI sanity check

OK, I think there's no easy (make that lazy) way to do what I want but given the Perl SOAP::Transport::HTTP::CGI code fragment below what I am looking to do is intercept all SOAP operation passing through the service and log the result of an operation or fault...

    SOAP::Transport::HTTP::CGI
        -> dispatch_to(
            #first arg needs to be the directory holding the PackageName.pm modules with no trailing "/". The args aftre the first are name of SPECIFIC packages to be loaded as needed by SOAP requests
            #Failure to call out specific moudules below will allow the external SOAP modules to be loaded, but the overall module @INC path for other Perl modules will be blocked for security reasons
            SOAP_MODULE_INCULDE, #name of the directory holding the PackageName.pm modules with no trailing "/"
            "TechnicalMetaDataExtraction", #prod - wrapper for EXIFTool
            "Ingest", #module (package) name
            "ImageManipulation", #module (package) name
            "FacebookBroadcast", #unfinished
            "CompressDecompress", #unfinished
            "ImageOCR", #prod - tesseract
            "HandleDotNet", #prod
            "Pipeline", #prod (needs work)
            "TwitterBroadcast", #prototype
            "Messaging", #prototype but text format email works
            "Property", #development
            "FileManager", #prototype
            "PassThrough" #prod - module to do location conversion (URL -> Fedora Obj+DS, Fedora Obj+DS -> file, URL -> InlineBase64, etc.) but format conversion
        ) #done with the dispacth_to section
        -> on_action(sub {
            #on_action method lets you specify SOAPAction understanding. It acceptsreference to subroutine that takes three parameters: SOAPAction, method_uri and method_name.
            #'SOAPAction' is taken from HTTP header and method_uri and method_name are extracted from request's body. Default behavior is match 'SOAPAction' if present and ignore it otherwise.
            #die SOAP::Data->type('string')->name('debug')->value("Intercepted call, SOAP request='".shift(@_)."'");

            if($Debug) {
                #@_ notes:
                #[0] - "http://www.example.org/PassThrough/NewOperation"
                #[1] - http://www.example.org/PassThrough/
                #[2] - NewOperation
                #[3] - "undefined"
                my %DataHash=(
                    message => @_[0]
                );

                #SendMessageToAMQTopic(localtime()." - ".@_[0]);
                SendDebugMessage(\%DataHash, "info");
            } #there's only one element passed at this level
        }) #end on_action
        #-> on_debug() #not valid for SOAP::Transport::HTTP::CGI
        #-> request() #valid, but does not fire - request method gives you access to HTTP::Request object which you can provide for Server component to handle request.
        #-> response() #does not fire - response method gives you access to HTTP::Response object which you can access to get results from Server component after request was handled.
        #-> options({compress_threshold => 10000}) #causes problems for the JavaScript soap client - removed for the moment
        -> handle() #fires but ignores content in sub - handle method will handle your request. You should provide parameters with request() method, call handle() and get it back with response().
    ;

Initially I thought I could get the information I needed from the "on_action" method, but that only contains the destination of the SOAP call (before it is sent?) and I'm looking for data in the operation result that will be sent back to the SOAP client. The documentation of "SOAP::Transport::HTTP::CGI" is a bit thin and there are few examples online.

Anyone know if this is possible give the what the code above is set up? If not, then the only other option is to alter each method of my SOAP service code modules to include the "SendDebugMessage" function.

I would suggest subclassing SOAP::Transport::HTTP::CGI and hooking into the handle() method. An untested and probably non-working example would be:

package MySoapCGI;
use Data::Dumper;
use SOAP::Transport::HTTP;
use base 'SOAP::Transport::HTTP::CGI';

sub handle {
    my $self = shift;
    $self->SUPER::handle(@_);
    warn Dumper($self->request);
    warn Dumper($self->response);
}

Replace the dumpers with whatever logging you want. You may need to do some XML parsing, because these will be the raw HTTP::Request and HTTP::Response .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM