如何获得Resteasy MultipartFormDataInput使用UTF-8解码字符串? [英] How can I get resteasy MultipartFormDataInput to decode strings using UTF-8?

查看:770
本文介绍了如何获得Resteasy MultipartFormDataInput使用UTF-8解码字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用resteasy 2.3.4-Final,并且在接受multipart/form-data的调用中存在UTF-8问题.我的API的使用者是iOS和Android设备.发送的任何字符串参数均不包含字符集,因此,resteasy似乎是使用us-ascii编码对字符串进行解码的.我已经做了很多工作来修复从db层开始的所有其他问题,以创建一个将字符编码强制为utf-8的过滤器.这解决了所有以表单URL编码的POST的问题,但是现在两个调用仍然不起作用,它们都是multipart/form-data调用.我了解消费者应该在消息部分中发送utf-8字符集,但是我正在尝试确定是否有任何方法可以强制使用UTF-8暂时解码所有内容,因为Apple大约需要2周的时间批准对我们的应用程序的更新并不理想,但我们可能不得不为此硬着头皮.有没有人做过此事并且成功上传了多部分表格?

I'm using resteasy 2.3.4-Final and having UTF-8 problems in calls that accept multipart/form-data. The consumers of my API are iOS and Android devices. Any string params that are sent, don't contain a charset so resteasy seems to be decoding the strings with us-ascii encoding. I've done plenty of work to fix everything else involved from the db layer up to create a filter that will force the character encoding to utf-8. This solved the problem for all form-url-encoded POSTs, but now two calls still don't work and they are both multipart/form-data calls. I understand that the consumers should send the utf-8 charset in the message parts, but I'm trying to figure out if there's any way to force everything to be decoded using UTF-8 temporarily because it would take about 2 weeks for Apple to approve an update to our application which isn't ideal, but we may have to bite the bullet on that one. Has anyone done this before and had success with multipart form uploads?

谢谢!

推荐答案

根据RESTEasy文档,应该可以覆盖默认的内容类型:

According to the RESTEasy documentation, it should be possible to override the default content type:

http://docs. jboss.org/resteasy/docs/2.3.4.Final/userguide/html_single/index.html#multipart_overwrite_default_content_type

import org.jboss.resteasy.plugins.providers.multipart.InputPart;

@Provider
@ServerInterceptor
public class ContentTypeSetterPreProcessorInterceptor implements
        PreProcessInterceptor {

    public ServerResponse preProcess(HttpRequest request,
            ResourceMethod method) throws Failure, WebApplicationException {
        request.setAttribute(InputPart.DEFAULT_CONTENT_TYPE_PROPERTY,
                "*/*; charset=UTF-8");
        return null;
    }

}

这篇关于如何获得Resteasy MultipartFormDataInput使用UTF-8解码字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆