Skip Headers
Oracle® SOA Suite Tutorial
Release 3 (10.1.3.1.0)

Part Number B28937-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

5 Creating the CreditService Project

This chapter describes how to create the CreditService project. It contains these sections:

5.1 About the CreditService Project

The CreditService project checks whether a customer's credit card is valid or not. In this SOA Order Booking application, the code simply checks the value of the credit card number. If the credit card number is less than 12345678, then the card is invalid. Otherwise, it is valid.

The CreditService project is developed in a "top-down" fashion: you start with a WSDL and using this WSDL file, you generate Java classes. RapidService is the opposite: it is developed in a "bottom-up" fashion, where you start with Java classes and you develop a WSDL file from the Java classes.

Note that the WSDL file for the CreditService project contains hardcoded values of localhost:8888. You need to modify these values if you meet any of these conditions:

5.2 Create a New Project for CreditService

Start by creating a new project for CreditService in JDeveloper:

  1. Right-click the SOADEMO application, and select New Project.

  2. In the New Gallery, in the Categories section, expand General and select Projects. In the Items section, select Empty Project.

    Figure 5-1 New Gallery for the CreditService Project

    Description of Figure 5-1 follows
    Description of "Figure 5-1 New Gallery for the CreditService Project"

    Click OK.

  3. In the Create Project dialog, enter "CreditService" in the Project Name field.

    Figure 5-2 Create Project Dialog for CreditService

    Description of Figure 5-2 follows
    Description of "Figure 5-2 Create Project Dialog for CreditService"

    Click OK.

    In the Application Navigator, you should see an empty CreditService project located under the SOADEMO application.

  4. Select File > Save to save your work.

5.3 Copy the WSDL File

Define the project type and copy the WSDL file from the soademo_101310_prod.zip file to the CreditService directory.

  1. Right-click the CreditService project, and select New.

  2. In the New Gallery dialog, in the Categories section, expand Business Tier and select Web Services. In the Items section, select WSDL Document.

    Figure 5-3 New Gallery for Setting Up the WSDL File

    Description of Figure 5-3 follows
    Description of "Figure 5-3 New Gallery for Setting Up the WSDL File"

    Click OK. This launches the Create WSDL Document dialog.

  3. In the Create WSDL Document dialog:

    • WSDL Name: enter CreditService.

    • Directory Name: accept the default (SOADEMO\CreditService\src).

    • Target Namespace: accept the default because you are going to overwrite the generated WSDL file anyway. In the WSDL file, the target namespace is http://www.globalcompany.com/ns/credit.

    Figure 5-4 Create WSDL Document Dialog

    Description of Figure 5-4 follows
    Description of "Figure 5-4 Create WSDL Document Dialog"

  4. Click OK.

  5. Close (by selecting File > Close) the CreditService.wsdl file that JDeveloper displays in the editor.

  6. Copy CreditService\src\CreditService.wsdl from the soademo_101310_prod.zip file and overwrite the generated CreditService.wsdl in the SOADEMO\CreditService\src directory.

5.4 Generate Java from the WSDL

In this step, you generate Java classes for the methods declared in the WSDL file.

  1. Right-click the CreditService project, and select New. In the New Gallery, in the Categories section, expand Business Tier and select Web Services. In the Items section, select Java Web Service from WSDL.

    Figure 5-5 New Gallery for Generating Java from WSDL

    Description of Figure 5-5 follows
    Description of "Figure 5-5 New Gallery for Generating Java from WSDL"

    Click OK. This launches the Create J2EE 1.4 Java Web Service from WSDL wizard. Click Next in the wizard to begin.

  2. In Step 1, Web Service Description, click Browse and select the CreditService.wsdl file from the SOADEMO\CreditService\src directory.

    Mapping File: leave blank.

    Figure 5-6 Create J2EE 1.4 Java Web Service from WSDL Wizard: Step 1, Web Service Description

    Description of Figure 5-6 follows
    Description of "Figure 5-6 Create J2EE 1.4 Java Web Service from WSDL Wizard: Step 1, Web Service Description"

    Click Next.

  3. In Step 2, Default Mapping Options:

    • Package Name: enter org.soademo.creditservice.

    • Root Package for Generated Types: enter org.soademo.creditservice.types.

    • Generate Data Binding Classes: select this option.

    • Reuse Existing Type Classes: select this option.

    • Map Headers to Parameters: select this option.

    Figure 5-7 Create J2EE 1.4 Java Web Service from WSDL Wizard: Step 2, Default Mapping Options

    Description of Figure 5-7 follows
    Description of "Figure 5-7 Create J2EE 1.4 Java Web Service from WSDL Wizard: Step 2, Default Mapping Options"

    Click Next.

  4. In Step 3, Specify Custom Data Type Serializer, leave blank and click Next.

    Figure 5-8 Create J2EE 1.4 Java Web Service from WSDL Wizard: Step 3, Specify Custom Data Type Serializer

    Description of Figure 5-8 follows
    Description of "Figure 5-8 Create J2EE 1.4 Java Web Service from WSDL Wizard: Step 3, Specify Custom Data Type Serializer"

  5. In Step 4, Handler Details, accept the defaults and click Next.

    Figure 5-9 Create J2EE 1.4 Java Web Service from WSDL Wizard: Step 4, Handler Details

    Description of Figure 5-9 follows
    Description of "Figure 5-9 Create J2EE 1.4 Java Web Service from WSDL Wizard: Step 4, Handler Details"

  6. In Step 5, State, do not select Stateful Service. Click Next.

    Figure 5-10 Create J2EE 1.4 Java Web Service from WSDL Wizard: Step 5, State

    Description of Figure 5-10 follows
    Description of "Figure 5-10 Create J2EE 1.4 Java Web Service from WSDL Wizard: Step 5, State"

  7. In the Finish screen, click Finish.

    JDeveloper displays CreditService.wsdl in design view in the editor.

5.5 Display the List of Files in the Structure Window

You should see the following files in the Structure window:

  1. Select View > Structure to display the Structure window.

  2. In the Application Navigator, select SOADEMO > CreditService > Application Sources > org.soademo.creditservice > CreditService.

    In the Structure window, you should see the following files:

    • CreditService.wsdl

    • ValidateCreditCard.java

    • CreditCardValidationFaultMessage.java

    • CreditCard.java

    • CreditService-java-wsdl-mapping.xml

    • ValidateCreditCardImpl.java

5.6 Build CreditService

Right-click the CreditService project and select Rebuild.

5.7 Write the Code to Perform Credit Card Validation

Double-click ValidateCreditCardImpl.java (from the Structure window) and edit the verifyCC method so that it looks like the following:

public boolean verifyCC(CreditCard creditCard)
                                  throws CreditCardValidationFaultMessage {
   boolean validOrNot = false;
   if ((creditCard.getCcType().equals("AMEX")) ||
         (creditCard.getCcType().equals("Visa"))) {
      validOrNot = true;
      Long ccnum = new Long (creditCard.getCcNum());
      if (ccnum < 12345678){
         validOrNot = false;
      } else {
         validOrNot = true;
      }
   } else {
      validOrNot = false;
   }
   return validOrNot;
}

5.8 Verify Hostname and Port in CreditService.wsdl

There are two CreditService.wsdl files:

You have to verify the hostname and port in both wsdl files.

  1. Double-click the first CreditService.wsdl (in the Application Navigator, CreditService.wsdl is located in SOADEMO > CreditService > Application Sources).

  2. In the editor, under Services, expand CreditService > ValidateCreditCardServiceSoapHttp > soap:address.

    Figure 5-11 JDeveloper Showing the CreditService.wsdl File in the Editor

    Description of Figure 5-11 follows
    Description of "Figure 5-11 JDeveloper Showing the CreditService.wsdl File in the Editor"

  3. Right-click soap:address and select Properties. This displays the soap:address Properties dialog.

    Figure 5-12 soap:address Properties Dialog

    Description of Figure 5-12 follows
    Description of "Figure 5-12 soap:address Properties Dialog"

  4. In the location field, edit the hostname and port in the URL as necessary. You may need to scroll all the way to the left to see the beginning of the URL.

    The hostname specifies where Oracle Application Server is running, and the port specifies the HTTP port at which Oracle HTTP Server or OC4J is listening.

  5. Click OK if you made any changes to the location. Click Cancel if you did not make any changes.

  6. Select File > Save to save any changes you made to the WSDL file.

  7. Repeat the same steps for the second wsdl file, located in CreditService > Web Content > WEB-INF\wsdl.

  8. Close both files in the editor.

5.9 Update the Context-Root

  1. Right-click WebServices.deploy (located in SOADEMO > CreditService > Resources) and select Properties. This displays the WAR Deployment Profile Properties dialog.

    Figure 5-13 WAR Deployment Profile Properties Dialog, General Section

    Description of Figure 5-13 follows
    Description of "Figure 5-13 WAR Deployment Profile Properties Dialog, General Section"

  2. Select General on the left side. On the right side, select Specify J2EE Web Context Root and enter CreditService as its value.

  3. Click OK.

  4. Select File > Save to save your changes.

5.10 Rebuild CreditService

Right-click the CreditService project and select Rebuild.

5.11 Deploy Credit Service to Oracle Application Server

When you created the Credit Service project, JDeveloper automatically created a WebServices.deploy deployment profile for you. You can use this deployment profile to deploy the Credit Service project to Oracle Application Server.

  1. Expand CreditService > Resources and right-click WebServices.deploy. Select Deploy to and your application server connection.

  2. In the Configure Application dialog, click OK.

After deploying CreditService, you can enter the following URL in a browser to see the WSDL for CreditService:

http://hostname:port/CreditService/ValidateCreditCardServiceSoapHttp?WSDL

For hostname, specify the name of the machine running Oracle Application Server.

For port, specify the HTTP port at which Oracle Application Server is listening. This is either the Oracle HTTP Server port or the OC4J port.

After deploying CreditService, you should see it in two places in the Application Server Control: in the Web Services tab (Figure 5-14) and the Applications tab (Figure 5-15) of the OC4J:home page.

Figure 5-14 Web Services Tab of OC4J:home Page Showing the ValidateCreditCardServiceSoapHttp Web Service

Description of Figure 5-14 follows
Description of "Figure 5-14 Web Services Tab of OC4J:home Page Showing the ValidateCreditCardServiceSoapHttp Web Service"

Figure 5-15 Applications Tab of OC4J:home Page Showing the SOADEMO-CreditService-WS Application

Description of Figure 5-15 follows
Description of "Figure 5-15 Applications Tab of OC4J:home Page Showing the SOADEMO-CreditService-WS Application"