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

RE: [soaplite] Re: Viewing incoming soap envelope and XML - from server side CGI

Expand Messages
  • Maurice McCabe
    If you do not want to modify the code here is another way: This is something like what I had to do: #!/usr/bin/perl use SOAP::Lite; use SOAP::Transport::HTTP ;
    Message 1 of 6 , Dec 8, 2003
    • 0 Attachment
      If you do not want to modify the code here is another way:
       
      This is something like what I had to do:
       
      #!/usr/bin/perl
       
      use SOAP::Lite;
      use SOAP::Transport::HTTP ;
      my $uri = 'mySOAPModule';
      my $deSerializer = LiteralDeserializer->new;

      $daemon = SOAP::Transport::HTTP::CGI
        -> deserializer(LiteralDeserializer->new)
        -> dispatch_to('/usr/local/SOAPmodules');
        -> handle ;
       
      BEGIN {
          package LiteralDeserializer;
          @LiteralDeserializer::ISA = 'SOAP::Deserializer';
          sub deserialize {
          my $self = shift;
       my $result = $self->SUPER::deserialize(@_);
         $result->{_message} = @_[0];
       return $result;
          }
       
      }
      In the mySOAPmodule.pm file:
       
      sub myMethod {
          my $envelope = pop; # envelope is always the last parameter on the parameter list
          my $myMessage = $envelope->{_message};
      }
       
      You can then write this to a file and view etc... (or just write it out from the deserializer, in which case you do not need 'myMethod')
       
      Accessing it from a method is useful because you can then process it as an XML file and extract complex variables, etc... For example:
      Assuming you have sent the following xml snippet like this in your the body of your envelope:
      .
      .
      .
      <myComplexArray>
          <myStruct>
              <StructField1>StructField1Value001</StructField1>
              <StructField2>StructField2Value001</StructField2>
          </myStruct>
          <myStruct>
              <StructField1>StructField1Value002</StructField1>
              <StructField2>StructField2Value002</StructField2>
          </myStruct>
      .
      .
      .
          <myStruct>
              <StructField1>StructField1Value00n</StructField1>
              <StructField2>StructField2Value00n</StructField2>
          </myStruct>
      </myComplexArray>
      .
      .
      .
       
      You can then extract the array using the following:
       
      sub getMyComplexArrayofStructFromPayload {
          my ($_messagel) = @_; # the same '_message' we isolated in the deserializer and retrieved from the envelope in 'myMethod'
          my $d = SOAP::Custom::XML::Deserializer
            -> deserialize($_message)
            -> valueof('//myComplexArray');
          my @myComplexArray;
          my $i;
          foreach my $myStruct ($d->myStruct) {
            $myComplexArray[$i][0] = $myStruct->StructField1;
            $myComplexArray[$i][1] = $myStruct->StructField2;
            $i++;
          }
          return @myComplexArray;
      }
       
      Of course, in general, it is probably better to add a method to your deserializer to deserialize your complex types. It is only a few extra steps, but I have not quite figured that one out yet.
       
      Maurice
      -----Original Message-----
      From: kgoess [mailto:kgoess@...]
      Sent: Monday, December 08, 2003 9:43 AM
      To: soaplite@yahoogroups.com
      Subject: [soaplite] Re: Viewing incoming soap envelope and XML - from server side CGI

      --- In soaplite@yahoogroups.com, "Craig (of course)" <rednivek@a...>
      wrote:
      > Is there a way to write the incoming soap envelope (and XML) to a
      server side file to 
      > make sure that the client is sending what I think it is?  I am not sure
      how to capture 
      > the raw stream or if that is possible...

      See message 3187 in this forum.



      To unsubscribe from this group, send an email to:
      soaplite-unsubscribe@yahoogroups.com



      Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
    • Kevin M. Goess
      ... Nice! Is there a similar way you can get at the outgoing XML from the server to the client? I find it pretty helpful to log the incoming and outgoing XML
      Message 2 of 6 , Dec 8, 2003
      • 0 Attachment
        > If you do not want to modify the code here is another way:

        Nice! Is there a similar way you can get at the outgoing XML from the server
        to the client? I find it pretty helpful to log the incoming and outgoing XML
        on the server. (The patch I posted does that, along with the HTTP headers.)

        --
        Kevin M. Goess
        Software Engineer
        Ensenda, Inc.
      • Maurice McCabe
        I have not done that but I would not be surprised if you could do the equivalent in the Serializer. Here is what my SOAP server loooks like ( I am using a
        Message 3 of 6 , Dec 8, 2003
        • 0 Attachment
          I have not done that but I would not be surprised if you could do the
          equivalent in the Serializer. Here is what my SOAP server loooks like ( I am
          using a LiteralSerializer generously contributed to the group, works with
          .NET, Axis clients, etc...):

          #!/usr/bin/perl

          use SOAP::Lite;

          SOAP::Transport::HTTP::CGI
          -> serializer(LiteralSerializer->new)
          -> deserializer(LiteralDeserializer->new)
          -> dispatch_to('/usr/local/SOAPmodules');
          -> handle ;

          BEGIN {

          package LiteralSerializer;
          @LiteralSerializer::ISA = 'SOAP::Serializer';
          sub xmlize {
          my $self = shift;
          my($name, $attrs, $values, $id) = @{+shift};
          $attrs ||= {};

          # keep only namespace attributes for all elements
          my $a = $attrs->{xmlns} ? {xmlns => $attrs->{xmlns}} : {};

          return $self->SUPER::xmlize([$name, $a, $values, $id]);
          }
          sub envelope {
          $_[2] = (UNIVERSAL::isa($_[2] => 'SOAP::Data') ? $_[2] :
          SOAP::Data->name($_[2])->attr({xmlns => $uri}))
          if $_[1] =~ /^(?:method|response)$/;
          shift->SUPER::envelope(@_);
          }

          package LiteralDeserializer;
          @LiteralDeserializer::ISA = 'SOAP::Deserializer';
          sub deserialize {
          my $self = shift;
          my $result = $self->SUPER::deserialize(@_);
          $result->{_message} = @_[0];
          return $result;
          }

          }


          Somewhere in the LiterSerializer is the outgoing message which can be
          isolated and logged. I think it is $a in xmlize() or $_[1] in envelope().
          Can someone confirm?

          Maurice

          -----Original Message-----
          From: Kevin M. Goess [mailto:kgoess@...]
          Sent: Monday, December 08, 2003 12:28 PM
          To: Maurice McCabe; soaplite@yahoogroups.com
          Subject: Re: [soaplite] Re: Viewing incoming soap envelope and XML -
          from server side CGI


          > If you do not want to modify the code here is another way:

          Nice! Is there a similar way you can get at the outgoing XML from the
          server
          to the client? I find it pretty helpful to log the incoming and outgoing
          XML
          on the server. (The patch I posted does that, along with the HTTP headers.)

          --
          Kevin M. Goess
          Software Engineer
          Ensenda, Inc.
        • jpeyser
          I would like to mention another way of displaying the XML without modifying any code. (Not as sophisticated or flexible as Maurice McCabe s solution [Message
          Message 4 of 6 , Dec 26, 2003
          • 0 Attachment
            I would like to mention another way of displaying the XML without
            modifying any code. (Not as sophisticated or flexible as Maurice
            McCabe's solution [Message 3222]).

            There is a module Debug::Trace (Johan Vromans) on CPAN. It will print
            call and return information for specified subroutines. Since, for a
            SOAP::Lite server, the incoming XML is an argument to the
            SOAP::Deserializer::deserialize routine and the outgoing XML is the
            output of the SOAP::Serializer::envelope routine, Debug::Trace will
            display both.

            Assuming daemon.pl is the server module, the following command will
            print the trace information for the two subroutines.

            perl -MDebug::Trace=":indent(1)",
            SOAP::Serializer::envelope,SOAP::Deserializer::deserialize daemon.pl

            Jonathan

            --- In soaplite@yahoogroups.com, "Maurice McCabe" <mmccabe@o...>
            wrote:
            > If you do not want to modify the code here is another way:
            >
            > This is something like what I had to do:
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.