playframework / playframework/play-ws
WSRequest.post(Document) set incorrect encoding in the XML Prolog
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 224
- Forks
- 92
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 28
Description
I use JAXB to marshal a Java Object to Document, then use WSRequest.post() to send the documet to a server. When marshaling, I set the encoding to EUC_KR:
...
Document document = db.newDocument();
marshaller.setProperty(Marshaller.JAXB_ENCODING, "EUC_KR");
marshaller.marshal(obj, document);
The POST request is:
ws.url(registerProductUrl)
.addHeader("Content-Type", "text/xml;charset=euc-kr")
.post(document);
This works well in Play 2.5.14, where the prolog in the request is
<?xml version="1.0" encoding="EUC-KR"?>
When upgrade to play 2.6.0, the prolog in the request changed to:
<?xml version="1.0" encoding="UTF-8"?>
that is, the encoding is now not "EUC-KR.
I do not find where WSRequest.post(Document) is implemented, but I find that play.libs.ws.XML.toBytes(Document document) has bug. It does not set the encoding when transform a XML document.
The following project can produce the issue:
https://github.com/guofengzh/play-xml-prolog-issue
see JaxbText.java in test/controller.
JaxbText.XMLtoBytesTest() use XML.toBytes() to reproduce the issue. The prolog it generated is:
<?xml version="1.0" encoding="UTF-8"?>
(the correct encoding should be "EUC-KR".
JaxbText.myToBytesTest() use the modified toBytes(), which set the encoding using:
transformer.setOutputProperty(OutputKeys.ENCODING, encoding);
and generate the correct encoding in the prolog:
<?xml version="1.0" encoding="EUC-KR"?>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with play.libs.ws.XML.toBytes(Document) and compare its behavior with JaxbText.java in test/controller. Run JaxbText.XMLtoBytesTest() and compare it with JaxbText.myToBytesTest(); the issue is done when WSRequest.post(Document) preserves the document's EUC-KR encoding in the XML prolog.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, scala
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100