Chapter 4. Creating and Deploying Web Services

Table of Contents

4.1. Overview
4.2. Creating and Deploying Java Class Web Services
4.3. Creating and Deploying EJB Web Services
4.4. Creating and Deploying WSDL Web Services
4.5. How to Determine an Endpoint Address
4.5.1. Servlet Endpoint
4.5.2. EJB Endpoint

This chapter describes how to create JAX-WS web service applications from Java class and WSDL files, how to deploy and package them, and how to manage them in JEUS 8.

4.1. Overview

The process for deployment is almost the same as for any other web services implemented either from Java class or WSDL file. Since JAX-WS web service implementation is POJO web service-oriented, there is much less number of deployment descriptors than in a JAX-RPC web service.

JAX-WS web services can be programmed without using a deployment descriptor, which was generally used for the implementation of JEUS 5 JAX-RPC web services. This enables a developer to develop web services more conveniently and rapidly (Descriptor free programming).

4.2. Creating and Deploying Java Class Web Services

Creating a web service, implemented from Java classes, as a WAR file involves binding service endpoint implementation classes and other Java classes (portable artifacts) used by the implementation class with multiple deployment descriptor (DD) files into a WAR format.

The following shows the web service implemented from the Java classes from the previous chapter in a WAR format grouped by directory.

META-INF/MANIFEST.MF
WEB-INF/classes/AddNumbersImplService_schema1.xsd
WEB-INF/classes/AddNumbersImplService.wsdl
WEB-INF/classes/fromjava/server/AddNumbersImpl.class
WEB-INF/classes/fromjava/server/jaxws/AddNumbers.class
WEB-INF/classes/fromjava/server/jaxws/AddNumbersResponse.class

As shown in the previous example, the WAR file consists of a service endpoint implementation class, portable artifact classes, and the web.xml file, which is the only DD file. The web.xml file is not required to implement a JAX-WS web service, but it is used here to obtain a preferred endpoint address. For more details about endpoint addresses, refer to "4.5. How to Determine an Endpoint Address".

The web service WAR file can be accessed when it is deployed using the method provided by JEUS 8. Enter the following command in the console to deploy the WAR file in JEUS 8.

$ ant build deploy

The following is the actual address for accessing the service after a successful deployment.

http://host:port/AddNumbers/AddNumbersImplService

4.3. Creating and Deploying EJB Web Services

Creating a web service, implemented from a Java class, as a JAR file involves binding a service endpoint implementation class and other Java classes (portable artifacts) used by the implementation class with multiple DD files into a JAR format.

The following shows the web service implemented from the stateless session beans from the previous chapter in a JAR format grouped by directory.

META-INF/MANIFEST.MF
fromejb/server/AddNumbersImpl.class
fromejb/server/jaxws/AddNumbers.class
fromejb/server/jaxws/AddNumbersResponse.class

As shown in the previous example, the JAR file consists of service endpoint implementation and portable artifact classes. For more information about endpoint addresses, refer to "4.5. How to Determine an Endpoint Address".

The web service JAR file can be accessed when deployed by using the method provided by JEUS 8. To deploy the JAR file in JEUS 8, enter the following command in the console.

$ ant build deploy

The following is the actual address for accessing the service after a successful deployment.

http://host:port/AddNumbersImplService/AddNumbersImpl

4.4. Creating and Deploying WSDL Web Services

Creating a web service, implemented from WSDL, as a WAR file involves binding a service endpoint interface, its service endpoint implementation class, and other portable artifacts with multiple DD files into a WAR file format.

The following shows the web service implemented from the WSDL from the previous chapter in a WAR format grouped by directory.

META-INF/MANIFEST.MF
WEB-INF/wsdl/AddNumbers.wsdl
WEB-INF/classes/fromjava/server/AddNumbers.class
WEB-INF/classes/fromjava/server/AddNumbersImpl.class
WEB-INF/classes/fromjava/server/AddNumbersPortType.class
WEB-INF/classes/fromjava/server/AddNumbersResponse.class
WEB-INF/classes/fromjava/server/AddNumbersService.class
WEB-INF/classes/fromjava/server/ObjectFactory.class
WEB-INF/classes/fromjava/server/package-info.class

As shown in the previous example, the WAR file consists of the service endpoint interface (AddNumbersPortType), an implementation of the interface (AddNumbersImpl), multiple portable artifact classes, and a single DD file, web.xml. The web.xml file is not required to implement a JAX-WS web service, but they are used here to obtain a preferred endpoint address. For more information about endpoint addresses, refer to "4.5. How to Determine an Endpoint Address".

The web service WAR file can be accessed when deployed using the method provided by JEUS 8. To deploy the WAR file in JEUS 8, enter the following command in the console.

$ ant build deploy

The following is the actual address for accessing the service after a successful deployment.

http://host:port/AddNumbers/AddNumbersService

4.5. How to Determine an Endpoint Address

In JEUS 8, a JAX-WS web service can be deployed without any deployment descriptor file (descriptor-free), such as web.xml or webservices.xml file, which was required in JEUS 5.

This section discusses how to determine an address to access a JAX-WS web service when the service is deployed to JEUS 8, for servlet based and EJB based web services.

4.5.1. Servlet Endpoint

A servlet endpoint URL is determined in the following priority order.

  1. When using the <url-pattern> element in web.xml

    The <url-pattern> element in the web.xml file is used to configure the web service URL. This value overwrites the default value of @EndpointDescription endpoint address.

    The following is an example of the web.xml file that configures the endpoint class named AddNumbersImpl.

    [Example 4.1] << web.xml >>

    <web-app>
        <display-name>fromwsdl</display-name>
        <description>fromwsdl</description>
        <servlet>
            <servlet-name>fromwsdl</servlet-name>
            <display-name>fromwsdl</display-name>
            <servlet-class>fromwsdl.server.AddNumbersImpl</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>fromwsdl</servlet-name>
            <url-pattern>/addnumbers</url-pattern>
        </servlet-mapping>
    </web-app>

    [Example 4.2] << AddNumbersImpl.java >>

    @WebService(serviceName="AddNumbers")
    @EndpointDescription(endpointUrl="MyService")
    public class AddNumbersImpl {
    
        public int addNumbers(int number1, int number2) {
            return number1 + number2;
        }
    }

    The following is the actual URL for the web service.

    http://server:port/context/addnumbers
  2. When using the @EndpointDescription Annotation

    If an endpointUrl variable is specified in the @EndpointDescription annotation, its value is the URL for accessing the web service. The value overwrites the default serviceName endpoint address in the @WebService annotation.

    The following is an example of an endpoint class.

    [Example 4.3] << AddNumbersImpl.java >>

    @WebService(serviceName="AddNumbers")
    @EndpointDescription(endpointUrl="MyService")
    public class AddNumbersImpl {
    
        public int addNumbers(int number1, int number2) {
            return number1 + number2;
        }
    }

    The following is the actual URL for the web service in this example.

    http://server:port/context/MyService
  3. When using the serviceName attribute of the @WebService Annotation

    If a serviceName variable is specified in the @WebService annotation, its value is the URL for the web service. This value overwrites the default endpoint address.

    The following is an example of an endpoint class.

    [Example 4.4] << AddNumbersImpl.java >>

    @WebService(serviceName="AddNumbers")
    public class AddNumbersImpl {
    
        public int addNumbers(int number1, int number2) {
            return number1 + number2;
        }
    }

    The following is the actual URL for the web service.

    http://server:port/context/AddNumbers
  4. Default value of an endpoint address + "Service"

    If nothing is specified but the @WebService annotation, the default value of the web service endpoint address is the endpoint class name + "Service".

    The following is an example of an endpoint class.

    [Example 4.5] << AddNumbersImpl.java >>

    @WebService
    public class AddNumbersImpl {
    
        public int addNumbers(int number1, int number2) {
            return number1 + number2;
        }
    }

    The following is the actual URL for the web service.

    http://server:port/context/AddNumbersImplService 

4.5.2. EJB Endpoint

The priority order for determining the EJB endpoint URL is the same as that of the servlet endpoint, but the method for determining the context is different.

The context is determined in the following priority order.

  1. When using the @EndpointDescription Annotation

    • Endpoint

      If an endpointUrl variable is specified in the @EndpointDescription annotation, this value is the URL for the web service. This value overwrites the default name endpoint address in the @WebService annotation.

      The following is an example of an endpoint class.

      [Example 4.6] << AddNumbersImpl.java >>

      @WebService(name="AddNumbersService")
      @EndpointDescription(endpointUrl="MyService")
      @Stateless
      public class AddNumbersImpl {
      
          public AddNumbersImpl() {
      
          }
      
          public int addNumbers(int number1, int number2) {
              return number1 + number2;
          }
      }

      The following is the actual URL for the web service.

      http://server:port/context/MyService
    • Context

      If a contextPath attribute value is used for the @jeus.webservices.annotation.EndpointDescription annotation, it overwrites the default context value.

      The following is an example of an endpoint class.

      [Example 4.7] << AddNumbersImpl.java >>

      @WebService(name="Hello", serviceName="AddNumbersService")
      @jeus.webservices.annotation.EndpointDescription(contextPath="EJBService",
          endpointUrl="MyEndpoint")
      @Stateless
      public class AddNumbersImpl {
      
          public AddNumbersImpl() {
      
          }
      
          public int addNumbers(int number1, int number2) {
              return number1 + number2;
          }
      }

      The following is the actual URL for the web service.

      http://server:port/EJBService/MyEndpoint
  2. When using the serviceName attribute of the @WebService Annotation

    • Endpoint

      If a name variable is specified in the @WebService annotation, its value is the URL for the web service. This value overwrites the default endpoint address.

      The following is an example of an endpoint class.

      [Example 4.8] << AddNumbersImpl.java >>

      @WebService(name="AddNumbersService")
      @Stateless
      public class AddNumbersImpl {
      
          public AddNumbersImpl() {
      
          }
      
          public int addNumbers(int number1, int number2) {
              return number1 + number2;
          }
      }

      The following is the actual URL for the web service.

      http://server:port/context/AddNumbersService
    • Context

      If a serviceName attribute value is used for the @WebService annotation, it overwrites the default context value.

      The following is an example of an endpoint class.

      [Example 4.9] << AddNumbersImpl.java >>

      @WebService(name="Hello", serviceName="AddNumbersService")
      @Stateless
      public class AddNumbersImpl {
      
          public AddNumbersImpl() {
      
          }
      
          public int addNumbers(int number1, int number2) {
              return number1 + number2;
          }
      }

      The following is the actual URL for the web service.

      http://server:port/AddNumbersService/Hello

  3. Default value of the context

    • Endpoint

      If nothing is specified but the @WebService annotation, the default value of the web service endpoint address is the name of the endpoint class.

      The following is an example of an endpoint class.

      [Example 4.10] << AddNumbersImpl.java >>

      @WebService
      @Stateless
      public class AddNumbersImpl {
      
          public AddNumbersImpl() {
      
          }
      
          public int addNumbers(int number1, int number2) {
              return number1 + number2;
          }
      }

      The following is the actual URL for the web service.

      http://server:port/context/AddNumbersImpl
    • Context

      The default value of a context is the service name (ServiceName) from the WSDL document of the web service. The default service name is specified by adding 'Service' to the endpoint class name.

      The following is the address for the web service of this endpoint class.

      http://server:port/AddNumbersImplService/AddNumbersImpl