-1

I want to map several methods to different URLs in a single servlet. The only I can find is what's described at this link

This seems a little too much work when other frameworks like Spring provide method annotations to map URLs to the methods.

But I want to keep my application free of such frameworks.

Is it possible to make use of any such 'annotation' mechanism without using complex frameworks like Spring or CXF?

Community
  • 1
  • 1
user2250246
  • 3,807
  • 5
  • 43
  • 71

1 Answers1

0

You can take a look at resteasy, which is an jax-rs implementation. Indeed it's a framework, but much lighter than Spring, and only designed to deal with annotation based rest services.

Example:
    @Path("/test")
    public class Endpoint {
    @GET
        @Produces("application/json")
        public Response listAll(@QueryParam("start") Integer startPosition, @QueryParam("max") Integer maxResult) {

           // all your code goes here

           return Response.ok().build();

        }
    }

Setting up RestEasy is as easy as creating a class like this:

@ApplicationPath("/rest")
public class RestApplication extends Application {
}

Whereas the rest url is at localhost/{appname}/rest/test

Simply add resteasy maven dependency with:

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxrs</artifactId>
    <version>3.0.11.Final</version>
</dependency>

Resteasy docs:

http://docs.jboss.org/resteasy/docs/3.0.9.Final/userguide/html/index.html

orbatschow
  • 1,497
  • 2
  • 13
  • 26