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): https://oss.sonatype.org/index.html#nexus-search;quick~ws.ament.hammock

Github: https://github.com/johnament/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:


  ws.ament.hammock
  hammock-core
  0.0.1


Add your REST Resource class:

@Path("/echo")
@RequestScoped
public class EchoResource {
    @GET
    @Produces("text/plain")
    public String greet() {
        return "hello";
    }
}

Implement the configuration, for application (via @ApplicationConfig)

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

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, org.jboss.weld.environment.se.StartMain .