• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

swapnildipankar/java_jersey_spring_hibernate_maven: Archetype starter project to ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

swapnildipankar/java_jersey_spring_hibernate_maven

开源软件地址(OpenSource Url):

https://github.com/swapnildipankar/java_jersey_spring_hibernate_maven

开源编程语言(OpenSource Language):

Java 100.0%

开源软件介绍(OpenSource 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]"
     }'



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap