Skip Menu |

This queue is for tickets about the SOAP-Lite CPAN distribution.

Report information
The Basics
Id: 98325
Status: open
Priority: 0/
Queue: SOAP-Lite

People
Owner: Nobody in particular
Requestors: oliver.lightfoot [...] retaildata.co.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Value of root element in SOAP Body ignored
Date: Tue, 26 Aug 2014 14:01:58 +0100
To: <bug-SOAP-Lite [...] rt.cpan.org>
From: Oliver Lightfoot <oliver.lightfoot [...] retaildata.co.uk>
I have found a bug in SOAP::Lite. SOAP::Lite version: 1.11. perl version: 5.10. OS: Debian Linux v6.0 (Squeeze) The bug occurs when you set a value for the root element in SOAP Body and do not have any child elements. Rather than using the value set on the root SOAP::Data object it sets the value to undef which results in the root element having the xsi:nil="true" attribute set. The following code replicates this bug: my $client = SOAP::Lite ->proxy('http://localhost:8080', timeout => 360) ->on_action(sub {return ""}); my $body = SOAP::Data->name("ns1:SendData")->value('SomeTestData11212')->type(""); $client->call($body); This results in the following XML: <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.foo.com/bar/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <ns1:SendData xsi:nil="true" /> </SOAP-ENV:Body> </SOAP-ENV:Envelope> As you can see the SendDate tag has been serialized as nil, however I propose it should actually be: <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.foo.com/bar/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <ns1:SendData>SomeTestData11212</ns1:SendData> </SOAP-ENV:Body> </SOAP-ENV:Envelope> Now the SendData tag has been serialized with the value set in the code example. I have tried to find out if this is considered valid SOAP XML and can fined nothing to suggest it is, so it seems to me that this is a valid expectation? I am working with a 3rd party SOAP server and this is certainly what they expect. I have found the code responsible for this behaviour in Lite.pm, line 1640, a copy is below: $body->set_value($parameters ? \$parameters : SOAP::Utils::encode_data()) if $body; The problem with this code is it will always overwrite the body value, ideally the code should check for a body value and use this but only if there are no other parameters, which obvously would be embedded as child elements and thus replace any root value? In order to change the behaviour so it will not ignore the root element value I change the code to: if ($body && !defined($body->value()) || defined($parameters)) { $body->set_value($parameters ? \$parameters : SOAP::Utils::encode_data()); } I hope that you seriously consider adopting this change, it seems like a valid use case, however I am sure you are much better placed to decide this. If you could let me know your decision one way or another that would be greatly appreciated. Thank you for your time. Best regards, -- Oliver Lightfoot Senior Developer The Retail Data Partnership Ltd Brewery House 4 Scotgate Stamford PE9 2YB Telephone 01780 480562
Can you please try the following test? I was not able to reproduce your problem with this on my local system. fredmoyer@aiko ~/dev/soaplite $ prove -lv t/41-RT_98325.t t/41-RT_98325.t .. 1..1 $VAR1 = '<?xml version="1.0" encoding="UTF-8"?><ns1:SendData xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">SomeTestData11212</ns1:SendData>'; ok 1 ok All tests successful. Files=1, Tests=1, 0 wallclock secs ( 0.02 usr 0.01 sys + 0.08 cusr 0.01 csys = 0.12 CPU) Result: PASS fredmoyer@aiko ~/dev/soaplite $ cat t/41-RT_98325.t use strict; use warnings; use Test::More; use SOAP::Lite; use Data::Dumper; plan tests => 1; my $client = SOAP::Lite ->proxy( 'http://localhost:8080', timeout => 360 ) ->on_action( sub { return "" } ); my $body = SOAP::Data->name( "ns1:SendData" )->value( 'SomeTestData11212' )->type( "" ); my $serialized = SOAP::Serializer->serialize( $body ); use Data::Dumper; warn(Dumper($serialized)); unlike($serialized, qr/nil/);
Subject: Re: [rt.cpan.org #98325] Value of root element in SOAP Body ignored
Date: Wed, 27 Aug 2014 10:09:27 +0100
To: <bug-SOAP-Lite [...] rt.cpan.org>
From: Oliver Lightfoot <oliver.lightfoot [...] retaildata.co.uk>
Thanks for your response. I have run your test and it passes, however I believe that the bug is not covered by your test because the bug is not in the serializer code but in the envelope code which gets called by the 'call' method. I have expanded your test script to show this, the second test fails on my system: prove -lv soaplitetest.t soaplitetest.t .. 1..2 $VAR1 = '<?xml version="1.0" encoding="UTF-8"?><ns1:SendData xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">SomeTestData11212</ns1:SendData>'; ok 1 $VAR1 = '<?xml version="1.0" encoding="UTF-8"?><soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://www.foo.com/bar/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><ns1:SendData xsi:nil="true" /></soap:Body></soap:Envelope>'; not ok 2 # Failed test at soaplitetest.t line 28. # '<?xml version="1.0" encoding="UTF-8"?><soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://www.foo.com/bar/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><ns1:SendData xsi:nil="true" /></soap:Body></soap:Envelope>' # matches '(?-xism:nil)' # Looks like you failed 1 test of 2. Dubious, test returned 1 (wstat 256, 0x100) Failed 1/2 subtests Test Summary Report ------------------- soaplitetest.t (Wstat: 256 Tests: 2 Failed: 1) Failed test: 2 Non-zero exit status: 1 Files=1, Tests=2, 1 wallclock secs ( 0.08 usr 0.02 sys + 0.54 cusr 0.06 csys = 0.70 CPU) Result: FAIL The amended test script is below: use strict; use warnings; use Test::More; use SOAP::Lite; use Data::Dumper; plan tests => 2; my $client = SOAP::Lite ->proxy( 'http://localhost:8080', timeout => 360 ) ->on_action( sub { return "" } ); my $body = SOAP::Data->name( "ns1:SendData" )->value( 'SomeTestData11212' )->type( "" ); my $serialized = SOAP::Serializer->serialize( $body ); use Data::Dumper; warn(Dumper($serialized)); unlike($serialized, qr/nil/); # Set namespace because call() complains otherwise $client->ns('http://www.foo.com/bar/', "ns1"); my $response = $client->call( $body ); my $request_content = $response->{_context}->{_transport}->{_proxy}->{_http_response}->{_request}->{_content}; use Data::Dumper; warn(Dumper($request_content)); unlike($request_content, qr/nil/); On 27/08/2014 03:17, via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=98325 > > > Can you please try the following test? I was not able to reproduce your problem with this on my local system. > > fredmoyer@aiko ~/dev/soaplite $ prove -lv t/41-RT_98325.t > t/41-RT_98325.t .. > 1..1 > $VAR1 = '<?xml version="1.0" encoding="UTF-8"?><ns1:SendData xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">SomeTestData11212</ns1:SendData>'; > ok 1 > ok > All tests successful. > Files=1, Tests=1, 0 wallclock secs ( 0.02 usr 0.01 sys + 0.08 cusr 0.01 csys = 0.12 CPU) > Result: PASS > > > fredmoyer@aiko ~/dev/soaplite $ cat t/41-RT_98325.t > use strict; > use warnings; > use Test::More; > use SOAP::Lite; > use Data::Dumper; > > plan tests => 1; > > my $client = SOAP::Lite > ->proxy( 'http://localhost:8080', timeout => 360 ) > ->on_action( sub { return "" } ); > > my $body = > SOAP::Data->name( "ns1:SendData" )->value( 'SomeTestData11212' )->type( "" ); > > my $serialized = SOAP::Serializer->serialize( $body ); > use Data::Dumper; > warn(Dumper($serialized)); > unlike($serialized, qr/nil/);
-- Oliver Lightfoot Senior Developer The Retail Data Partnership Ltd Brewery House 4 Scotgate Stamford PE9 2YB Telephone 01780 480562