使用 Jersey 添加方法注释

发布于 2024-08-21 12:20:48 字数 1005 浏览 2 评论 0原文

我们一直在使用 Jersey 作为我们的网络服务,它非常棒而且简单。有没有办法在方法定义中添加一个小的描述注释(也许使用像 @Description 这样的注释):

@GET
@Path("/schema/classes/")
@Produces( { APPLICATION_RDF, TEXT_N3, APPLICATION_JSON })
@Description("Lists all ontology classes")
public Response getClasses() throws JobOntoException {
  ...
}

并且在 WADL 中会给出类似的内容:

<application>
 <doc jersey:generatedBy="Jersey: 1.1.5 01/20/2010 03:55 PM"/>
  <resources base="http://localhost:9998/">
   <resource path="/jobonto">
    <resource path="/schema/classes/">
     <method name="GET" id="getClasses">
      **<description>"Lists all ontology classes"</description>**
      <response> 
       <representation mediaType="application/rdf+xml"/>
       <representation mediaType="text/rdf+n3"/>
       <representation mediaType="application/json"/>
      </response>
     </method>
    </resource>
    ...

谢谢,Renaud

We've been using Jersey for our webservice and it's been great and straightforward. Is there a way to add a small description comment within a method definition (maybe using an annotation like @Description):

@GET
@Path("/schema/classes/")
@Produces( { APPLICATION_RDF, TEXT_N3, APPLICATION_JSON })
@Description("Lists all ontology classes")
public Response getClasses() throws JobOntoException {
  ...
}

And in the WADL that would give something like:

<application>
 <doc jersey:generatedBy="Jersey: 1.1.5 01/20/2010 03:55 PM"/>
  <resources base="http://localhost:9998/">
   <resource path="/jobonto">
    <resource path="/schema/classes/">
     <method name="GET" id="getClasses">
      **<description>"Lists all ontology classes"</description>**
      <response> 
       <representation mediaType="application/rdf+xml"/>
       <representation mediaType="text/rdf+n3"/>
       <representation mediaType="application/json"/>
      </response>
     </method>
    </resource>
    ...

Thanks, Renaud

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月竹挽风 2024-08-28 12:20:48

您应该尝试扩展 WadlGeneratorConfig

You should try extending the WadlGeneratorConfig.

×眷恋的温暖 2024-08-28 12:20:48

这是一个更好的主意。将描述放入用于链接到该资源的表示形式中。

您使用什么媒体类型来表示您的服务的根部? Xhtml 对此非常有用,因为它易于解析,具有对链接的现有支持,并且在浏览器中可以很好地呈现。

Here is an even better idea. Put the description in the representation that you use to link to this resource.

What media type are you using for the representation at the root of your service? Xhtml can be very useful for this because it is easy to parse, has existing support for links and renders nicely in a browser.

妖妓 2024-08-28 12:20:48

Renaud,

您是否使用 WADL 向客户端开发人员提供服务描述?

如果是这样,请注意这不是 RESTful,因为它违反了超媒体约束。 WADL 表示客户端开发人员不得依赖的信息。 WADL 本质上包含有关可用转换的信息,并且超媒体约束要求此类信息在运行时发现,而不是在设计时已知。

因此,在表单意义上使用 WADL 广告运行时是很好的[1],因为您可以更改 WADL 而不会破坏任何客户端。

[1] 虽然风格是有争议的 - 就我个人而言,我宁愿设计特定于领域的媒体

类型

Renaud,

are you using the WADL to provide a service description to the client developer?

If so, please not that this is not RESTful as it violates the hypermedia constraint. WADL expresses information that a client developer must not rely on. WADL essentially contains information about available transitions and the hypermedia constraint requires such information to be discovered at runtime, not to be known at design time.

Thus, using WADL ad runtime in the sense of a form is fine[1] because you can change the WADL without breaking any clients.

[1] Though the style is debatable - personally, I would rather design domain specific media types

Jan

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文