Tapestry + REST
Asked Answered
S

3

10

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?

Sonority answered 4/5, 2010 at 12:25 Comment(2)
Tapestry 5 follows restful principles all by itself. Would you like to add a RESTful web service to your application? Please clarify your question so people can make sense of it.Stunner
Good question that I was wondering myself +1Mozellemozes
S
11

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.

Stunner answered 6/5, 2010 at 10:10 Comment(0)
G
10

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.

Greenburg answered 16/5, 2010 at 16:17 Comment(3)
I have used resteasy with tapestry app via Tynamo module and it was very straight-forward. Worked like a charm (though I had very simple requirements)Intracutaneous
Actually you do not need tynamo for using RESTEasy at all.Croft
I would go with the tynamo module, I've used this in a number of projects and it works fine.Drumfish
C
0

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.

Chamness answered 22/5, 2023 at 19:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.