Developing, Deploying and Managing Web Services Using JDeveloper and Oracle Application Server
Developing, Deploying and Managing Web Services Using JDeveloper and Oracle Application Server
Services Using
JDeveloper and Oracle Application Server
Overview
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:
Scenario
In JDeveloper you would like to develop components for common
functions and deploy them as web services. You would also like to be able to
manage the web service for such aspects as logging and security, and monitor
the HTTP requests and responses generated by invoking the web service.
Prerequisites
Before starting this tutorial, you should:
If you receive a message asking if you want to migrate from a previous version, click No.
3. Start Oracle Application Server Containers for J2EE (OC4J) by double-clicking
<JDEV_HOME>\jdev\bin\start_oc4j.bat.
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.
Watch the resulting command window and wait until you see the message 'Oracle Containers for
J2EE 10g (10.1.3.0.0) initialized'. Then you can minimize the window, but do not close it.
4. Create a connection in JDeveloper to OC4J:
Click the Connections tab (If the Connections tab is not visible, choose View
> Connection Navigator from the menu).
On the Type page of the wizard, enter the Connection Name of oc4jconn and
click Next.
On the Test page of the wizard, click Test Connection. After testing, the
Status message should display Success!. (If it displays error messages, click
Back and correct the connection information that you have entered. )
1.
In the Application Navigator, right-click the Applications node and select New Application
from the context menu.
2.
3.
In the Create Project dialog, enter a Project Name of GetDates and click OK.
4.
In the Application Navigator, right-click the GetDates project and select New from the
context menu.
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.
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.
10.
Click Make
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.
Click Next.
On the Specify Custom DataType Serializers page of the wizard, click Next.
On the Methods page of the wizard, select the check boxes next to both methods from the
Note: If you get an error about not being able to load the interface datespackage.GetDatesWS,
then repeat steps 1-5.
6. If it is not already open in the editor, open the WSDL document for the web service: Under the
GetDates project in the Application Navigator, expand Web Content and WEB-INF\wsdl, then
double-click GetDatesWS.wsdl.
Another way to open the WSDL is to right-click the GetDatesWS web service in the Application
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 and copy the
8. If the file is still open, click the GetDates.java tab at the top of the editor, or reopen the
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.
1. If the file is still open, click the GetDatesWS.wsdl tab at the top of the editor, or reopen the
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.
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.
Deploying
and Testing the Web Service
To deploy and test the web service that you have created,
perform the following steps:
1. In the Application Navigator, expand the Resources node. Right-click WebServices.deploy, and
2. Open a browser and paste the URL you copied from the WSDL file above, which is the
3. The getDate Test page displays an area where you can specify parameters for the method.
Because this method does not take any parameters, just click Preview SOAP.
4. The Preview of Request window shows you the SOAP request that will be sent. Click Invoke to
send the request and invoke the getDate method of the web service.
5. After you invoke the web service, the bottom part of the window displays the SOAP envelope
containing the result, which is today's date and time. It looks something like this:
<ns0:result>2005-11-15T16:51:26.566-07:00</ns0:result>
6. Click Back twice to return to the GetDatesWS endpoint page, then click getDateHence.
In the box provided for the daysHence parameter enter the number 5, to return the date five days
hence. Click Preview SOAP.
8. The preview shows the value 5 that will be passed as the daysHence parameter. Click Invoke.
After you invoke the web service, the bottom part of the window displays the SOAP envelope
containing the result, which is the date and time five days from today. It looks something like
this:
<ns0:result>2005-11-20T17:01:21.682-07:00</ns0:result>
In the parameter value field enter the number 365, to return the date a year
hence.
Click Invoke.
The resulting SOAP envelope contains the result, which is the date and time
one year from today. It looks something like this:
<ns0:result>2006-11-15T17:04:57.282-07:00</ns0:result>
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
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.
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
7. Invoke each of the web service operations a few times, as you did in the testing steps 3-8 in the
8. Click the Home tab. You should see that the Invocations value has been incremented to reflect
10 In the Enable/Disable Features page, Ctrl-click to select Logging 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.
.
Deselect the check boxes for Request Messages, Response Messages, and Fault Messages 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.
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
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 tutorial, 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.
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.
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 Application 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:/C:/JDeveloper/jdevstudio1013/jdev/mywork/JavaWebService/GetDates/public_html/WEBINF/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
datespackageproxy, then click Next.
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 Application Navigator to open it).
8. In the editor, locate the following line of comment in the main() method:
Click Make
9.
Click Run
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
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
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.
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. 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).
5. When you are debugging a web service, you can change the contents of a request packet and
7. To close HTTP Analyzer window, click the x on the Http Analyzer tab.