Apache-Voodoo

 view release on metacpan or  search on metacpan

lib/Apache/Voodoo/Soap.pm  view on Meta::CPAN

				$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));
		}
		elsif ($e->isa("Exception::Class::DBI") && $self->{'engine'}->is_devel_mode()) {
			$self->{'status'} = $self->{'mp'}->server_error;
			$self->_server_fault($self->{'mp'}->server_error, $@->description, {
				"message" => $@->errstr,
				"package" => $@->package,
				"line"    => $@->line,
				"query"   => $@->statement
			});
		}
		elsif ($self->{'engine'}->is_devel_mode()) {
			$self->{'status'} = $self->{'mp'}->server_error;
			$self->_server_fault($self->{'mp'}->server_error, ref($e)?$e->error:"$e");
		}
		else {
			$self->{'status'} = $self->{'mp'}->server_error;
			$self->_server_fault($self->{'mp'}->server_error, "Internal Server Error");
		}
	}

	$self->{'status'} = $self->{'mp'}->ok;
	return $content;
}

sub _client_fault {
	my $self = shift;
	$self->_make_fault('Client',@_);
}

sub _server_fault {
	my $self = shift;
	$self->_make_fault('Server',@_);
}

sub _make_fault {
	my $self = shift;

	my ($t,$c,$s,$d) = @_;

	my %msg;
	if (defined($c)) {
		$msg{'faultcode'} = $t.'.'.$c;
	}
	else {
		$msg{'faultcode'} = $t;
	}

	warn($msg{'faultcode'});
	$msg{'faultstring'} = $s;
	$msg{'faultdetail'} = $d if (defined($d));



( run in 0.858 second using v1.01-cache-2.11-cpan-39bf76dae61 )