in reply to Re^7: Soap::lite - https ?
in thread Soap::lite - https ?

I managed to get this code working. I had to modify /site/lib/SOAP/HTTP.pm and change the call to
$self->{_daemon} = HTTP::Daemon::SSL->new(@params) or Carp::croak +"Can't create daemon: $!";
so it would use the SSL version. This is going to make it tough to propagate my code.

Replies are listed 'Best First'.
Re^9: Soap::lite - https ?
by erroneousBollock (Curate) on Aug 16, 2007 at 17:17 UTC
    Excellent, so you have a working HTTPS server. (You can put it on whatever port you wish... 443 is just a convention.)

    Now, you don't want to be changing SOAP or SOAP::Lite for deployment, so the trick is to invert control;
    instead of SOAP::Lite calling HTTP::Daemon, you create a one-shot HTTP::Request handler around SOAP::Lite, and have that handle the request passed to it by HTTP::Daemon::SSL.

    So inside your pre-existing HTTP::Daemon::SSL loop...
    (where you'd normally parse the HTTP request and construct some HTTP response)
    ... firstly, construct an HTTP::Request object:

    # I usually molest $raw_request_string a little here... my $request = HTTP::Request->parse($raw_request_string);
    create a one-off soap handler:
    my $soap = SOAP::Transport::HTTP::Server -> new(YOUR_SOAP_SPECIFIC_ARGS) -> dispatch_to(YOUR_CLASS);
    then feed the request object to the soap handler:
    # and I usually munge headers/SOAPaction here... $soap->request($request);
    dispatch the request to your class via SOAP::Lite:
    $soap->handle();
    finally, pull out the response it built:
    my $response = $soap->response;
    As I implied earlier in this thread, doing it this way gives you more control over the HTTP request life-cycle... which means you can serve more than just SOAP rpc's from the service.

    As an example, you can inspect the request (say before constructing the HTTP::Request object) and determine (based on the URI) whether you want to respond as SOAP rpc, respond with WSDL describing the service, or even respond with HTML explaining how to use the service.

    (In my webservice framework I do all those, plus JSONRPC and some dynamic web content.)

    -David

      Ok. It finally took a complete uninstall/reinstall of Active Perl to fix whatever was up with my system.
      Here's the 'finished' product - for posterity.
      use HTTP::Daemon::SSL; use HTTP::Status; use SOAP::Lite; use SOAP::Transport::HTTP; # my soap package use auth; # Make sure you have a certs/ directory with "server-cert.pem" # and "server-key.pem" in it before running this! my $daemon = HTTP::Daemon::SSL->new(LocalPort => 8001) || die; my $soap = SOAP::Transport::HTTP::Server -> new ( ) -> dispatch_to(qw(auth)); print "Please contact me at: <URL:", $daemon->url, ">\n"; while (my $conn = $daemon->accept()) { while (my $request = $conn->get_request()) { $soap->request($request); $soap->handle(); my $response = $soap->response(); $conn->send_response($response); } $conn->close; undef($conn); }
      This will 'service' my soap requests at https://<server>:8001.

      Thank you very much for your extensive help on this matter. I wouldn't have gotten anywhere without it.
        I have tried to use this code on my linux server and it keeps dieing at the line:
        my $daemon = HTTP::Daemon::SSL->new(LocalPort => 8001) || die;
        I have HTTP::Daemon::SSL installed and I have the pem files in the certs directory.
        Can anyone help me out with getting this working?
        Thanks

        Okay, I got the SSL Soap server working. I had to point the object at the server and cert pem files. When I run a test request though I get the 500 connection refused error.

        Any help is appreciated.