Wednesday, February 26, 2014

Announcing Hammock

I'd like to introduce the world to Hammock

Hammock is based on my last blog post, creating a light weight service to run JAX-RS resources over a minimalistic configuration.

Binaries are currently up on Sonatype OSS (I hope they sync to MVN central shortly):;quick~ws.ament.hammock


What is Hammock?

Hammock is a light weight integration between JBoss RestEasy, Undertow and Weld.  Leveraging Weld SE, it provides automatic resource scanning and minimal binding code to launch a web container (Undertow) running the basic services to launch a full JAX-RS application.

Getting Started

Getting started with Hammock is simple.  Add a reference to the project in your pom.xml:


Add your REST Resource class:

public class EchoResource {
    public String greet() {
        return "hello";

Implement the configuration, for application (via @ApplicationConfig)

public class ApplicationConfigBean implements WebServerConfiguration {
    public int getPort() {
        return 8080;
    public String getContextRoot() {
        return "/api";
    public Collection getProviderClasses() {
        return Collections.EMPTY_LIST;
    public Collection getResourceClasses() {
        return Collections.singleton(EchoResource.class);
    public String getBindAddress() {
        return "";

You can optionally also do this for a management interface as well (via @ManagementConfig).  The resources tied to each of these configurations would then be launched when you start your application.

Starting your app can be done manually via Weld SE, or by using their built in class, .


  1. Cool stuff John. Glad to see you taking your code/ideas we discussed on the resteasy list and making it a reality. Let me know of any changes you need in resteasy to make this work

  2. Interesting. Would be cool to see how this performs vs Wildfly to get an idea of the additional overhead introduced since they both use the same components.

    There was some discussion of adding Wildfly to the TechEmpower benchmark project, but it doesn’t look like it has been done yet:

    Would be awesome to see them both up there.

  3. I've been searching for a while for a simple, embedded CDI/REST setup and found Hammock last week. Very nice!

    What would be a simple way to add a regular http servlet?


  4. I think I figured it out. Not sure if this is the best approach:

    ServletInfo defaultServlet = Servlets.servlet("DefaultServlet", DefaultServlet.class)

    ... .addServlet(resteasyServlet).setDeploymentName("ResteasyUndertow")
    .setResourceManager(new FileResourceManager(new File("web"), 1000))

  5. Hi John, the idea is brilliant and hammock works like a charm for creating standalone rest services. But I still wonder, what the ContextRoot configuration property is used for. How does it relate to the @ApplicationPath annotation used for Jax-RS Application? It seems to be internally added UriInfo request path but when I enter it in the browser it seems to be added again, ending up with the error: Could not find resource for full path: http://localhost:80/contextRoot/contextRoot/resource