此内容没有您所选择的语言版本。

15.10. Configure File Extensions


15.10.1. Map File Extensions to Media Types in the web.xml File

Summary

Some clients, like browsers, cannot use the Accept and Accept-Language headers to negotiate the representation's media type or language. RESTEasy can map file name suffixes to media types and languages to deal with this issue. Follow these steps to map media types to file extensions, in the web.xml file.

Procedure 15.4. Map Media Types to File Extensions

  1. Open the web.xml file for the application in a text editor.
  2. Add the context-param resteasy.media.type.mappings to the file, inside the web-app tags:
    <context-param>
        <param-name>resteasy.media.type.mappings</param-name>
    </context-param>
    
  3. Configure the parameter values. The mappings form a comma delimited list. Each mapping is delimited by a ::

    Example 15.16. Example Mapping

    <context-param>
        <param-name>resteasy.media.type.mappings</param-name>
        <param-value>html : text/html, json : application/json, xml : application/xml</param-value>
    </context-param>
    

15.10.2. Map File Extensions to Languages in the web.xml File

Summary

Some clients, like browsers, cannot use the Accept and Accept-Language headers to negotiate the representation's media type or language. RESTEasy can map file name suffixes to media types and languages to deal with this issue. Follow these steps to map languages to file extensions, in the web.xml file.

Procedure 15.5. Map File Extensions to Languages in the web.xml File

  1. Open the web.xml file for the application in a text editor.
  2. Add the context-param resteasy.language.mappings to the file, inside the web-app tags:
    <context-param>
        <param-name>resteasy.language.mappings</param-name>
    </context-param>
    
  3. Configure the parameter values. The mappings form a comma delimited list. Each mapping is delimited by a ::

    Example 15.17. Example Mapping

    <context-param>
        <param-name>resteasy.language.mappings</param-name>
        <param-value> en : en-US, es : es, fr : fr</param-name>
    </context-param>
    

15.10.3. RESTEasy Supported Media Types

Table 15.4. Media Types
Media Type Java Type
application/*+xml, text/*+xml, application/*+json, application/*+fastinfoset, application/atom+* JaxB annotated classes
application/*+xml, text/*+xml org.w3c.dom.Document
*/* java.lang.String
*/* java.io.InputStream
text/plain primitives, java.lang.String, or any type that has a String constructor, or static valueOf(String) method for input, toString() for output
*/* javax.activation.DataSource
*/* byte[]
*/* java.io.File
application/x-www-form-urlencoded javax.ws.rs.core.MultivaluedMap
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.