 | Create Web services with IDS
One of the features of Data Studio is the ability to create Data Web
Services. You can expose your database operations (invocation of a
stored procedure, select, insert, or update statements) easily as Web
services with a few clicks of a button, and then Data Studio takes
care of creating the Web application for you. It can create both SOAP
and 'REST'ful services for you. You can then deploy the Web
application (that includes the Web service classes and the WSDL file)
on a Web server, and you are done.
You need to create a new project first. Perform the following the
steps:
- Go to File > New > Project > Data
Development Project.
- Name the project
ifmxproject, and click
Next.
- Use the connection name that you created for your Informix
database.
- Answer Yes to Open Associated Perspective.
Now you are ready to create Web services. Perform the following
steps:
- In the Data Project Explorer, select the project that you have
just created.
- Right-click on Web Services, and select New Web
Service.
- Name the Web service ifmxservice, and click
Finish.
- Right-click on the Web Service, and click New
Operation.
- Type in an SQL statement to select three fields from the cust
table, as shown in Figure 8:
Figure 8.
Creating an operation
- Select Validate to confirm that the statement is valid.
Leave the name as "Operation1".
- Pick the Web service ifmxservice from the previous step,
and then click Build and Deploy.
- This tutorial uses WebSphere Application Server Community Edition
2.1. The steps in the next section list the configuration steps
for WebSphere Application Server Community Edition 2.1. This
example also uses the REST scenario, instead of SOAP.
- Click on Finish. This creates all the necessary components
for you.
Figure 9.
Deploying a Web service
Configure
WebSphere Application Server Community Edition
This section includes a set of steps for how to configure WebSphere
Application Server Community Edition 2.1 to make it work with Informix
and then get the Web service running.
- The installer comes with Data Studio Developer 2.1 when the
option is enabled. It is found in the <install
dir>/dsdev/bin directory. Run the installer.
- After installing the server, bring up the server by selecting
IBM WebSphere > Application Server Community
Edition > Start the server.
- Open a web browser and type in the default url:
http://127.0.0.1:8080/console/portal
- The default username/password to log in: system/manager.
Figure 10.
WebSphere Application Server Community Edition
Administration Console
Follow the steps below if you do not want the workbench
to register the database connection with the Web server.
- Since IBM Data Server Driver for JDBC and SQLJ is already
registered, you have an option to add Informix JDBC Driver
if you desire to use that driver instead. Add the
ifxjdbc.jar file to the WebSphere Application Server
Community Edition repository. In order to do this in the
Administrative Console, select Console Navigation
> Services > Repository.
- In the Repository Viewer, fill in the fields, and click
Install. Use the following values for the
fields:
- Pick up ifxjdbc.jar from the appropriate
location.
- In the Group field, specify
com.informix.jdbc.
- In the Artifact field, specify
ifxjdbc.
- In the Version field, specify 11.0.
- In the Type field, specify jar.
Figure 11. Driver JAR
file
- Create an IDS database pool by using the Geronimo database
pool wizard. Each Web service that you deploy on the
server must use a unique database pool.
- Name the database pool and select Informix as the
database type.
- Select the following driver JAR file:
com.informix.jdbc/ifxjdbc/11.0/jar.
- The next step is to set up the database pool connection.
Select Database Pools under Services folder on the
left screen.
- Create a new database pool by clicking on Using the
Geronimo database pool wizard.
- Specify the name of the database pool and database type,
then click on Next.
- Fill in the following fields (as illustrated in Figure 12):
- JDBC Driver Class:
com.informix.jdbc.IfxDriver
- Driver Jar: com.informix.jdbc/ifxjdbc/11/jar
- DB User Name: the username used to connect to the database
- DB Password: <DB password>
- Confirm Password: <confirm password>
- Port: <The server port>
- dbservername: <The database server name>
- Database:
gsdb
- Host: <The host name>
Figure 12. Parameters
(Click here to see a larger
image of Figure 12.)
- After pressing Next, verify that the JDBC Connect
URL is valid.
- Optionally, you can specify values for parameters of the
connection pool.
- Record the value of the groupID and artifactID parameters for the
database connection pool. You must specify these values when you
deploy the Web service that uses this database connection pool.
The values of the groupID and artifactID parameters are
case-sensitive. In this example, the groupID is console.dbpool and
the artifactID is gs_db.
- Click Finish and deploy, and make sure you can connect to
your database.
Ensure the geronimo-web.xml file generated by the Data Studio has the
matching information in the highlighted portion.
Listing 1.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1"
xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2"
xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2">
<dep:environment>
<dep:dependencies>
<dep:dependency>
<dep:groupId>console.dbpool</dep:groupId>
<dep:artifactId>GSDB</dep:artifactId>
<dep:version>1.0</dep:version>
<dep:type>rar</dep:type>
</dep:dependency>
</dep:dependencies>
</dep:environment>
<context-root>ifmxprojectifmxservice</context-root>
<naming:resource-ref>
<naming:ref-name>jdbc/ifmxservice</naming:ref-name>
<naming:pattern>
<naming:groupId>console.dbpool</naming:groupId>
<naming:artifactId>GSDB</naming:artifactId>
<naming:name>GSDB</naming:name>
</naming:pattern>
</naming:resource-ref>
</web-app>
|
Create the Web archive file (WAR file) to be deployed to the Web
server. To do this, complete the following steps:
- Switch to the Java perspective by going to Window >
Open Perspective > Java.
- For your Web service ifmxservice and your project ifmxproject,
there is a Web project called "ifmxprojectifmxserviceWeb" that
has been created.
- Generate the WAR File by clicking on the project, then
right-click and select Export.
- Select WAR file, and then click Next.
Figure
13. Export into WAR file
- Create the file in an appropriate location to be used later in
the WebSphere Application Server Community Edition deployment
panel.
Figure
14. Export to a local system
Now, switch back to the Administration Console and deploy the WAR file
by performing the following steps:
- Log back in to the Administration Console.
- Go to Applications > Deploy New, and pick the
WAR file created earlier.
Figure
15. Deploy WAR file
If you have used all of the defaults as mentioned in the tutorial, use
the following URL in a browser window to look at the service in
action:
http://localhost:8080/ifmxprojectifmxservice/rest/ifmxservice/Operation1/.
If your Web applications port is not 8080, you may have to change the
port to match your environment.
|  |