Calling A Web Service From Oracle Forms 11g: Purpose
Calling A Web Service From Oracle Forms 11g: Purpose
Purpose
Time to Complete
Overview
Scenario
Prerequisites
Identifying the Web service
Creating a Web service proxy
Setting up Forms to call the web service
Summary
Purpose
This tutorial covers calling a Web service from Oracle Forms 11g.Using a simple example, you will see how you call a Web service from Oracle
Forms. You will use JDeveloper to build the interface to the Web service with minimum of coding.
Time to Complete
Approximately 30 minutes.
Overview
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 11.1.1.2.0 and JDeveloper 11.1.1.2.0.
Scenario
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.
Prerequisites
Before starting this tutorial, you should:
2. Have access to or have installed Forms 11g (Forms Services and Forms Builder).
1. In the Applications Navigator, click New Application or choose File->New and select Applications node.
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 Generic Application from the Application Template list.
Click Next
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 check the Source Files and Generated Class Files dropdown lists.
You may change these versions depending on the version of the JRE you are using with Forms to ensure that the compiled classes
from JDeveloper can be read by the JRE used by Form.
If you wish to create a Web service proxy for use with Oracle Forms 10g then you would have to choose 1.4 since that is the version
of the JRE used by Forms 10g (Otherwise you may see an "Unsupported major.minor version"). The JAX-WX proxy is only
supported in JRE 1.5. Steps for calling a Web service for Forms 10g can be found here.
6.
Click Save All or select File | Save All to save your work.
Click OK.
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 and accept the default Client Style: JAX-WS
Style.
Click Next.
3. 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
4. JDeveloper will now display a Java client file in the code editor. This is the stub that will call the external web service.
5.
Click Save All or select File | Save All to save your work. Then compile all.
1. In the SendServiceSoapClient you will see a main method with the comment // Add your code to call the desired methods. Add the followings:
Note: Replace the values between < > with your own values
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
{
System.setProperty("http.proxyHost", "<your proxy>");
System.setProperty("http.proxyPort", "<port>");
System.setProperty("http.nonProxyHosts","localhost|<your machine name>");
}
Note: Replace the values between < > with your own values.
The final class should look similar with the following:
Note that, 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 or select File | Save All to save your work. Then compile all.
4. Run the class. If everything went fine, the process should exit with 0 and a text message should be received on the phone number specified in the
code.
5. Now, that the web service is accessible, we should implement the sendMessage method by adding the following code:
public String sendMessage (String recipient, String body, MessageType type, MessengerHeader header)
{
sendService = new SendService();
SendServiceSoap sendServiceSoap = sendService.getSendServiceSoap();
header = new MessengerHeader();
header.setAccount("<your account number>");
header.setUsername("<your username>");
header.setPassword("<your password>");
return sendServiceSoap.sendMessage(recipient, body, type, header);
}
This will be the actual method that will be called from Forms.
Deploy the Web service proxy
1. Select File | New in JDeveloper's (11gR1) menu. The New Gallery dialog appears.
Select Deployment Profiles option on the left, then on the right, pick JAR File. Click OK.
6. Right -click on the Project and select Deploy -> archive1. This will deploy the JAR file to the file system.
Setting up Forms to call the web service
The next step is configuring Forms to access the web service client created earlier.
2 . You may also want to check that the JAR file location is available on the CLASSPATH of your default.env (this is the
default name) file.
DECLARE
jo ora_java.jobject;
xo ora_java.jobject;
rv varchar2(100);
ex ora_java.jobject;
BEGIN
JO := SendServiceSoapClient.new;
RV := SendServiceSoapClient.sendMessage(JO,:BLOCK3.PHONE_NUMBER, :BLOCK3.MESSAGE_BODY, xo, xo);
EXCEPTION
WHEN ORA_JAVA.JAVA_ERROR then
message('Unable to call out to Java, ' ||ORA_JAVA.LAST_ERROR);
WHEN ORA_JAVA.EXCEPTION_THROWN then
ex := ORA_JAVA.LAST_EXCEPTION;
message(Exception_.toString(ex));
END;
2. Compile and run the Form.
Summary
You have used this simple example to identify a Web service, create a stub using JDeveloper 11gR1, and call it from Oracle Forms 11gR1.
Credits