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

Re: [soaplite] Getting HTTP Headers

Expand Messages
  • rjray@blackperl.com
    The SOAP::Lite client object abstracts most of the communication layer away for you, so to get the info you want you would have to subclass one of the relevant
    Message 1 of 6 , Sep 13, 2002
    • 0 Attachment
      The SOAP::Lite client object abstracts most of the communication layer away
      for you, so to get the info you want you would have to subclass one of the
      relevant classes that the client objects use.

      Actually, I'm not sure it can be done at this point, with SOAP::Lite 0.55.
      There is no hook for when the client object gets the response back from the
      LWP::UserAgent side of the object. And sub-classing at the transport level
      isn't really an option, since SOAP::Lite chooses that behind the scenes based
      on the URI you give for an endpoint.

      Paul?

      Randy
      --
      """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
      Randy J. Ray rjray@...
      Campbell, CA rjray@...
      <A HREF="http://www.svsm.org">Silicon Valley Scale Modelers</A>
    • Simon West
      Hi again I have received a way of reading something from the HTTP headers (thanks Jonathan!), using the on_debug event as follows...
      Message 2 of 6 , Sep 13, 2002
      • 0 Attachment
        Hi again

        I have received a way of reading something from the HTTP headers
        (thanks Jonathan!), using the on_debug event as follows...

        VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV

        sub BEGIN {
        package My::Trace;

        sub defaultlog {
        my $caller = (caller(1))[3];
        $caller = (caller(2))[3] if $caller =~ /eval/;
        chomp(my $msg = join ' ', @_);
        ###------------------------
        my @msg = split /\n/, $msg;
        foreach (@msg) {
        chomp;
        if (/Client-Peer/) {
        print "|$_|\n";
        $My::Trace::HdrLine = $_;
        }
        }
        ###------------------------
        #Comment out following line to supress trace/debug.
        printf STDERR "%s: %s\n", $caller, $msg;
        }
        }

        Sub defaultlog (taken from SOAP::Trace) has been modified to search
        for a line that contains 'Client-Peer' (or for whatever you are
        looking in the Header). The line will be loaded into variable
        $My::Trace::HdrLine, which you can parse to get the value.

        The SOAP::Lite object must use this class.

        my $soapObject = SOAP::Lite
        -> service($SERVICE)
        -> on_debug(sub { &My::Trace::defaultlog; } );

        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

        My next question (as is always the case), is how to set one. I'm
        getting the impression that SOAP::Lite might not be the way to go for
        this :-( Pity as it's fantastic for regular SOAP stuff...

        Simon



        --- In soaplite@y..., "Simon West" <simon.west@p...> wrote:
        > Hi all
        >
        > Firstly i'm pretty new to Perl so please bear with me :-)
        >
        > The WebService i'm talking to send an ID as part of the HTTP
        > headers. How do I get this id and then resend it on further
        requests?
        >
        > The code is below (as I said I'm still new to perl...) The service
        > is an ASP.NET address book sample. How would I extend this to read
        a
        > HTTP header when a SOAP reply is returned??????
        >
        >
        > Thanks in advance....
        >
        > Simon
        >
        >
        >
        > use SOAP::Lite;
        >
        > $SERVICE
        >
        = 'http://MSSoapSampleServer:8080/MSSoapSamples/AddrBook/Service/Rpc/I
        > sapiVb/AddrBook.WSDL';
        >
        > sub dumpHash {
        > local($x) = @_;
        > foreach $i (sort keys %$x) {
        > printf "$i : $$x{$i} \n";
        > }
        > }
        >
        > sub dumpArray {
        > local($x) = @_;
        > $i = 0;
        > foreach (@$x) { # Access the entire array.
        > printf "$$x[$i++]\n";
        > }
        > }
        >
        > sub prompt {
        > local($text) = @_;
        > print "\n$text : ";
        > $reply = <STDIN>;
        > chop $reply;
        > return $reply;
        > }
        >
        >
        > sub connectSoap {
        > my $soapObject = SOAP::Lite
        > -> service($SERVICE);
        > return $soapObject;
        > }
        >
        >
        > sub getNames {
        > local($soap) = shift;
        > my $soap_response = $soap
        > -> GetNames();
        > return $soap_response;
        > }
        >
        > sub getAddr {
        > local ($soap) = shift;
        > local ($name) = shift;
        > my $soap_response = $soap
        > -> GetAddr("$name");
        > return $soap_response;
        > }
        >
        > sub printAddr{
        > local ($addr) = shift;
        > print "\nName : $$addr{name}";
        > print "\nStreet : $$addr{street}";
        > print "\nCity : $$addr{city}";
        > print "\nState : $$addr{state}";
        > print "\nZip : $$addr{'zip-code'}";
        >
        > $i = 0;
        > $x = $$addr{'phone-numbers'};
        >
        > foreach (@$x) { # Access the entire array.
        > if ($i == 0) {
        > print "\nPhone# : ";
        > }
        > else {
        > print " : ";
        > }
        > printf "$$x[$i++]\n";
        > }
        > }
        >
        > $connection = connectSoap();
        > #$names = getNames($connection);
        > #dumpArray($names);
        > #$choice = prompt("Select a name");
        > #$addr = getAddr($connection, $choice);
        > $addr = getAddr($connection, "Kim");
        > printAddr($addr);
      • jpeyser
        Actually, sub-classing the transport level is possible and it will give us a hook to the LWP::UserAgent (I should have tried this yesterday). sub BEGIN { use
        Message 3 of 6 , Sep 13, 2002
        • 0 Attachment
          Actually, sub-classing the transport level is possible and it will
          give us a hook to the LWP::UserAgent (I should have tried this
          yesterday).

          sub BEGIN {
          use SOAP::Lite;
          use SOAP::Transport::HTTP;

          package My::Transport;

          @ISA = qw(SOAP::Transport);

          package My::Transport::HTTP::Client;

          @ISA = qw(SOAP::Transport::HTTP::Client);

          sub send_receive {

          ### Copy code from Transport/HTTP.pm, replacing $resp
          ### with $My::Transport::HTTP::Client::resp.

          }

          } #end BEGIN


          my $soapObject = SOAP::Lite
          -> service($SERVICE)
          -> transport(My::Transport->new);

          ### Now we have access to the HTTP headers
          print $My::Transport::HTTP::Client::resp->content_type, "\n";

          Jonathan

          --- In soaplite@y..., rjray@b... wrote:
          > The SOAP::Lite client object abstracts most of the communication
          layer away
          > for you, so to get the info you want you would have to subclass one
          of the
          > relevant classes that the client objects use.
          >
          > Actually, I'm not sure it can be done at this point, with
          SOAP::Lite 0.55.
          > There is no hook for when the client object gets the response back
          from the
          > LWP::UserAgent side of the object. And sub-classing at the
          transport level
          > isn't really an option, since SOAP::Lite chooses that behind the
          scenes based
          > on the URI you give for an endpoint.
          >
          > Paul?
          >
          > Randy
          > --
          > """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
          """""""""""
          > Randy J. Ray
          rjray@b...
          > Campbell, CA
          rjray@s...
          > <A HREF="http://www.svsm.org">Silicon Valley Scale Modelers</A>
        • Paul Kulchenko
          Hi Simon, ... As always, there is little bit easier way (idea grabbed from examples in cookbook: http://cookbook.soaplite.com/): use SOAP::Lite +trace =
          Message 4 of 6 , Sep 13, 2002
          • 0 Attachment
            Hi Simon,

            --- Simon West <simon.west@...> wrote:
            > I have received a way of reading something from the HTTP headers
            > (thanks Jonathan!), using the on_debug event as follows...
            As always, there is little bit easier way (idea grabbed from examples
            in cookbook: http://cookbook.soaplite.com/):

            use SOAP::Lite +trace =>
            [transport => sub {
            our $header;
            $header = $_[0]->header('Client-Peer') if
            $_[0]->isa('HTTP::Response');
            $_[0]->header('Client-Peer', $header) if $header &&
            $_[0]->isa('HTTP::Request');
            }]
            ;

            > My next question (as is always the case), is how to set one. I'm
            > getting the impression that SOAP::Lite might not be the way to go
            > for
            > this :-( Pity as it's fantastic for regular SOAP stuff...
            This code will work for both, getting and setting headers. Let me
            know if that's not what you want ;)

            Best wishes, Paul.


            __________________________________________________
            Do you Yahoo!?
            Yahoo! News - Today's headlines
            http://news.yahoo.com
          • rjray@blackperl.com
            Actually, I had forgotten to look at the on_debug angle. That s probably the easiest way, certainly easier than creating two different sub-classes (though that
            Message 5 of 6 , Sep 13, 2002
            • 0 Attachment
              Actually, I had forgotten to look at the on_debug angle. That's probably the
              easiest way, certainly easier than creating two different sub-classes (though
              that one is more extensible). It is harder to get ones hands into the client
              side of things than on the server side. I have examples in the book that show
              sub-classing the server classes to get access to the HTTP headers, but nothing
              like that for the clients.

              Randy
              --
              """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
              Randy J. Ray rjray@...
              Campbell, CA rjray@...
              <A HREF="http://www.svsm.org">Silicon Valley Scale Modelers</A>
            Your message has been successfully submitted and would be delivered to recipients shortly.