Chapter 21. Creating and Deploying JAX-RPC Web Services

Table of Contents

21.1. Creating and Deploying Java Web Services
21.1.1. Configuring Service Configuration File
21.1.2. Creating WSDL and JAX-RPC Mapping Files
21.1.3. Configuring Web Service DD File
21.1.4. Packaging and Deploying
21.2. Creating and Deploying EJB Web Services
21.2.1. Configuring Web Service Configuration File
21.2.2. Creating WSDL File and JAX-RPC Mapping File
21.2.3. Configuring Web Services DD File
21.2.4. Packaging and Deploying

This chapter describes how to create and deploy JAX-RPC web services whose endpoint is a Java class or an EJB.

JEUS provides a command-line tool and an Apache Ant tool to facilitate an easier JAX-RPC web service creation. Use the following steps to create and deploy JAX-RPC web services.

  1. Configure the service configuration file (service-config.xml).

  2. Create the WSDL file and JAX-RPC mapping file for Java EE web services.

  3. Configure the web service deployment descriptors ('webservices.xml' and 'jeus-webservices-dd.xml')

  4. Package and deploy the generated web service modules.

JEUS JAX-RPC web services provide a command-line tool and Ant Task for instantiating web services. Either tool can be used depending on preference.

Using Command-line Tool

JAX-RPC web services provide the command-line tool for creating a web service.

Usage: java2wsdl [options] configuration_file
where [options] include:
-classpath <path>           specify where to find input class files
-cp <path>                  same as -classpath <path>
-d <directory>              specify where to place generated output files
-verbose                    [optional] turn verbose mode on

To instantiate the web service by using the service-config.xml file shown in "21.1.1. Configuring Service Configuration File", execute command from the command line.

The following is an example of executing the command by assuming that the compiled Java class back-end files exist in the 'JEUS_HOME/sample/classes' folder.

JEUS_HOME/sample$java2wsdl -cp ./classes service-config.xml

The WSDL file (DocLitEchoService.wsdl) and JAX-RPC mapping file (DocLitEchoService-mapping.xml) are created when the previous command is executed.

Using Ant Tool

JEUS JAX-RPC web services provide an Ant Task called 'java2wsdl'. It takes the service configuration file path as an input and generates the WSDL file and JAX-RPC mapping file.

Compile the Java class files with the following command.

ant compile

The WSDL file and JAX-RPC mapping file are created in the './build' directory.

The compile Ant Task is internally processed in the order of '-pre-compile', 'do-compile', and '-postcompile'. The '-post-compile' process creates the WSDL file and JAX-RPC mapping file as shown in the following.

<target name="-post-compile">
    <mkdir dir="${build.war.dir}/WEB-INF/wsdl"/>
    <antcall target="java2wsdl">
        <param name="java2wsdl.option" 
               value="-classpath ${build.classes.dir}
               -d ${build.war.dir}/WEB-INF ${src.conf}/service-config.xml" />
    </antcall>
</target>

The web service DD (Deployment Descriptor) file is an XML file that contains the deployment configurations. The web service DD file provides a web service engine with information about web service deployment and web service back-end search methods.

There are 2 kinds of web service DD files. First one is the webservices.xml file, a standard web service DD file defined by the Java EE web services specification. The other one is the 'jeus-webservicesdd. xml' file, a JEUS specific deployment descriptor file.

Configuring Java EE Web Services DD File

The name of the Java EE web services DD file must be 'webservices.xml'.


In the previous example, the service name is 'DocListEchoService'. The WSDL file path is the 'WEB-INF/wsdl' directory of the WAR file, and the name of the file is 'DocListEchoService.wsdl'. The JAX-RPC mapping file path is the 'WEB-INF' directory, and the name of the file is 'DocLitEchoService-mapping.xml'. In order to access the service, the port named 'EchoPort' in the WSDL must be used and an SEI and Servlet must be created for this port. For more information, refer to
"Chapter 24. Creating JAX-RPC Web Service Configuration File".

Configuring JEUS Web Service DD File

The name of the JEUS web services DD file must be 'jeus-webservices-dd.xml'.


Note

For more information, refer to "22. Configuring jeus-client-dd.xml" of the "JEUS XML Reference Guide".

Java web services package Java classes and web service DD files like web modules. Web service modules are packaged into an EAR (Enterprise Application Archive) file that contains the web application WAR and EJB JAR files.

This section describes how to package and deploy EAR files.

Packaging EAR Files

A Java EE application is an independent business solution that can utilize web component, EJB, or JavaEE connectors, and it can be packaged into an EAR (Enterprise Archive) file. An EAR file contains the application deployment descriptors and may contain additional Java EE components and connectors packaged as EJB JAR, WAR, or RAR file.

A Java web service is packaged into a WAR file since it is created using the servlet programming model. An EJB endpoint is packaged into an EJB JAR file because an EJB is where SOAP messages are handled.

EAR
 |
 +-- WAR file
 |
 +-- JAR file
      |
      +-- EJB Web service component
 |
 +-- META-INF
      |
      +-- Standard application.xml file

JavaEE components packaged into an EAR file are defined in the application.xml file of the 'META-INF' directory.

The following is a sample application.xml file of an EAR application that contains a web module as a Java EE component.


The package name and the module context information of the web module are configured in the <web> element.

Deploying Web Services (EAR)

The deployment procedures for web services are identical to those for other Java EE applications. After the EAR package has been deployed, the web service can be invoked via the Internet.

The following is the URL of the deployed service.

http://host:port/DocLitEchoService/DocLitEchoService

After implementing the web service using EJB, the business logic of the EJB needs to be converted into a web service and deployed. The instantiation and deployment of an EJB web service is identical to that of a Java web service. JEUS provides a command-line tool and Apache Ant tool to facilitate an easier creation of JAX-RPC web services.

Use the following steps to instantiate and deploy a web service.

  1. Configure the web service configuration file (service-config.xml).

  2. Create the WSDL file and JAX-RPC mapping file for Java EE web services.

  3. Configure the web service deployment descriptors. (webservices.xml, jeus-webservices-dd.xml, and ejb-jar.xml)

  4. Package and deploy the web service modules.

JEUS JAX-RPC web services provide a command-line tool and Ant Task for instantiating web services. Either tool can be used depending on preference.

Using Command-line Tool

JEUS JAX-RPC web services provide a command-line tool for creating web services.

Usage: java2wsdl [options] configuration_file

where [options] include:
-classpath <path>   specify where to find input class files
-cp <path>          same as -classpath <path>
-d <directory>      specify where to place generated output files
-level <log-level>  specify a log level
-verbose            [optional] turn verbose mode on

To instantiate the web service by using the service-config.xml file shown in the previous section, execute the following command, assuming that the compiled Java class back-end files exist in the 'JEUS_HOME/sample/classes' folder.

JEUS_HOME/sample$java2wsdl -cp ./classes ejb-service-config.xml

When you execute the previous command, WSDL file (AddressBookService.wsdl) and JAX-RPC mapping file (AddressBookService-mapping.xml) are created.

Using Ant Tool

JEUS JAX-RPC web services provide an Ant Task called 'java2wsdl' for creating web services. It takes the service configuration file path as an input and generates the WSDL file and JAX-RPC mapping file.

Compile the Java class files with the following command.

ant compile

The WSDL file and JAX-RPC mapping file are created under the './build' directory.

The compile Ant Task is internally processed in the order of '-pre-compile', 'do-compile', and '-postcompile'. The '-post-compile' process that creates the WSDL file and JAX-RPC mapping file shown in the following.

<target name="-post-compile">
    <mkdir dir="${build.classes.dir}/META-INF/wsdl"/>
    <antcall target="java2wsdl">
        <param name="java2wsdl.option" 
               value="-classpath ${build.classes.dir}
        -d ${build.classes.dir}/META-INF ${src.conf}/ejb-service-config.xml" />
    </antcall>
</target>

Enter the file path of the service configuration file by using the 'configufilepath' attribute of the <java2wsdl> element, and enter the file path of the compiled Java class files by using the 'refid' attribute of the <classpath> element. After executing these commands, a WSDL file and JAX-RPC mapping file are created.

Web services DD (Deployment Descriptor) file is an XML file that contains the deployment configurations. The file provides the web service engine with information about web service deployment and web service back-end search methods.

There are two kinds of web services DD file. First one is the webservices.xml file, a standard web service DD file defined by the Java EE web services specification. The other one is the 'jeus-webservicesdd. xml' file, a JEUS specific deployment descriptor file.

Configuring Java EE Web Service DD File

The name of the Java EE web service DD file must be 'webservices.xml'.


In the file, the service name is 'AddressBookService'. The WSDL file path is the 'WEB-INF/wsdl' directory of the JAR package, and the name of the file is 'AddressBookService.wsdl'. The JAX-RPC mapping file path is the 'META-INF' directory, and the name of the file is 'AddressBookServicemapping. xml'.

In order to connect to the service, the port named 'AddressBookIFPort' in the WSDL must be used and an SEI and EJB must be created for this port.

Configuring JEUS Web Services DD File

The name of the JEUS web services DD file must be 'jeus-webservices-dd.xml'.


The URL for invoking an EJB web service is configured in the JEUS web services deployment descriptor file. The URL consists of a context path and URL pattern. The context path is set in the <ejb-contextpath> element, and the URL pattern is set in the <ejb-endpoint-url> element within the <port> element.

The following is the actual URL for invoking the web service.

http://host:port/webservice/AddressBookService

An EJB-based web service is packaged with the web services DD and WSDL into an EJB JAR package. The EJB JAR package is then packaged into a standard enterprise application EAR file with other web application WAR and EJB JAR packages.

This section describes how to package and deploy EAR files.

Packaging EAR File

A Java EE application is an independent business solution that can utilize web component, EJB, or JavaEE connectors, and it can be packaged into an EAR (Enterprise Archive) file. An EAR file contains the application deployment descriptors and may contain additional Java EE components and connectors packaged as EJB JAR, WAR, or RAR file.

JSE (JAX-RPC Service Endpoint) is packaged into a WAR file since it is created using a servlet programming model. An EJB endpoint is packaged into an EJB JAR file because an EJB is where SOAP messages are handled.

EAR
 |
 +-- WAR file
      |
      +-- JSE(JAX-RPC Servlet Endpoint) Web service component
 |
 +-- JAR file
      |
      +-- EJB Web service component
 |
 +-- META-INF
      |
      +-- Standard application.xml file

JavaEE components packaged into an EAR file are defined in the application.xml file of the 'META-INF' directory.

The following is a sample application.xml file of an EAR application that contains a web module as a Java EE component.


The JAR package name of the EJB-based web service is configured in the <ejb> element.

Deploying Web Services (Deploying EAR Applications)

The deployment procedures for web services are identical to those for other Java EE applications. After the EAR package has been deployed, web services can be invoked via the internet.