java - Spring Integration http 出站网关和 UTF-8

标签 java xml utf-8 spring-integration

我正在尝试使用 Spring Integration 从网络加载多语言 XML 文件。不幸的是,Spring Integration 似乎将其视为其他形式的编码。这是我的配置的相关部分:

<int-http:outbound-gateway id="example"
    request-channel="requests"
    url="http://localhost/test.xml"
    http-method="GET"
    expected-response-type="java.lang.String"
    charset="UTF-8"
    reply-timeout="1234"
    reply-channel="replies"/>

我检索到的文本被视为 ISO-8859-1。我之所以相信这一点,是因为如果我重新编码然后解码,我就会得到正确的文本。像这样的事情:

public void handleReply(String rawXML) {
    String forRealzies = "";
    try {
        String hack1 = URLEncoder.encode(rawXML, "ISO-8859-1");
        forRealzies = URLDecoder.decode(hack1, "UTF-8");
    } catch(UnsupportedEncodingException e1) {
        e1.printStackTrace();
    }
    // forRealzies now has the properly encoded String
}

我真的希望我在 XML 配置中做错了什么。有什么建议吗?

最佳答案

您应该在内容类型上设置字符集;请参阅here .

关于java - Spring Integration http 出站网关和 UTF-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25466127/

相关文章:

java - Java 中 MySQL 插入语句的性能 : Batch mode prepared statements vs single insert with multiple values

java - 在 Java 中获取 Ipv6 完整格式

html - 如何判断以下网页源代码是 XHTML、HTML 还是 XML?

python - Redis-py是否支持unicode和utf-8以及它是如何工作的

java - 设置默认 Java 字符编码

java - 我怎样才能让这个开关只选择 3 个选项之一?

java - 如何在 StAX 中跟踪大文件的解析进度?

c# - 由于特殊字符,在 VB.Net 中解析 XML 失败

java - UTF-8 到 UTF16 解析

java - JTextArea 的开始和结束索引检索