Apache-Voodoo
view release on metacpan or search on metacpan
lib/Apache/Voodoo/Soap.pm view on Meta::CPAN
my $m = ref($self->{'engine'}->_app->{'controllers'}->{$uri});
if ($m eq "Apache::Voodoo::Loader::Dynamic") {
$m = ref($self->{'engine'}->_app->{'controllers'}->{$uri}->{'object'});
}
# FIXME here ends the hackery
my $wsdl;
eval {
# FIXME the other part of the Pod::WSDL version hack
$wsdl = $PWSDL->new(
source => $m,
location => $self->{'mp'}->server_url().$uri,
pretty => 1,
withDocumentation => 1
);
$wsdl->targetNS($self->{'mp'}->server_url());
};
if ($@) {
$self->{'mp'}->content_type('text/plain');
my $s = "Error generating WSDL:\n\n$@";
$s =~ s/\cJ/\n/g;
$self->{'mp'}->print($s);
}
else {
$self->{'mp'}->content_type('text/xml');
$self->{'mp'}->print($wsdl->WSDL);
}
$self->{'mp'}->flush();
$return = $self->{'mp'}->ok;
}
else {
$return = $self->{'soap'}->handle($r);
}
$self->{'engine'}->status($self->{'status'});
return $self->{'status'};
}
sub handle_request {
my $self = shift;
my @params = @_;
my $params = {};
my $c=0;
foreach (@params) {
$_ = unbless($_) if $self->{'engine'}->{'config'}->{'soap_unbless'};
if (ref($_) eq "HASH") {
while (my ($k,$v) = each %{$_}) {
$params->{$k} = $v;
}
}
$params->{'ARGV'}->[$c] = $_;
$c++;
}
my $uri = $self->{'mp'}->uri();
my $filename = $self->{'mp'}->filename();
# if the SOAP endpoint happens to overlap with a directory name
# libapr "helpfully" appends a / to the end of the uri and filenames.
$uri =~ s/\/$//;
$filename =~ s/\/$//;
$filename =~ s/\.tmpl$//;
unless ($self->{'run'}->{'method'} eq 'handle') {
$filename =~ s/([\w_]+)$/$self->{'run'}->{'method'}_$1/i;
$uri =~ s/([\w_]+)$/$self->{'run'}->{'method'}_$1/i;
}
unless (-e "$filename.tmpl" &&
-r "$filename.tmpl") {
$self->{'status'} = $self->{'mp'}->not_found();
$self->_client_fault($self->{'mp'}->not_found(),'No such service:'.$filename);
};
my $content;
eval {
$self->{'engine'}->begin_run();
$content = $self->{'engine'}->execute_controllers($uri,$params);
};
if (my $e = Exception::Class->caught()) {
if ($e->isa("Apache::Voodoo::Exception::Application::Redirect")) {
$self->{'status'} = $self->{'mp'}->redirect;
$self->_client_fault($self->{'mp'}->redirect,"Redirected",$e->target);
}
elsif ($e->isa("Apache::Voodoo::Exception::Application::DisplayError")) {
# apparently OK doesn't return 200 anymore, it returns 0. When used in conjunction
# with a SOAP fault that lets the server default it to 500, which isn't what we want.
# The server didn't have an internal error, we just didn't like what the client sent.
$self->{'status'} = 200;
$self->_client_fault($e->code, $e->error, $e->detail);
}
elsif ($e->isa("Apache::Voodoo::Exception::Application::AccessDenied")) {
$self->{'status'} = $self->{'mp'}->forbidden;
$self->_client_fault($self->{'mp'}->forbidden, $e->error, $e->detail);
}
elsif ($e->isa("Apache::Voodoo::Exception::Application::RawData")) {
$self->{'status'} = $self->{'mp'}->ok;
return {
'error' => 0,
'success' => 1,
'rawdata' => 1,
'content-type' => $e->content_type,
'headers' => $e->headers,
'data' => $e->data
};
}
elsif ($e->isa("Apache::Voodoo::Exception::Application::SessionTimeout")) {
$self->{'status'} = $self->{'mp'}->ok;
$self->_client_fault(700, $e->error, $e->target);
}
elsif ($e->isa("Apache::Voodoo::Exception::RunTime") && $self->{'engine'}->is_devel_mode()) {
# Apache::Voodoo::Exception::RunTime
# Apache::Voodoo::Exception::RunTime::BadCommand
# Apache::Voodoo::Exception::RunTime::BadReturn
$self->{'status'} = $self->{'mp'}->server_error;
$self->_server_fault($self->{'mp'}->server_error, $e->error, Apache::Voodoo::Exception::parse_stack_trace($e->trace));
}
( run in 1.428 second using v1.01-cache-2.11-cpan-7fcb06a456a )