How to stop server to process xml in request

36 views
Skip to first unread message

Vikki

unread,
Feb 10, 2017, 12:30:48 AM2/10/17
to Play Framework
[Fatal Error] :83:14: Character reference "&#4" is an invalid XML character.

I don't get a chance to clean invalid xml neither a chance to capture and log xml with invalid chars.

Please help. It breaking the flow.

Igmar Palsenberg

unread,
Feb 10, 2017, 2:08:36 AM2/10/17
to Play Framework


Op vrijdag 10 februari 2017 06:30:48 UTC+1 schreef Vikki:
[Fatal Error] :83:14: Character reference "&#4" is an invalid XML character.

I don't get a chance to clean invalid xml neither a chance to capture and log xml with invalid chars.

Please help. It breaking the flow.

Start by telling how your flow works. In other words : How do you process the XML.


Igmar 

Vikki

unread,
Feb 11, 2017, 2:28:43 PM2/11/17
to Play Framework
Hi,

Thats the problem. Request never reaches my controller. Play sees content-type as application/xml and try to process body. All i see is this error on console.

If i can get access to raw body, I can clean, then process with sax.

Igmar Palsenberg

unread,
Feb 13, 2017, 6:15:21 AM2/13/17
to Play Framework

 
Thats the problem. Request never reaches my controller. Play sees content-type as application/xml and try to process body. All i see is this error on console.

If i can get access to raw body, I can clean, then process with sax.

Assuming you have : 

CompletionStage<Result> foo() {
    .....
}

annotate the method with : 

@BodyParser.Of(BodyParser.TolerantText.class)

That will discard the fact that it's XML, and you can do request().body().asText(). No that you're responsible for verifying the correct mime type (TolerantText will ignore the mime type), and also for correcting the content. You do have do you own parsing from scratch, since the body parser in this case doesn't do that anymore (inject ObjectMapper and use that).


Igmar

Vikki

unread,
Feb 14, 2017, 7:12:10 AM2/14/17
to Play Framework
Thanks a lot Sir!
Reply all
Reply to author
Forward
0 new messages