Creating a JAX-WS Web Service from an Existing WSDL File } }

 Files   Prepare   Run   Troubleshooting   Related Topics 

 

About the Example

This example shows how to use the wsdlc and jwsc Ant tasks in combination to create a JAX-WS based Web Service based on an existing WSDL file.

For the sake of clarity, the WSDL file is very simple. The Web service is called WarehouseService, and it contains a single operation ShipGoods that takes as inputs a product number, quantity and customer name and returns the status of the shipment.

The example shows how to first execute the wsdlc Ant task, which takes as input the WSDL file, and, based on the operations, parameters, return values, and so on in the WSDL, generates a set of artifacts that together provide a partial implementation of the JAX-WS based Web Service described by the WSDL file. These components include:

The example shows how to use the type attribute of the wsdlc Ant task to generate a partial JAX-WS implementation of a Web Service, as opposed to the default JAX-RPC Web Service.

After running the wsdlc Ant task and updating the wsdlc-generated JWS file, the example shows how to run the jwsc Ant task against the JWS file to create a deployable Web Service. The only additional attribute specify in this case is the compiledWsdl attribute of the <jws> child element, which points to the wsdlc-generated JAR file that contains the JWS interface file and the data binding artifacts. You must also use the type attribute of the jwsc Ant task to specify that jwsc generate a JAX-WS Web Service, rather than the default JAX-RPC Web Service.

The example then deploys the Web Service to the examplesServer as usual, and generates a standalone Java client application that invokes the shipGoods operation of the WarehouseService Web Service. The WarehouseServiceClient.java application uses the JAX-WS Stubs generated by the clientgen WebLogic Web Service Ant task, based on the WSDL of the WarehouseService Web Service.


 

Files Used in the Example

Directory Location:

MW_HOME/wlserver_10.3/samples/server/examples/src/examples/webservices/jaxws/wsdl2service/

(where MW_HOME is the directory containing your Oracle WebLogic Server installation)

File

Click source files to view code.

Description

build.xml Ant build file that contains targets for building and running the example.
WarehouseServiceClient.java Standalone client application that invokes the deployed WarehouseService Web Service. Uses the JAX-WS Stubs generated by clientgen, based on the WSDL of the Web Service.
WarehouseService_WarehouseShipmentsPortImpl.java Prepackaged implementation of WarehouseService.
wsdl_files/WarehouseService.wsdl Existing WSDL file from which the wsdlc Ant task generates the needed components, including the JWS interface that represents the WarehouseService Web Service that has a single method, shipGoods.


 

Prepare the Example

 

Prerequisites

Before working with this example:

  1. Install Oracle WebLogic Server, including the examples.
  2. Start the Examples server.
  3. Set up your environment.

 

Configure Oracle WebLogic Server

  No special configuration is required for this example

 

Build and Deploy the Example

Change to the SAMPLES_HOME\server\examples\src\examples\webservices\jaxws\wsdl2service directory, where SAMPLES_HOME refers to the main Oracle WebLogic Server examples directory, such as d:\Oracle\Middleware\wlserver_10.3\samples.

  1. Execute the following command:

    prompt> ant generate.from.wsdl

    This command executes the wsdlc Ant task on the specified WSDL file to generate the components described in the introduction above.
  2. Using your favorite Java editor or IDE, open the file output\Warehouse\imp\examples\webservices\jaxws\wsdl2Service\WarehouseService_WarehouseShipmentsPortImpl.java and modify the shipGoods() method:
      public boolean shipGoods(examples.webservices.jaxws.wsdl.Item item,java.lang.String customer)  {
        int pn = item.getProductNumber();
        int quantity = item.getQuantity();
        System.out.println("Customer " + customer + " wants " + quantity + " pieces of  Goods '" + pn + "' to be shipped.");
        System.out.println("Shipping goods now.");
        return true;
       }
      }
    This simulates adding business logic to the JWS implementation file. This sample has provided an ant target copy.serviceimpl which will copy a prepackaged WarehouseService_WarehouseShipmentsPortImpl.java to the directory output\Warehouse\imp\examples\webservices\jaxws\wsdl\wsdl2Service.
  3. Execute the following command:

    prompt> ant build.service client

    The build.service target executes the jwsc Ant task that compiles and builds the Web Service; the client target builds the client application that invokes the Web Service.
  4. Execute the following command:

    prompt> ant deploy

    This command deploys the example on the wl_server domain of your Oracle WebLogic Server installation.

 

Run the Example

To run the example, follow these steps:

  1. In your development shell, run the WarehouseServiceClient Java application by using the following command from the main example directory (SAMPLES_HOME\server\examples\src\examples\webservices\jaxws\wsdl2service):

    prompt> ant run

  2. After building and running the example, you can view the WSDL of the WarehouseService Web Service in your Web browser:

    http://host:port/WarehouseService/WarehouseService?WSDL

    Where:

    • host refers to the machine on which Oracle WebLogic Server is running
    • port refers to port on which Oracle WebLogic Server is listening

    This URL is the same as the value of the location attribute of the <soap:address> element in the original WSDL, except that the host and port of the hosting server is obviously changed to that of Oracle WebLogic Server.

 

Check the Output

If your example runs successfully, you will get the following message in the command shell from which you ran the client application:

Buildfile: build.xml

run:
[java] Goods has been shipped!

BUILD SUCCESSFUL
Total time: 6 seconds


 

Troubleshooting


 

Related Topics

(Internet connection required.)