开发者

Tapestry + REST

开发者 https://www.devze.com 2022-12-29 06:18 出处:网络
I want to add REST to my tapestry project, and so need to know how开发者_如何学编程 to implement it.

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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消