Skip to content

FinixLei/renascence_finix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

renascence_finix Project


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.

  1. Download and install a MySQL 5.x database from http://dev.mysql.com/downloads/mysql/5.0.html#downloads.

  2. Run "mvn jetty:run" and view the application at http://localhost:8080.

  3. 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.


Restful API samples:

API-1: pull product per the specified category

Request

URI Method Comments
/commodity/product GET Pull the products of one given category

Parameters

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

Headers

None

Body

None

Response

Status line

  • 200 OK. Get the categories successfully.
  • 400 Bad request. The request is not conform with restrictions.
  • 500 Internal Server Error. Server has logic errors.

Body

{
   'has_more': bool,
   'pus':[
               {
                   'id': integer,
                   'name': string,
                   'description': string,
                   'price': float,
                   'items': [
                                {
                                    'id': integer,
                                    'pictures': [string, ...]
                                },
                                ...
                            ]
               },
               ...
               
           ]
}

Sample:

curl http://localhost:8080/renascence_finix/commodity/product?category_1=200&category_2=2001&sortby=price&desc=false&start=1&amount=5/

API-2: list all the categories

Request

URI Method Comments
/commodity/category GET Pull the categroies of products

Parameters

None

Headers

None

Body

None

Response

Status line

  • 200 OK. Get the categories successfully.
  • 400 Bad request. The request is not conform with restrictions.
  • 500 Internal Server Error. Server has logic errors.

Return Body


    [
        {
            'id': integer,
            'name': string,
            'sub_categories': [
                                  {
                                      'id': integer,
                                      'name': string
                                  },
                                  ...
                              ]
        },
        ...
    ]

Sample:

curl http://localhost:8080/renascence_finix/commodity/category


Quick Start

  • 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.


Steps for adding one RESTFUL API

Below is the example for constructing API-2 (list all the categories) above.

  1. 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.

  2. In dao package, add CategoryFirstLevelDao.java and CategorySecondLevelDao.java;
    They are interface, which extends GenericDao. This is for normal CRUD.

  3. 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.

  4. 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.

  5. 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.

  6. In WEB-INF folder, add one "serviceBean" to cxf-servlet.xml

OK, One Restful Web Service is done.

About

one appfuse project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages