Catalyst::Action::SOAP - Action superclass


Catalyst-Controller-SOAP documentation Contained in the Catalyst-Controller-SOAP distribution.

Index


Code Index:

NAME

Top

Catalyst::Action::SOAP - Action superclass

SYNOPSIS

Top

  # not used directly.

DESCRIPTION

Top

This is the superclass used by the Document and the RPC actions.

TODO

Top

Almost all the SOAP protocol is unsupported, only the method dispatching and, optionally, the soap-decoding of the arguments are made.

AUTHORS

Top

Daniel Ruoso <daniel@ruoso.com>

BUG REPORTS

Top

Please submit all bugs regarding Catalyst::Controller::SOAP to bug-catalyst-controller-soap@rt.cpan.org

LICENSE

Top

This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.


Catalyst-Controller-SOAP documentation Contained in the Catalyst-Controller-SOAP distribution.

{ package Catalyst::Action::SOAP;

  use base qw/Catalyst::Action/;
  use XML::LibXML;

  __PACKAGE__->mk_accessors(qw/xml_parser/);

  sub new {
      my $class = shift;
      my $self = $class->SUPER::new(@_);
      $self->xml_parser(XML::LibXML->new());
      return $self;
  }

  sub prepare_soap_helper {
      my ($self, $controller, $c) = @_;
      $c->stash->{soap} = Catalyst::Controller::SOAP::Helper->new();
  }

  sub prepare_soap_xml_post {
      my ($self, $controller, $c) = @_;
      # This should be application/soap+xml, but some clients doesn't seem to respect that.
      if ($c->req->content_type =~ /xml/ &&
          $c->req->method eq 'POST') {
          my $body = $c->req->body;
          my $xml_str = ref $body ? (join '', <$body>) : $body;
          $c->log->debug("Incoming XML: $xml_str") if $c->debug;
          eval {
              $c->stash->{soap}->envelope($xml_str);
              $c->stash->{soap}->parsed_envelope($self->xml_parser->parse_string($xml_str));
          };
          if ($@) {
              $c->stash->{soap}->fault({ code => 'SOAP-ENV:Client', reason => 'Bad XML Message', detail => $@});
          }
      } else {
          $c->stash->{soap}->fault({ code => 'SOAP-ENV:Client', reason => 'Bad content-type/method'});
      }
  }
};

1;

__END__