spring - Camel : Jetty response encoding

标签 spring jetty apache-camel

我想在Camel环境中使用Jetty组件。这是我的 spring-config.xml 的摘录:

...
<bean id="webEnc" class="web.WebEnc" />
<camelContext>
    <route>
        <from uri="jetty:http://0.0.0.0/enc" />
        <process ref="webEnc" />
    </route>
</camelContext>
...

这是用于返回String的代码:

import org.apache.camel.Exchange;
import org.apache.camel.Processor;

public class WebEnc implements Processor{

    @Override
    public void process(Exchange exchange) throws Exception {
        exchange.getOut().setBody("abcäöüß\"€一二三"); //the last three symbols are chinese for '123'
    }
}

本地地址可以工作( http://127.0.0.1/enc ),但浏览器无法正确显示字符串(显示为 'abcà¤à¶àÜàŸ"â‚一二三')。我认为问题是一些编码。如何设置编码,例如“utf-8”?
我在这里找不到任何有关编码或字符集或其他内容的提示( http://camel.apache.org/jetty.html )像这样。

最佳答案

我认为您必须在输出消息中使用 utf-8 字符集设置 Content-Type header ,如下所示:

@Override
public void process(Exchange exchange) throws Exception {
    exchange.getOut().setBody("abcäöüß\"€一二三"); //the last three symbols are chinese for '123'
    exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "text/html; charset=utf-8");
}

关于spring - Camel : Jetty response encoding,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30001261/

相关文章:

java - 如何加快seda关闭速度?

java - Docker-compose:/app.war 中没有主要 list 属性

java - 在同一台机器上运行两个 Jetty 服务器

java - Camel "activemq component"的性能问题

rest - Camel - 使用 Java DSL 通过动态路由发出并行 GET 请求并聚合结果

android - Android 上 Jetty 上的 Jersey 抛出 ContainerException : "No WebApplication provider is present"

java - Apache Camel - 将拆分元素聚合到列表中

spring - 使用 java 应用程序在 heroku 上安装 wkhtmltopdf

java - 如何从xml文件中取出bean定义?

spring - 使用 Spring 处理 REST 应用程序中映射的不明确处理程序方法