REST API Maven Dependency : Jersey + Jetty

Hooooh …. finally !!! After devoting ample number of hours with lots of R&Ds, finally able to resolve the long running dependencies between Jersey and Jetty when developing a REST API.

I am posting the article because working and running the REST API with TOMCAT or similar server would be easy but might not with embedded JETTY Server (What I felt). I have experienced lot of dependency issues thorough out the setup. Hence I am posting to help and might save the setup time hopefully.

Why I felt the Jetty Server is so cool over Tomcat :

  1. Full-featured and standards-based.
  2. Embeddable and Asynchronous.
  3. Open source and commercially usable.
  4. Dual licensed under Apache and Eclipse.
  5. Flexible and extensible, Enterprise scalable.
  6. Strong Tools, Application, Devices and Cloud computing supported.
  7. Low maintenance cost.
  8. Small and Efficient.

The following is couple of (out of all) errors faced at the time of setup. A very simple but commonly occurred exception.

  • Error code : 52
ERR_EMPTY_RESPONSE – No Data Received
Error code : 52  
Sudhirs-MacBook-Pro-2:yanagishima-5.0 sudhir.pradhan$ curl -L -X GET http://localhost:8083/presto/hello

curl: (52) Empty reply from server
  • Error code : 500
java.lang.NoSuchMethodError: org.eclipse.jetty.server.Response.getResponse(Ljavax/servlet/http/HttpServletResponse;)Lorg/eclipse/jetty/server/Response;

The complete dependency configuration (Jersey + Jetty + Maven) : pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <!--
    @author : Sudhir R. Pradhan
    @date   : Jun 09 2017
    -->

    <groupId>ZQueryEngine</groupId>
    <artifactId>ZQE</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <version.jersey>2.26-b03</version.jersey>
        <version.aws>1.11.133</version.aws>
        <version.jetty>9.2.14.v20151106</version.jetty>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.glassfish.jersey</groupId>
                <artifactId>jersey-bom</artifactId>
                <version>${version.jersey}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

        </dependencies>

    </dependencyManagement>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-server -->
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-server</artifactId>
            <version>${version.jersey}</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <version>${version.jersey}</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet</artifactId>
            <version>${version.jersey}</version>
        </dependency>

        <!-- do not use jettison, prefer jackson
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jettison</artifactId>
            <version>${version.jersey}</version>
        </dependency>
        -->
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jackson</artifactId>
            <version>${version.jersey}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-processing</artifactId>
            <version>${version.jersey}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-multipart</artifactId>
            <version>${version.jersey}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-sse</artifactId>
            <version>${version.jersey}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.8.8</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.8.8</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.8.8</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.containers/jersey-container-jetty-http -->
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-jetty-http</artifactId>
            <version>${version.jersey}</version>
        </dependency>


        <!-- if you are using Jersey client specific features -->
        <!--
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
            <version>${version.jersey}</version>
        </dependency>
        -->

        <!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk -->
        <!-- <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk</artifactId>
            <version>${version.aws}</version>
        </dependency> -->

        <!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-core -->
        <!-- <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-core</artifactId>
            <version>${version.aws}</version>
        </dependency>-->

        <!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-s3 -->
        <!-- <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-s3</artifactId>
            <version>${version.aws}</version>
        </dependency>-->

        <!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-athena -->
        <!-- <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-athena</artifactId>
            <version>1.11.133</version>
        </dependency>-->

        <!-- https://mvnrepository.com/artifact/com.amazonaws.athena.jdbc/AthenaJDBC41 -->
        <!-- <dependency>
            <groupId>com.amazonaws.athena.jdbc</groupId>
            <artifactId>AthenaJDBC41</artifactId>
            <version>1.1.0-atlassian-hosted</version>
        </dependency> -->


        <!-- https://mvnrepository.com/artifact/com.facebook.presto/presto-client -->
        <!-- <dependency>
            <groupId>com.facebook.presto</groupId>
            <artifactId>presto-client</artifactId>
            <version>0.177</version>
        </dependency>-->


        <!-- https://mvnrepository.com/artifact/com.facebook.presto/presto-spi -->
        <!-- <dependency>
            <groupId>com.facebook.presto</groupId>
            <artifactId>presto-spi</artifactId>
            <version>0.177</version>
        </dependency>-->

        <!-- https://mvnrepository.com/artifact/com.facebook.presto/presto-tpch -->
        <!-- <dependency>
            <groupId>com.facebook.presto</groupId>
            <artifactId>presto-tpch</artifactId>
            <version>0.177</version>
        </dependency>-->


        <!-- https://mvnrepository.com/artifact/com.facebook.presto/presto-jdbc -->
        <!-- <dependency>
            <groupId>com.facebook.presto</groupId>
            <artifactId>presto-jdbc</artifactId>
            <version>0.60</version>
        </dependency>-->

        <!-- https://mvnrepository.com/artifact/com.facebook.presto/presto-parser -->
        <!-- <dependency>
            <groupId>com.facebook.presto</groupId>
            <artifactId>presto-parser</artifactId>
            <version>0.177</version>
        </dependency>-->

        <!-- https://mvnrepository.com/artifact/org.jooq/jooq -->
        <!-- <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq</artifactId>
            <version>3.9.3</version>
        </dependency>-->


        <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.25</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.25</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.25</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/com.google.inject/guice -->
        <!--<dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>4.0</version>
        </dependency>-->

        <!-- https://mvnrepository.com/artifact/com.google.inject.extensions/guice-servlet -->
        <!--<dependency>
            <groupId>com.google.inject.extensions</groupId>
            <artifactId>guice-servlet</artifactId>
            <version>4.0</version>
        </dependency>-->

        <!-- https://mvnrepository.com/artifact/io.airlift/http-client -->
        <!--<dependency>
            <groupId>io.airlift</groupId>
            <artifactId>http-client</artifactId>
            <version>0.148</version>
        </dependency>-->

        <!-- https://mvnrepository.com/artifact/io.airlift/json -->
        <!--<dependency>
            <groupId>io.airlift</groupId>
            <artifactId>json</artifactId>
            <version>0.148</version>
        </dependency>-->

        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/fluent-hc -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>fluent-hc</artifactId>
            <version>4.5.3</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.komamitsu/fluency -->
        <!--<dependency>
            <groupId>org.komamitsu</groupId>
            <artifactId>fluency</artifactId>
            <version>1.3.0</version>
        </dependency>-->

        <!--<dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.16</version>
            <scope>provided</scope>
        </dependency>-->

        <!-- https://mvnrepository.com/artifact/me.geso/tinyorm -->
        <!--<dependency>
            <groupId>me.geso</groupId>
            <artifactId>tinyorm</artifactId>
            <version>1.13.0</version>
        </dependency>-->

        <!-- https://mvnrepository.com/artifact/net.sf.jopt-simple/jopt-simple -->
        <dependency>
            <groupId>net.sf.jopt-simple</groupId>
            <artifactId>jopt-simple</artifactId>
            <version>5.0.3</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.eclipse.jetty.aggregate/jetty-all -->
        <dependency>
           <groupId>org.eclipse.jetty.aggregate</groupId>
           <artifactId>jetty-all</artifactId>
           <version>${version.jetty}</version>
       </dependency>

       <dependency>
           <groupId>org.eclipse.jetty</groupId>
           <artifactId>jetty-server</artifactId>
           <version>${version.jetty}</version>
       </dependency>


       <dependency>
           <groupId>org.eclipse.jetty</groupId>
           <artifactId>jetty-servlet</artifactId>
           <version>${version.jetty}</version>
       </dependency>

       <!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-http -->
       <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-http</artifactId>
            <version>${version.jetty}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-util -->
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-util</artifactId>
            <version>${version.jetty}</version>
        </dependency>

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-io</artifactId>
            <version>${version.jetty}</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-io -->
        <!--<dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-io</artifactId>
            <version>9.3.17.v20170317</version>
        </dependency> -->

    </dependencies>
    
</project>

I will also try to post ,

  • The complete end-to-end sample project with Jersey + Jetty
  • A sample project to develop REST API to work with Amazon ATHENA & S3.
  • A sample project to develop REST API to work with Facebook PRESTO & Hive & S3.

Hope the the article helps.

Cheers …..

Advertisements