我正在使用RESTEasy在Wildfly 8.2中构建REST服务。这基本上工作,但它不是UTF-8。如何强制RESTEasy(Wildfly 8.2)使用UTF8?
我的配置是这样的:
我用的是自动JAXRS激活Wildfly由一代导致的RESTEasy来解决这个空类:
@ApplicationPath("/rest")
public class JaxRsActivator extends Application
{
}
我的REST实现是这样的:
@Path("/user")
@Produces(MediaType.APPLICATION_JSON)
public class UserResource
{
@GET
@Path("/{firstname}-{lastname}")
public Response printMessage(@PathParam("firstname") String param1, @PathParam("lastname") String param2)
{
return Response.ok().entity(new TestObject(param1, param2)).build();
}
}
当我通过
调用此资源http://localhost:8080/mywebserver/rest/user/Déborah-François
我得到结果:
{"name1":"Déborah","name2":"François"}
交付的编码为Windows-1252。这是为什么?我想要在Wildfly上配置UTF-8。
[更新]
当我添加到的jboss-web.xml中这一点,甚至不工作:
<default-encoding>UTF-8</default-encoding>
(我不明白为什么UTF-8是不是默认在所有。在我看来这是必须的)
引用为什么UTF-8不是默认值。 AFAIK没有规定为URI使用UTF-8的标准。常用的方法是使用ISO-8859-1并对所有不适合此字符集的字符进行网址编码。 – lefloh
我试图在jboss-web.xml和standalone.xml中设置''作为[描述在这里](https://issues.jboss.org/browse/WFLY-2533? focusedCommentId = 12933050&page = com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-12933050)但无效果。我用Wildfly 8.1.0.Final试了一下。也许你可以尝试修复版本(8.0.0.CR1),看看它是否有效? –
lefloh
@lefloh当我创建一个测试客户端并向我的服务器发送UTF-8请求时,编码在响应输出上工作。 – Bevor