CASCON 2005 WTP tutorial
| ![]() |
By Ella Belisario, Jeffery Liu
|
|
The purpose of this tutorial is to demonstrate the overall capabilities of the WTP tools for the end users who are new to the tools. Some familiarity with WSDL and Web services is required for understanding certain parts of this tutorial. |
|
You will learn how to use WTP to administrate data contained in an Apache Derby database. You'll create and manage a J2EE application, and expose your application as a Web service. You'll also develop a user interface using JSP. Finally, you will deploy your application to an Apache Tomcat server and see your application in action. |
|
In this tutorial you will create a prototype of the marketing system, where participants can register their items through the Web Service which will make them available to all the other users. |
|
Participant needs to set up a database with the table of the items and create a Web Service with the given WSDL interface that enables sharing those items with others. |
|
The existing Web Service that is provided with this tutorial has interfaces to register items, look up the list of all available items and the details of any item given its name. Users can acess this Web Service and test it integrated with their own. |
|
After finishing this tutorial you will be able to do the following: |
|
|
|
|
|
Getting Started | |
|
|
In order to work with content of this tutorial you will need the following:
Apache Derby is available from http://db.apache.org/derby/derby_downloads.html |
|
Once you have downloaded WTP and prerequisites, unzip them to the same folder and you are ready to go! Launch Eclipse workbench. |
|
|
|
Creating Web project using wizard | |
|
|
The first thing we will do is to set up the Web project where we can add our Web Service and JSP files. |
|
To create an Web project invoke wizard using workbench menu File>New>Project...>Web>Dynamic Web Project |
|
|
|
|
|
On the wizard page enter the name of the project "ParticipantWeb" and configure server environment for it. |
|
|
|
|
|
![]() | Setting up Tomcat 5.0.28 Web server |
Select New Server Runtime and select Apache Tomcat v5.0 from the list, then click Next |
|
|
|
|
|
Browse to the installation of the Apache Tomcat v5.0 and select Sun Java 1.4.2 SDK. Tomcat requires a Java SDK in order to compile JSP files. Ensure that the JRE preference settings point to an SDK install location. |
|
|
|
|
|
At the end of this step you will find your "ParticipantWeb" project in the Project Explorer of J2EE perspective. |
|
|
|
|
|
Setting up Derby database | |
|
|
The next thing we will do is to create a database for storing the user items to be shared with other users. WTP provides a set of tools that help very easily to access and work with the databases. This includes Database Explorer. |
|
We will create a database called participant using Apache Derby 10.1.1.0. |
|
First open Database Explorer view by going to Window>Show View>Other... |
|
|
|
|
|
![]() | Creating and connecting to the database |
|
|
On the Database Explorer view open New Connection wizard |
|
|
|
|
|
New Connection wizard requires you to select a database manager ( Derby 10.0 ) and select database location and the driver jar file. |
|
You should have Apache Derby 10.1.1.0 installed on your system, so browse to that location and fill in the information. |
|
For the database location, you can choose any location, give it a name "participant". |
|
By keeping Create the database if required checked, the connection URL will contain the fragment "create=true". |
|
|
|
|
|
At the end of this step you will find your "participant" database in the Database Explorer view. |
|
|
|
|
|
![]() | Adding a table |
|
|
We will add one table ITEMS to the database to store data about user items that will be shared with the help of the Web Service with other users. |
|
To create a new table, on the Database Explorer use context menu of Tables folder of your database. |
|
|
|
|
|
SQL Editor opens with the sample table script, replace it with the one we provide and use editor context menu Run SQL to create the table. |
|
You can find table creation script in /cascon2005/data/ITEMS_Table.sql |
|
|
|
|
|
![]() | Adding some test data |
|
|
Now that you have the ITEMS table ready, add some sample data using WTP data editor. |
|
On the ITEMS table in the Database Explorer view select context menu Data>Open |
|
|
|
|
|
You'll see a table-based editor. Just enter some items and "save" the editor. Without you writing any SQL statement the database gets updated! |
|
Check out messages on the Data Output view or view contents by selecting context menu Data>Sample Contents on ITEMS table. |
|
|
|
|
|
You database and items are setup now. The next step is to create a Web Service which retreive those items. |
|
|
|
Generating Web Service from WSDL file | |
|
|
In this part of the tutorial, you will create a Web service that takes an item name as input, and returns the details for the item. We will then register this Web service and the items that you would like advertise with a marketing server. This marketing server is already setup on another machine. After registering your Web servide and your items, other people will be able to browse them. |
|
|
|
![]() | Exploring WSDL file with WSDL editor |
|
|
Copy participant.wsdl file from /cascon2005/data to your Web project and open it with WSDL editor. |
|
WSDL editor has a source page, graph view, properties and outline views. Source page has all the standard editing capabilities: syntax highliting, content assist, as-you-type validation and formatting. Graph page provides structural view of the parts of a WSDL file and a structure creation context menus. |
|
|
|
After some exploration of the WSDL editor, create SOAP binding using Add Binding context menu of the Binding part in the WSDL graph page. Select existing port type and select SOAP protocol. |
|
|
|
|
|
Now you need to specify service element. Using Add Service context menu of the Service part in the WSDL graph page. Type name "participant". |
|
Using Add Port context menu on the "participant" service, create new port for the service. Select existing binding and select SOAP protocol. |
|
|
|
|
|
Now you can see your WSDL files ready for generating a Web Service |
|
|
|
|
|
![]() | Using WSDL service generation wizard |
|
|
On the Package Explorer on participant.wsdl file select context menu Web Services>Generate Java bean skeleton You'll see Web Services wizard. Keeping all the defaults, you can go through and generate your Web Service. |
|
|
|
|
|
At the end of this step you will see in the Project Explorer view the generated Web Service classes and the participantSOAP.wsdl file that contains the real address of the Web Service. You need to use this address as a call back for the other clients to see the details of your items. |
|
|
|
|
|
Implementing your service | |
|
|
![]() | Integrating with the database layer |
|
|
Now you can implement the access to the database in your Web Service. Just copy the provided class DerbyDatabase.java into your package. You may need to replace the location of your participant database. |
|
The SELECT statement in getItemDetail method is based on the ITEMS table that was created in the previous step. |
|
The next thing you need to do is to add an implementation of ParticipantSOAPImpl.getItemInfo() method. The sample implementation could be copied from /cascon2005/data/participant/ParticipantSOAPImpl.java |
|
Now it's almost ready to run. The last thing is to add derby.jar to your project. Copy it from c:/db-derby-10.1.1.0-bin/lib/derby.jar into WEB-INF/lib directory of ParticipantWEB project. Also dont't forget to disconnect from the Derby database on the Database Explorer so that application can connect to it and let's try running what you've made! |
|
|
|
Testing the application | |
|
|
It's seasy to test Web Services using Web Services explorer. First start Apache Tomcat server in the Servers view. |
|
|
|
|
|
On the Package Explorer on ParticipantWeb/Web Content/wsdl/participantSOAP.wsdl file select context menu Web Services>Test with Web Services Explorer. You'll see the Web Services Explorer as in editor part. |
|
Select getItemInfoRequest and as a parameter enter the name of the item that you have in your database. Press GO. Can you see the results on the status part of the Web Services explorer? |
|
|
|
|
|
Congratulations! That makes the big part of the tutorial. Now by integrating with the other Web Service you can let other participants know what items you have for the auction and be able to explore at their items. |
|
|
|
![]() | Test integration with the other Web Services |
Select WSDL Main root on the Navigator of the Web Services Explorer. On the Actions part type URL of the other Web Service: |
|
http://machineName:8080/MarketServerWeb/wsdl/MarketServer.wsdl |
|
Press GO |
|
The other service interfaces should appear on the Web Services Explorer. |
|
|
|
|
|
Select registerClient interface to register your items. In the callBackAddress parameter field put the address of your service that you created in this tutorial, e.g. |
|
http://yourmachine:8080/ParticipantWeb/services/participantSOAP |
|
Try getItems interfaces to see the list of all registerd items of all the participants. Then choose a name and call getItemDetails interface to get some more item info. Observe the Status part of the Web Services Explorer. |
|
|
|
Creating a JSP page | |
|
|
For a bonus, you can create a JSP for your items and learn how to run and debug it in the workbench. |
|
Create a new JSP file in ParticipantWeb/WebContent folder by using context menu of the Project Explorer |
|
|
|
|
|
Open JSP file with the JSP editor. The JSP editor, like the WSDL editor that you have used in the tuturial, has all the standard editing capabilities: syntax highliting, content assist, as-you-type validation and formatting. |
|
Add some content to the page (you can copy content of /cascon2005/data/MyItem.jsp). This is a sample page that sets and displays the property values of the Item bean. |
|
The values are a little mixed up in the table. Try using JSP content assist to select the correct methods of the bean and inspect values of the properties of the Item bean in the JSP debugger. |
|
Put a break point on the first scriplet so that you can step through the JSP while debugging. |
|
|
|
|
|
It's easy to debug JSP. First, make sure that Apache Tomcat is not running or stop it from the Servers view. From the Project Explorer select your JSP file context menu on the Debug As>Debug On Server. You can step through the lines by clicking tollbar icons on the Debug view, see the value of the variables on the Variables view. |
|
|
|
|
|
Review | |
|
|
You have seen many tools during this tutorial. To review, there were
|