2.7.11.5. 多部分消息覆盖默认回退内容类型
默认情况下,如果部分 文本/plain 中不存在 用作回退。这由 MIME RFC 定义。但是,某些 Web 客户端(如许多浏览器)可能会为文件部分发送 Content-Type 标头;charset=us-asciiContent-Type 标头,但不适用于 多部分/格式数据 请求中的所有字段。这可能会导致服务器端的字符编码和取消处理错误。RESTEasy 的 PreProcessInterceptor 基础架构可用于更正此问题。您可以使用它为每个请求动态定义另一个非 RFC 兼容回退值。
示例:将 * / *; charset=UTF-8 设置为默认 Fallback
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;
}
}