A webservice which performs CRUD operations.
###################################### README
Author : Shalima Sidhik Date : 11/12/2015 Updated : 11/16/2015, 11/17/2015 #####################################
- Introduction
- Resources
- Modus Operandi
- Deployment
- Testing
- FAQ
- Issues
- Improvements to be made
This module upon deployment will publish a webservice which will perform CRUD operations along with some other operations.
The operations include :
-
Create a claim and persisting to the backing store And xml input is given to the webservice and a claim is created and persisted in the backing store. A SUCCESS or Error message will appear on the page.
-
Read a claim from backing store A claim number is given as input and a claim is read from the backing store and displayed.
-
Read a list of claims by date range of loss date A date range is given as input and a list of claims are read from backing store with loss date in the given range.
-
Update a claim in the backing store A claim given as input xml is updated on the backing store.
-
Read a specific vehicle A vehicle is read from the backing store with vin and claim number given as input.
-
Delete claim from backing store A claim is deleted from the backing store.
Database : Embedded HSQLDB Frameworks : Spring (Dependency injection), Hibernate (ORM mapping), JAXB(Xml binding), JAX-RS with Jersey(REST Webservice), Log4j, Jersey (Client) Logging : Log4j Server : JBoss Testing : JUnit, Postman
HSQLDB embedded database is used in the project.
The model has 3 tables : CLAIM, LOSSINFOTYPE, VEHICLEINFOTYPE.
CLAIM has OneToOne relationship with LOSSINFOTYPE where claimnumber of CLAIM is the primary key in the LOSSINFOTYPE table.
CLAIM has OneToMany relationship with VEHICLEINFOTYPE where claimnumber of CLAIM is the foreign key in the VEHICLEINFOTYPE. The primary key of Vehicleinfotype is vin.
The DB is initialized with createDB.SQL and insertDB.SQL scripts.
1. Created tables in DB.
2. Autogenerated model classes with reverse engineering utility of the hibernate.
1. JAXB classes are autogenerated with the help of JAXB.
WebServiceClient -> MitchellApplication -> MitchellRestResource -> MitchellService -> BaseDAO -> DB
MitchellApplication
Starts from here.
MitchellRestResource
Has the POST, GET, PUT and DELETE methods.
Converts the JAXB classes to model classes wherever necessary and sends them to corresponding service methods.
MitchellService
Has corresponding service methods.
MitchellServiceImpl implements the respective methods.
Uses the DAOFactory to get respective DAO objects and inputs are sent to the DAOs.
BaseDAO
Interface implemented by all DAOs
All DAO interfaces have corresponding DAOImpl classes where the methods are implemented.
Database transactions are performed here and the response is sent back.
dbInit.xml
Used to initialize the DB using Spring
spring.xml
Used to inject dependency and also register datasource.
springTest.xml
Used for testing
log4j.properties
Has properties for log4j loggin
hibernate.cfg.xml (Used for auto code generation of model classes)
Configuring the hibernate with the datasource
hibernate.reveng.xml (Used for auto code generation of model classes)
Used for reverse engineering
createDB.sql (/db)
SQL script for creatisng the tables
insertDB.sql (/db)
SQL script for inserting data into the table
Deploy the code in any of the following ways.
- Deploy the war file in a server
- Open the code in eclipse and run as server.
Test the program in any of the following ways
- Use Postman (an extension in google chrome) or any other extension for that matter.
- Use testWebServiceClient to test the code.
-
Reading all the claims (@GET) http://localhost:8080/org.mitchell.claim/resources/claims
-
Create a claim (@POST) http://localhost:8080/org.mitchell.claim/resources/claims/create/{xmlInput}
-
Update a claim(@PUT) http://localhost:8080/org.mitchell.claim/resources/claims/update/{xmlInput}
-
Delete a claim(@DELETE) http://localhost:8080/org.mitchell.claim/resource/deleteClaim/{claimNumber:String}
-
Read a claim(@GET) http://localhost:8080/org.mitchell.claim/resources/claims/getClaim/{claimNumber:String}
-
Read claims in given loss date range http://localhost:8080/org.mitchell.claim/resources/claims/getInDateRange/{fromDate:.*}/{toDate:.*}?fromDate={String}&toDate={String}
-
Read a vehicle from the table http://localhost:8080/org.mitchell.claim/resources/claims/getVehicle/{claimNumber:.*}/{vin:.*}?claimNumber={String}&vin={String}
What if I want to change the Datasource ? Change the datasource properties in spring.xml and alter the dbInit, if using, or delete it and you are good to go.
What if I want to change the webservice ? Change or delete the mitchellRestResource file and everything else stays the same.
What if I want to add more tables in DB ? Add the table and reverse engineer the model classes using hibernate.
What if I want to change the XML Schema ? Autogenerate the jaxb classes from the new schema using JAXB and use it.
A few issues and bugs are yet to be fixed :
An illegal mismatch while testing client
Potential root cause : A mismatch in the version in jsr311-api and jersey bundle.
Constraint violation in update and delete method
Potential root cause : The DB is not initialized properly everytime program is deployed.
If 'Session.close()' not commented, upon deployment, throws exception during database transactions but works fine with Unit test
Potential root cause : A version mismatch between hibernate and spring.
The unit test cases except client test case are working.
Fix the issues.
Improve the test cases.
Check the boundary conditions. If using another DB, use mock objects for testing.
Improve logging.