Coder Social home page Coder Social logo

swapnildipankar / java_jersey_spring_hibernate_maven Goto Github PK

View Code? Open in Web Editor NEW
28.0 11.0 23.0 332 KB

Archetype starter project to create RESTful WS using Java, Jersey WS, Spring, Hibernate, Maven, Liquibase, MySQL and MongoDB. Code for integrating with Hibernate/MySQL and MongoDB/NoSQL.

License: GNU General Public License v3.0

Java 100.00%

java_jersey_spring_hibernate_maven's Introduction

Archetype starter project to create RESTful WS using Java, Jersey WS, Spring, Hibernate, Maven, Liquibase. Sample code for integrating with Hibernate/MySQL and MongoDB/NoSQL.

Note: This is a skeletal archetype framework. Using the sample code, developers can send a sample CURL call (see section "Sample test CURL calls" below) to the running web service and see the changes propagated all the way to the databases. There are, currently, two webservice end points, /user and /purchase for demonstrating MySQL and MongoDB respectively. Developers will have to write the actual functionality to make use of the framework.

  • New: Support for MongoDB
  • Coming Up: Support for Cassandra
  • Coming Up: Support for NuoDB

Developers:

  • Parth Parekh - parthparekh at gmail dot com
  • Swapnil Dipankar - dswapnil at gmail dot com

Technologies used in the project

  • Java
  • Jersey WS Framework
  • Spring Framework
  • Hibernate
  • Maven
  • Liquibase
  • MySQL
  • Mongo DB

Prerequisite packages

Note: The project has been tested on several versions of Mac OSX and Ubuntu Linux, but can work on any other platform as long as the packages mentioned in this section are available on the platform. Ensure that the user has sudo access to the host

  • OpenJDK SDK (run command sudo apt-get install openjdk-6-jdk, if not present) Note: Sun JDK can be used instead of OpenJDK without impacting the functionality of the framework
  • Git (run command sudo apt-get install git or sudo apt-get install git-core, if not present)
  • Maven (run command sudo apt-get install maven2, if not present)
  • Curl (run command sudo apt-get install curl, if not present)
  • MySQL Server (run command sudo apt-get install mysql-server, if not present)
  • MongoDB (run command sudo apt-get install mongodb, if not present)
  • Vim (optional) (run command sudo apt-get install vim, if not present)
  • IntelliJ Idea Community Edition (optional) (download IDE from http://www.jetbrains.com/idea/download/index.html)
  • Cocoa REST Client (optional, this is only for Mac OSX) (download from https://code.google.com/p/cocoa-rest-client/)

Prerequisite MySQL database and tables

  • Ensure that MySQL is running and has the root password as password (Else, modify the hibernate.cfg.xml file with correct database credentials)
  • Ensure that database test exists (Else, create a database test with the access credentials specified in hibernate.cfg.xml file)

Prerequisite MongoDB database

  • Ensure that MongoDB is running (run command mongod --master --dbpath path_to_directory_that_will_contain_database_data)
  • Ensure that database purchase has user with credentials (purchase_user, purchase4user) (Else, modify the credentials in file resources/mongodb/mongo-config.json)

Steps to compile, install and run code

Run the following commands in the given sequence:

  • git clone https://github.com/swapnildipankar/java_jersey_spring_hibernate_maven.git
  • cd java_jersey_spring_hibernate_maven
  • mvn clean install (Depending on the connection speed, this step may take several minutes when executing this command for the first time)
  • mvn resources:resources liquibase:update -P database-localhost -Dliquibase.password=password (This creates the table user in the database test)
  • mvn tomcat7:run (The tomcat server should now be ready to accept requests on port 8400)

Sample test CURL calls (http://localhost:8400/demows/user - this uses MySQL for persistence)

  • POST Request:
	curl -i -H "Content-Type: application/json" -X POST -d \
	'{
		"username":"johndoe",
		"password":"ǝopuɥoɾ",
		"name_first":"John",
		"name_middle":"M",
		"name_last":"Doe",
		"date_of_birth":14,
		"month_of_birth":10,
		"year_of_birth":1978
	}' 'http://localhost:8400/demows/user'
  • Response:
	'{
		"id": 1,
		"username": "johndoe",
		"password": "41a87d0faca541b691f11c6d51874f37b989f0cb1b0075cce599e94f82cbbdfc",
		"name_first": "John",
		"name_middle": "M",
		"name_last": "Doe",
		"user_status": "PENDING",
		"user_status_code": "P",
		"date_of_birth": 14,
		"month_of_birth": 10,
		"year_of_birth": 1978,
		"created_at": 1355386501092,
		"updated_at": 1355386501092
	}'
  • PUT Request:
	curl -i -H "Content-Type: application/json" -X PUT -d \
	'{
		"id":"1",
		"username":"johndoe",
		"password":"ǝopuɥoɾ",
		"name_first":"John",
		"name_middle":"M",
		"name_last":"Doe",
		"user_status":"ACTIVE",
		"date_of_birth":14,
		"month_of_birth":10,
		"year_of_birth":1978
	}' 'http://localhost:8400/demows/user/1'
  • Response:
	'{
		"id": 1,
		"username": "johndoe",
		"password": "41a87d0faca541b691f11c6d51874f37b989f0cb1b0075cce599e94f82cbbdfc",
		"name_first": "John",
		"name_middle": "M",
		"name_last": "Doe",
		"user_status": "ACTIVE",
		"user_status_code": "A",
		"date_of_birth": 14,
		"month_of_birth": 10,
		"year_of_birth": 1978,
		"created_at": 1355386501092,
		"updated_at": 1355388359982
	}'
  • GET (By User ID) Request:
	curl 'http://localhost:8400/demows/user/1'
  • Response:
	'{
		"id": 1,
		"username": "johndoe",
		"password": "41a87d0faca541b691f11c6d51874f37b989f0cb1b0075cce599e94f82cbbdfc",
		"name_first": "John",
		"name_middle": "M",
		"name_last": "Doe",
		"user_status": "ACTIVE",
		"user_status_code": "A",
		"date_of_birth": 14,
		"month_of_birth": 10,
		"year_of_birth": 1978,
		"created_at": 1355386501092,
		"updated_at": 1355388359982
	}'
  • GET (By UserName) Request:
	curl 'http://localhost:8400/demows/user/username/johndoe'
  • Response:
	'{
		"id": 1,
		"username": "johndoe",
		"password": "41a87d0faca541b691f11c6d51874f37b989f0cb1b0075cce599e94f82cbbdfc",
		"name_first": "John",
		"name_middle": "M",
		"name_last": "Doe",
		"user_status": "ACTIVE",
		"user_status_code": "A",
		"date_of_birth": 14,
		"month_of_birth": 10,
		"year_of_birth": 1978,
		"created_at": 1355386501092,
		"updated_at": 1355388359982
	}'
  • DELETE Request:
	curl -i -H "Content-Type: application/json" -X DELETE -d \
	'{
		"id":"1",
		"username":"johndoe",
		"password":"ǝopuɥoɾ",
		"name_first":"John",
		"name_middle":"M",
		"name_last":"Doe",
		"date_of_birth":14,
		"month_of_birth":10,
		"year_of_birth":1978
	}' 'http://localhost:8400/demows/user/1'
  • Response: [Notice that the user gets marked as 'DELETED' and is not removed from the database]
	'{
		"id": 1,
		"username": "johndoe",
		"password": "41a87d0faca541b691f11c6d51874f37b989f0cb1b0075cce599e94f82cbbdfc",
		"name_first": "John",
		"name_middle": "M",
		"name_last": "Doe",
		"user_status": "DELETED",
		"user_status_code": "D",
		"date_of_birth": 14,
		"month_of_birth": 10,
		"year_of_birth": 1978,
		"created_at": 1355386501092,
		"updated_at": 1355388912852
	}'

Sample test CURL calls (http://localhost:8400/demows/purchase - this uses MongoDB for persistence)

  • POST Request:
    curl -i -H "Content-Type: application/json" -X POST -d \
    '{
        "billing_address": {
            "first_name" : "Travis",
            "city" : "San Franciso",
            "postal_code" : "94000",
            "street_2" : "Street 2",
            "last_name" : "John",
            "street_1" : "Street 1",
            "country_code" : "US",
            "phone_number" : "415-415-1000",
            "name" : "Travis John",
            "state" : "CA"
        },
        "shipping_address": {
            "first_name" : "Johnny",
            "city" : "San Antonio",
            "postal_code" : "32000",
            "street_2" : "Street 2",
            "last_name" : "Cash",
            "street_1" : "Street 1",
            "country_code" : "US",
            "phone_number" : "420-420-1000",
            "name" : "Johnny Cash",
            "state" : "TX"
        },
        "billing_card": {
            "card_type" : "AMERICAN_EXPRESS",
            "card_number" : "kIXI51g+t88DJjaNguPMEQ==",
            "security_code" : "1004",
            "expiration_month" : 3,
            "expiration_year" : 2020,
            "encryption_type" : "sha512"
        },
        "user_ip_address": "127.127.127.127",
        "email": "[email protected]",
        "invoice_number": "INVOICE123",
        "client_id": "CLIENT124",
        "user_id": "PERSON123",
        "order_number": "WON123",
        "create_date": "MAR-21-2013",
        "transaction": {
            "currency_code" : "USD",
            "transaction_amount" : "1099.99"
        }
    }' 'http://localhost:8400/demows/purchase'
  • Response:
	'{
       "id" : "5159d6d9456668495a2de972",
       "order_number" : "WON123",
       "create_date" : "MAR-21-2013",
       "user_ip_address" : "127.127.127.127",
       "transaction" : {
         "currency_code" : "USD",
         "transaction_amount" : "1099.99"
       },
       "invoice_number" : "INVOICE123",
       "user_id" : "PERSON123",
       "billing_address" : {
         "first_name" : "Travis",
         "city" : "San Franciso",
         "postal_code" : "94000",
         "street_3" : null,
         "street_2" : "Street 2",
         "last_name" : "John",
         "street_1" : "Street 1",
         "country_code" : "US",
         "phone_number" : "415-415-1000",
         "name" : "Travis John",
         "state" : "CA"
       },
       "shipping_address" : {
         "first_name" : "Johnny",
         "city" : "San Antonio",
         "postal_code" : "32000",
         "street_3" : null,
         "street_2" : "Street 2",
         "last_name" : "Cash",
         "street_1" : "Street 1",
         "country_code" : "US",
         "phone_number" : "420-420-1000",
         "name" : "Johnny Cash",
         "state" : "TX"
       },
       "client_id" : "CLIENT124",
       "billing_card" : {
         "card_type" : "AMERICAN_EXPRESS",
         "card_number" : "kIXI51g+t88DJjaNguPMEQ==",
         "security_code" : "1004",
         "expiration_month" : "3",
         "expiration_year" : "2020",
         "encryption_type" : "sha512"
       },
       "email" : "[email protected]"
     }'

java_jersey_spring_hibernate_maven's People

Contributors

swapnildipankar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.