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

XML Document to SOM object trouble

Expand Messages
  • killgore9999
    Hello, I was wondering if anyone might be able to offer some insight on my problem. I am writing tests for a perl script which relies on SOAP to send and
    Message 1 of 3 , May 1, 2008
    • 0 Attachment
      Hello, I was wondering if anyone might be able to offer some insight
      on my problem.

      I am writing tests for a perl script which relies on SOAP to send and
      receive data from a server. In an effort to simplify the tests and
      isolate the server from consideration, I am trying to simulate the
      server's xml responses using locally stored xml files rather than
      actually calling the server's methods. In effect, this will allow me
      to feed custom server messages into the script so that I can more
      easily control and analyze the output.

      To do this, I have written a custom perl object with nothing but a
      'call' method. My script will instantiate this object in place of the
      usual SOAP::Lite object. My call method will accept the parameters,
      read the appropriate XML file, and return a SOM object as if the call
      had really gone through to the server.

      My problem is with the creation of this SOM object. According to:
      http://search.cpan.org/~mkutter/SOAP-Lite-0.71.04/lib/SOAP/SOM.pod

      :quote:
      $som = SOAP::SOM->new($message_as_xml);
      As said, the need to actually create an object of this class should be
      very rare. However, if the need arises, the syntax must be followed.
      The single argument to new must be a valid XML document the parser
      will understand as a SOAP response.
      :/quote:

      My case seems to clearly be one of these rare needs. I have tried
      passing just about everything I can think of into this method through
      the $message_as_xml parameter, but I am constantly getting error
      messages such as "Not an ARRAY reference at
      /opt/perl5.6.1/lib/site_perl/5.6.1/SOAP/Lite.pm line 385" and "Can't
      use string ("<?xml version='1.0' encoding='ut") as an ARRAY ref while
      "strict refs" in use at
      /opt/perl5.6.1/lib/site_perl/5.6.1/SOAP/Lite.pm line 385".

      I have tried passing the xml directly as a file, as a string, as a
      number of pre-parsed xml objects, arrays, and others, as well as a
      string representing the file name, and anything else I could think of,
      but there appears to be no information available about what exactly
      this needs to be. I've tried looking at the perl lite code itself to
      get a clue, but I'm afraid I'm not quite good enough of a perl
      programmer to glean any clues.

      Would anyone be able to show me a simple example of how to use this
      method to create a SOM object from a valid XML file? I'd be extremely
      grateful.

      --Mike
    • Joe Hourcle
      ... [trimmed] ... I d inspect what s actually being sent over the wire -- I m guessing that you have an XML declaration inside the SOAP body (ie, your solution
      Message 2 of 3 , May 1, 2008
      • 0 Attachment
        On Thu, 1 May 2008, killgore9999 wrote:

        > Hello, I was wondering if anyone might be able to offer some insight
        > on my problem.
        >
        > I am writing tests for a perl script which relies on SOAP to send and
        > receive data from a server. In an effort to simplify the tests and
        > isolate the server from consideration, I am trying to simulate the
        > server's xml responses using locally stored xml files rather than
        > actually calling the server's methods. In effect, this will allow me
        > to feed custom server messages into the script so that I can more
        > easily control and analyze the output.

        [trimmed]

        > My case seems to clearly be one of these rare needs. I have tried
        > passing just about everything I can think of into this method through
        > the $message_as_xml parameter, but I am constantly getting error
        > messages such as "Not an ARRAY reference at
        > /opt/perl5.6.1/lib/site_perl/5.6.1/SOAP/Lite.pm line 385" and "Can't
        > use string ("<?xml version='1.0' encoding='ut") as an ARRAY ref while
        > "strict refs" in use at
        > /opt/perl5.6.1/lib/site_perl/5.6.1/SOAP/Lite.pm line 385".

        I'd inspect what's actually being sent over the wire -- I'm guessing that
        you have an XML declaration inside the SOAP body (ie, your solution
        resulted in the message having an extra SOAP header applied to it)

        In your case, if you're sending exact messages -- I'd probably skip
        SOAP::Lite entirely for the testing, and just use a plain old CGI script
        and return the test responses.

        -----
        Joe Hourcle
      • Joe Joe
        Thanks Joe for the help -- I was able to solve my problem, it seems that the xml file needs to be deserialized for it to be cast to a SOM object. Instead of
        Message 3 of 3 , May 1, 2008
        • 0 Attachment
          Thanks Joe for the help --

          I was able to solve my problem, it seems that the xml file needs to be deserialized for it to be cast to a SOM object. Instead of SOAP::SOM->new($XML) I should have been using:

              my $result = SOAP::Deserializer->deserialize(<XML>);

          Thanks all

          --Mike

          Joe Hourcle <oneiros@...> wrote:


          On Thu, 1 May 2008, killgore9999 wrote:

          > Hey Joe, thanks for the reply --
          >
          > The xml document that I'm using is as follows:
          >
          >
          >
          > xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
          >
          >
          >
          > xmlns:ns="http://super.cool.host.edu/ServiceV1/service/xsd">
          > 101
          > 102
          > 103
          >
          >
          >
          >
          > As for your CGI script idea, that's definitely another option but I
          > kind of have my heart set on having local files which can be read by
          > my object and returned to the client as if they were live soap messages.


          open (XML, '<', '/path/to/xml/file')
          || die ("Couldn't read file : $!");
          print $appropriate_soap_headers, "\n\n", ;
          close (XML);


          Personally, I store in my test message the full HTTP response (including
          headers, so I don't have to compute content length, etc.), so I just open
          the file and print the contents.

          -----
          Joe Hourcle


          Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.

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