Loading ...
Sorry, an error occurred while loading the content.

Re: [soaplite] How do I add custom trace callbacks?

Expand Messages
  • Petar Shangov
    Hi, I have tried enabling all traces but that is no what I need. +trace- all gives me this: SOAP::Transport::new: () SOAP::Serializer::new: ()
    Message 1 of 9 , Mar 24, 2009
    • 0 Attachment
      Hi, I have tried enabling all traces but that is no what I need. +trace->'all' gives me this:

      SOAP::Transport::new: ()
      SOAP::Serializer::new: ()
      SOAP::Deserializer::new: ()
      SOAP::Parser::new: ()
      SOAP::Server::new: ()
      SOAP::Transport::HTTP::Server::new: ()
      SOAP::Transport::HTTP::Daemon::new: ()
      Contact to SOAP server at http://localhost:8080/
      SOAP::Server::handle: ()
      SOAP::Deserializer::deserialize: ()
      SOAP::Parser::decode: ()
      SOAP::SOM::new: ()
      SOAP::Data::new: ()
      SOAP::Data::DESTROY: ()
      (eval): HASH(0x145635c) HASH(0x1471264)
      SOAP::Data::new: ()
      SOAP::Server::handle: SOAP::Data=HASH(0x14e7a7c)
      SOAP::Serializer::envelope: ()
      SOAP::Serializer::envelope: get_setResponse SOAP::Data=HASH(0x14e7a7c)
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::SOM::DESTROY: ()

      I need to be able to print out the complete requests and responses, such as:

      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:MyWebServices">
      <soapenv:Header/>
      <soapenv:Body>
      <urn:get_set>
      <parameter>
      ...
      </parameter>
      </urn:get_set>
      </soapenv:Body>
      </soapenv:Envelope>

      Regards,

      Petar



      ----- Original Message ----
      > From: rahed <raherh@...>
      > To: Petar Shangov <pshangov@...>
      > Cc: soaplite@yahoogroups.com
      > Sent: Monday, 23 March, 2009 22:44:30
      > Subject: Re: [soaplite] How do I add custom trace callbacks?
      >
      > Petar Shangov writes:
      >
      > > Hi, I have a SOAP::Lite based server and an need to enable soma
      > > advanced debugging. In particular, I need to print out the full
      > > requests and responses for each call. But I cannot get my callbacks to
      > > get invoked. In my soap server script (currently running in a
      > > development environment with SOAP::Transport::HTTP::Daemon) I have
      > > tried:
      > >
      > > use SOAP::Lite +trace => [debug => sub {print "test!\n";}];
      > >
      > > but nothing happens. I have tried printing to a filehandle as well, but still
      > no result.
      > I simply use
      >
      > use SOAP::Lite +trace=>'all';
      >
      > It's documented in SOAP::Trace.
      >
      > --
      > Radek
      >
      >
      > ------------------------------------
      >
      > Yahoo! Groups Links
      >
      >
      >
    • Petar Shangov
      Hi, Using WinXP, Strawbery Perl 5.10, latest SOAP::Lite from cpan. I am running the daemon script from the command line. Like I said, I tried printing to a
      Message 2 of 9 , Mar 24, 2009
      • 0 Attachment
        Hi,

        Using WinXP, Strawbery Perl 5.10, latest SOAP::Lite from cpan. I am running the daemon script from the command line.

        Like I said, I tried printing to a file as well, just in case STDOUT got redirected somewhere, but that did not work either. I think the problem is with the callback not being invoked at all.



        ----- Original Message ----
        > From: Peter Farr <Peter.Farr@...>
        > To: Petar Shangov <pshangov@...>
        > Sent: Tuesday, 24 March, 2009 16:49:05
        > Subject: Re: How do I add custom trace callbacks?
        >
        > Peter, what environment is this? Unix or Windows? I believe the output will go
        > to stdout so you will have to run your daemon from the command line to see it.
        >
        > --- In soaplite@yahoogroups.com, Petar Shangov wrote:
        > >
        > >
        > > Hi, I have a SOAP::Lite based server and an need to enable soma
        > > advanced debugging. In particular, I need to print out the full
        > > requests and responses for each call. But I cannot get my callbacks to
        > > get invoked. In my soap server script (currently running in a
        > > development environment with SOAP::Transport::HTTP::Daemon) I have
        > > tried:
        > >
        > > use SOAP::Lite +trace => [debug => sub {print "test!\n";}];
        > >
        > > but nothing happens. I have tried printing to a filehandle as well, but still
        > no result.
        > >
        > > Regards,
        > >
        > > Petar
        > >
      • Petar Shangov
        Hi, I have attached a sample test script that produces no output on my machine. Regards, Petar
        Message 3 of 9 , Mar 24, 2009
        • 0 Attachment
          Hi,

          I have attached a sample test script that produces no output on my machine.

          Regards,

          Petar



          ----- Original Message ----
          > From: Peter Farr <Peter.Farr@...>
          > To: Petar Shangov <pshangov@...>
          > Sent: Tuesday, 24 March, 2009 17:41:23
          > Subject: Re: How do I add custom trace callbacks?
          >
          > Peter, if you want to you send me your code and I will try to run it in
          > my Linux environment. I can run it under my debugger and see if I can
          > see what is happening.
          > -
          > Regards,
          >
          > Peter
          >
          > Emancipate yourselves from mental slavery;
          > None but ourselves can free our minds.
          > Bob Marley, Redemption Song
          >
          >
          > On Tue, 2009-03-24 at 08:19 -0700, Petar Shangov wrote:
          > > Hi,
          > >
          > > Using WinXP, Strawbery Perl 5.10, latest SOAP::Lite from cpan. I am running
          > the daemon script from the command line.
          > >
          > > Like I said, I tried printing to a file as well, just in case STDOUT got
          > redirected somewhere, but that did not work either. I think the problem is with
          > the callback not being invoked at all.
          > >
          > >
          > >
          > > ----- Original Message ----
          > > > From: Peter Farr
          > > > To: Petar Shangov
          > > > Sent: Tuesday, 24 March, 2009 16:49:05
          > > > Subject: Re: How do I add custom trace callbacks?
          > > >
          > > > Peter, what environment is this? Unix or Windows? I believe the output will
          > go
          > > > to stdout so you will have to run your daemon from the command line to see
          > it.
          > > >
          > > > --- In soaplite@yahoogroups.com, Petar Shangov wrote:
          > > > >
          > > > >
          > > > > Hi, I have a SOAP::Lite based server and an need to enable soma
          > > > > advanced debugging. In particular, I need to print out the full
          > > > > requests and responses for each call. But I cannot get my callbacks to
          > > > > get invoked. In my soap server script (currently running in a
          > > > > development environment with SOAP::Transport::HTTP::Daemon) I have
          > > > > tried:
          > > > >
          > > > > use SOAP::Lite +trace => [debug => sub {print "test!\n";}];
          > > > >
          > > > > but nothing happens. I have tried printing to a filehandle as well, but
          > still
          > > > no result.
          > > > >
          > > > > Regards,
          > > > >
          > > > > Petar
          > > > >
          > >
        • rahed
          ... Apparently you access your local server. I haven t tried this. When you call a remote host you must get what you want, xml request & response. I guess the
          Message 4 of 9 , Mar 24, 2009
          • 0 Attachment
            Petar Shangov <pshangov@...> writes:

            > Hi, I have tried enabling all traces but that is no what I need. +trace->'all' gives me this:
            >
            > SOAP::Transport::new: ()
            > SOAP::Serializer::new: ()
            > SOAP::Deserializer::new: ()
            > SOAP::Parser::new: ()
            > SOAP::Server::new: ()
            > SOAP::Transport::HTTP::Server::new: ()
            > SOAP::Transport::HTTP::Daemon::new: ()
            > Contact to SOAP server at http://localhost:8080/
            > SOAP::Server::handle: ()
            > SOAP::Deserializer::deserialize: ()
            > SOAP::Parser::decode: ()
            > SOAP::SOM::new: ()
            > SOAP::Data::new: ()
            > SOAP::Data::DESTROY: ()
            > (eval): HASH(0x145635c) HASH(0x1471264)
            > SOAP::Data::new: ()
            > SOAP::Server::handle: SOAP::Data=HASH(0x14e7a7c)
            > SOAP::Serializer::envelope: ()
            > SOAP::Serializer::envelope: get_setResponse SOAP::Data=HASH(0x14e7a7c)
            > SOAP::Data::new: ()
            > SOAP::Data::new: ()
            > SOAP::Data::new: ()
            > SOAP::Data::new: ()
            > SOAP::Data::new: ()
            > SOAP::SOM::DESTROY: ()

            Apparently you access your local server. I haven't tried this. When you
            call a remote host you must get what you want, xml request & response.

            I guess the trace is not enabled for your particular case or the service
            is called wrongly.

            For instance when calling

            $soap = SOAP::Lite->new(
            uri => ("http://www.webserviceX.NET"),
            proxy => ('http://www.webservicex.com/globalweather.asmx' ),
            );

            the trace is like this:

            SOAP::Transport::new: ()
            SOAP::Serializer::new: ()
            SOAP::Deserializer::new: ()
            SOAP::Parser::new: ()
            SOAP::Lite::new: ()
            SOAP::Transport::HTTP::Client::new: ()
            SOAP::Data::new: ()
            SOAP::Lite::call: ()
            SOAP::Serializer::envelope: ()
            SOAP::Serializer::envelope: GetCitiesByCountry SOAP::Data=HASH(0xe91964)
            SOAP::Data::new: ()
            SOAP::Data::new: ()
            SOAP::Data::new: ()
            SOAP::Data::new: ()
            SOAP::Data::new: ()
            SOAP::Transport::HTTP::Client::send_receive: HTTP::Request=HASH(0xea1d14)
            SOAP::Transport::HTTP::Client::send_receive: POST http://www.webservicex.com/globalweather.asmx HTTP/1.1
            Accept: text/xml
            Accept: multipart/*
            Accept: application/soap
            Content-Length: 552
            Content-Type: text/xml; charset=utf-8
            SOAPAction: http://www.webserviceX.NET/GetCitiesByCountry

            <?xml version="1.0" encoding="UTF-8"?>
            <soap:Envelope
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
            xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
            <soap:Body>
            <GetCitiesByCountry xmlns="http://www.webserviceX.NET">
            <CountryName xsi:type="xsd:string">Singapore</CountryName>
            </GetCitiesByCountry>
            </soap:Body>
            </soap:Envelope>
            SOAP::Transport::HTTP::Client::send_receive: HTTP::Response=HASH(0x1091a9c)
            SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 200 OK
            Cache-Control: private, max-age=0
            Date: Tue, 24 Mar 2009 19:36:05 GMT
            Server: Microsoft-IIS/6.0
            Content-Length: 702
            Content-Type: text/xml; charset=utf-8
            Client-Date: Tue, 24 Mar 2009 19:36:13 GMT
            Client-Peer: 209.162.186.60:80
            Client-Response-Num: 1
            X-AspNet-Version: 1.1.4322
            X-Powered-By: ASP.NET

            <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetCitiesByCountryResponse xmlns="http://www.webserviceX.NET"><GetCitiesByCountryResult><NewDataSet>
            <Table>
            <Country>Singapore</Country>
            <City>Singapore / Paya Lebar</City>
            </Table>
            <Table>
            <Country>Singapore</Country>
            <City>Singapore / Changi Airport</City>
            </Table>
            </NewDataSet></GetCitiesByCountryResult></GetCitiesByCountryResponse></soap:Body></soap:Envelope>
            SOAP::Deserializer::deserialize: ()
            SOAP::Parser::decode: ()
            SOAP::SOM::new: ()
            SOAP::SOM::DESTROY: ()
            SOAP::Lite::DESTROY: ()
            SOAP::Serializer::DESTROY: ()
            SOAP::Data::DESTROY: ()
            SOAP::Data::DESTROY: ()
            SOAP::Data::DESTROY: ()
            SOAP::Data::DESTROY: ()
            SOAP::Data::DESTROY: ()
            SOAP::Data::DESTROY: ()
            SOAP::Transport::DESTROY: ()
            SOAP::Transport::HTTP::Client::DESTROY: ()
            SOAP::Deserializer::DESTROY: ()
            SOAP::Parser::DESTROY: ()


            --
            Radek
          • Lee Carmichael
            Hello Petar, You can you be more specific by adding transport layer debugging: use SOAP::Lite +trace = [ transport = sub { print calls to transport for
            Message 5 of 9 , Mar 24, 2009
            • 0 Attachment
              Hello Petar,

              You can you be more specific by adding transport layer debugging:
              use SOAP::Lite +trace => [
              transport => sub { print "calls to transport for request and response\n";
              ];
              It is important to know that this must be defined before any other use SOAP::Lite statement (I'm not sure why but i had troubles with it other places).

              You can create smarter logging subs by doing the following (note: untested and brief):

              use SOAP::Lite +trace => [
              transport => &transport_logger
              ];

              sub transport_logger {
              my $in = shift; # SOAP::Lite pushes in the object its call

              ## only log request and responses
              return unless ref $in =~ /HTTP::(Request|Request)/'

              open my $fh, '>>', 'transport.log' or return;
              printf $fh "%s: %s\n", ref $in, ( $in->content ? $in->content : "N/A" );
              close $fh;

              return;
              }

              You can see more details about how SOAP::Trace works at: http://search.cpan.org/~mkutter/SOAP-Lite-0.710.08/lib/SOAP/Trace.pod
              I have a little write up on this at my blog: http://blog.leecarmichael.com/2009/03/adding-http-requestresponse-logging-to.html

              HTH,

              Lee


              > > Hi, I have a SOAP::Lite based server and an need to enable soma
              > > advanced debugging. In particular, I need to print out the full
              > > requests and responses for each call. But I cannot get my callbacks to
              > > get invoked. In my soap server script (currently running in a
              > > development environment with SOAP::Transport: :HTTP::Daemon) I have
              > > tried:
              > >
              > > use SOAP::Lite +trace => [debug => sub {print "test!\n";}] ;
              > >
              > > but nothing happens. I have tried printing to a filehandle as well, but still
              > no result.
              > I simply use
              >

            • Lee Carmichael
              Hello Petar, After seeing your example, I just realized that you are trying to debug a server. Sorry my last post won t be much help since it seems that
              Message 6 of 9 , Mar 25, 2009
              • 0 Attachment
                Hello Petar,

                After seeing your example, I just realized that you are trying to debug a server. Sorry my last post won't be much help since it seems that transport level debugging is a client only option.

                It seems that most of the server code doesn't have any trace statements besides the empty create/destroy ones (you can see these as SOAP::Trace::trace( '()' ) ).

                You tell what is traceable by looking through the code for SOAP::Trace::<signal>. For example in SOAP::Lite under the package SOAP::Server you can see an entry like:

                    SOAP::Trace::result(@results);

                It seems that you could get information from parameters or results for servers. Which doesn't strike me as terribly helpful.

                I did have an idea that i tested out. Since you said you were trying to debug request and responses, these will get passed to the deserializer and serializer. I was able to write a stub that logs the requests by sub classing the existing deserializer class into one that includes logging.

                Here is an example:

                #!/usr/local/bin/perl5

                use SOAP::Lite +trace => 'all';
                use SOAP::Transport::HTTP;
                use warnings;
                use strict;

                package DebugDS;

                use SOAP::Lite;
                use Data::Dumper qw(Dumper);
                our @ISA =  qw( SOAP::Deserializer ); ## can't use base due to error about deserializer not returning true...

                sub deserialize {
                    SOAP::Trace::trace('()');
                    my $self = shift;

                    SOAP::Trace::trace( $_[0] );

                    return $self->SUPER::deserialize( @_ );
                }

                package main;

                my $daemon;
                my $end_port = 9905;
                my $started = 0;

                foreach (my $port = 9900; $port <= $end_port; $port++ ) {
                    eval {
                        $daemon = SOAP::Transport::HTTP::Daemon
                            -> new( LocalAddr => 'localhost', LocalPort => $port )
                            -> dispatch_to( '../../lib/', 'TestSoap' )
                            -> deserializer( DebugDS->new );
                    };

                    if (!$@) {
                        $started = 1;
                        last;
                    }
                }

                if (! $started ) { die "ERROR: Failed to start webserver: $@\n"; }

                print "Contact to SOAP server at ", $daemon->url, " ($$)\n";

                $daemon->handle;

                exit;
                ------------------------------------------

                I'm sure you could do something similar to SOAP::Transport::HTTP::Daemon by using a sub class to do custom processing of the accept and dumping out the request/response content. Maybe I'll look at that tonight.

                HTH,

                Lee
              • Petar Shangov
                Hi, thanks to everyone who responded. ... rahed, the problem turned out to be that all the relevant tracing calls are made inside SOAP::Transport::HTTP::Client
                Message 7 of 9 , Mar 25, 2009
                • 0 Attachment
                  Hi,

                  thanks to everyone who responded.

                  ----- Original Message ----
                  > From: rahed <raherh@...>
                  > To: Petar Shangov <pshangov@...>
                  > Cc: soaplite@yahoogroups.com
                  > Sent: Tuesday, 24 March, 2009 21:41:48
                  > Subject: Re: [soaplite] How do I add custom trace callbacks?
                  >
                  > Apparently you access your local server. I haven't tried this. When you
                  > call a remote host you must get what you want, xml request & response.
                  >
                  > I guess the trace is not enabled for your particular case or the service
                  > is called wrongly.
                  >
                  > For instance when calling
                  >
                  > $soap = SOAP::Lite->new(
                  > uri => ("http://www.webserviceX.NET"),
                  > proxy => ('http://www.webservicex.com/globalweather.asmx' ),
                  > );
                  >
                  > the trace is like this:
                  >
                  > ...

                  rahed,

                  the problem turned out to be that all the relevant tracing calls are made inside SOAP::Transport::HTTP::Client and so this code does not work when S::L is used as a server, which is my case.



                  ----- Original Message ----
                  > From: Peter Farr <Peter.Farr@...>
                  > To: Petar Shangov <pshangov@...>
                  > Sent: Tuesday, 24 March, 2009 20:43:13
                  > Subject: Re: How do I add custom trace callbacks?
                  >
                  > Peter, I typed this response into the Yahoo group but I haven't seen it
                  > show up yet, so here it is again:
                  >
                  > I can get your daemon to print to a log and to stdout with the following
                  > change:
                  >
                  > use SOAP::Lite +trace => [ all =>
                  > sub {
                  > open LOGFILE,">>trace.log";
                  > print LOGFILE "This:" . $_[0] . "\n";
                  > close LOGFILE;
                  > warn("This:" . $_[0] . "\n");
                  > }
                  >
                  > ];
                  >
                  > When I change "all" to "debug" it stops working, but "transport" (or any
                  > other valid value) works okay. I suspect a conflict between debug and
                  > the SOAP::Transport::HTTP::Daemon code. I don't know what is causing it,
                  > but you could always file a bug and see what happens.

                  Peter,

                  I got this to work, but it still did not print out the request and response strings. The 'debug' option does not work since when used as a server, S::L encounters no calls to SOAP::Trace::debug() during its lifetime. I ended up inserting these calls manually, and submitted a bug report (https://rt.cpan.org/Ticket/Display.html?id=44568).

                  > From: Lee Carmichael <lecar_red@...>
                  > To: Petar Shangov <pshangov@...>; soaplite@yahoogroups.com
                  > Sent: Wednesday, 25 March, 2009 19:37:40
                  > Subject: Re: [soaplite] Re: How do I add custom trace callbacks?
                  >
                  > Hello Petar,
                  >
                  > After seeing your example, I just realized that you
                  are trying to debug a server. Sorry my last post won't be much help
                  since it seems that transport level debugging is a client only option.
                  >
                  > It
                  seems that most of the server code doesn't have any trace statements
                  besides the empty create/destroy ones (you can see these as
                  SOAP::Trace::trace( '()' ) ).
                  >
                  > You tell what is traceable by
                  looking through the code for SOAP::Trace::<signal>. For example
                  in SOAP::Lite under the package SOAP::Server you can see an entry like:
                  >
                  > SOAP::Trace::result(@results);
                  >
                  > It seems that you could get information from parameters or results for servers. Which doesn't strike me as terribly helpful.
                  >
                  > I
                  did have an idea that i tested out. Since you said you were trying to
                  debug request and responses, these will get passed to the deserializer
                  and serializer. I was able to write a stub that logs the requests by
                  sub classing the existing deserializer class into one that includes
                  logging.
                  >
                  > Here is an example:
                  >
                  > ...
                  >
                  > I'm
                  sure you could do something similar to SOAP::Transport::HTTP::Daemon by
                  using a sub class to do custom processing of the accept and dumping out
                  the request/response content. Maybe I'll look at that tonight.

                  Lee,

                  I received your mail just after I had posted a bug report. Your approach is probably safer in the long run since I am now using a locally modified version of S::L.

                  On a side note, I need server debugging since I will be testing my server with various non-perl clients, and it is easier to do my testing on the perl side.


                  Regards,

                  Petar
                Your message has been successfully submitted and would be delivered to recipients shortly.