Overview of Assembling a WebLogic Web Service Manually

Assembling a WebLogic Web Service refers to gathering all the components of the service (such as the EJB JAR file, the SOAP message handler classes, and so on), generating the web-services.xml deployment descriptor file, and packaging everything into an Enterprise Application EAR file that can be deployed on WebLogic Server.

Typically you never assemble a WebLogic Web Service manually, because the procedure is complex and time-consuming. Rather, use the WebLogic Ant tasks such as servicegen, autotype, source2wsdd, and so on to automatically generate all the needed components and package them into a deployable EAR file.

If, however, your Web Service is so complex that the Ant tasks are not able to generate the needed components, or you want full control over all aspects of the Web Service assembly, then use this chapter as a guide to assembling the Web Service manually.

Assembling a WebLogic Web Service Manually: Main Steps

Package or compile the back-end components that implement the Web Service into their respective packages. For example, package stateless session EJBs into an EJB JAR file and Java classes into class files.

Understanding the web-services.xml File

The web-services.xml deployment descriptor file contains information that describes one or more WebLogic Web Services, such as the back-end components that implement the Web Service; the non-built-in data types used as parameters and return values; the SOAP message handlers that intercept SOAP messages; and so on. As is true for all deployment descriptors, web-services.xml is an XML file.

Based on the contents of the web-services.xml deployment descriptor file, WebLogic Server dynamically generates the WSDL of a deployed WebLogic Web Service. See WebLogic Web Services Home Page and WSDL URLs for details on getting the URL of the dynamically generated WSDL.

A single WebLogic Web Service consists of one or more operations; you can implement each operation using methods of different back-end components and SOAP message handlers. For example, an operation might be implemented with a single method of a stateless session EJB or with a combination of SOAP message handlers and a method of a stateless session EJB.

A single web-services.xml file contains a description of at least one, and maybe more, WebLogic Web Services.

If you are assembling a Web Service manually (necessary, for example, is the service uses SOAP message handlers and handler chains), you need to create the web-services.xml file manually. If you assemble a WebLogic Web Service with the servicegen Ant task, you do not need to create the web-services.xml file manually, because the Ant task generates one for you based on its introspection of the EJBs, the attributes of the Ant task, and so on.

Even if you need to manually assemble a Web Service, you can use the servicegen Ant task to create a basic template, and then use this document to help you update the generated web-services.xml with the extra information that servicegen does not provide.

Creating the web-services.xml File Manually: Main Steps

The web-services.xml deployment descriptor file describes one or more WebLogic Web Service. The file includes information about the operations that make up the Web Services, the back-end components that implement the operations, data type mapping information about non-built-in data types used as parameters and return values of the operations, and so on. See Examining Different Types of web-services.xml Files for complete examples of web-services.xml files that describe different kinds of WebLogic Web Services. You can use any text editor to create the web-services.xml file.

Create the root <web-services> element which contains all other elements:

<web-services>...</web-services>

If one or more of your Web Services include SOAP message handlers to intercept SOAP messages, create a <handler-chains> child element of the <web-services> root element and include all the relevant child elements to describe the handlers in the handler chain, the order in which they should be invoked, and so on. For details, see Updating the web-services.xml File with SOAP Message Handler Information.

For each Web Service you want to define, follow these steps:

Create a <web-service> child element of the <web-services> element. Use the name, targetNamespace, and uri attributes to specify the name of the Web Service, its target namespace, and the URI that clients will use to invoke the Web Service, as shown in the following example:

To specify that the operations in your Web Service are all document-oriented, use the style="document" attribute. The default value of the style attribute is rpc, which means the operations are all RPC-oriented.

Create a <components> child element of the <web-service> element that lists the back-end components that implement the operations of the Web Service. For details, see Creating the <components> Element.

If the operations in your Web Service use non-built-in data types as parameters or return values, add data type mapping information by creating <types> and <type-mapping> child elements of the <web-service> element. For details, see Creating the Data Type Mapping File.

Note: You do not have to perform this step if the operations of your Web Service use only built-in data types as parameters or return values. See Supported Built-In Data Types for a list of the supported built-in data types.

Create an <operations> child element of the <web-service> element that lists the operations that make up the Web Service:

Creating the <components> Element

Use the <components> child element of the <web-service> element to list and describe the back-end components that implement the operations of a Web Service. Each back-end component has a name attribute that you later use when describing the operation that the component implements.

Note: If you are creating a SOAP message handler-only type of Web Service in which handlers and handler chains do all the work and never execute a back-end component, you do not specify a <components> element in the web-services.xml file. For all other types of Web Services you must declare a <components> element.

You can list one of the following types of back-end components:

<stateless-ejb>

This element describes a stateless EJB back-end component. Use either the <ejb-link> child element to specify the name of the EJB and the JAR file where it is located or the <jndi-name> child element to specify the JNDI name of the EJB, as shown in the following example:

Creating <operation> Elements

The <operation> element describes how the public operations of a WebLogic Web Service are implemented. (The public operations are those that are listed in the Web Service's WSDL and are executed by a client application that invokes the Web Service.) The following example shows an <operation> declaration:

Typically, every instance of an <operation> element in the web-services.xml file includes the name attribute which translates into the public name of the Web Service operation. The only exception is when you use the method="*" attribute to specify all methods of an EJB or Java class in a single <operation> element; in this case, the public name of the operation is the name of the method.

To specify with a single <operation> element that you want to include all the methods of an EJB or Java class, use the method="*" attribute; in this case, the public name of the operation is the name of the method:

<operation component="simpleStockQuoteBean" method="*"></operation>

To specify that an operation only receives data and does not return anything to the client application, add the invocation-style attribute:

The example also shows how to specify the full signature of a method with the method attribute. You only need to specify the full signature of a method if your EJB or Java class overloads the method and you thus need to unambiguously declare which method you are exposing as a Web Service operation.

To specify that an operation is implemented with a SOAP message handler chain and a method of a stateless session EJB, use the name, component, method, and handler-chain attributes:

To specify that an operation is implemented with just a SOAP message handler chain, use just the name and handler-chain attributes:

<operation name="justHandler" handler-chain="myHandler">

</operation>

Specifying the Parameters and Return Value of the Operation

Use the <params> element to explicitly declare the parameters and return values of the operation.

You do not have to explicitly list the parameters or return values of an operation. If an <operation> element does not have a <params> child element, WebLogic Server introspects the back-end component that implements the operation to determine its parameters and return values. When generating the WSDL of the Web Service, WebLogic Server uses the names of the corresponding method's parameters and return value.

You explicitly list an operation's parameters and return values when you need to:

Make the name of the parameters and return values in the generated WSDL different from those of the method that implements the operation.

Map a parameter to a name in the SOAP header request or response.

Use out or in-out parameters.

Use the <param> child element of the <params> element to specify a single input parameter and the <return-param> child element to specify the return value. You must list the input parameters in the same order in which they are defined in the method that implements the operation. The number of <param> elements must match the number of parameters of the method. You can specify only one <return-param> element.

Use the attributes of the <param> and <return-param> elements to specify the part of the SOAP message where parameter is located (the body or header), the type of the parameter (in, out, or in-out), and so on. You must always specify the XML Schema data type of the parameter using the type attribute. The following examples show a variety of input and return parameters.

To specify that a parameter is a standard input parameter, located in the header of the request SOAP message, use the style and location attributes as shown:

Out and in-out parameters enable an operation to return more than one return value (in addition to using the standard <return-value> element.) The following sample <param> element shows how to specify that a parameter is an in-out parameter, which means that it acts as both an input and output parameter:

<param name="inoutparam" style="inout" type="xsd:int" />

Because the default value of the location attribute is Body, both the input and output parameter values are found in the body of the SOAP message.

The following example shows how to specify a standard return value located in the header of the response SOAP message:

<return-param name="result" location="Header" type="xsd:string" />

Optionally use the <fault> child element of the <params> element to specify your own Java exception that is thrown if there is an error while invoking the operation. This exception will be thrown in addition to the java.rmi.RemoteException exception. For example:

EJB Component Web Service with Built-In Data Types

One kind of WebLogic Web Service is implemented using a stateless session EJB whose parameters and return values are one of the built-in data types. The following Java interface is an example of such an EJB:

The example shows a Web Service called stockquotes. The Web Service is implemented with a stateless session EJB whose <ejb-name> in the ejb-jar.xml file is StockQuoteBean and is packaged in the EJB JAR file called stockquoteapp.jar. The internal name of this component is simpleStockQuoteBean. The Web Service has one operation, called getLastTradePrice, the same as the EJB method name. The input and output parameters are inferred from the method signature and thus do not need to be explicitly specified in the web-services.xml file.

Note: The servicegen Ant task does not include the methods of EJBObject when generating the list of operations in the web-services.xml file.

The previous example shows how to explicitly list an operation of a Web Service. You can, however, implicitly expose all the public methods of an EJB by including just one <operation method="*"> element, as shown in the following example:

EJB Component Web Service with Non-Built-In Data Types

A more complex type of Web Service is one whose operations take non-built-in data types as parameters or return values. Because these non-built-in data types do not directly map to a XML/SOAP data type, you must describe the data type in the web-services.xml file.

For example, the following interface describes an EJB whose two methods return a TradeResult object:

In the example, the <types> element uses XML Schema notation to describe the XML representation of the TradeResult data type. The <type-mapping> element contains an entry for each data type described in the <types> element (in this case there is just one: TradeResult.) The <type-mapping-entry> lists the serialization class that converts the data between XML and Java, as well as the Java class file used to create the Java object.

EJB Component and SOAP Message Handler Chain Web Service

Another type of Web Service is implemented with both a stateless session EJB back-end component and a SOAP message handler chain that intercepts the request and response SOAP message. The following sample web-services.xml file describes such a Web Service:

The example shows a Web Service that includes a SOAP message handler-chain called submitOrderCrypto used for decrypting and encrypting information in the SOAP request and response messages. The handler chain includes one handler, implemented with the com.example.security.EncryptDecrypt Java class. The handler takes two initialization parameters that specify the elements in the SOAP message that need to be decrypted and encrypted.

The Web Service defines one stateless session EJB back-end component called orderbean.

The submitOrder operation shows how to combine a handler-chain with a back-endback-end component by specifying the method, component, and handler-chain attributes in combination. When a client application invokes the submitOrder operation, the submitOrderCrypto handler chain first processes the SOAP request, decrypting the credit card information. The handler chain then invokes the submit() method of the orderbean EJB, passing it the modified parameters from the SOAP message, including the purchase-order input parameter. The submit() method then returns an order-number, which is encrypted by the handler chain, and the handler chain finally sends a SOAP response with the encrypted information to the client application that originally invoked the submitOrder operation.

SOAP Message Handler Chain Web Service

You can also implement a WebLogic Web Service with just a SOAP message handler chain and never invoke a back-end component. This type of Web Service might be useful, for example, as a front end to an existing workflow processing system. The handler chain simply takes the SOAP message request and hands it over to the workflow system, which performs all the further processing.

The following sample web-services.xml file describes such a Web Service:

The example shows a Web Service that includes one SOAP message handler chain, called enterWorkflowChain. This handler chain has one handler, implemented with the Java class com.example.WorkFlowEntry, that takes as an initialization parameter the JNDI name of the existing workflow system.

The Web Service defines one operation called enterWorkflow. When a client application invokes this operation, the enterWorkflowChain handler chain takes the SOAP message request and passes it to the workflow system running on WebLogic Server whose JNDI name is workflow.entry. The operation is defined as asynchronous one-way, which means that the client application does not receive a SOAP response.

Note that because the enterWorkflow operation does not specify the method and component attributes, no back-end component is ever invoked directly by the Web Service. This also means that the web-services.xml file does not need to specify a <components> element.