Changing charset in XmlPath

44 views
Skip to first unread message

Irene

unread,
Mar 4, 2013, 6:11:52 AM3/4/13
to rest-a...@googlegroups.com
Hi!

I've read the manuals but still can't get this right) So the question is:
I have url that returns xml file encoded with windows-1251. I want to obtain XmlPath for it and use it.
My code is something like this:

Response r = given()
                .cookies(needed cookies)
                .response().expect()
                .log().ifStatusCodeMatches(any(Integer.class))
                .when().get(url);
XmlPath path = r.getBody().xmlPath();

And then it fails to parse:
[Fatal Error] :7:7: Invalid byte 2 of 2-byte UTF-8 sequence.


I tried to add

RestAssured.config = newConfig().decoderConfig(decoderConfig().defaultContentCharset("windows-1251"));

before defining response, but it didn't help. What is the correct way to deal with differently encoded xml files?
Thanks.

Johan Haleby

unread,
Mar 5, 2013, 1:52:19 AM3/5/13
to rest-a...@googlegroups.com
Hmm does it work if you do something like:

String xmlValueIn = given()
                .cookies(needed cookies)
                .response().expect()
                .log().ifStatusCodeMatches(any(Integer.class))
                .when().get(url).path("x.y");

Where "x.y" is a valid path to a value in your XML?

If not, does something like this work:

given()
                .cookies(needed cookies)
                .response().expect()
                .body("x.y", equalTo("z"))
                .log().ifStatusCodeMatches(any(Integer.class))
                .when().get(url)


Regards,
/Johan


--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Message has been deleted

Irene

unread,
Mar 5, 2013, 2:44:40 AM3/5/13
to rest-a...@googlegroups.com
Wow! I actually used an ugly workaround:

byte[] b = r.getBody().asByteArray();
XmlPath path = new XmlPath(new String(b, needed charset))

But your second suggestion magically works!

Johan Haleby

unread,
Mar 5, 2013, 11:36:54 AM3/5/13
to rest-a...@googlegroups.com
Ok so the reason is that stand-alone XmlPath doesn't support charset without going through the work-around that you used. When you configure REST Assured to use windows-1251 you only configure REST Assured and not XmlPath.

/Johan
Reply all
Reply to author
Forward
0 new messages