Just in time for holidays, Seam REST 3.0.0.Alpha2 was released. It's been a while since Alpha1 and therefore this release brings a lot of new features.

Seam Catch integration

Seam Catch provides an infrastructure for robust and unified exception processing. When both Catch and REST modules are deployed, Seam REST hooks into the JAX-RS runtime and catches unhandled exceptions. Subsequently, these exceptions are routed through Catch and can be handled using the Catch handler methods.

 

public void handleException(@Handles @RestRequest CaughtException<NoResultException> event,
   @RestResource Builder builder)
{
   builder.status(404).entity("The requested resource does not exist.");
}

 

 

With the @RestRequest qualifier, exceptions can be filtered based on their origin (e.g. NoResultException that occurs during JAX-RS invocation will be handled by this method while an exception of the same type that is thrown within JSF processing will not.)

 

The @RestResource enables resources like Response or ResponseBuilder, which are needed to handle the exception, to be injected.

 

RESTEasy Client framework integration

The RESTEasy Client Framework is a framework for writing clients for REST-based web services. It reuses JAX-RS metadata for creating HTTP requests. Take the following interface as an example:

 

@Path("/task")
@Produces("application/xml")
public interface TaskService
{
    @GET
    @Path("/{id}")
    Task getTask(@PathParam("id") long id);
}

The interface describes a remote JAX-RS service. With Seam REST, it is possible to simply @Inject a client for this service without implementing the interface:

 

@Inject @RestClient("http://example.com")
private TaskService taskService;

...

Task task = taskService.getTask(1);

 

RESTEasy takes care of proxying the interface. Every method invocation on the interface is translated to an HTTP request and sent to the server. RESTEasy also converts the HTTP response to a Java object.

 

Integration with the RESTEasy Client Framework is optional and only available when RESTEasy is available on classpath.

 

Templating support

Seam REST allows HTTP responses to be created using templates. Instead of being bound to a particlar templating engine, Seam REST comes with support for multiple templating engines and support for others can be plugged in.

 

To enable templating for a particular method, decorate the method with the @ResponseTemplate annotation. Path to a template file to be used for rendering is required.

 

@ResponseTemplate("/freemarker/task.ftl")
public Task getTask(@PathParam("taskId") long taskId) {
...
}

 

The template can be written in various templating engine's formats. Seam REST comes with support for FreeMarker and Apache Velocity. An SPI for extending the set of suported templating engines is provided.

 

What makes Seam REST's templating support even more interesting is that you can use EL names within the templates. Therefore, there is no need for an extra effort to make your objects reachable from within the template.

Migration to Seam Solder

The Weld Extensions project has been renamed to Seam Solder recently. Seam REST has been migrated to Seam Solder.

 

What's next?

For the next release, we are going to focus on:

  • overal stability and code cleanup improvements
  • completing documentation and examples
  • improving Bean Validation integration [SEAMREST-9]
  • and more...

 

Check it out

 

[Combined JAR] [Distribution] [JIRA] [API docs] [Reference guide] [Release Notes]