2.7.11.7. 为多部分消息覆盖默认 Fallback charset
在某些情况下,多部分消息的部分可能具有 Content-Type 标头且没有 charset 参数。如果设置了 InputPart.DEFAULT_CONTENT_TYPE_PROPERTY 属性,并且值具有 charset 参数,则该值将被附加到没有 charset 参数的现有 Content-Type 标头中。
您还可以使用 常量 。
InputPart.DEFAULT_CHARSET_PROPERTY( setresteasy.provider.multipart.inputpart.defaultCharset)指定默认的 char
示例:指定默认 charset
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_CHARSET_PROPERTY, "UTF-8");
return null;
}
}
注意
如果设置了 InputPart.DEFAULT_CONTENT_TYPE_PROPERTY 和 InputPart.DEFAULT_CHARSET_PROPERTY,则 InputPart.DEFAULT_CHARSET_PROPERTY 的值将覆盖 InputPart.DEFAULT_CONTY 的值中的任何 charset。