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

1206Re: [soaplite] Re: Using SOAP::Transport::IO::Server to process request

Expand Messages
  • ian c rogers
    Feb 1, 2002
    • 0 Attachment
      > If you have file or stream you can use SOAP::Transport::IO to handle
      > that. If you have HTTP, you can use SOAP::Transport::HTTP::* module
      > to handle that. If you use combination of those and want to handle
      > transport level yourself, you can use SOAP::Server to handle payload:

      SOAP::Server got me much further, but I'm still having sporadic results.

      Let me explain in a bit more detail what I'm trying to do, as I feel I might
      be approaching this the wrong way. I have a simple program that has a
      simple (forking) HTTP server within it. The HTTP server may be called upon
      to serve a few specific files, or it may receive a SOAP request. I handle
      either by reading in the HTTP header like so:

      # Read HTTP header info
      LINE: while ( $buf = <CLIENT> ) {
      chomp( $buf );
      last LINE if ( length( $buf ) == 1 );
      $some_data .= "$buf\n";
      }

      and then serve the file if I see /^GET (\/.+txt) HTTP/ or handle the SOAP
      if I see /^POST \/SOAPONAROPE HTTP/. Here's how I'm handling the SOAP now:

      $request_xml = "";
      LINE: while ( recv( CLIENT, $buf, 1, 0 ) ) {
      $request_xml .= $buf;
      last LINE if ( $request_xml =~ /<\/SOAP-ENV:Envelope>/ ||
      $request_xml eq "" );
      }
      $response_xml = SOAP::Server
      ->dispatch_to( 'TestPackage' )
      ->handle($request_xml);

      print CLIENT "HTTP/1.1 200 OK\n";
      print CLIENT "Content-Type: text/xml\n\n";
      print CLIENT "$response_xml\n";

      is simply:

      package TestPackage;

      sub test_routine {
      my ( $self, $email, $password, $XML ) = @_;

      return "AW YEAH!\n";
      }

      And the soap_client.pl is:

      $soap_uri = "http://localhost/TestPackage";
      $soap_proxy = "http://localhost/SOAPONAROPE";
      print "calling test_routine via $soap_proxy: ";
      print SOAP::Lite # fix tags
      -> uri($soap_uri)
      -> proxy($soap_proxy)
      -> test_routine( $email, $password, $XML )
      -> result . "\n";
      exit;

      Sample output:

      $ ./soap_client.pl
      calling test_routine via http://localhost/SOAPONAROPE: AW YEAH!

      $ ./soap_client.pl
      calling test_routine via http://localhost/SOAPONAROPE: AW YEAH!

      $ ./soap_client.pl
      calling test_routine via http://localhost/SOAPONAROPE: AW YEAH!

      $ ./soap_client.pl
      calling test_routine via http://localhost/SOAPONAROPE: AW YEAH!

      $ ./soap_client.pl
      calling test_routine via http://localhost/SOAPONAROPE: 500 read timeout
      at ./soap_client.pl line 30
      $ ./soap_client.pl
      calling test_routine via http://localhost/SOAPONAROPE: AW YEAH!

      $ ./soap_client.pl
      calling test_routine via http://localhost/SOAPONAROPE: AW YEAH!

      On the timeout run, the header info is read, but the server blocks forever
      on the recv() at LINE. I've added some code to take a look at the socket to
      see if there's any data to be read there, and as you might guess, sometimes
      there isn't (which avoids the timeout but not the larger problem). Why not?

      Clearly I'm no whiz at handling the transport myself and I'd prefer not to.
      Is there another way in my case? If not, suggestions? Any idea why my
      soap_client.pl would be sending header only then blocking sometimes? What
      other factors might be to blame?

      Thanks again for your help. Sorry for the delay in follow-up, I had minor
      surgery Weds am. :)

      ian
    • Show all 5 messages in this topic