挂毯 +休息

发布于 2024-08-31 14:15:39 字数 199 浏览 4 评论 0 原文

我想将 REST 添加到我的 Tapestry 项目中,因此需要知道如何实现它。

更好的方法是什么?

谢谢。

[编辑,从答案复制:]我必须将 GET、PUT、POST 和 DELETE 服务添加到我的 Tapestry 应用程序中。我看到 Tapestry 有 RESTful url,但是 JAX-RS 和注释呢?

I want to add REST to my tapestry project, and so need to know how to implement it.

What is the better way ?

thx.

[Edit, copied from answer:] I have to add GET, PUT, POST and DELETE services to my tapestry application. I see that Tapestry has RESTful url but what about JAX-RS and annotations?

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

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

发布评论

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

评论(3

誰ツ都不明白 2024-09-07 14:15:39

您可以使用 Restlet API 或可以作为 servlet 运行的任何其他 JAX-RS 实现。

为了使 Web 服务与 Tapestry 良好共存,您必须在 Tapestry 应用程序模块

/**
 * Keep Tapestry from processing requests to the web service path.
 * 
 * @param configuration {@link Configuration}
 */
public static void contributeIgnoredPathsFilter(
        final Configuration<String> configuration) {
    configuration.add("/ws/.*");
}

此代码片段告诉 Tapestry 过滤器不要处理对 Web 服务所在的 /ws/ 路径的请求。

下面的代码片段显示了使用 Tapestry 加上 Restlet Servlet 时您的 web.xml 应该是什么样子:

<filter>
    <filter-name>app</filter-name>
    <filter-class>org.apache.tapestry5.spring.TapestrySpringFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>app</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!-- Restlet adapter -->
<servlet>
    <servlet-name>WebService</servlet-name>
    <servlet-class>
        com.noelios.restlet.ext.spring.SpringServerServlet
    </servlet-class>

    ...
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>WebService</servlet-name>
    <!-- This path must also be set in AppModule#contributeIgnoredPathsFilter,
        otherwise Tapestry, being a request filter, will try to handle 
        requests to this path. -->
    <url-pattern>/ws/*</url-pattern>
</servlet-mapping>

这应该可以帮助您入门。

You could use the Restlet API or any other JAX-RS implementation that can run as a servlet.

To have the web service co-exist nicely with Tapestry, there is one thing you have to configure in your Tapestry application module:

/**
 * Keep Tapestry from processing requests to the web service path.
 * 
 * @param configuration {@link Configuration}
 */
public static void contributeIgnoredPathsFilter(
        final Configuration<String> configuration) {
    configuration.add("/ws/.*");
}

This snippet tells the Tapestry filter not to handle requests to the /ws/ path where the web service is located.

Here's a snippet showing what your web.xml should approximately look like with Tapestry plus a Restlet Servlet:

<filter>
    <filter-name>app</filter-name>
    <filter-class>org.apache.tapestry5.spring.TapestrySpringFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>app</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!-- Restlet adapter -->
<servlet>
    <servlet-name>WebService</servlet-name>
    <servlet-class>
        com.noelios.restlet.ext.spring.SpringServerServlet
    </servlet-class>

    ...
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>WebService</servlet-name>
    <!-- This path must also be set in AppModule#contributeIgnoredPathsFilter,
        otherwise Tapestry, being a request filter, will try to handle 
        requests to this path. -->
    <url-pattern>/ws/*</url-pattern>
</servlet-mapping>

That should help you get started.

金橙橙 2024-09-07 14:15:39

如果您想将 REST Web 服务集成到 Tapestry 项目中,那么 Tapestry 的 RESTful URL 可能还不够。

可以通过 RESTEasy 集成到 Tapestry 中-resteasy+guide" rel="noreferrer">此 Tynamo 模块。 RESYEasy 与 JAX-RS 兼容。

我没有将 RESTEasy 与 Tapestry 一起使用,但与 Spring 2.5 一起使用,并且效果非常好。

If you want integrate a REST web service into a Tapestry project then Tapestry's RESTful URLs are probably not enough.

It is possible to integrate RESTEasy into Tapestry via this Tynamo module. RESYEasy is JAX-RS compatible.

I haven't used RESTEasy with Tapestry, but with Spring 2.5, and it worked really well.

许仙没带伞 2024-09-07 14:15:39

自 Tapestry 5.8.0 起,对 REST 端点的支持是一项内置功能。编写端点与在页面类中编写 onActivate() 方法几乎相同。

示例:

Object onHttpGet(String name, BigDecimal lat, BigDecimal lon) {
    Waypoint w = new Waypoint(lat, lon, name);
    waypointService.save(w);
    return HttpStatus.created();
}

所有好的 Tapestry 东西(例如参数类型强制、请求处理链等)都可用,因此可以轻松地将 REST 支持添加到现有 Tapestry Web 应用程序。不需要 JAX-RS 技能,因为它不是 JAX-RS 实现。

有关更多详细信息,请参阅 Tapestry 文档

Support for REST endpoints is a built-in feature since Tapestry 5.8.0. Writing and endpoint is pretty much the same as writing an onActivate() method in a page class.

Example:

Object onHttpGet(String name, BigDecimal lat, BigDecimal lon) {
    Waypoint w = new Waypoint(lat, lon, name);
    waypointService.save(w);
    return HttpStatus.created();
}

All the good Tapestry stuff like parameter type coercion, request processing chains etc. is available, so one can easily add REST support to existing Tapestry webapps. JAX-RS skills are not required, since it's not a JAX-RS implementation.

See the Tapestry Docs for more details.

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