Files   Prepare   Run   Troubleshooting   Related Topics 

About the Example

This example shows how to create a simple WebLogic Web Service using JWS metadata annotations.

Metadata annotations are a new J2SE 5.0 feature that provides the ability to associate additional data alongside Java classes, interfaces, methods, and fields. The set of annotations used to annotate Web Service files are called JWS annotations. WebLogic Web Services use standard JWS annotations, as defined by the Web Services Metadata for the Java Platform specification (JSR-181) as well as WebLogic-specific ones for added value.

The generated Web Service in this example, called Simple, has a single operation, sayHello(String), that returns the input String parameter.

The SimpleImpl.java Java source file (also called JWS file) forms the basis of the Web Service. The file uses both standard (defined by JSR-181) and WebLogic-specific JWS annotations to define the shape and behavior of the Web Service.

In particular, the JWS file uses the following standard JWS annotations:

The JWS file uses the following WebLogic-specific JWS annotation:

To use the various JWS annotations, you must first import the annotation interfaces into your JWS file:

//Standard JWS annotations
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

//WebLogic-specific JWS annotation
import weblogic.jws.WLHttpTransport;

The SimpleImpl.java file defines a single public method that is exposed as a Web Service operation: sayHello(String). Because the @WebMethod annotation on the method does not specify the operationName attribute, the public name of the operation in the WSDL will be the same as the name of the method: sayHello.

To generate a Web Service from the JWS file, use the jwsc WebLogic Web Service Ant task, as shown in the build.xml file. This Ant task compiles the JWS file, and generates the additional files needed to implement a standard Java EE Web Service: the Web Service deployment descriptors, the WSDL file, and so on. The Ant task automatically generates all the components into an Enterprise Application directory structure, which you can then deploy to WebLogic Server. This example uses the wldeploy WebLogic Ant task to deploy the Web Service.

The Client.java class is a standalone Java application that invokes the sayHello operation of the Simple Web Service. It uses the JAX-RPC Stubs generated by the clientgen WebLogic Web Service Ant task, based on the WSDL of the Simple Web Service.


Files Used in the Example

Directory Location:

BEA_HOME/wlserver_10.3/samples/server/examples/src/examples/webservices/jws_basic/simple/

(where BEA_HOME is the directory containing your WebLogic Server installation)

File

Click source files to view code.

Description

SimpleImpl.java Java source file that contains the JWS metadata annotations (both standard and WebLogic-specific) that define the JWS-implemented Web Service.
Client.java Standalone client application that invokes the deployed Web Service. Uses the JAX-RPC Stubs generated by clientgen, based on the WSDL of the Web Service.
JWS_WebService.jsp JSP file that is invoked when you click on the Run the example link for this example from the main Examples Server JSP.
build.xml Ant build file that contains targets for building and running the example.

Prepare the Example

Prerequisites

Before working with this example:

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

Configure WebLogic Server

There are no server configurations for this example.

Build and Deploy the Example

  1. Change to the SAMPLES_HOME\server\examples\src\examples\webservices\jws_basic\simple directory, where SAMPLES_HOME refers to the main WebLogic Server examples directory, such as d:\bea\wlserver_10.0\samples.
  2. Execute the following command from the shell where you set your environment:

    prompt> ant build

    This command compiles and stages the example.
  3. Execute the following command from the shell where you set your environment:

    prompt> ant deploy

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

Run the Example

To run the example, follow these steps:

  1. Complete the steps in the "Prepare the Example" section.
  2. In your development shell, run the Client Java application by using the following command from the main example directory (SAMPLES_HOME\server\examples\src\examples\webservices\jws_basic\simple):

    prompt> ant run

  3. After building and running the example, you can view the WSDL of the Web Service by browsing to the following URL in your Web browser:

    http://host:port/jws_basic_simple/SimpleService?WSDL

    where

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] Got result: Here is the message: 'Hi there!'
    BUILD SUCCESSFUL
    
           Total time: 7 seconds

Troubleshooting


Related Topics

(Internet connection required.)


Copyright © 1996, 2008, Oracle and/or its affiliates. All Rights Reserved.