【问题标题】:Jersey: Disable automatic Wadl Generation for OPTIONS request without using a web.xml file?Jersey:在不使用 web.xml 文件的情况下禁用 OPTIONS 请求的自动 Wadl 生成?
【发布时间】:2018-04-16 04:11:42
【问题描述】:

我想完成与这个问题相同的事情:Disable automatic Wadl Generation for OPTIONS request,但我们没有web.xml 文件。我们还使用了ResourceConfig,其中getProperties 方法是最终的,所以我不能按照other questions 中的建议覆盖它。我尝试在扩展ResourceConfig 的类中调用property("com.sun.jersey.config.feature.DisableWADL", "true");,但没有成功。

如何禁用 WADL?

我们使用的是 Jersey 2.25.1。我尝试阅读the Jersey docs on WADL,但无法阅读该页面,因为弹出错误消息说明有关 syntaxhighlightingerror/xml 刷子的内容。

【问题讨论】:

    标签: jakarta-ee java-8 jersey glassfish


    【解决方案1】:

    您使用了错误的属性。您使用com.sun.jersey 看到的任何内容都将适用于 Jersey 1.x。你想要的是jersey.config.server.wadl.disableWadl,或者更好的是使用常量。

    ServerProperties.WADL_FEATURE_DISABLE

    【讨论】:

    • 谢谢!您是否知道我如何将响应类型设为application/json(真的是所有内容的默认值)?现在,禁用 WADL 后,它设置为 text/plain
    • 我不知道。我从来没有做过。您可以尝试的一件事是使用response filter 并将ContainerResponseContext 转换为ContainerResponse 并使用它的setMediaType。但这可能不仅仅是“默认”,而且实际上是对任何现有媒体类型的硬覆盖。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-12
    • 1970-01-01
    相关资源
    最近更新 更多