How to deal with invalid characters in a WS output when using CXF?

前端 未结 4 1575
感动是毒
感动是毒 2021-02-07 06:00

I\'m using Spring, CXF and Hibernate to build a WebService that perform search queries on a foreign database that I have read-only access.

The problem is that some entri

4条回答
  •  余生分开走
    2021-02-07 06:25

    The top-rated answer didn't work for me, as the given Unicode encoding was rejected. With a slight alteration however, it displayed the desired behaviour:

    public static String CleanInvalidXmlChars(String text, String replacement) {
        String re = "[^\\u0009\\u000A\\u000D\\u0020-\\uD7FF\\uE000-\\uFFFD\\u0001\\u0000-\\u0010\\uFFFF]";
        return text.replaceAll(re, replacement);
    }
    

提交回复
热议问题