Developer's Forum
~: Neelmani Welcomes You :~  
  Home
  Profession
  Java :: FAQ
  Ejb : FAQ
  JSP :: FAQ
  JSF :: FAQ
  BPEL :: FAQ
  ADF
  XML
  Web Services
  Application Server Vs Web Server
  API : Faces/AdfFaces
  DataBase
  MVC
  Codes
  Hr Questions
  Online Classroom
  Career
  Login Page
  Results
  My Location
  Contact
Web Services

Developing, Deploying and Managing Web Services Using JDeveloper

Developing Web Services: Three Easy Steps

Purpose

In this lab, using JDeveloper you experiment with different techniques to create and deploy a Java web service and manage it using Application Server Control.

 

Prerequisites

Step 1: Developing, Deploying and Managing Web Services Using JDeveloper and Oracle Application Server

Step 2: Creating the Web Service on PL/SQL Package

Step 3: Developing Contract-Driven Web Services Using JDeveloper

 

Overview

In the first section of this lab you publish a Java class as a web service. You deploy and test it, then you use Application Server Control

to manage the web service. You also create a web service proxy for the web service and monitor it with the HTTP Analyzer.

In the second section of the lab, you create a database connection, then you publish an existing PL/SQL package as a web service.

In the third section, you use JDeveloper to develop a Java web service using a top-down approach. You start by creating an XML

schema, create the WSDL contract and then generate the Web Service.

 

Note: The three independent sections can be completed in any order.

Web services are discrete reusable software components that can be incorporated into applications. They build upon existing XML and

HTTP protocols and use the following standards:

WSDL (Web Services Description Language): an XML-based language for defining web services

SOAP (Simple Object Access Protocol): an XML-based protocol for accessing services on the Web by using XML syntax to send

commands over HTTP

UDDI (Universal Description, Discovery, and Integration): a universal catalog of web services that enables software to discover

and integrate with services on the Web

JDeveloper provides many features to help you to create and deploy web services and to find existing web services to use in your

applications. This lab shows you how to use some of JDeveloper's web services tools to create and optionally to monitor web services,

and also how to use Application Server Control to manage a web service.

Back to Main Topic List

 

Prerequisites

Before starting any step for this lab, you should:

Developing, Deploying and Managing Web Services Using JDeveloper a... http://stcontent.oracle.com/content/dav/oracle/Libraries/Java%20Curricu...

2 of 81 9/20/2006 2:23 PM

1. Run a script to reset the database and the JDeveloper environment. Double click the desktop icon labeled Reset.

2. Double-click the desktop icon labeled JDeveloper to start the JDeveloper version used in this lab.

If the Migrate User Settings dialog box opens, click NO.

Close the Tip of the Day window, JDeveloper is now ready for use.

3. Start Oracle Application Server Containers for J2EE (OC4J) by double-clicking the desktop icon labeled start_oc4j.

If prompted for a password, enter welcome1. Nothing displays as you enter the password. You will have to reenter it

on the next line to confirm. If you are not asked for a password, for later steps you will need to know what password

was set when OC4J was initially started.

Developing, Deploying and Managing Web Services Using JDeveloper a... http://stcontent.oracle.com/content/dav/oracle/Libraries/Java%20Curricu...

3 of 81 9/20/2006 2:23 PM

Back to Main Topic List

Section 1: Developing, Deploying and Managing Web Services Using JDeveloper

and Oracle Application Server

 

Purpose

In this section, you publish a Java class as a web service. You deploy and test it, then you use Application Server Control to manage

the web service. You also create a web service proxy for the web service and monitor it with the HTTP Analyzer.

 

Scenario

Creating the Java Class

Creating the Web Service on the Java Class

Exploring the WSDL Editor

Deploying and Testing the Web Service

Managing the Web Service

Monitoring the Web Service

 

Creating the Java Class

JDeveloper allows you to use an existing web service or to create one with Java or PL/SQL. In this lab, you create a web service that is

based on a Java class.

 

To create the Java class for the web service, perform the following steps:

 

1. In the Applications Navigator, right-click the Applications node and select New Application from the context menu.

Developing, Deploying and Managing Web Services Using JDeveloper a... http://stcontent.oracle.com/content/dav/oracle/Libraries/Java%20Curricu...

4 of 81 9/20/2006 2:23 PM

 

2. In the Create Application dialog, enter the Application Name of JavaWebService.

From the Application Template drop down list, select No Template [All Technologies].

Click OK.

 

3. In the Create Project dialog, enter a Project Name of GetDates and click OK.

 

4. In the Applications Navigator, right-click the GetDates project and select New from the context menu.

Developing, Deploying and Managing Web Services Using JDeveloper a... http://stcontent.oracle.com/content/dav/oracle/Libraries/Java%20Curricu...

5 of 81 9/20/2006 2:23 PM

 

5. In the New Gallery, select the General node in the Categories list, and then in the Items list select Java Class. Click

 

OK.

 

6. In the Create Java Class dialog, enter:

Name: GetDates

Package: datespackage

Click OK.

The new Java class is created and displayed in the editor.

 

7. In the editor, create a method getDate() that uses java.util.Calendar to return the date and time.

public Calendar getDate()

{

return Calendar.getInstance();

}

 

8. Because the code refers to a class that is not yet available to this package, you are prompted to import the class.

Press [Alt]+[Enter] to import the suggested class java.util.Calendar.

 

9. In the editor, create a second method getDateHence() that uses java.util.GregorianCalendar to add a

user-defined number of days, specified as the int parameter daysHence, to today's date. Add the following code

below the getDate() method, pressing [Alt]+[Enter] when prompted to import

java.util.GregorianCalendar:

public Calendar getDateHence( int daysHence)

{

GregorianCalendar myCalendar = new GregorianCalendar();

myCalendar.add(GregorianCalendar.DATE, daysHence);

return myCalendar;

}

 

10. Click Make to compile the class. The log should show successful compilation.

Back to Section 1 Topic List

Back to Main Topic List

 

Creating a Web Service on the Java Class

To create a web service based on the Java class that you just created, perform the following steps:

 

1. Right-click the GetDates project and select New from the context menu.

 

2. In the New Gallery, expand Business Tier in the Categories list and select Web Services, then select Java Web Service from

the Items list. Click OK.

 

3. In the Select J2EE Web Service Version dialog, select J2EE 1.4 (JAX-RPC) Web Service, then click OK.

 

4. If the Welcome page of the Create Java J2EE 1.4 Web Service dialog displays, click Next.

In the Class page of the wizard

Enter GetDatesWS for the Web Service Name.

Select datespackage.GetDates from the Component To Publish dropdown list.

Select the "Generate annotations into class" check box.

Click Next.

 

5.On the Message Format page of the wizard, click Next.

On the Specify Custom DataType Serializers page of the wizard, click Next.

On the Mapping page of the wizard, click Next.

On the Methods page of the wizard, select the check boxes next to both methods from the Available Methods list and click

Finish.

 

6. If it is not already open in the editor, open the WSDL document for the web service: Under the GetDates project in the

Applications Navigator, expand Web Content and WEB-INFwsdl, then double-click GetDatesWS.wsdl.

Another way to open the WSDL is to right-click the GetDatesWS web service in the Applications Navigator and select Go to

WSDL from the context menu.

 

7. Click the Source tab of the WSDL editor. Scroll to the bottom of the WSDL file to the URL defined in the soap:address node. It

should be similar to:

http://138.3.51.14:8888/JavaWebService-GetDates-context-root/GetDatesWSSoapHttpPort

Select the entire URL in the editor and press [Ctrl]+[C] to copy it to the clipboard. You will use this URL in a later step.

 

8. If the file is still open, click the GetDates.java tab at the top of the editor, or reopen the GetDates.java file by double-clicking it in

the Applications Navigator: (JavaWebService > GetDates > Application Sources > datespackage > GetDates.java).

Note the Java 5 annotation (line beginning with "@") that has been generated because of the selection you made above.

Inclusion of annotations is optional.

 

9. Click Save All to save your work.

Back to Section 1 Topic List

Back to Main Topic List

 

Exploring the WSDL Editor

There is another way to develop web services that is called contract-driven, or top-down, development. This approach is more

responsive to business requirements, rather than simply creating a service layer in a bottom-up manner by wrapping existing systems

using web services. In JDeveloper, the top-down approach uses the WSDL editor, rather than the wizard, to create a new WSDL and

generate all the classes and service artifacts. You will use this approach in the third section of this lab. However, now you can examine

the WSDL editor to see what the wizard created for you and how all the elements are related. To explore the WSDL editor, perform the

following steps:

 

1. If the file is still open, click the GetDatesWS.wsdl tab at the top of the editor, or reopen the GetDatesWS.wsdl file by

double-clicking it in the Applications Navigator: (JavaWebService > GetDates > Web Content > WEB-INFwsdl >

GetDatesWS.wsdl)

Click the Design tab at the bottom of the editor to view the visual editor.

In the Services column, select the GetDatesWSSoapHttpPort node.

Observe how the content of the Bindings and Port Types columns are now highlighted and connected.

 

Note: You may need to select View | Refresh from the JDeveloper menu in order to see all the connections. To

make viewing easier, you can double-click the tab at the top of the editor to maximize the editor window. You can

restore the window by double-clicking it again.

 

2. In the Bindings column, select the getDate node.

Observe how the getDate binding is linked to the getDate operation in the Port Types column.

Note: You may need to select View | Refresh from the JDeveloper menu in order to see all the connections.

 

3. Expand the getDateHence binding node, and select the input node.

Observe how the GetDatesWS_getDateHence message (under Messages) is connected to the getDateHence

operation (under Port Types), which is in turn connected to the input node of the getDateHence binding.

Note: You may need to select View | Refresh from the JDeveloper menu in order to see all the connections.

Back to Section 1 Topic List

Back to Main Topic List

 

Deploying and Testing the Web Service

To deploy and test the web service that you have created, perform the following steps:

 

1. In the Applications Navigator, expand the Resources node. Right-click WebServices.deploy, and select Deploy to

> oc4jconn from the context menu.

(Note: This assumes that you have started OC4J and have created a connection to it as described in Prerequisites.)

In the Configure Application dialog, click OK.

The log window should show successful deployment.

 

2. Open a browser and paste the URL you copied from the WSDL file above, which is the GetDatesWS endpoint page

generated by OC4J.

The endpoint page for the GetDatesWS displays. Note the dropdown list with links to the two methods: getDate and

getDateHence.

Click getDate.

 

3. The page displays an area where you can specify parameters for the method. Because this method does not take

any parameters, just click the Invoke button to invoke the getDate method of the web service.

 

4. After you invoke the web service, the window displays the SOAP envelope containing the test result, which is

today's date and time. It looks something like this:

<ns0:return>2006-08-23T18:14:00.713+01:00</ns0:return>

 

5. Click Back to return to the GetDatesWS endpoint page, then select getDateHence.

 

6. The GetDateHence method requires a parameter.

In the box provided for the daysHence parameter enter the number 5, to return the date five days hence. Click

Invoke.

 

7. After you invoke the web service, the Test Result window displays the date and time five days from today. It looks

something like this:

<ns0:return>2006-08-28T18:30:20.495+01:00</ns0:return>

 

8. Retest the GetDateHence method with a different value:

Click Back to return to the getDatesHence page.

In the parameter value field enter the number 365, to return the date a year hence.

Click Invoke.

The Test Result page contains the result, which is the date and time one year from today. It looks something

like this:

<ns0:return>2007-08-23T18:32:38.248+01:00</ns0:return>

Leave the browser open for the next section.

Back to Section 1 Topic List

Back to Main Topic List

 

Managing the Web Service

To use Oracle Application Server Control to manage the web service, perform the following steps:

1. Using the same server and port number, in the browser enter the URL for application server control:

http://<server>:<port>/em (i.e.: http://localhost:8888/em)

The Application Server Control login screen displays.

Enter a username of oc4jadmin and a password of welcome1 (or whatever password was used when initially

starting OC4J), then click Login.

 

2. On the home page, click the Web Services tab.

Developing, Deploying and Managing Web Services Using JDeveloper a... http://stcontent.oracle.com/content/dav/oracle/Libraries/Java%20Curricu...

21 of 81 9/20/2006 2:23 PM

 

3. Click the GetDatesWSSoapHttpPort link.

 

4. You can view performance information from the service port home page. You can see the number of times the web

service has been invoked, the number of faults, and the average response time in milliseconds.

Click the Operations tab.

 

5. On the Operations tab you can view the performance information for the getDate and getDateHence operations:

1. Total Requests

2. Total Faults

3. Response Time

4. Active Requests

5. Highest Concurrent Requests

Click the Home tab

 

6. Click Test Service.

 

7. Invoke each of the web service operations a few times, as you did in the testing steps 3-8 in the Deploying and

Testing the Web Service topic.

Now return to the Operations page. You should see that the Total Requests have been incremented according to

the number of invocations you made for each operation.

8. Click the Home tab. You should see that the Invocations value has been incremented to reflect the total number of

invocations for both operations.

 

9. Click the Administration tab, then click Enable/Disable Features.

 

10. In the Enable/Disable Features page, Ctrl-click to select Tracing and Auditing from the Available Features list, then

click Move to shuttle them to the Enabled Features list.

 

Click OK.

 

11. On the Administration tab, click Edit Configuration for the Auditing feature.

 

12. By default, all auditing is available for both operations.

Deselect the check boxes for Request Message, Response Message, and Fault Message for the getDate

operation, leaving the ones for the getDateHence operation selected.

Click OK.

 

.

13. Again invoke each of the web service operations a few times, as you did in the testing steps 3-8 in the Deploying

and Testing the Web Service topic.

Use Windows Explorer to open the file<jdev_home>j2eehomelogwsmgmtauditinglog.xml.

 

14. In the log file you are able to see the invocations of the web service operations (screen shots show Notepad with

Word Wrap turned on (Format > Word Wrap):

Header information

Arguments passed to the web service

Values returned by the web service

 

Note that you see the invocations of the getDateHence operation only, as you specified in the auditing options.

When you are finished examining the log file, you can close it.

Although you will not do so in this lab, another thing that you can do with Application Server Control of web services

is to set the inbound security policies for JAX RPC web services deployed in OC4J container 10.1.3. You can set

options such as requiring a username/password for authentication, requiring the message body to be signed, and

requiring encryption of the message body. These administrative features can also be defined and managed from

within JDeveloper.

Back to Section 1 Topic List

Back to Main Topic List

Monitoring the Web Service (optional)

This topic shows you how to use the HTTP Analyzer to examine the request/response packets sent and received by JDeveloper when

you run a proxy to a web service. When you start the HTTP Analyzer, it updates the proxy settings in JDeveloper so that all TCP data is

sent through an intermediate port and then on to your original proxy, if one is defined. The proxy settings are restored when you turn the

HTTP Analyzer off, or when you exit JDeveloper.

To monitor the web service, perform the following steps:

Create a web service proxy

Use the HTTP Analyzer

Back to Section 1 Topic List

Back to Main Topic List

Creating a web service proxy

1. To use the HTTP Analyzer, you need to create a web service proxy so that you can run the service from within JDeveloper.

You must create the web service proxy in a new project.

In the Applications Navigator, right-click the JavaWebService application and select New Project from the context menu.

 

The New Gallery opens with Empty Project highlighted -- just click OK.

2. In the Create Project dialog, enter a Project Name of GetDatesWSProxy, then click OK.

3. Right-click the GetDatesWSProxy project and select New from the context menu.

In the New Gallery, expand Business Tier and select Web Services in the Categories list, then in the Items list select Web

Service Proxy and click OK.

 

4. If the Welcome page of the Create Web Service Proxy wizard displays, click Next.

On the Web Service Description page of the wizard, invoke the WSDL Document URL dropdown list and select the WSDL

that appears in the tooltip, which is similar to the following (although the initial part of the path is different for your computer):

file:<jdev_home>/jdev/mywork/JavaWebService/GetDates/public_html/WEB-INF/wsdl/GetDatesWS.wsdl

Press the [Tab] key to validate the WSDL, then click Next.

 

5.On the Port Endpoints page of the wizard, select the option Run against a service deployed to an external server. Select

the Port Name and Endpoint URL that appear in the list, then click Next.

 

6. Click Next on the next two wizard pages (Custom Mappings and Defined Handlers).

On the Default Mapping Options page of the wizard, change the Package Name to datespackage.proxy, then click Next.

 

7. Click Next on the Support Files page of the wizard.

On the Finish page you should see both methods listed. Click Finish.

The web service proxy generation process creates four directories and numerous files, and opens

datespackage.GetDatesWSSoapHttpPortClient.java in the editor (if this file does not open automatically,

double-click it in the Applications Navigator to open it).

 

8. In the editor, locate the following line of comment in the main() method:

// Add your own code here :

Below that line, add the following code:

int addDays = 5;

System.out.println("The date and time "

+ addDays + " days hence is: " + myPort.getDateHence(addDays));

Click Make to save and compile the file.

9. Click Run to run the class.

The message log displays the URL that is called on one line. On the next line it displays your message "The future date and

time: " followed by the date as a GregorianCalendar object.

Back to Topic

Back to Section 1 Topic List

Back to Main Topic List

 

Using the HTTP Analyzer

1. Display the HTTP Analyzer window by selecting View > HTTP Analyzer. The Http Analyzer window opens. By

default it is docked at the lower right of JDeveloper's user interface.

Start monitoring the packets by clicking Start in the HTTP Analyzer.

 

2. Re-run the class. The request/response packets are listed in the HTTP Analyzer.

 

3. To see the contents of a packet pair, select it in the History page, then click the Data tab. The data page shows the

value that was sent to the web service in the request information (left panels), and the value returned by the web

service in the response information (right panels).

 

If you have run other things with the HTTP Analyzer started, you can use the Previous Request/Response Pair

and Next Request/Response Pair buttons to examine other packet pairs.

 

4. When you are debugging a web service, you can change the contents of a request packet and resend it so as to

see the changes in the response packet.

To try this, in the request packet that sent the value 5, change the value to 365. Then click Resend Request .

 

5. The amended packet is sent. Click Next Request/Response Pair and examine the response packet to see the

change.

 

6. To close HTTP Analyzer window, click the x on the Http Analyzer tab.

 

7. Back into JDeveloper, right click the JavaWebService node in the Applications Navigator and choose Delete from

context.

On the Warning dialog, click Yes. This delete operation removes the current application from the Applications

Navigator but preserves it on your file system.

Back to Topic

Back to Section 1 Topic List

Back to Main Topic List

Section 2: Developing a Web Service from a PL/SQL package

Purpose

In this section of the lab, you create a database connection. Then you use an existing PL/SQL package to publish it as Web Service.

Developing, Deploying and Managing Web Services Using JDeveloper a... http://stcontent.oracle.com/content/dav/oracle/Libraries/Java%20Curricu...

39 of 81 9/20/2006 2:23 PM

Topics for Section 2

This section covers the following topics:

Scenario

Creating a database connection

Creating a New Application for the Web Service based on a PL/SQL Package

Publishing a PL/SQL Package as a Web Service

Scenario

You want to use JDeveloper to publish a Web Service based on a PL/SQL package.

Back to Section 2 Topic List

Back to Main Topic List

Creating a Database Connection

Java Database Connectivity (JDBC) is a standard application programming interface (API) that is used for connecting a Java

application to relational databases. JDeveloper uses a connection navigator to maintain connection information for your application. The

connection navigator makes it easy to create, manage, and test database connections.

To create a JDBC connection to the HR schema, perform the following steps:

 

1. Click the Connections tab on the Application Navigator. If the Connections tab is not showing, choose View |

Connection Navigator from the JDeveloper main menu.

 

2. Right-click the Database node and choose New Database Connection from the context menu.

 

3. In the Create Database Connection Wizard, review the information on the Welcome page and then click Next.

 

4. In the Connection Name field, enter hrconn. Click Next to continue.

 

5. On the Authentication page: enter hr in the Username field and hr in the Password field. Select Deploy password.

 

Click Next to continue.

 

6. On the Connections page, the default values for the connection should be the following:

Driver: Thin

Host name: localhost

JDBC Port: 1521

SID: XE

Leave the fields set to these default values.

 

Click Next to continue.

 

7. Click Test Connection.

If the database is available and the connection details are correct, you see the word Success! displayed in the

Status window.

If an error occurs, verify the connection settings, click Back to make any necessary changes, and then retest the

connection.

If the connection is successful, click Finish to complete the connection.

 

You have just created a connection to the database that supplies the PL/SQL Package for the Web Service you

build in this tutorial.

Back to Section 2 Topic List

Back to Main Topic List

Creating a New Application for the Web Service based on a PL/SQL Package

JDeveloper allows you to use an existing web service or to create one with Java or PL/SQL. In this lab, you create a web service that is

based on a PL/SQL Package.

To create the web service from the PL/SQL Package, perform the following steps:

 

1. Back in the Applications Navigator remove any existing application. Right click each existing application name and

choose Delete from context.

 

On the Warning dialog, click Yes. This delete operation removes the current application from the Applications

Navigator but preserves it on your file system.

The Applications Navigator should now look like this:

 

2. In the Applications Navigator, right-click the Applications node and select New Application from the context menu.

 

3. In the Create Application dialog, enter the Application Name of PL_SQL_WS.

From the Application Template drop down list, select No Template [All Technologies].

Click OK.

 

4. In the Create Project dialog, enter a Project Name of GetEmployee and click OK.

 

5. The Applications Navigator should now look like this:

Back to Section 2 Topic List

Back to Main Topic List

Publishing a PL/SQL Package as a Web Service

To create a web service based on the PL/SQL Package, perform the following steps:

 

1. Click the Connections Navigator tab, and expand the Database node.

 

2. Expand the hrconn > HR > Packages > EMP_FETCHER and right click the EMP_FETCHER node corresponding to the header part

of the Package and select Open from context.

 

3. The header of the package opens in the editor. The code shows that the PL/SQL package gets an input value for an employee

number and returns the record for this employee.

 

4. In the Connections Navigator, right click the EMP_FETCHER > EMP_FETCHER node and select the Publish as Web Service

option.

Back to Section 2 Topic List

Back to Main Topic List

 

Section 3: Developing Contract-Driven Web Services Using JDeveloper

Purpose

In this section, you use JDeveloper to develop a Java web service using a top-down approach.

Topics for Section 3

This section covers the following topics:

Creating the WSDL Contract Document

Generating the Web Service from the WSDL Contract Document

Testing the Web Service

Back to Section 3 Topic List

Back to Main Topic List

Creating the WSDL Contract Document

To create the WSDL contract document, perform the following steps:

Create a schema

Create a WSDL contract document

Define the service interface

Define the service implementation

Back to Section 3 Topic List

Back to Main Topic List

Creating a Schema

You first create a schema, and add some elements to it. You then import the schema into a WSDL document.

1. Back in the Applications Navigator remove any existing application. Right click each existing application name and

choose Delete from context.

 

On the Warning dialog, click Yes. This delete operation removes the current application from the Applications

Navigator but preserves it on your file system.

The Applications Navigator should now look like this:

In the Application Navigator, right-click the Applications node and select New Application from the context menu.

 

2. In the Create Application dialog, enter TopDownContractDevelopment as the application name and select the

No Template option. Click OK.

 

 

3. In the Create Project dialog, enter the Project Name WSDLDocument and click OK.

 

4. Right-click the WSDLDocument project and select New from the context menu.

 

5. In the New Gallery, expand General in the Categories list and select XML; then from the Items list select XML

 

Schema. Click OK.

 

6. In the Create XML Schema dialog, enter a Name of CreditRating.xsd, then click OK.

The schema is created and opened in the editor.

 

7. Select the schema in the editor, and click in the box to the right of targetNamespace. Type

http://myCompany.com/CreditRating/types over the example name.

 

8. You now begin to add elements to the schema. Elements are like variables that are global to the web service.

You can use the design editor to add elements.

In the design editor, click exampleElement, and type ssn as the name.

 

9. Right-click ssn and select Set Type from the context menu.

 

10. Click the arrow on the right of the box and choose xsd:string from the dropdown list.

 

11. Add another element. You can do this by dragging the element component from the Component Palette and

dropping it onto <schema>.

 

12. Click inside the element and overtype the default name with rating.

.

13. Set its type to xsd:int, by using the dropdown list as before.

 

14. In the same way, add a third element with the name error and a type of xsd:string.

Click Save All to save your schema.

Back to Topic

Back to Section 3 Topic List

Back to Main Topic List

Creating the WSDL Contract Document

Next you create the WSDL contract document, and import the schema you created in the previous steps, into it.

1. Right-click the WSDLDocument project and choose New from the context menu. Expand the Business Tier node in

the New Gallery, and choose Web Services in the Categories pane, and WSDL Document in the Items pane.

 

2. Type CreditRating as the WSDL Name, and http://myCompany.com/CreditRating as the Target Namespace.

Click OK.

 

3. Notice that the CreditRating WSDL has been created and opened in the editor. Ensure that you are in the Design

tab for the editor window and the Structure window. If not, click the Design tab at the bottom left in each window.

The windows should look like the screenshot below.

 

4. In the Structure window right-click Types and choose Insert types... from the context menu.

 

5. Right-click the types sub-node and from the context menu choose Insert inside types-->XML Schema.

 

6. In the Insert XML Schema Item dialog, choose schema and click OK.

 

7. Right-click the schema sub node in the Structure window, and choose Insert inside schema-->import.

 

8. Ensure that the Properties Inspector window is visible. If it is not, choose View-->Property Inspector.

In the PI, specify the location of the schema (click ... to browse for it if you wish). Specify CreditRating.xsd as

the id and http://myCompany.com/CreditRating/types as the schema namespace.

9. Click the Source tab in the editor to view the code for the CreditRating.wsdl file. Right-click and choose Reformat to

tidy up the code and make it more readable.

 

10. Now that you can see the values in the Definitions tag more clearly, add the following line at the end of the tag:

xmlns:types="http://myCompany.com/CreditRating/types"

Click Save All to save the WSDL document containing the imported schema.

Back to Topic

Back to Section 3 Topic List

Back to Main Topic List

Defining the Service Interface

Now you add the abstract or reusable elements of the WSDL. This is all the developer might create at this stage to allow others to use

the WSDL to generate the underlying Java implementation class that they must code to.

You define the service interface by specifying:

Messages: the XML datatypes that are the in/out parameters of the operation

 

PortType: the equivalent of the method signature, including operations and the messages (parameters) that they use

Bindings: association of a PortType with a specific protocol and data format

In this example, you define one operation for this service that gets the credit rating of the loan applicant. To define the service interface,

perform the following steps:

1. First you add three messages.

In the editor window, click the Design tab of CreditRating.wsdl, then click Switch View so that the Messages

element is in the left-most position. This step is not necessary, but makes it easier to see what you are creating first.

2. In the Structure window, select the Design tab.

Right-click Messages and select Insert Message from the context menu.

3. In the New Message dialog, enter the Message Name CreditRatingRequestMessage, then click OK.

 

4. In the Structure window, right-click message - CreditRatingRequestMessage and select Insert Inside Message -

CreditRatingRequestMessage > http://schemas.xmlsoap.org/wsdl/ > part.

5. In the New Part dialog, enter a Part Name of ssn and types:ssn as the Part Type.

6. In the same manner as in steps 2 - 5, add the following messages and their corresponding part types:

Message Name Part Name Part Type

CreditRatingResponseMessage rating types:rating

CreditRatingFaultMessage error types:error

After adding the messages, you can click on any element in the Structure window or the Design tab of the editor and

you are able to see and modify its values in the Property Inspector.

 

7. Now you define the PortType, which is the service interface, the equivalent of the method signature that specifies

operations and the messages (parameters) that they use.

In the Structure window, right-click PortTypes and select Insert portType.

8. In the New Port Type dialog, enter the Port Type Name of CreditRating, then click OK.

 

9. In the Structure window, right-click the CreditRating portType and select Insert inside portType -Credit Rating >

operation.

 

10. In the New Operation dialog, enter the Operation Name processCreditRating.

The Operation Type should be Request Response.

From the Input drop-down list, select tns:CreditRatingRequestMessage, which is one of the messages you

defined earlier.

From the Output drop-down list, select tns:CreditRatingResponseMessage, which is another of the messages you

defined earlier.

Select Add Fault.

Enter a Fault Name of NegativeCredit.

From the Fault drop-down list, select tns:CreditRatingFaultMessage, which is the third message you defined

earlier.

Click OK.

 

11. Expand the CreditRating Port Type in the WSDL editor to see how the messages are associated with the operation.

Click the different components of the operation to see the messages associated with each.

Note that the request message is associated with the input to the process, the response message is associated with

the output from the process, and the fault message is associated with the NegativeCredit named fault.

12. The final part of creating the service interface is defining the bindings. You bind the Port Type to a specific protocol

(HTTP) and data format (SOAP).

In the Structure window, right-click Bindings and select Insert binding from the context menu.

 

13. In the New Binding dialog, enter a binding Name of CreditRatingSoapHttp.

Leave all other fields as defaults. The Port Type defaults to the Port Type that you created.

Click OK.

14. In the design editor, expand the binding that you just created to see the details.

Notice that when you click any element, the Design tab of the editor shows its relationship to other elements.

 

15. In the editor, click the Source tab.

Scroll to the NegativeCredit fault definition toward the end of the file. Change the line:

<soap:body use="literal" parts="ssn"/>

to:

<soap:fault use="literal" name="NegativeCredit"/>

Back to Topic

Back to Section 3 Topic List

Back to Main Topic List

Defining the Service Implementation

The final step in creating a WSDL document is to create the service implementation definition. This definition includes the port that

specifies the binding that a particular implementer is going to implement and possibly the server where the service will run.

To define the service implementation, perform the following steps:

 

1. In the Design tab of the Structure window, right-click Services and select Insert service from the context menu.

 

2. In the Insert Service dialog, enter a name of CreditRatingService, then click OK.

 

3. In the Structure window, right-click service - CreditRatingService, then from the context menu select Insert inside

service - CreditRatingService > http://schemas.xmlsoap.org/wsdl/ > port.

 

4. In the New Port dialog, enter a Port Name of CreditRatingServiceSoapHttpPort. The Binding Name defaults

to the binding that you created. Click OK.

 

5. In the Structure window, right-click port - CreditRatingServiceSoapHttpPort, then from the context menu select

Insert inside port > soap:address.

 

6. In the Insert Address dialog, for the location enter any string, such as tbd, because it is not necessary at this stage

to specify where the finished service will run. Click OK.

7. In the Application Navigator, right-click CreditRating.wsdl and select Validate WSDL from the context menu.

 

The Message tab in the log window tells you if there are any errors, and the Source tab in the Structure window

gives you details of any errors.

8. Click Save All to save your work.

Back to Section 3 Topic List

Back to Main Topic List

Generating the Web Service from the WSDL Contract Document

To generate the web service, perform the following steps:

1. In the Application Navigator, right-click the TopDownContractDevelopment application and select New Project from the

context menu.

In the New Gallery, select Empty Project in the Items list and click OK.

 

2. In the Create Project dialog, enter a Project Name of Service, then click OK.

 

3. Right-click the Service project and select New from the context menu.

In the New Gallery, expand Business Tier and select Web Services in the Categories list, then select Java Web Service

from WSDL in the Items list. Click OK.

 

4. Click Next on the Welcome Page of the Create J2EE 1.4 Java Web Service from WSDL wizard.

On the Web Service Description page of the wizard, from the WSDL Document URL drop-down list select the

CreditRating.wsdl that you just created. Click Next.

 

5. On the Default Mapping Options page of the wizard, you could click Next to page through all the options. However, because

you are accepting all the defaults, you can just click Finish.

Now you have a full web service and all the JAX-RPC files to deploy and run the service.

 

6. In the Application Navigator, expand Application Sources and the service package under the Service project.

Note that JDeveloper has created a new service called CreditRatingService. Select CreditRatingService in the Application

Navigator to see other associated files displayed in the Structure window.

 

7. The CreditRatingService.wsdl file opens in the editor. Click the Design tab. Under Services, expand CreditRatingService

and CreditRatingServiceSoapHttpPort.

Select soap:address and look at its Property Inspector. You can see that the location, which you had specified as tbd, has

now defaulted to your local machine. This changes depending on where you actually deploy the service. This soap address, or

endpoint, is the location (URI) of the web service on the network.

By default, JDeveloper creates WSDLs with an endpoint that uses port 8888, because that is the default that would be used

with an external server. Because you are testing the web service with the embedded (not external) OC4J, you should change

the default port number to the port being used by the embedded OC4J server. To see what port that is, you can invoke Tools

> Embedded OC4J Server Preferences, then click Startup in the tree at the left. The port number for the embedded server is

shown in the HTTP field. Once you have obtained the port number, you can dismiss the preferences window.

 

If the soap:address in the WSDL is different from that of the embedded OC4J port, change it to the correct port number.

 

8. Select CreditRatingService in the Application Navigator and in the Structure window double-click CreditRatingImpl.java to

open it in the editor. Notice that it takes a String as a parameter and that the name of the parameter is ssn, which is the

name of the Message parameter that you created earlier.

You need to add the actual implementation of the method. Replace:

return 0;

with:

int id;

try

{

// Parses integer value of first 3 numbers form SSN

id = Integer.parseInt(ssn.substring(0,3));

}

catch(NumberFormatException e)

{

// if SSN is invalid returns -1

 

return -1;

}

if(id < 300)

{

// If value of the first 3 numbers from customer SSN is less

// than 300, credit rate is 1.

return 1;

}

else if(id < 600)

{

// If value less than 600, credit rate is 2.

return 2;

}

else if(id <900)

{

// If value less than 900, credit rate is 3.

return 3;

}

else

{

// Otherwise, credit rate is 0.

return 0;

}

9. You also need to ensure that CreditRatingImpl.java correctly implements the endpoint interface CreditRating.java.

In the interface, the processCreditRating() method throws a CreditRatingFaultMessage exception, so check to see

 

that the processCreditRating() method in CreditRatingImpl.java also throws a CreditRatingFaultMessage

exception. If it does not, add the following code to the processCreditRating() method signature in

CreditRatingImpl.java:

throws CreditRatingFaultMessage

Click Save All to save your work.

10. In the Application Navigator, right-click CreditRatingService and select Run from the context menu. This deploys the web

service to JDeveloper's embedded OC4J server. You should see a message in the log window indicating that the web service

has been started.

Back to Section 3 Topic List

Back to Main Topic List

Testing the Web Service

Now you test the web service by creating a client to call it. To test the web service, perform the following steps:

1. In the Application Navigator, right-click the TopDownContractDevelopment application and select New Project from

the context menu.

In the New Gallery, select Empty Project in the Items list and click OK.

 

2. In the Create Project dialog, enter a Project Name of Client, then click OK.

3. Right-click the Client project and select New from the context menu.

In the New Gallery, expand Business Tier and select Web Services in the Categories list, then select Web Service

Proxy in the Items list. This uses the web service's WSDL to generate a client proxy that has all the public available

data interfaces as the web service. Client applications can then use the proxy object to access the web service.

Click OK.

 

4. If the Welcome page of the Create Web Service Proxy wizard displays, click Next.

On the Web Service Description page of the wizard, select CreditRatingService.wsdl from the drop down list.

Selecting this file populates the Mapping File field. Click Next.

 

5.On the Port Endpoints page of the wizard, select the default radio button - Run against a service deployed to

Embedded OC4J.

You can click Next to tab through the pages if you wish. However, you are accepting all defaults, so you can just click

Finish.

The file CreditRatingServiceSoapHttpPortClient.java is created and automatically opened in the editor

window.

 

6. You need to add code to call the web service. In the code editor, after the line:

// Add your own code here

Add the following code:

int rating = myPort.processCreditRating("78964022");

System.out.println("Credit Rating is " + rating);

 

7. Click Run . The web service returns its results to the log window.

Back to Section 3 Topic List

Back to Main Topic List

Login
 
 
Username:
Password:
 
Free Download
 
  >Free Download :: JDeveloper 10.3.X

>Free Download :: Oracle 10g

>Free Download :: Microsoft SQL Server 2008

 
Download Tutorial
 
  > SOA Best Practices: The BPEL Cookbook

>Tutorial : Oracle Application Server

>Tutorial : JDeveloper
 
 
 

Xsys Software Technologies.
The Best Center for Training & Project Work in Bangalore.
 
Today, there have been 1 visitors (2 hits) on this page!...By Neelmani
This website was created for free with Own-Free-Website.com. Do you want your own website too?
Register for free