Tuesday, November 2, 2010

Integrating Web Services into your ADF Application Part 1

As promised, I am uploading the presentation slides (Oracle ADF 11g Enhanced Capabilities & Features) along with a complete step-by-step tutorial on how to integrate Web Services into your ADF Application using a Web Service Data Control along with the source code of my demo (JavaWebService & ADFHelloWorldJava).


Create a Java Class and Expose it as a Web Service
1. In the Applications Navigator, click New Application. Another option is to use the File->New... menu option to create a new application.
2. In the Create Application dialog box, specify the Application Name to be JavaWebService. Notice that the directory changes to match the new name. You can change the C:\JDeveloper\mywork part of the path to create your files in another location.

In the Application Package Prefix field set the value to be demo. In the Application Templates choose the Generic Application and click Next.
3. In step 2 of the Create Application Wizard, specify the Project Name to be HelloWorld and click Finish.
4. Right click the HelloWorld project and select New.

5. Under the General category, select Java Class.
6. In the Create Java Class , specify the Name to be HelloWorld and uncheck the “Constructors from Superclass” and “Implement Abstract Methods” options and click OK.

7. In the HelloWorld.java class, copy and paste the following code:

public String sayHello(String firstname, String lastname){
return "Hello " + firstname + " " + lastname;
}
8. Right click the HelloWorld.java class and select Create Web Service.
9. This initiates the Create Java Web Service Wizard. In the Select Deployment Platform, leave the default platform selected (Java EE 1.5 with support for JAX-WS Annotations) and click Next.
10. In the Generation Option, leave the defaults and click Next.
11. In the Message Format, select SOAP Bindings 1.2 and click Next.
12. In the Methods, make sure that the sayHelo method is selected and click Finish.
13. If you open HelloWorld.java, you will notice that the wizard appended some annotations to the class to expose it as a Web Service. Right click HelloWorld.java and choose Run to deploy it to the Integrated WebLogic Server.
14. Once deployed, you will notice in the WebLogic console a Target URL. This is the url of the deployed HellWorld Web Service. JDeveloper provides you with a Web Service Test Client, so if you click on the url, it will open the test client, allowing you to test the web service.
15. If you enter your name and surname and click Send Request, the web service should respond with a message “Hello name surname”, where name is the name that you have specified and surname is the surname that you have specified in the web service call.
16. Before proceeding to the next step and creating our Fusion ADF Web Application that will consume this web service that we have just created, please make sure that you have copied the target url of the deployed web service as this will be needed in the next steps.

Create an ADF Fusion Application and a Web Service Data Control to Consume the HelloWorld Web Service
1. In the Applications Navigator, click New Application.

2. In the Create Application dialog box, specify the Application Name to be ADFHelloWorldJava. Notice that the directory changes to match the new name. You can change the C:\JDeveloper\mywork part of the path to create your files in another location.

In the Application Package Prefix field set the value to be demo. In the Application Templates choose the Fusion Web Application (ADF) and click Finish.
3. In the Application Navigator you'll see two new projects now, one called Model and the other called ViewController. Right click the model project and select New.
4. Under the Business Tier category, select Web Services and then from the items select Web Service Data Control.
5. In the Create Web Service Data Control Wizard, specify the name for the Data Control to be HelloWorld and the URL to be the url that you have copied before. Please note that at the end of the url, you need to append ?wsdl to specify the WSDL file of the Web Service, and click Next.
6. In the Data Control Operations, shuttle the HelloWorldService to the selected pane and click Finish.
7. Right click the ViewController project and select New.
8. Under the Web Tier category, select JSF and then from the items select JSF Page.
9. In the Create JSF page, specify the File Name to be HelloWorld.jspx and make sure that the “Create as XML Document(*.jspx)” option is checked. Under Initial Page Layout and Content select Blank Page and click OK.
10. Expand the Data Control section and drag the sayHello method onto the HelloWorld.jspx page as an ADF Parameter Form.
11. On the Edit Form Fields, just click OK.

12. As you can see, ADF automatically created an ADF form based on the method’s input parameters and included a submit button to call the web service.
13. The HelloWorld Web Service returns a String. To display the output of the web service, just drag the String output from the Data Control below the sayHello button as an ADF Output Text.
14. Right click the page and choose Run.
15. Provide a value for sayHello_arg0 (Firstname) and a value for sayHello_arg1 (Lastname) and click the sayHello button.
16. The HelloWorld Web Service is called and returns a message “Hello name surname”, where name is the name that you have specified and surname is the surname that you have specified in the web service call.


I will be publishing "Integrating Web Services into your ADF Application Part 2" which will include calling a Web Service programmatically using a web service data control in the next couple of days, followed by a tutorial on how to secure your ADF Application using ADF Security.

Engjoy!

3 comments:

  1. Hi,

    I have a Web Service Data Control.
    Instead of accessing and displaying data from Web Service Data Control on a page,
    I want to access the Data Control programatically directly in a java class.
    How do we get the handle of WS Data Control, methods and return values in a java class?

    ReplyDelete
  2. You can do that using a web service proxy. It will create you with all the necessary java classes so that you can call your web services programmtically using java.

    I have demoed this in another post (http://antonis-antoniou.blogspot.com/2010/11/integrating-web-services-into-your-adf_23.html).

    ReplyDelete
  3. As a ADF beginner, I find this blog one of the best. Very informative and comprehensive!
    Thanks Antonis. Keep it up!

    ReplyDelete