Tapestry + REST

2020-08-15 01:34发布

问题:

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?

回答1:

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.



回答2:

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.



标签: rest tapestry