Professional Documents
Culture Documents
21 Mar 2007
Java™ 2 Platform, Enterprise Edition (J2EE) 1.4 supports two types of Web service
endpoints: Plain Old Java Object (POJO) and Enterprise JavaBeans (EJB)
endpoints. IBM® WebSphere® Application Server Community Edition (also referred
to as Community Edition in this tutorial) is a J2EE 1.4-certified application server that
provides support for these two types of Web service endpoints. This tutorial shows
you how to use the Eclipse Web Tools Platform (WTP) to create an enterprise
application that implements both POJO and EJB Web service endpoints, using IBM
DB2® Express-C as the database for the application. You'll use the Community
Edition server adapter (formerly known as the Eclipse plug-in) to deploy the
application to an Community Edition instance. And finally, you'll develop a client to
call the Web services.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 1 of 49
developerWorks® ibm.com/developerWorks
implements both POJO and EJB Web service endpoints. You'll use IBM DB2®
Express-C as the database for the application, and you'll use the Community Edition
server adapter to deploy the application to an Community Edition instance.
Afterward, you'll use the Eclipse WTP Web service testing functions to test your Web
services and write clients to invoke them.
Prerequisites
To succeed with this tutorial, you should be familiar with Java development in
general and, specifically, server-side Java development. You should understand the
general concepts behind relational databases and be familiar with basic J2EE
concepts, such as deployment descriptors and WAR archives. You should also be
familiar with XML, XML schemas, Eclipse, and the Eclipse WTP. Prior experience
with application servers, Web services, and relational databases is also
recommended.
System requirements
You need to download the following required (no-charge) applications to follow along
with this tutorial and work with the sample code included:
• Support for the JDK/JRE listed above with at least 512MB of main
memory (1GB recommended)
• At least 10MB of additional free disk space to install the software
components and examples
The instructions in this tutorial are based on a Microsoft® Windows® operating
system. All of the tools and techniques covered in this tutorial also work on Linux®
and UNIX® operating systems.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 2 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
Two of the important specifications that are used by Web services are:
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 3 of 49
developerWorks® ibm.com/developerWorks
service endpoints described earlier. In the case of a POJO Web service, the
request-response flow is shown in Figure 1. Note: This graphic presents a simplified
view, and it doesn't show all the details of the integration of Axis with Community
Edition.
In the flow of events depicted in Figure 1, first the Web service is deployed in the
server using custom Community Edition deployers. During the deployment process,
all the information in the deployment descriptor is extracted by the deployer and
populated into a GBean -- namely, AxisWebServiceContainer. Now, during the
startup of the application, all the servlets are registered with Tomcat. During the
registration process, a custom servlet called POJOWebServiceServlet is registered
for URLs corresponding to POJO Web services. The AxisWebServiceContainer
and the POJO representing the Web service are put in the ServletContext, and their
corresponding keys are passed to the POJOWebServiceServlet as initialization
parameters. Now, whenever the Web service is invoked using its configured URL,
the POJOWebServiceServlet is invoked, and it looks up the
AxisWebServiceContainer and POJO and passes them to Axis along with the
request and response objects. Axis then invokes the required method on the POJO
and returns the response. In the case of an EJB Web service, the EJB container --
OpenEJB -- also comes as a layer between the request and response. A simplified
representation of the request-response flow in the case of an EJB Web service is
shown in Figure 2.
Note that the enterprise bean is hosted in the EJB container. It's invoked by the
EJBContainerProvider class, which is the pivot handler that's registered in Axis.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 4 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
So, the pivot handler, which is a custom one packaged with Community Edition,
takes care of invoking the session bean deployed in the OpenEJB container. Also, a
valve is registered -- EJBWebServiceValve -- which lets the Web service requests
be processed in a custom manner. This valve takes care of invoking the methods on
the AxisWebServiceContainer class.
• Login
• Registration
• User Details
• Available Stocks
• User Portfolio
The application provides the following two Web services:
• StockService
• UserStockService
Figure 3 shows the application flow.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 5 of 49
developerWorks® ibm.com/developerWorks
The user is first shown the Login page. From there, the user enters his or her user
name and password and submits the page. After validation of the user's credentials,
the Available Stocks page is displayed, where the user can view all the stocks that
are for sale on the exchange at that time. The user can choose to buy any stock
(provided there's enough money in his or her account) by clicking the Buy button.
After the transaction completes successfully, the user is brought back to the
Available Stocks page.
Clicking the View Your Portfolio link takes the user to his or her portfolio, which
shows all the stocks the user owns. The user can sell whichever stock he or she
owns from this page. This page also shows the user's free cash in the user cash
field. If the user is new, he or she can go to the Registration page by clicking the
Register button on the Login page. The user can then enter all the fields and click
Submit to register. He or she can also view the available stocks and his or her
portfolio in a stand-alone client by invoking two Web services: StockService and
UserStockService, respectively.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 6 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
4. Click Finish.
A new database called TRADEDB is created and listed under All Databases (see
Figure 4).
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 7 of 49
developerWorks® ibm.com/developerWorks
In the previous section, you created a database called TRADEDB. Now you'll create
tables for users (USERS), stocks (STOCKS), and user accounts
(TRADINGACCOUNT) within that database. The fields within the different tables are
shown in Table 1.
Table 1. USERS
Field name Data type Key
userid VARCHAR(15)
PRIMARY
KEY NOT
NULL
name VARCHAR(50)
password VARCHAR(24)
address VARCHAR(96)
cash DECIMAL
Table 2. STOCKS
Field name Data type Key
ID VARCHAR(8)PRIMARY
KEY NOT
NULL
name VARCHAR(100)
Price DECIMAL
Table 3. TRADINGACCOUNT
Field name Data type Key
userid VARCHAR(15)
FOREIGN
KEY NOT
NULL
stockid VARCHAR(18)
FOREIGN
KEY NOT
NULL
quantity INT
3. Add a column to the table, then click Add and enter the column name.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 8 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
6. Click Next > Next > Next to navigate to the screen titled Define keys on
new table. Click Add Primary.
7. From the available columns, select the column for primary key, and click
Finish.
12. In the PARENT table (or nickname section), select the schema as the
schema where you have created these tables.
13. Select STOCKS as the name of the table. This shows the primary key
STOCKS in the primary key list.
14. In the Available columns section, select STOCKID, and click the > button.
16. Repeat this procedure, and map the USERID field of the USERS table to
USERID of TRADINGACCOUNT.
After you complete the previous steps, the tables are created under the
ADMINISTRATOR schema. (Note: Schema assignment depends on the Windows
login that you're using. If you log in as db2admin, the tables are created under the
DB2ADMIN schema.) After creation, the tables can be viewed in the DB2 Express-C
Control Center, as shown in Figure 5.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 9 of 49
developerWorks® ibm.com/developerWorks
Now follow these instructions to populate the tables with values (see Figure 6):
5. Follow the same steps for all other tables. Note that you can use the
values in the db2_brokerage.sql file, which is in the sql directory.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 10 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
Alternatively, you can also create the database, tables, and data using an SQL script
by performing the following steps. The sample in this tutorial has a script file called
db2_brokerage.sql; execute this script from a DB2 command line to create the
database and tables as follows:
2. Execute the script file from the DB2 command window (db2 -tvf
db2_brokerage.sql). This path should be given if db2_brokerage.sql is in
the same directory where the command is executed. Otherwise, you must
give the full path instead of db2_brokerage.sql.
If there are no errors, you should see all SQL commands executed successfully. The
script creates the database and all the related tables, as shown in Figure 7.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 11 of 49
developerWorks® ibm.com/developerWorks
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 12 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
2. Click Window > Open Perspective > Other > J2EE to open the J2EE
perspective.
6. In the next screen, select the appropriate JRE, and fill in the Application
Server Installation Directory field with the installation directory
(C:\Program
Files\IBM\WebSphere\AppServerCommunityEdition), then click
Finish. An Community Edition V1.1 instance is created in the Servers
view.
2. Select File > New Project > Web > Dynamic Web project.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 13 of 49
developerWorks® ibm.com/developerWorks
6. Click Next.
8. Click Finish.
2. Select File > New Project > J2EE > Enterprise application project.
6. Click Next.
8. Click Finish.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 14 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
3. From the Import dialog box, select General > File System, and click
Next.
4. From the File System dialog box, browse to where you extracted the
compressed file provided with the article, and in From Directory, select
<zip-file-directory>/web-src/.
5. Expand the web-src directory in the left pane, and select com.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 15 of 49
developerWorks® ibm.com/developerWorks
9. In the Java Build Path dialog box, select the Projects tab.
10. Click Add, select BrokerageEjb in the Required Project Selection dialog
box, then select OK.
11. Return to the Java Build Path dialog box, and select OK.
You now have all the classes imported. To import the JavaServer Pages (JSP) files,
perform the following steps. The JSP files are also imported into Eclipse:
2. In the Import dialog box, select General > File System, then click Next.
3. From the File System dialog box, browse to the JSPs directory in the
brokerage.zip file, which contains all the JSPs, and click OK. The JSPs
are listed in the right pane.
1. Right-click the package you want your EJB class to belong to.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 16 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
not set correctly, go to Window > Preferences > Xdoclet, and click the
XDoclet. Set the XDoclet Home tag to point to the home directory of
XDoclet in your system. Select the right version, and click OK.)
5. In the Enterprise JavaBean dialog box, enter the relevant information, and
click Next.
6. Continue entering the remaining information, and then click Next >
Finish.
Here, <dest-dir> equals the absolute path of the directory to put the generated
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 17 of 49
developerWorks® ibm.com/developerWorks
classes, WSDL, and mapping files. <workspace> equals the absolute path of the
Eclipse workspace directory. And <wasce_home> equals the Community Edition
installation directory.
Note: After installing the Java WSDP, you can add <JWSDP_HOME>\jaxrpc\bin
to the PATH environment variable so that you can access wscompile from the
command prompt. The default value of JWSDP_HOME is C:\Sun\jwsdp-2.0.
After generating the WSDL and mapping files for each Web service, put them in the
appropriate locations in the Eclipse projects:
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 18 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
Because the Eclipse WTP provides schema-based editors for each of the plans, you
don't need to manually write these descriptors. To create plans using the editor,
follow these steps, and refer to Figure 9:
3. Select the Design tab of the editor to open a new editor showing a tree
structure.
4. Right-click the web-app to display all the possible operations you can do
using the editor. The editor shows all the children you can add and
remove.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 19 of 49
developerWorks® ibm.com/developerWorks
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 20 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
2. Click the Naming tab of the Community Edition Deployment Plan Editor.
3. In the Resource References section, click the Add button. This brings up
the Resource Reference Details screen.
5. Click Finish.
Figure 11. Resource Reference Details
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 21 of 49
developerWorks® ibm.com/developerWorks
7. Click Add, and add two dependencies with the following details:
• Group ID: geronimo
• Artifact ID: axis
• Version: 1.1
• Artifact type: car
• Group ID: console.dbpool
• Artifact ID: TradeDS
• Version: 1.0
• Artifact type: rar
8. This creates the deployment plan for the Web application. When you click
the Source tab, the contents of the plan should appear as shown in
Listing 3. Alternatively, you can enter the contents of Listing 3 directly into
the Source editor.
Listing 3. Entry into the Source editor
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 22 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
(Note: Lines two through four in Listing 3 were broken due to space constraints.)
Listing 3 shows the geronimo-web.xml file. Here, the environment tag represents
the Web application environment. It defines the module ID of the Web module as
well as the dependencies -- for example, the modules on which this module
depends. The context-root tag gives the context root of the Web application to
be /brokerage. The other important tag is the resource-ref tag, which is used
to map the name jdbc/TradeDB to the database pool TradeDS, which you'll
deploy in the following sections. This results in the corresponding data source being
bound to java: comp/env/jdbc/TradeDB in Java Naming and Directory Interface
(JNDI).
The openejb-jar.xml file is created in the META-INF directory of the EJB module, as
shown in Listing 4.
Listing 4. openejb-jar.xml
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 23 of 49
developerWorks® ibm.com/developerWorks
(Note: Lines two through five in Listing 4 were broken due to space constraints.)
The openejb-jar.xml file also contains the module ID and dependency declarations. It
has a session element that's used to map the name of the bean to a jndi-name in
this case. The resource-ref element is also present. The Community Edition
Deployment Plan Editor for openejb-jar.xml is shown in Figure 12.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 24 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
Listing 5. geronimo-application.xml
(Note: The second and third lines in Listing 5 were broken due to space constraints.)
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 25 of 49
developerWorks® ibm.com/developerWorks
You don't need to make any changes to this file for this application. The WTP also
provides schema-based XML editors for writing the plans. The schema-based editor
for ejb-plan is shown in Figure 13.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 26 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
1. Select File > Import > J2EE, select EAR File, and click Next.
3. Click Next after selecting both the Web and EJB modules.
4. Click Finish.
5. Click I agree in the license dialog. The EAR file is imported, and the
respective Eclipse projects are created.
8. Rebuild all the projects. Four errors and 16 warnings remain, but ignore
these for the time being.
Define a server
To deploy an application, you first need to create a server in the Eclipse WTP by
following the steps below:
1. Right-click within the Servers Tab window, and select New Server (see
Figure 14).
Figure 14. Define a new server
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 27 of 49
developerWorks® ibm.com/developerWorks
3. In the New Server dialog box, fill in the Application Server Installation
Directory field so that it points to the server home directory, and click
Next.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 28 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
5. Click Finish.
To start the server and log in to the console, follow these steps:
1. In the Servers tab, right-click Community Edition 1.1, and select Start.
This starts the server inside Eclipse.
2. When the server status becomes started, right-click the server icon again,
and select Launch Community Edition Console.
3. Now enter the user name as system and the password as manager, and
click the Login button. This takes you to the Welcome page of the
administration console.
A database pool is necessary to connect to DB2. You can create this by deploying a
database pool plan using the wizard that's available in the Community Edition
Console. Do the following:
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 29 of 49
developerWorks® ibm.com/developerWorks
4. Enter TradeDS in the field Name for Database Pools, and click Next.
6. You can test the connection to check for any errors and then deploy the
data source.
7. You may see a license-related error. To work around this error, go back
and click the Skip Test and Show Plan button.
9. Add a dependency to the DB2 license .jar file in the repository, as shown
in Listing 6.
Listing 6. Add dependency to DB2 license .jar file
<dep:dependency>
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 30 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
<dep:groupId>com.ibm.db2</dep:groupId>
<dep:artifactId>db2jcc_license_cu</dep:artifactId>
<dep:version>8.2</dep:version>
<dep: type>jar</dep:type>
</dep:dependency>
10. Now you can deploy the pool by deploying this plan. Select the Deploy
New option from the console.
13. Once you deploy the pool, it's started and running. You can also use the
plan file, provided in the plans directory of brokerage.zip, after editing the
properties to reflect your database configuration. Remember that the user
you configure in the plan should have access to the schema where you
created the tables.
Figure 17. Installed J2EE connectors
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 31 of 49
developerWorks® ibm.com/developerWorks
1. Right-click the server icon, and select Add and remove projects.
2. In the Add and Remove Projects dialog box, select BrokerageApp, and
click Add to add this project to the Configured projects list.
3. Click Finish.
4. Right-click the server icon, and select Publish to deploy the application.
1. Shut down Eclipse, restart it, and then try again. The problem may stop
occurring.
2. If step 1 doesn't solve the problem, export the .ear file to a temporary
location, open it with an extraction tool, and remove the http: directory
from the WAR file inside the EAR file.
Now you need to deploy this application using the Admin console (see Figures 18
and 19).
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 32 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 33 of 49
developerWorks® ibm.com/developerWorks
2. Right-click and select Run As, and then select Run on Server.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 34 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
1. Log in to the application by entering the user name j2ee and password
password. You're taken to the Available Stocks page.
2. Under one of the available stocks, enter the quantity 2, and select the
Buy radio button.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 35 of 49
developerWorks® ibm.com/developerWorks
4. After the request is submitted, click the View Your Portfolio link, which
takes you to the Portfolio screen. You can sell stocks similarly here.
Figure 21. Available Stocks page
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 36 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
5. Click the User Info button to access the page showing user details.
Figure 23. User details
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 37 of 49
developerWorks® ibm.com/developerWorks
6. If you want to register a new user, click the Register button on the Login
page to access the registration page where you can enter user details.
The WTP provides a tool called Web Services Explorer that lets you test the Web
services you've deployed. The following steps describe how to use the Web
Services Explorer to invoke the Web services that you deployed for testing:
2. Expand this node to reveal two subnodes called Clients and Services.
3. Expand the Services node to reveal two subnodes representing the two
Web services that you deployed.
Figure 24. Using Web Services Explorer
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 38 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 39 of 49
developerWorks® ibm.com/developerWorks
6. Click the getStocks link under Operations to bring up the Actions screen.
7. Click Go to invoke the Web service. The output is shown in the Status
pane, as shown in Figure 26.
Figure 26. The Status pane
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 40 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
1. Select File > New > Project > Web > Dynamic Web Project, then click
Next.
2. Give the project name as ServiceClient, and click Finish to create the
project.
4. Expand this node to reveal two subnodes called Clients and Services.
5. Expand the Services node to reveal two subnodes representing the two
Web services that you deployed.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 41 of 49
developerWorks® ibm.com/developerWorks
9. Click Finish. This generates the following classes inside the ServiceClient
project:
• UserStockIF
• UserStockIFBindingStub
• UserStockIFProxy
• UserStockService
• UserStockServiceLocator
Now you can write a client that uses these classes and invoke the Web service in
the Client class:
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 42 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
1. Import the contents in the client directory from the extracted file (provided
with this article) to the respective directories (for example, import web.xml
and geronimo-web.xml into WEB-INF; import source files to src; and
import .jsp files to the root of the WebContent directory).
package com.dev.trade.client;
import java.io.IOException;
import java.rmi.RemoteException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.rpc.ServiceException;
import com.dev.trade.service.UserStockIF;
import com.dev.trade.service.UserStockService;
import com.dev.trade.service.UserStockServiceLocator;
import com.dev.trade.service.types.Stock;
public class ClientServlet extends HttpServlet {
protected void doGet(HttpServletRequest arg0,
HttpServletResponse arg1)
throws ServletException, IOException {
listUserStocks(arg0, arg1);
}
protected void doPost(HttpServletRequest arg0,
HttpServletResponse arg1)
throws ServletException, IOException {
// TODO Auto-generated method stub
listUserStocks(arg0, arg1);
}
public void listUserStocks(HttpServletRequest request,
HttpServletResponse response) throws IOException {
String name = (String) request.getParameter("name");
String password = (String)
request.getParameter("password");
UserStockService userStockService = (UserStockService)
new UserStockServiceLocator();
UserStockIF userStockIF = null;
try {
userStockIF = userStockService.getUserStockIFPort();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 43 of 49
developerWorks® ibm.com/developerWorks
The following steps are necessary to run the Web service client:
2. Right-click the server icon in the Servers pane, and select Add Remove
Projects.
5. Enter the user ID J2EE and the password password, then click Submit
Query to get a listing of the user's stocks.
Figure 28. User's stocks
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 44 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 45 of 49
developerWorks® ibm.com/developerWorks
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 46 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
Downloads
Description Name Size Download method
Tutorial source code brokerage.zip 65KB HTTP
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 47 of 49
developerWorks® ibm.com/developerWorks
Resources
Learn
• See "Using the Eclipse Plug-in for WebSphere Application Server Community
Edition" (developerWorks, April 2006) for more information on the plug-in.
• Visit the WebSphere Application Server Community Edition content area here
on developerWorks for a comprehensive set of tools and resources.
• Get product documentation for WebSphere Application Server Community
Edition.
• "Get started with WebSphere Application Server Community Edition" (April
2006, developerWorks) today using this helpful guide.
• Read the developerWorks article "Using the Web console in WebSphere
Application Server Community Edition" to get started using the Web console.
• Learn more about "Using the Eclipse Plug-in for WebSphere Application Server
Community Edition" (developerWorks, April 2006).
• Explore the WebSphere Application Server Community Edition technical
support offerings available from IBM.
• Get more information on WSDL.
• Get more information on the SOAP specification.
• Check out the developerWorks Apache Geronimo project area for articles,
tutorials, and other resources to help you get started developing with Geronimo
today.
• Visit the Apache Geronimo Web site.
• Check out the IBM Support for Apache Geronimo offering, which lets you
develop Geronimo applications backed by world-class IBM support.
• Visit the developerWorks Open source zone for extensive how-to information,
tools, and project updates to help you develop with open source technologies
and use them with IBM's products.
• Stay current with developerWorks technical events and webcasts.
• Browse for books on these and other technical topics at the Safari bookstore.
Get products and technologies
• Download the WebSphere Application Server Community Edition server
adapter (formerly known as the Eclipse plug-in).
• Download the Eclipse Web Tools Platform from eclipse.org.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
Page 48 of 49 © Copyright IBM Corporation 1994, 2008. All rights reserved.
ibm.com/developerWorks developerWorks®
• Download Apache Axis, a Java platform for creating and deploying Web
services applications.
• Download your free copy of WebSphere Application Server Community Edition
-- a lightweight J2EE application server built on Apache Geronimo open source
technology that is designed to help you accelerate your development and
deployment efforts.
• Download free software for rapid results, and kick-start your Java application
development.
• Innovate your next open source development project with IBM trial software,
available for download or on DVD.
Discuss
• Participate in the discussion forum for this content.
• Get involved in the developerWorks community by participating in
developerWorks blogs.
Trademarks
IBM, the IBM logo, DB2, and WebSphere are registered trademarks of IBM in the
United States, other countries, or both.
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the
United States, other countries, or both.
Microsoft and Windows are trademarks of Microsoft Corporation in the United States,
other countries, or both.
UNIX is a registered trademark of The Open Group in the United States and other
countries.
Linux is a registered trademark of Linus Torvalds in the United States, other
countries, or both.
Develop and deploy J2EE Web services using WebSphere Application Server Community Edition
© Copyright IBM Corporation 1994, 2008. All rights reserved. Page 49 of 49