Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not get capture from xml response #493

Closed
balroggg opened this issue Feb 26, 2022 · 9 comments · Fixed by #502
Closed

Can not get capture from xml response #493

balroggg opened this issue Feb 26, 2022 · 9 comments · Fixed by #502
Labels
enhancement New feature or request
Milestone

Comments

@balroggg
Copy link

balroggg commented Feb 26, 2022

Archlinux, Hurl version:

hurl -V
hurl 1.6.0 libcurl/7.81.0 OpenSSL/1.1.1m zlib/1.2.11 brotli/1.0.3840 1.5.2 libidn2/2.3.2 libssh2/1.10.0 1.47.0

Example:

test.hurl

POST https://test_api
Content-Type: application/xml; charset=utf-8
file,test.xml;

HTTP/2 200
[Captures]
tr_id: xpath "//Envelope/Body/OTA_AirAvailRS/@TransactionIdentifier"

But only get Nodeset0, expected value from xml response.

* Captures
* tr_id: Nodeset0
* 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body xmlns:ns1="http://www.opentravel.org/OTA/2003/05"><ns1:OTA_AirAvailRS EchoToken="11868765275150-1300257934" PrimaryLangID="en-us" RetransmissionIndicator="false" SequenceNmbr="1" TransactionIdentifier="TID$1645916657245273489-.demo2144" 
@balroggg
Copy link
Author

I checked xpath on http://xpather.com/ and seems it's should work.

@jcamiel
Copy link
Collaborator

jcamiel commented Feb 27, 2022

Hi,

I think your XPath query is right and returns effectively a node (as we hint it in the logs).

Could you try to use the string XPath function to convert this node to a string ?

POST https://test_api
Content-Type: application/xml; charset=utf-8
file,test.xml;

HTTP/2 200
[Captures]
tr_id: xpath "string(//Envelope/Body/OTA_AirAvailRS/@TransactionIdentifier)"

So instead of:

tr_id: xpath "//Envelope/Body/OTA_AirAvailRS/@TransactionIdentifier"

Use

tr_id: xpath "string(//Envelope/Body/OTA_AirAvailRS/@TransactionIdentifier)"

We don't convert nodes returned from query because you can also evaluate tests on collections (like count etc...)

If your capture is still not working, could you send the complete XML body?

Regards,

@balroggg
Copy link
Author

With string I just get empty value

* Captures
* tr_id: 
* 

I reduced a little xml body,

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body xmlns:ns1="http://www.opentravel.org/OTA/2003/05"><ns1:OTA_AirAvailRS EchoToken="11868765275150-1300257934" PrimaryLangID="en-us" RetransmissionIndicator="false" SequenceNmbr="1" TransactionIdentifier="TID$16459590516432752971.demo2144" Version="2006.01"></ns1:OTA_AirAvailRS></soap:Body></soap:Envelope>

@balroggg
Copy link
Author

@jcamiel
Copy link
Collaborator

jcamiel commented Feb 27, 2022

Thanks,
I can see now why the capture is not working, it's because of the Xml Namespace in the xml body and the way we treat it.
For the moment, you can rewrite your capture like this:

POST https://test_api
Content-Type: application/xml; charset=utf-8
file,test.xml;

HTTP/2 200
[Captures]
tr_id: xpath "string(//*[name()='Envelope']/*[name()='Body']/*[name()='OTA_AirAvailRS']/@TransactionIdentifier)"

Not ideal, we are going to look if we can improve Xml Namespace support.

Can you test it with this new xpath expression ?

@balroggg
Copy link
Author

Same results as before(empty id). 😢

@balroggg
Copy link
Author

//*[name()='soap:Envelope'] - find something by xpather
//*[name()='Envelope'] - not
maybe xpath not valid?

@balroggg
Copy link
Author

This works for me thanks!

tr_id: xpath "string(//*[name()='soap:Envelope']/*[name()='soap:Body']/*[name()='ns1:OTA_AirAvailRS']/@TransactionIdentifier)"

@jcamiel
Copy link
Collaborator

jcamiel commented Feb 27, 2022

Yes ! Exactly, I forget the prefixes (and didn't test it)

We'll improve the xml namespace support so the capture will (probably) be:

POST https://test_api
Content-Type: application/xml; charset=utf-8
file,test.xml;

HTTP/2 200
[Captures]
tr_id: xpath "string(//soap:Envelope/soap:Body/ns1:OTA_AirAvailRS/@TransactionIdentifier)"

(it is not working now)

@jcamiel jcamiel linked a pull request Mar 11, 2022 that will close this issue
@jcamiel jcamiel added the enhancement New feature or request label Mar 11, 2022
@fabricereix fabricereix added this to the 1.7.0 milestone Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants