Rest webservice using: Jersey, Guice, JPA 2.0 (EclipseLink), SQlite, Jetty.

Project description

I have created a simple tutorial project which binds some of java technologies that can be use while writing webservices.
Project is available on github at https://github.com/tmorcinek/rest-webservice-training


Important informations

Technologies/Frameworkds that are used:

  1. Maven (building, organizing tool)
  2. Jersey (JAX-RS implementation)
  3. Guice (IoC Container)
  4. EclipseLink (JPA 2.0 implementation – ORM)
  5. SQlite (Database)
  6. Jetty (Application Server)



How to use

To run the server you need to execute program. Class com.morcinek.server.webservice.Main contains main() method. So you can easily execute it in debug or normal mode through your IDE. If you are old-school you can always compile it with maven and run it in command line.
First time you run it, program creates database. In our case, since we use SQLite, there will be file sample.db created.


How to access webservice resources

Setup

As it is set in main() method. You can access resources from localhost where port number is 8080 and context path /api.

...
    public static final String CONTEXT_PATH = "/api";
    public static final int PORT = 8080;
...
        Server server = new Server(PORT);
        ServletContextHandler root = new ServletContextHandler(server, CONTEXT_PATH, ServletContextHandler.SESSIONS);
...

Base URL

Base url looks like this: http://localhost:8080/api/.

Resources

The Application Resource have path /service, with two specific path

  1. /authors returns list of authors in json.
  2. /date returns current system date.

and :

...
@Path("/service")
...
    @GET
    @Path("/authors")
    public Response getAuthors() {
...
    @GET
    @Path("/date")
    public Response getSystemDate() {
...

Accessing

You can access those resources under:

  1. http://localhost:8080/api/service/authors
  2. http://localhost:8080/api/service/date


Where to find it

As it was mentioned above, the tutorial project you can find on github at https://github.com/tmorcinek/rest-webservice-training.


Help

If you want some more information about how to create rest webservices please visit my other posts, where I describe (step by step), how to create one:
First restful web service with mave
Restful web service with maven – continuation


Reklamy

Skomentuj

Wprowadź swoje dane lub kliknij jedną z tych ikon, aby się zalogować:

Logo WordPress.com

Komentujesz korzystając z konta WordPress.com. Wyloguj / Zmień )

Zdjęcie z Twittera

Komentujesz korzystając z konta Twitter. Wyloguj / Zmień )

Facebook photo

Komentujesz korzystając z konta Facebook. Wyloguj / Zmień )

Google+ photo

Komentujesz korzystając z konta Google+. Wyloguj / Zmień )

Connecting to %s