[Xml-compile] Confusions with XML::Compile::SOAP::Daemon::CGI
and Apache
Patrick Powell
papowell at astart.com
Wed Mar 20 15:24:19 GMT 2013
I have done this on several systems. Let me supply a couple of hints for
dealing with problems that you may encounter.
1. You will want to use non-parsed headers. This means you will need to
use:
.../nph-xxxx.cgi for the name of the script.
Now I have not tried this, but you can probably get the Apache
Rewrite facility
to change index.cgi into nph-index.cgi. In discussions with some
Apache experts
they claim to do this for PHP scripts and it works. YMMV.
2. create the $query object. WARNING: make sure that your $daemon value
actually got created... and that you are using the right one...
And don't forget
to put the directory where your modules are in the lib array:
#!/usr/bin/perl -w
use warnings;
use strict;
use lib qw( /usr/local/..../MY_SOAP_MODULES );
use MySOAPServer qw( $daemon );
if( !$$MySOAPServer::daemon ){
$MySOAPServer::daemon = MySOAPServer::CompileCGIDaemon( ... )
if( !$MySOAPServer::daemon ){
exit with error message to log AND to user
}
}
my $query = CGI->new;
$MySOAPServer::daemon->runCgiRequest( query => $query );
exit 0;
3. There is some discussion in the XML-Compile documentation on using
CGI scripts. If you have problems, then I strongly recommend
starting
with the examples in the documentation. Also, if you need to
add/modify
headers, etc., this is in the documentation as well. Watch out
for Apache.
It is a bit too helpful and I ended up having to use non-parsed
header support
to get the right headers returned.
4. You can run the CGI script from the command line. If you want to
do this
then you will need to supply the parameters. Here is an evil way to
do this.
Edit the nph-index.cgi script and do:
##########
########## NPH START
##########
my $VAR1 = {
'CONTENT_LENGTH' => '0',
'CONTENT_TYPE' => 'text/xml; charset="utf-8"',
'DOCUMENT_ROOT' => '/rmi/htdocs',
'GATEWAY_INTERFACE' => 'CGI/1.1',
'HTTP_CONNECTION' => 'Keep-Alive, TE',
'HTTP_HOST' => 'localhost',
'HTTP_KEEP_ALIVE' => '300',
'HTTP_SOAPACTION' => '"DlRampMeterStatusRequest"',
'HTTP_TE' => 'deflate,gzip;q=0.3',
'HTTP_USER_AGENT' => 'libwww-perl/5.837',
'HTTP_X_LWP_VERSION' => '5.837',
'HTTP_X_XML_COMPILE_CACHE_VERSION' => '0.991',
'HTTP_X_XML_COMPILE_SOAP_VERSION' => '2.25',
'HTTP_X_XML_COMPILE_VERSION' => '1.21',
'HTTP_X_XML_LIBXML_VERSION' => '1.70',
'MOD_PERL' => 'mod_perl/2.0.4',
'MOD_PERL_API_VERSION' => 2,
'PATH' =>
'/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin',
'QUERY_STRING' => '',
'REMOTE_ADDR' => '127.0.0.1',
'REMOTE_PORT' => '31397',
'REQUEST_METHOD' => 'POST',
'REQUEST_URI' => '/TMDD/nph-server.cgi',
'SCRIPT_FILENAME' => '/rmi/htdocs/TMDD/nph-server.cgi',
'SCRIPT_NAME' => '/TMDD/nph-server.cgi',
'SERVER_ADDR' => '127.0.0.1',
'SERVER_ADMIN' => 'webmaster at laptop_81.private',
'SERVER_NAME' => 'localhost',
'SERVER_PORT' => '80',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'SERVER_SIGNATURE' => '',
'SERVER_SOFTWARE' => 'Apache/2.2.17 (FreeBSD) DAV/2 PHP/5.3.5 with
Suhosin-Patch mod_ssl/2.2.17 OpenSSL/0.9.8n mod_perl/2.0.4 Perl/v5.10.1',
'UNIQUE_ID' => 'TwSYpH8AAAEAABeYPrEAAAAE'
};
while( my($k,$v) = each %$VAR1 ){
$ENV{$k} = $v;
}
use CGI;
my $query = CGI->new;
$query->param('POSTDATA',<<'EOF');
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header><wsa:To
xmlns:wsa="http://www.w3.org/2005/08/address
ing">http://tmdd.owner.center.com/c2cxml/</wsa:To><wsa:Action
xmlns:wsa="http://www.w3.org/2005/08/addressing">DlRampMeterStatusRequest</wsa:Action>
</SOAP-ENV:Header><SOAP-ENV:Body><tmdd:deviceInformationRequestMsg
xmlns:tmdd="http://www.ite.org/tmdd"><authentication><user-id>ctoc</user-id></device-information-type></tmdd:deviceInformationRequestMsg></SOAP-ENV:Body></SOAP-ENV:Envelope>
EOF
trace "QUERY " . Dumper($query);
$MySOAPServer::daemon->runCgiRequest( query => $query );
This will set the environment variables so that CGI is happy. You can
then set the SOAP query to be used
by editting the text.
Now you can simply do: perl nph-index.cgi
Add trace/debugging flags, use perl debugger, etc.
4. Once you get the 'basic' nph-index.cgi script working (i.e. - the
basic one in the documentation)
set up Apache to use the script. Then in the script put:
my $query = CGI->new;
{
local $Data::Dumper::Indent = 1;
my $fh = new FileHandle( ">>/tmp/parms");
print $fh "VARS " . Dumper( $ENV ) . "\n"
print $fh "QUERY " . Dumper( $query );
}
## .... generate something
Use: perl client --server=http://...../nph-index.cgi SOAP_METHOD
where SOAP_METHOD is your query you want to make.
Now you have the values for the VAR and POSTDATA.
Good luck. Send me or the list email if you have any problems.
On 03/19/13 10:02, Dan Lyke wrote:
> I got a basic SOAP server working on my internal test environment
> using XML::Compile::SOAP::Daemon::AnyDaemon, but for various reasons
> both our internal ops folks and the external vendor (for key and CA
> management stuff) would prefer Apache.
>
> So I'm trying to move this over to Apache2 with mod_perl.
>
> In my Apache error logs I'm currently seeing:
>
> [Tue Mar 19 09:57:28 2013] [error] [client 64.142.18.31] malformed
> header from script. Bad header=HTTP/1.1 200 Answer included: index.cgi
> [Tue Mar 19 09:57:28 2013] [warn] /index.cgi did not send an HTTP header
>
> My index.cgi looks like:
>
> #!/usr/bin/perl -w
> use warnings;
> use strict;
> use MySOAPServer qw( $daemon );
> $daemon->runCgiRequest( query => $query );
> exit 0;
>
> My Apache directory config looks like:
>
> Options Indexes FollowSymLinks MultiViews
> PerlHandler ModPerl::Registry
> PerlOptions +ParseHeaders
> AddHandler perl-script .cgi
> Options +ExecCGI
> Order allow,deny
> Allow from all
>
> I've been trying to figure out how to redirect a valid SOAP XML request
> file straight to index.cgi without the server in the way, but keep
> getting complaints about content-type .
>
> Anyone got suggestions on how I can debug this?
>
> Thanks.
>
> Dan
>
> _______________________________________________
> Xml-compile mailing list
> Xml-compile at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/xml-compile
>
--
Patrick Powell Astart Technologies
papowell at astart.com 1530 Jamacha Road, Suite X,
Network and System El Cajon, CA 92019
Consulting 858-874-6543
Web Site: www.astart.com FAX 858-357-9931
More information about the Xml-compile
mailing list