Sunday, March 6, 2011

Data service for the Shopping cart with WSO2 Carbon Studio

In the earlier post, you saw how to take the approach to convert your normal business into a SOA supported business.
In this example, we need to create five carbon application projects to support various aspects of this shopping cart.
   1. AcmeBackendServices - to create all the back-end related artifacts
   2. AcmeFrontendMonitor - to create all front-end gadgets
   3. AcmeFrontendOperator - to create Web application artifact to manage Acme shopping cart
   4. AcmeFrontendUser - to create front-end portal
   5. AcmeShoppingService - to create inter-mediate message passing ESB artifacts

Set up your environment to create the shopping cart's data service in carbon studio
  • Step 1
Download and install carbon studio.
  • Step 2
Check out the latest version of shopping cart sample from here. This contains
resources related to several artifact types such as ESB, BPS, Data Services, Gadgets etc.
  • Step 3
Go to the directory where the shopping cart is located. From there, build the shopping cart sample with the following command
    mvn clean install -Dmaven.test.skip=true
For this, you should have apache-maven installed in your machine. (Don't have maven? Download and install as per README)
  • Step 4
Download the WSO2 Data Services Server to deploy the created data service. The installed location will be refered as DS_HOME

Creating Data Service
From here onwards I will refer the location of your shopping cart sample as, SHOPPING-CART_HOME
  • Step 1
If you have successfully built the shopping cart sample as stated in above step 3, you should see a directory called "database" in SHOPPING-CART_HOME/target.
Copy that to your DS_HOME/samples. (Merge the two database folders.)
Now you have the database setup regarding shopping cart (with tables such as Category, Product, Customer, Payment etc.) in your system.
  • Step 2
Now we will create the legacy database system of Acme Shopping Cart.
With Carbon studio, you can create data service artifacts pointing to a data service descriptor file (.dbs) in several ways. In this sample, we will just import the data service descriptor file that we have checked out. (SHOPPING-CART_HOME/data-service/dbs/ShoppingCartDS.dbs)
  • Step 3
If you have already installed carbon studio to your Eclipse IDE, create a new carbon application project AcmeBackendServices.
For that, go to File --> New --> Project...
 Select Carbon Application Project from the wizard.
 

Give the name for the project as AcmeBackendServices and a location to save and click Finish.

Now you will see a new project is created with the given name, according to the following structure.
 
  • Step 4
TO create a data service, right click on AcmeBackendServices CApp project and select Data Service from the menu.

  
Now you will get a wizard. Since we already have the data service descriptor (.dbs) file in the checked out SHOPPING-CART_HOME/data-services/dbs directory, we will select the option Import data service from file. Give the location to the .dbs file.
Select AcmeBackendServices CApp project and click Finish.

  • Step 5
Now you will see new Data Service artifact is created under AcmeBackendServices project.
Congratulations!!
You have set up the data service required for the Acme Shopping cart.
  • Step 6
We use this data service, to connect with other partners. Usually we do not connect the legacy databases to applications as it is. Therefore for each and every creation of configurations in the sample, we will be using the created data service. To get the service URL for this service which allows you to use this in any other server, we need to create this artifact in a server.

Go to root-artifact.xml.
There it will show the Existing artifacts in that CApp. At this moment, you will see only ShoppingCartDS as an available artifact. Select it and save.
  

Now we can create the carbon application archive (.car) project out of this AcmeBackendServices by clicking on top right corner icon in the root-artifact.xml graphical view.


Specify a location to save the .car
  • Step 7
Start the DS server and go to management console.
Go to Manage -> Applications -> Add
Upload the created AcmeBackendServices.car
   


Go to Manage -> Services -> List
If the .car got deployed without any errors, you will see the ShoppingCartDS listed there.
   
You can click on Try this service and see whether it is working properly.

You have successfully exposed your legacy database to the shopping cart application now through a web service.

Await for the next post. It will demonstrate how to create a gadget to view these database information.

1 comment:

  1. Hi Manisha,

    as I try to build the sample project, I get the following stack trace;

    https://docs.google.com/document/d/1DtVIYONbpyy_BiOh4hzogdhlC7aYJbpNcDSYJcQPLNA/edit

    I'm using Maven 3.0.4, I have downloaded all dependencies, I'm on JDK 1.7.0._07...

    Thanks in advance...

    ReplyDelete