In
this tutorial, you are introduced to Web services. Using a simple example, you
will see how you call a Web service from Oracle Forms. You will use JDeveloper
and Oracle ADF to build the interface to the Web service with minimum of coding.
Approximately 30 minutes
This tutorial covers the following topics:
![]() | Overview |
![]() | Scenario |
![]() | |
![]() | |
![]() | Calling a Web service from Oracle Forms |
![]() | Summary |
Place
the cursor over this icon to load and view all the
screenshots for this tutorial. (Caution: This action loads all screenshots simultaneously,
so, depending on your Internet connection, may result in a slow response time.)
Note: Alternatively, you can place the cursor over an individual icon in the following steps to load and view only the screenshot associated with that step. You can hide an individual screenshot by clicking it.
While this example uses very simple coding examples, it shows how to create a stub for calling an external Web service and then call that stub from Oracle Forms. This example assumes you are using Oracle Forms 9.0.4 and JDeveloper 10.1.3.1.
The scenario for this application will be kept as simple as possible in order to focus on the elements of the technology; however once you have an understanding of the simple case it can be easily applied to more "real world" examples. The scenario is that from the Oracle Forms "Summit" order/entry application, you can call a Web service that sends an SMS message to a phone with details about the order.
The first step of this tutorial will be to identify the Web service that provides the SMS messaging capability. There are various registries that provide this behavior. In this example, Esendex provide a number if different Web services. In particular, the following SMS service provides various options for sending SMS message. This example will use the SendMessage service. You can register for a free account to test this service at the following link. (Note that, additional steps MAY be required for an HTTPS web services but this is beyond the scope of this how to)
![]() | Create the Application | |
![]() | Set up the Browser Proxy | |
![]() | Create the Web service proxy | |
![]() | Test the web Service | |
![]() | Deploy the Web service proxy |
You will now create the application in which your business logic code will be placed.
1. |
In the Applications Navigator, right-click the Applications node and select New Application... from the context menu.
|
2. | In the Create Application dialog, enter the Application Name WebServicesApp. Notice that as you enter the application name, the directory name changes automatically. Select the Application Template No Template [All technologies] from the Application Template dropdown list.
Click OK.
|
3. | In the Create Project dialog, enter the Project Name WebServiceProxy.
Click OK. The Applications Navigator shows the WebServiceApp application and the new project
|
4. | In the Applications Navigator, right-click the WebServiceProxy node and select Project Properties... from the context menu.
|
5. | Select the Compiler node and set the Source and Target dropdown lists to 1.4.
Click OK. Depending on the version of the JRE you are using with Forms, you will probably have to do this step to ensure that the compiled classes from JDeveloper can be read by the JRE used by Form. Otherwise you would get a "Unsupported major.minor version" error when importing the Java class.
|
6. | Click
Save All
|
If your network uses a proxy for accessing the Internet you will need to tell JDeveloper the name of the proxy. If not, you may omit these steps.
1. |
From the main menu, choose Tools then Preferences.
|
2. | Click Web Browser and Proxy and then select the Use HTTP Proxy Server. Set the Host Name, Port Number and Exceptions as required.
Click OK.
|
In this section you will create a Web service proxy to call the external Web service.
1. | Right-click the new project and select New from the context menu. In the New Gallery select Web Services under the Business Tier node and then Web Service Proxy. Click OK
|
2. | In the Create Web Service Proxy dialog click Next if the Welcome screen is displayed. When prompted for the WSDL Document URL paste the URL of the WSDL file for the SendMessage service. At the time of writing, that URL is currently http://www.esendex.com/secure/messenger/soap/SendService.asmx?wsdl. click Next then Finish.
|
3. | JDeveloper will now display a Java client file in the code editor. This is the stub that will call the external web service.
|
4. | Click Save
All
|
JDeveloper will automatically create a main method in the Web service proxy meaning you can run and test the web service. This proxy (simply a Java class), should be open in the code editor. Alternatively you can select the class from the Application or System Navigator.
1. | In the SendServiceSoapClient you will see a main method with the comment //Add your own code here. Add the following: // Add your own code here
|
2. | You also need to add code to this class so it knows the correct proxy to use if being run outside of the confines of JDeveloper (which it will be when being called from Forms) static Note, depending on the proxy, assuming you have one, you may also be required to supply a username and password for the proxy. This would be set in a similar manner to above.
|
3. | Click
Save All
|
4. | Right
-click on the Java client and select Run from the context menu.
This will run the client which will call the Web Service and send the SMS to the
phone. |
5. | Now that you have tested the main method, you need to update the SendMessage method, since this is the method that will actually be called by Forms. MessengerHeader
header = new MessengerHeader();
|
6. | Click
Save All |
You have built and tested the Web service proxy from within JDeveloper. In order to call the Web service proxy from Forms, the proxy must be deployed to the file system as a JAR file.
1. | Right-click the new project and select New from the context menu. In the New Gallery select Deployment Profiles under the General node and then JAR file. Click OK
|
2. | You can accept the default name and directory (take a note of them). Click OK
|
3. | The JAR Deployment Profile Properties appears. Click OK
|
4. | Click
Save All
|
5. | Right -click on the archive file under the Resources node and select Deploy to JAR file. This will deploy the JAR file to the file system |
![]() | Setting up the CLASSPATH | |
![]() | Importing the Java Code | |
![]() | Calling the imported Java class |
Oracle Forms needs to be able to see the relevant Java files. These files are exposed to Forms by adding to the CLASSPATH environment variable.
1. |
On Windows, click Start, Settings then Control Panel from the context menu.
|
2. | Double-click on System. Under Advanced click on Enironment Variables. Select CLASSPATH and then Edit or New. Add the location of the JAR file created above (including the JAR file name)
Click OK.
|
3. | Download http://download.oracle.com/otn/java/oc4j/101320/wsclient_extended_101320.zip and extract the contained JAR file. Add the location of the JAR file (including the JAR file name) to the CLASSPATH Click OK on the open dialogs.
|
4. | The JAR file locations also need to be added to your Forms runtime environment so they can be accessed at runtime. To do this, add both JAR file locations to the CLASSPATH of your default.env (this is the default name) file. If already running, restart OC4J.
|
The final step is to show that this Web service can now be easily consumed from your own application code.
1. | Start the Oracle Forms Builder (note that the Builder must be restarted in order to pick up the new CLASSPATH)
|
2. | For the chosen Form, from the menu select Program then Import Java Classes... Note: for the Java Importer Options, you need to uncheck, Generate persistent names check box. Otherwise, the PL/SQL block will throw compilation errors.
|
3. | Expand the list of Java classes to find the SendServiceSoapClient Java class. Click Import.
|
4. | In
the Import Classes field enter java.lang.String then click Options
and check Include inherited mehtods/fields, click OK then click
Import.
|
5. | Repeat
for java.lang.Exception |
The final step is to write the PL/SQL at the appropriate trigger point in the Form.
1. |
At the appropriate trigger point add the following code. DECLARE EXCEPTION
|
2. | Compile and run the Form.
|
You have used this simple example to identify a Web service, create a stub, and call it from Oracle Forms