This is a project generated from appfuse. The project object model (pom) is defined in the file pom.xml.
As a normal appfuse project, the following 3 steps are the same as appfuse.
-
Download and install a MySQL 5.x database from http://dev.mysql.com/downloads/mysql/5.0.html#downloads.
-
Run "mvn jetty:run" and view the application at http://localhost:8080.
-
More information can be found at:
http://appfuse.org/display/APF/AppFuse+QuickStart/
Actually, the work on this project is to create RESTFUL APIs. See below.
URI | Method | Comments |
/commodity/product | GET | Pull the products of one given category |
Parameter | Value | Required | Comments |
category1 | string | YES | The first category |
category2 | string | No | The second category |
sortby | string | No | The filed for sorting |
desc | bool | No | The sort type |
start | integer | No | The start index of paging |
amount | integer | YES | The amount of one page |
None
None
- 200 OK. Get the categories successfully.
- 400 Bad request. The request is not conform with restrictions.
- 500 Internal Server Error. Server has logic errors.
{
'has_more': bool,
'pus':[
{
'id': integer,
'name': string,
'description': string,
'price': float,
'items': [
{
'id': integer,
'pictures': [string, ...]
},
...
]
},
...
]
}
URI | Method | Comments |
/commodity/category | GET | Pull the categroies of products |
None
None
None
- 200 OK. Get the categories successfully.
- 400 Bad request. The request is not conform with restrictions.
- 500 Internal Server Error. Server has logic errors.
[
{
'id': integer,
'name': string,
'sub_categories': [
{
'id': integer,
'name': string
},
...
]
},
...
]
curl http://localhost:8080/renascence_finix/commodity/category
-
Step 1. cd /<path_to_renascence_finix>
-
Step 2. mvn install
-
Step 3. Import the test data
- mysql -u<user_name> -p -h localhost renascence_finix < Mysql/data_category.sql
- mysql -u<user_name> -p -h localhost renascence_finix < Mysql/data_product_item.sql
-
Step 4. mvn jetty:run
-
Step 5. Run curl command to try the APIs.
Below is the example for constructing API-2 (list all the categories) above.
-
In model package, add CategoryFirstLevel.java and CategorySecondLevel.java;
This is to use @Entity, @Table, @Id, @Column and some other JPA annotations to create DB schema. -
In dao package, add CategoryFirstLevelDao.java and CategorySecondLevelDao.java;
They are interface, which extends GenericDao. This is for normal CRUD. -
In dao.hibernate package, add CategoryFirstLevelDaoHibernate.java and CategorySecondLevelDaoHibernate.java;
Use @Repository("<table_name>") before the class definition.
This is the Implementation of the interface above. -
In service package, add CategoryManager.java
This is a interface.
Use JAXRS annotations like @Path(""), @GET, @PUT, @POST, @Consumes("application/json"), @Produces("application/json").
This is to define web service and HTTP methods handler.
This is also to connect web service and DAO. -
In service.impl package, add CategoryManagerImpl.java
Use JAXRS annotations like @Service("<service_manager>"), @WebService(serviceName="<service_name>"), @WebMethod.
This is the implementation of the interface above. -
In WEB-INF folder, add one "serviceBean" to cxf-servlet.xml
OK, One Restful Web Service is done.