I am getting following exception from webservices:
com.ctc.wstx.exc.WstxUnexpectedCharException: Illegal character ((CTRL-CHAR, code 15))
I know the reason behind this, I am getting "Control Characters" in data I want to return. And in XML CTRL-CHAR
are not allowed.
I searched for the solution, and many places I found the code to remove CTRL-CHAR
.
The concern is shall I end up loss of data if I remove control characters from data?
I want the clean solution may encoding, instead of removing control char.
I would do what OrangeDog suggest. But if you want to solve it in your code try:
replaceAll("[\\x00-\\x09\\x11\\x12\\x14-\\x1F\\x7F]", "")
\\x12
is the char.
Thanks guys for you inputs. I am sharing solution might be helpful for others.
The requirement was not to wipe out CONTROL CHAR, it should remain as it is in DB also and one WS sends it across n/w client should able to get the CONTROL CHAR. So I implemented the code as follow:
Sharing sample code and output bellow.
Sample code:
System.out.println("NewSfn");
System.out.println(URLEncoder.encode("NewSfn", "UTF-8"));
System.out.println(URLDecoder.decode("NewSfn", "UTF-8"));
Output:
NewSfn
New%0FSfn
NewSfn
So client will recieve CONTROL CHARs.
EDIT: Stack Exchange is not showing CONTROL CHAR above. NewSfn
is like this New(CONTROL CHAR)Sfn
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With