User guide for Tapestry-resteasy module

tapestry-resteasy provides integration with Tapestry 5 and JBoss’ RESTEasy, an implementation JAX-RS (Java API for RESTful Web Services). JAX-RS is a very nice little spec and if you know what it is about, the following should be very easy to understand. Otherwise, read up on it at Jersey’s overview (the reference implementation) or the actual specification. JBoss’ RESTEasy provides a few more features over the reference implementation.


Add the tapestry-resteasy dependency to your pom.xml

To use tapestry-resteasy (an independent module of Tynamo), you need to add the following dependency to your pom.xml:


No need to edit your web.xml.

tapestry-resteasy integrates with the Tapestry’s HttpServletRequest pipeline.

Create a package named “rest” for your rest services.

tapestry-resteasy will scan the “rest” package and automatically add singleton resources to the configuration.

If you want to add extra packages, besides InternalConstants.TAPESTRY_APP_PACKAGE_PARAM + “.rest”, to be scanned for annotated REST resource classes you can contribute your package names to the ResteasyPackageManager.

public static void contributeResteasyPackageManager(Configuration<String> configuration)

Code your singleton resource.

Good practices:


import org.tynamo.examples.simple.MyDomainObject;

import java.util.List;

public class MyDomainObjectResource

	private PersistenceService persistenceService;

	public MyDomainObjectResource(PersistenceService persistenceService) {
		this.persistenceService = persistenceService;

	@Produces({"application/xml", "application/json"})
	public List<MyDomainObject> getAllDomains()
		return (persistenceService.getInstances(MyDomainObject.class));

	@Produces({"application/xml", "application/json"})
	public Response post(MyDomainObject domainObject)
		return Response.ok().build();

	@Produces({"application/xml", "application/json"})
	public MyDomainObject getDomainObject(@PathParam("id") Long id)
		MyDomainObject domainObject = persistenceService.getInstance(MyDomainObject.class, id);
		if (domainObject == null)
			throw new WebApplicationException(Response.Status.NOT_FOUND);
		return domainObject;


Annotate your entities.

Don’t forget to annotate your entities with JAXB annotations. You need at least @XmlRootElement. See:

package org.tynamo.examples.simple.entities;

import org.hibernate.validator.NotNull;
import org.tynamo.descriptor.annotation.PropertyDescriptor;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "mydomainobject")
public class MyDomainObject
	private Long id;

	private String name;

	@GeneratedValue(strategy = GenerationType.AUTO)
	@PropertyDescriptor(index = 0)
	public Long getId()
		return id;

	public void setId(Long id)
	{ = id;

	@NotNull(message = "name can't be null")
	public String getName()
		return name;

	public void setName(String name)
	{ = name;

	public boolean equals(Object o)
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;

		MyDomainObject that = (MyDomainObject) o;

		return getId() != null ? getId().equals(that.getId()) : that.getId() == null;

	public int hashCode()
		return (getId() != null ? getId().hashCode() : 0);

	public String toString()
		return getName();

Add a provider library to your pom.xml

By default tapestry-resteasy does not includes any marshaller/unmarshaller dependency.

You will need to manually add the dependency to your pom.xml

The previous examples use the JSON marshaller/unmarshaller provided by the resteasy-jettison-provider library. This provider allows you to marshall JAXB annotated POJOs to and from JSON, it wraps the Jettison JSON library to accomplish this.


If you don’t need JAXB and only you only need JSON support, you can use the JSON marshaller/unmarshaller provided by the resteasy-jackson-provider library. I personally find Jackson’s output format more intuitive than the format provided by either BadgerFish or Jettison.


You could use JAXB and Jackson together but be aware of the possible conflicts with the JAXB providers

Contribute singleton resources

If the rest services autodiscovery is not enough for you, you can manually contribute singleton resources in your AppModule:

 * Contributions to the RESTeasy main Application, insert all your RESTeasy singletons services here.
public static void configureRestResources(Configuration<Object> singletons, MyDomainObjectResource myDomainObjectResource)

Since the upgrade to Tapestry 5.3 and the move from Javassist to Plastic your JAX-RS annotations must be on the service interface or RESTEasy will not be able to find them.

Live class reloading

Available since tapestry-resteasy 0.2.1!

Reloading is limited to services that can be proxied, so to enable live class reloading for your REST services you need to create them as regular Tapestry IoC services with an interface and an implementation of that interface. You then have the option to leave them both in the autodiscovery package or explicitly bind them as services and contribute them to Read more about how service implementation reloading works in:

Here is an example from the tapestry-resteasy test suite.

public static void bind(ServiceBinder binder) { binder.bind(ReloadableEchoResource.class, ReloadableEchoResourceImpl.class); }

@Contribute( public static void configureRestResources(Configuration singletons, ReloadableEchoResource reloadableEchoResource) { singletons.add(reloadableEchoResource); }

Swagger integration

Add dependency to org.tynamo:tapestry-resteasy-swagger:0.0.2 (currently)

Integrates with swagger2 (openAPI v3). Fully configurable with an external configuration file.

OpenAPI spec is published under *//openapi.json* or *//openapi.yaml* Swagger UI is available at */webjars/swagger-ui/3.25.0?url=/mycustomresteasyprefix/openapi.json*


The default mapping prefix under which your rest resources are available is “rest”. You can easily change this by overriding the symbol in your application defaults:

public static void setApplicationDefaults(MappedConfiguration<String, Object> configuration) {
     configuration.add(ResteasySymbols.MAPPING_PREFIX, "/api");


If you get this exception:

Caused by: java.lang.ClassCastException: cannot be cast to org.codehaus.stax2.XMLInputFactory2

Add this to your system properties:

like so: mvn jetty:run

<!-- Run the application using "mvn jetty:run" -->
		<!-- Log to the console. -->
		<requestLog implementation="org.mortbay.jetty.NCSARequestLog">
			<!-- This doesn't do anything for Jetty, but is a workaround for a Maven bug
				 that prevents the requestLog from being set. -->

Check google for more information:

version table

tapestry-resteasy Tapestry RESTEasy notes:
0.0.1 5.1.x 1.1.GA see tapestry-resteasy-0.0.1 guide
0.2.1 5.2.x 2.0.1.GA  
0.3.0 5.3.x 2.3.0.GA  
0.3.1 5.3.x 3.0-beta-4  
0.3.2 5.3.x 3.0.1.Final  
0.4.0 5.4.x 3.0.7.Final  
0.5.0 5.4.x 3.1.4.Final  
0.6.0 5.5.x 3.11.2.Final