Create a Java Web Service from a WSDL

A web service is a discrete, reusable software component that is accessed programmatically over the Internet to return a response. A WSDL (Web Service Description Language) document describes a web service and the operations the service exposes through a set of definitions. You can work in JDeveloper's IDE to quickly define a WSDL document, and then create a Java web service from the WSDL.

Create a New Application: Use the Create Application wizard to create a generic application.

Create a WSDL Document: Use the WSDL visual editor to create the WSDL definition of a service that supports one operation (method).

Create a Java Web Service from the WSDL: Use the Create Java Web Service from WSDL wizard to generate and publish a service class and expose a method as a web service operation.

Add Service Implementation Code: Use the source editor to add code to the generated service implementation class.

Use the HTTP Analyzer to Test the Web Service: Run the web service in JDeveloper's integrated server and test the service in the HTTP Analyzer.

Add a Policy to the Web Service: Use the Java Web Service editor to add an Oracle Web Service Manager security policy. Then test the web service in the HTTP Analyzer.

 

Create a New Application and Project

tell me more icon Creating a New Application and Project

The JDeveloper application is the highest level in the organizational structure. It stores information about the objects you are working with, while you are creating your application. It keeps track of your projects and the environment settings while you are developing.   [ tell me more...]





  1. Open the Create Application wizard [ File > New > General > Applications.
  2. To follow along with the example, enter the application name ServiceFromWsdl.
  3. Select Generic Application in the Applica tion Template list, and click Finish .

    tell me more icon Application Templates

    Application templates provide you with a quick way to create the project structure for standard applications with the appropriate combination of technologies already specified. The new application created from the template appears in the Application Navigator already partitioned into tiered projects, with the associated technology scopes set in each project.   [ tell me more...]




    tell me more icon In the IDE

    When you complete the steps for creating a new application and project, the Projects panel in the Application Navigator should look like this:  [ tell me more...]



 

Create a WSDL Document

tell me more icon Creating a WSDL Document

A WSDL (Web Service Description Language) document describes a web service and the operations (methods) the service exposes through a set of definitions.   [ tell me more...]





  1. In the Application Navigator, select the project you just created and open the Create WSDL Document dialog [ File > New > Business Tier > Web Services > WSDL Document] . To follow along with the example, enter CreditRating as the WSDL name, and click OK.

    tell me more icon WSDL Document Example

    To follow along with the example, in this step and throughout the cards, enter values as shown in the instructions. Then you will be able to follow the steps in the cue cards exactly as written.   [ tell me more...]



  2. In the Application Navigator, select the project again, and open the Create XML Schema dialog [ File > New > General > XML > XML Schema] . Enter CreditRatingDetails.xsd as the file name.
  3. Click B rowse next to the Directory field to open the Choose Directory dialog. Click the public_html folder and click Select to store the schema file in the public_html directory of the project. Then click OK.
  4. In the XSD schema editor, click Source at the bottom of the editor window to switch to the XML editor. Copy and paste the XML schema sample code provided.
    code sample icon Use sample code
  5. Click filesave icon Save to save the file. In the editor window, click the Design tab to return to the visual editor.
  6. In the editor window, grab the xmlschema icon CreditRatingDetails.xsd document tab and drag it down, and drop it when you see a purple box spanning across the entire bottom of the window.

    tell me more icon Importing the XML Schema

    After creating the XML schema document, the editor window should look something like this:  [ tell me more...]



  7. In the XSD schema editor, drag CreditRatingDetailsElement and drop it on the Port Types pane in the WSDL visual editor.
  8. In the Create Port Type dialog, enter RatingService in the Port Type Name field, then click OK.

    tell me more icon WSDL Document Structure

    A WSDL (Web Service Description Language) document is an XML-formatted document that describes a web service and the operations (or methods) the service exposes through a set of definitions. As you create a WSDL document using the integrated tools, JDeveloper generates the XML code for you, which you can view by using the XML editor.  [ tell me more...]



  9. In the WSDL visual editor, expand interface icon RatingService in the Port Types pane. Then select web method icon CreditRatingDetailsElementOperation. In the Property Inspector, change the value of Name to processRating and press Enter.

    tell me more icon WSDL Editor

    The default view of the WSDL visual editor is Design, which provides a visual way to add elements to a WSDL document. There are four panes on the visual editor, namely, Messages, Port Types, Bindings/Partner Link Types, and Services. You can collapse and expand any pane by clicking the grey small plus sign icon or grey small minus sign icon icon in front of the name.   [ tell me more...]



  10. In the WSDL visual editor, drag interface icon RatingService and drop it on the Bindings/Partner Link Types pane. In the Create Binding dialog, deselect SOAP 11 . Then select S OAP 12 . Make sure Document/Literal is selected in the Message Encoding dropdown list. Then click OK.

    tell me more icon Bindings, Port Types, and Messages

    By default, when you drag and drop a port type on the Bindings/Partner Link Types pane, JDeveloper displays the Create Binding dialog. If you wish to create a partner link type, click dropdown icon next to green add icon Add and select Add partnerLinkType from the dropdown menu.  [ tell me more...]



  11. In the WSDL visual editor, drag soap server icon RatingServiceSOAP12Binding and drop it on the Services pane.

    tell me more icon Services

    A service is a collection of ports. A port defines a specific network address for a binding, which is a specific communication protocol for each message in each operation of a port type.   [ tell me more...]



  12. Click the save all icon Save All to save your work.
  13. In the Application Navigator, right-click wsdl definition icon CreditRating.wsdl and choose Va lidate WSDL .

    tell me more icon In the IDE

    When you complete the steps for creating a WSDL document, the WSDL visual editor should look similar to this, if all panes are expanded:   [ tell me more...]



 

Create a Java Web Service from the WSDL

tell me more icon Creating a Java Web Service from the WSDL

JDeveloper makes it easy to create a web service from a WSDL document by providing a wizard.   [ tell me more...]





  1. In the Application Navigator, select the project and open the Create Java Web Service from WSDL wizard [ File > New > Business Tier > Web Services > Java Web Service from WSDL] . If the Welcome page of the wizard displays, click Next .
  2. On step 2 of the wizard, Select Deployment Platform, select Java EE 1.5, with support for JAX-WS Annotations. Click Next .

    tell me more icon Selecting the Deployment Platform

    When you use the wizard to create the first Java web service in a project, you have to select the J2EE or Java EE version using the Select Deployment Platform page, which looks like this:  [ tell me more...]



  3. On step 3, Select Web Service Description, select CreditRating.wsdl from the WSD L Document URL dropdown listbox. Make sure Java under Service Type is selected, and Copy WSDL Locally is not selected. Click Next .

    tell me more icon Selecting the Web Service Description

    The WSD L Document URL dropdown listbox lists the existing WSDL documents in the current application. When you select the WSDL document you created earlier, make sure Copy WSDL Locally is not selected because you already have the WSDL document in the project.   [ tell me more...]



  4. On step 4, Specify Default Mapping Options, enter project1 as the package name and project1.types as the root package name. Then click Finish .
  5. Click the save all icon Save All to save your work.

    tell me more icon In the IDE

    When you finish the wizard steps for creating the Java web service from the WSDL, JDeveloper displays messages in the Web Services Log window that tell you the generation is complete.   [ tell me more...]



 

Add the Service Implementation Code

tell me more icon Adding the Service Implementation Code

In this example, you will add the service implementation code in the RatingServiceImpl.java file that JDeveloper generated when you used the wizard to create the Java web service from the WSDL.   [ tell me more...]





  1. In the Application Navigator, double-click webservice icon RatingServiceImpl.java to open the file in the source editor.

    tell me more icon Using Java Source Editor Features

    The insert or replace mode for the editor is controlled by the Insert key on the keyboard. The default is insert mode. Press Insert to toggle between insert and replace mode.  [ tell me more...]



  2. In the processRating() method, add the service implementation code for the operation.
    code sample icon Use sample code
  3. Click the save all icon Save All to save your work.
  4. In the Application Navigator, right-click webservice icon RatingService and choose Test Web Service to run the service.

    tell me more icon Testing the Web Service in Integrated WebLogic Server

    After you create a web service, you will usually test it to ensure that you get the results you expect. JDeveloper's IDE allows you to deploy the web service to an integrated server for testing.   [ tell me more...]



  5. In the Request pane of the HTTP Analyzer window, enter 987654321 in the ssn parameter field. Then click the send request icon Send Request. You should see rating 0 in the Response pane.

    tell me more icon HTTP Analyzer

    The HTTP Analyzer allows you to examine and monitor HTTP request and response packets. When you select Test Web Service, by default JDeveloper displays the HTTP Analyzer log window and HTTP Analyzer Instances window below the editor window. The web service deploys to Integrated WebLogic Server, then JDeveloper displays the HTTP Analyzer test window with the Request and Response panes placed side by side.   [ tell me more...]




    tell me more icon In the IDE

    After you test the web service, the HTTP Analyzer test window in the IDE should look similar to this:   [ tell me more...]



 

Add a Policy to the Web Service

tell me more icon Adding a Policy to the Web Service

A web service policy consists of facts or assertions, and rules that apply to a particular web service. To begin adding a policy to the web service, you will open the Java Web Service properties editor.   [ tell me more...]





  1. In the Application Navigator, right-click webservice icon RatingService and choose Pr operties from the context menu.
  2. In the Java Web Service Editor, select Configure Policies, then select OWSM Policies . In the Security section, click green plus icon Add.

    tell me more icon Web Service Policies

    Policies are additional business functionality for web services, such as logging and security capabilities. The Configure Policies page of the Java Web Service Editor enables you to attach either Oracle Web Service Manager policies or Oracle WebLogic Server policies. The type of policy a web service can use is constrained by the type of web services it is: For JAX-WS, you can attach Oracle Web Service Manager (security only) policies or Oracle WebLogic Server policies; for JAX-RPC, you can attach Oracle WebLogic policies only.  [ tell me more...]



  3. In the Select Policy From List dialog, select oracle/wss_username_token_service_policy, then click OK.
  4. Click OK to close the editor. If a warning dialog displays, click Yes .
  5. Click the save all icon Save All to save your work.
  6. In the Application Navigator, right-click webservice icon RatingService and choose Test Web Service .
  7. In the HTTP Analyzer window, Request pane, expand SOAP Headers. Select Include next to WS-Security: Header. Then under Security | UsernameToken, enter the username and password for the integrated server.

    tell me more icon Web Services Security

    WS-Security (Web Services Security) is a standard communications protocol for applying security to web services. The WS-Security specification provides mechanisms to help developers of web services secure SOAP message exchanges, for example, by encoding and attaching binary security tokens in the headers of messages. The WS-Security UsernameToken Profile specification describes how to encode UsernameTokens with the WS-Security specification. Through UsernameTokens, a web service consumer can supply a means of identifying the requestor by “username”, and optionally using a password to authenticate that identity to the web service producer.   [ tell me more...]



  8. At the bottom of the Request pane, enter 987654321 in the ssn parameter field. Then click the send request icon Send Request. You should see rating 0 in the Response pane.

    tell me more icon In the IDE

    When you complete the steps for adding the policy, you should see the following @SecurityPolicy annotation that JDeveloper added to the RatingServiceImpl.java file in the source editor:  [ tell me more...]



 











Copyright © 1997, 2009, Oracle. All rights reserved.

false ,,,,,,,,,,,,,,,