Web Services provide client neutral access to data and other services. JDeveloper allows you to create different types of Web Services quickly and easily....
show more or lessRead more...

In this tutorial, you will create 4 different Web Services: a POJO Annotation-Driven service, a Declaratively-Driven POJO service, a service for existing WSDL, and an EJB service. The focus of these scenarios is to demonstrate and test Java EE 5 web services. In particular this means JAX-WS (Java API for XML Web Services) and annotation handling. JAX-WS enables you to enter annotations directly into the Java source without the need for a separate XML deployment descriptor

At the end of the tutorial you create an ADF Client application that consumes the web service you created.



Purpose Duration Application

This tutorial shows you how to build and consume Web Services. The tutorial shows several end-to-end scenarios for creating web services. After you develop several web services, you create a client application that uses those services.

To see the complete application you will create, click the Download button to download a zip of the completed application, and then unzip it in a temporary folder of your choice.

4 hours Download WebService.zip
Part 1: Building a POJO Annotation-Driven Service
In this first part of the tutorial, you install the required lab files, start JDeveloper, and open the startup application and project.
Step 1: Getting Ready
  1. Download the lab files and save the WebService.zip file in the directory you will use for this tutorial (such as d:\Temp.)

    save as dialog box

  2. Open the directory where you saved the file, right-click the WebService.zip and extract the file. Use WinZip or whatever zip utility you have.

    Extract wizard

  3. Start JDeveloper by selecting Start > Programs > Oracle Fusion Middleware 11.1.2.0.0 > JDeveloper Studio 11.1.2.0.0

    Programs Start JDeveloper

  4. If the Migrate User Settings dialog opens, click No.

  5. If prompted for a User Role, choose Default Role.

    Select Role

  6. If the Tip of the Day window opens, click Close .

  7. You should now see the JDeveloper IDE. Close the Start page by hovering your mouse over the tab and clicking the X on the tab.

    jdev ide

  8. Select the Application Navigator tab and click Open Application (alternatively, you can select File | Open)

    open jdeveloper

  9. In the Open Application dialog box, locate the Web Service directory created when unzipping the WebService.zip file and select WebService.jws.

    Open Application Dialog

  10. Click Open

    The Application Navigator should look like this:

    Application Navigator

Step 2: Adding a Plain Old Java Object (POJO) to contain a Web Service Method

In this section you start with a project that contains plain old Java classes and add an annotated method that you publish as a web service.

Web service annotation is a feature of J2EE which takes complexity out of creating and deploying Web Services. Show more or lessRead more... . Web service annotation allows you to define web services from within a POJO. This feature of J2EE eliminates the need for complex configuration of the web service and the web server. J2EE introspects the deployed classes a creates the web server configuration on-the-fly. This frees up the developer to concentrate more on the service rather than the tedious details of deployment.
  1. In the Application Navigator, expand the Annotation project nodes to show the POJO classes:

    • Dept.java describes the department structure

    • Emp.java describes the employee structure

    • MyCompany.java populates information about departments and employees

    Application Navigator showing Department, Employee, and My Company java classes
  2. In the Application Navigator, double-click MyCompany.java to edit it.

    application navigator

  3. Add an @WebService annotation after the import statements.The IDE will add the import for the WebService class.
    This annotation denotes that the class contains a method to be used by a web service.

    Java Editor Window

  4. In the margin of the editor, click Quick Hint (light bulb icon) and select the Configure project for web services option.

    Java editor window configure for web service

  5. In the Select Deployment Platform dialog box, ensure that Java EE 1.5, with support for JAX-WS Annotations is selected.

    select deployment platform

  6. Click OK. This step adds the javax.jws.WebService import statement to the Java class if it is not already there and creates a web.xml file.
    The Application Navigator should look like the following:

    Notice that the icon for MyCompany.java class is changed to represent a WebService class, and the web.xml file has been added to your project.

    application navigator with web xml

  7. Click Save All save all to save your work.

  8. In the Code Edtior, scroll to the bottom of the class and add the following code statements:


    This loop returns information about all employees working in a specific department.
    The code in the editor window should look like:

    java editor with method

  9. Create a second annotation before the getDeptInfo() method. The annotation signifies this is the method to be exposed from the web service. Add a blank line above the getDeptInfo() method, and start typing @WebMethod. Code insight pops up up a list of available syntaxes. Select WebMethod from the list.

    Java editor add web method

  10. If suggested, press [Alt]+[Enter] to add the import javax.jws.WebMethod; statement (although this statement may be added automatically.)

    java editor with imnport suggestion

    The class should now look like the following:

    java editor with completed method

  11. Click Save All save all to save your work.

  12. You can use the Property Inspector to modify the characteristics of the class. In the menu bar, select View | Property Inspector and it will open as a tab in the bottom portion of the IDE.
    Note: If the Property Inspector opens in a different part of the IDE, you can drag its tab and drop it on the bottom panel if you would rather work with it there.

    Select View Property Inspector

  13. To display the properties of the MyCompany class in the Property Inspector, select the Source tab at the bottom of the Structure window, then select the top level MyCompany class name.

    property inspector

  14. The Property Inspector displays a few finger tabs on the left side of the window. Select the Web Services tab and notice that the Service Name has the word 'Service' appended to the class name.

  15. Change the Service Name to MyCompanyWS. Notice that the class reflects the name change.

    property inspector

  16. Click Save All save all to save your work.

    You have now created a POJO Web Service. In this next section, you will test you Web Service.

Step 3: Testing a Web Service
In this section you compile, deploy and test the web service using the HTTP Analyzer. Show more or lessRead more...

JDeveloper includes a web service testing mechanism called the HTTP Analyzer. When you use the HTTP analyzer to test web services, JDeveloper compiles and deploys the service to the integrated web server. It then invokes the analyzer, allowing you to send and receive values from the web service.
  1. Before testing the web service, check that your web browser settings are correct. Choose Tools > Preferences and then scroll down the list on the left to select the Web Browser and Proxy page. Ensure that the Use HTTP Proxy Server check box is not selected, then click OK.

    Web Server Proxy Settings

  2. In the Application Navigator, right-click the MyCompany.java node and in the context menu, select Test Web Service.

    application navigator select test web service

    This option invokes the integrated WebLogic Server, deploys the service, and then starts the analyzer. It may take a few seconds to start WebLogic Server if you are running it for the first time. If this is the first time you test a service, Windows may ask you about blocking content. Allow the content to be displayed.

  3. The top portion of the HTTP Analyzer editor window displays the URL for the web service, the WSDL URL, and the exposed Operations. Select the MyCompanyPort.getDeptInfo(,) operation from the list.

    http analyzer

    The bottom portion of the analyzer is split into two areas: Request and Response. The request area shows all the arguments from the exposed method (in this case, only one argument.) When the web service is executed, the Response area shows the results.

    http analyzer requrest response window

  4. In the Request area, enter a department number value (10, 20 or 30) in the arg0 field.

    http analyzer requrest response window

  5. In the toolbar area of the analyzer, click Send Request, or click the Send Request button send request buttonbelow the argument.

    send request button

  6. The analyzer sends the request to the service, returning after a few seconds the information about employees working in the specified department.

    http analyzer with results

  7. Click the HTTP Content tab at the bottom of the editor to look at the xml code.

    http analyzer http content

  8. Click the Raw Message tab at the bottom of the editor for another presentation of the code.

    http analyzer raw message

  9. Click the SOAP Structure tab at the bottom of the editor, and then in the top part of the HTTP Analyzer, click the WSDL URL link.

    http analyzer wsdl url

  10. This opens the visual editor for the web service. In the Port Types panel, expand the getDeptInfo | input | getDeptInfo nodes.

    http analyzer port types

  11. To the left of the Port Types panel, click the small Plus sign at the top of Messages to show message contents.

    http analyzer show messages

    A new graphical representation shows the flow for any message you select.

    http analyzer showing service messages

  12. Right-click any tab in the editor window and select the Close All option.

    close all windows

  13. Collapse the Annotation project node in the Application Navigator.

    application navigator

Bookmark Print Expand all | Hide all
Back to top
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.