[Catalyst-commits] r7619 - in
Catalyst-Controller-SOAP/1.0/trunk/lib/Catalyst: Action
Action/SOAP Controller
ruoso at dev.catalyst.perl.org
ruoso at dev.catalyst.perl.org
Thu Apr 17 14:02:47 BST 2008
Author: ruoso
Date: 2008-04-17 14:02:47 +0100 (Thu, 17 Apr 2008)
New Revision: 7619
Modified:
Catalyst-Controller-SOAP/1.0/trunk/lib/Catalyst/Action/SOAP.pm
Catalyst-Controller-SOAP/1.0/trunk/lib/Catalyst/Action/SOAP/DocumentLiteral.pm
Catalyst-Controller-SOAP/1.0/trunk/lib/Catalyst/Action/SOAP/RPCEndpoint.pm
Catalyst-Controller-SOAP/1.0/trunk/lib/Catalyst/Controller/SOAP.pm
Log:
[C-C-SOAP] Now generates SOAP1.1 fault messages. It was generating SOAP1.2 even in the SOAP1.1 namespace.
Modified: Catalyst-Controller-SOAP/1.0/trunk/lib/Catalyst/Action/SOAP/DocumentLiteral.pm
===================================================================
--- Catalyst-Controller-SOAP/1.0/trunk/lib/Catalyst/Action/SOAP/DocumentLiteral.pm 2008-04-17 11:07:36 UTC (rev 7618)
+++ Catalyst-Controller-SOAP/1.0/trunk/lib/Catalyst/Action/SOAP/DocumentLiteral.pm 2008-04-17 13:02:47 UTC (rev 7619)
@@ -22,9 +22,9 @@
};
if ($@) {
$c->stash->{soap}->fault
- ({ code => [ 'env:Sender' => 'env:Body' ],
+ ({ code => 'Client',
reason => 'Bad Body', detail =>
- 'Schema validation on the body failed.'});
+ 'Schema validation on the body failed: '.$@});
} else {
$self->NEXT::execute($controller, $c, $body);
}
Modified: Catalyst-Controller-SOAP/1.0/trunk/lib/Catalyst/Action/SOAP/RPCEndpoint.pm
===================================================================
--- Catalyst-Controller-SOAP/1.0/trunk/lib/Catalyst/Action/SOAP/RPCEndpoint.pm 2008-04-17 11:07:36 UTC (rev 7618)
+++ Catalyst-Controller-SOAP/1.0/trunk/lib/Catalyst/Action/SOAP/RPCEndpoint.pm 2008-04-17 13:02:47 UTC (rev 7619)
@@ -18,7 +18,7 @@
my @children = grep { UNIVERSAL::isa( $_, 'XML::LibXML::Element') } $body->getChildNodes();
if (scalar @children != 1) {
$c->stash->{soap}->fault
- ({ code => [ 'env:Sender' => 'env:Body' ],
+ ({ code => 'Client',
reason => 'Bad Body', detail =>
'RPC messages should contain only one element inside body'})
} else {
@@ -41,16 +41,16 @@
};
if ($@) {
$c->stash->{soap}->fault
- ({ code => [ 'env:Sender' => 'env:Body' ],
+ ({ code => 'Client',
reason => 'Bad Body', detail =>
- 'Malformed parts on the message body'});
+ 'Malformed parts on the message body: '.$@});
} else {
my $action = $controller->action_for($operation);
if (!$action ||
!grep { /RPC(Encoded|Literal)/ } @{$action->attributes->{ActionClass}}) {
$c->stash->{soap}->fault
- ({ code => [ 'env:Sender' => 'env:Body' ],
+ ({ code => 'Client',
reason => 'Bad Operation', detail =>
'Invalid Operation'});
} else {
Modified: Catalyst-Controller-SOAP/1.0/trunk/lib/Catalyst/Action/SOAP.pm
===================================================================
--- Catalyst-Controller-SOAP/1.0/trunk/lib/Catalyst/Action/SOAP.pm 2008-04-17 11:07:36 UTC (rev 7618)
+++ Catalyst-Controller-SOAP/1.0/trunk/lib/Catalyst/Action/SOAP.pm 2008-04-17 13:02:47 UTC (rev 7619)
@@ -29,10 +29,10 @@
$c->stash->{soap}->parsed_envelope($self->xml_parser->parse_string($xml_str));
};
if ($@) {
- $c->stash->{soap}->fault({ code => 'env:Sender', reason => 'Bad XML Message', detail => $@});
+ $c->stash->{soap}->fault({ code => 'Client', reason => 'Bad XML Message', detail => $@});
}
} else {
- $c->stash->{soap}->fault({ code => 'env:Sender', reason => 'Bad content-type/method'});
+ $c->stash->{soap}->fault({ code => 'Client', reason => 'Bad content-type/method'});
}
}
};
Modified: Catalyst-Controller-SOAP/1.0/trunk/lib/Catalyst/Controller/SOAP.pm
===================================================================
--- Catalyst-Controller-SOAP/1.0/trunk/lib/Catalyst/Controller/SOAP.pm 2008-04-17 11:07:36 UTC (rev 7618)
+++ Catalyst-Controller-SOAP/1.0/trunk/lib/Catalyst/Controller/SOAP.pm 2008-04-17 13:02:47 UTC (rev 7619)
@@ -225,7 +225,7 @@
if (scalar @{$c->error}) {
$c->stash->{soap}->fault
- ({ code => [ 'env:Sender' ],
+ ({ code => 'Client',
reason => 'Unexpected Error', detail =>
'Unexpected error in the application: '.(join "\n", @{$c->error} ).'!'});
$c->error(0);
@@ -235,45 +235,54 @@
my $response = XML::LibXML->createDocument();
my $envelope = $response->createElementNS
- ($namespace,"Envelope");
+ ($namespace,"SOAPENV:Envelope");
$response->setDocumentElement($envelope);
# TODO: we don't support header generation in response yet.
my $body = $response->createElementNS
- ($namespace,"Body");
+ ($namespace,"SOAPENV:Body");
$envelope->appendChild($body);
if ($soap->fault) {
my $fault = $response->createElementNS
- ($namespace, "Fault");
+ ($namespace, "SOAPENV:Fault");
$body->appendChild($fault);
my $code = $response->createElementNS
- ($namespace, "Code");
+ ($namespace, "SOAPENV:faultcode");
$fault->appendChild($code);
+ my $codestr = $soap->fault->{code};
+ if (my ($ns, $val) = $codestr =~ m/^\{(.+)\}(.+)$/) {
+ my $prefix = $code->lookupNamespacePrefix($ns);
+ if ($prefix) {
+ $code->appendText($prefix.':'.$val);
+ } else {
+ $code->appendText($val);
+ }
+ } else {
+ $code->appendText('SOAPENV:'.$codestr);
+ }
- $self->_generate_Fault_Code($response,$code,$soap->fault->{code}, $namespace);
+ my $faultstring = $response->createElementNS
+ ($namespace, "SOAPENV:faultstring");
+ $fault->appendChild($faultstring);
+ $faultstring->appendText($soap->fault->{reason});
- if ($soap->fault->{reason}) {
- my $reason = $response->createElementNS
- ($namespace, "Reason");
- $fault->appendChild($reason);
- # TODO: we don't support the xml:lang attribute yet.
- my $text = $response->createElementNS
- ($namespace, "Text");
- $reason->appendChild($text);
- $text->appendText($soap->fault->{reason});
- }
- if ($soap->fault->{detail}) {
+ if (UNIVERSAL::isa($soap->fault->{detail}, 'XML::LibXML::Node')) {
my $detail = $response->createElementNS
- ($namespace, "Detail");
+ ($namespace, "SOAPENV:detail");
+ $detail->appendChild($soap->fault->{detail});
$fault->appendChild($detail);
+ } elsif ($soap->fault->{detail}) {
+ my $detail = $response->createElementNS
+ ($namespace, "SOAPENV:detail");
+ $fault->appendChild($detail);
# TODO: we don't support the xml:lang attribute yet.
my $text = $response->createElementNS
- ($namespace, "Text");
+ ('http://www.w3.org/2001/XMLSchema','xsd:documentation');
$detail->appendChild($text);
$text->appendText($soap->fault->{detail});
}
@@ -304,25 +313,7 @@
$c->res->body($envelope->toString());
}
- sub _generate_Fault_Code {
- my ($self, $document, $codenode, $codeValue, $namespace) = @_;
- my $value = $document->createElementNS
- ($namespace, "Value");
- if (ref $codeValue eq 'ARRAY') {
- $value->appendText($codeValue->[0]);
- my $subcode = $document->createElementNS
- ($namespace, 'SubCode');
- $codenode->appendChild($value);
- $codenode->appendChild($subcode);
- $self->_generate_Fault_Code($document, $subcode, $codeValue->[1], $namespace);
- } else {
- $value->appendText($codeValue) if $codeValue;
- $codenode->appendChild($value);
- }
- }
-
-
};
{ package Catalyst::Controller::SOAP::Helper;
More information about the Catalyst-commits
mailing list