+

Search Tips   |   Advanced Search

Implement web services applications with JAX-WS

When starting from existing JavaBeans or enterprise beans, we can use a bottom-up approach to developing Web services based on JAX-WS.

Determine the existing JavaBeans or enterprise beans to expose as a JAX-WS web service.

IBM WebSphere Application Server supports JAX-WS and JAX-RPC. Using the strategic JAX-WS programming model, development of web services and clients is simplified through support of a standards-based annotations model. Although JAX-RPC and applications are still supported, take advantage of the easy-to-implement JAX-WS programming model to develop new web services applications and clients.best-practices

To develop web services based on JAX-WS, we can use a bottom-up development approach starting from existing JavaBeans or enterprise beans or we can use a top-down development approach starting with an existing WSDL file. This task describes the steps when using the bottom-up development approach.

When developing JAX-WS web services starting from existing JavaBeans or enterprise beans, we can expose the bean as a JAX-WS web service using annotations. Adding the @WebService or @WebServiceProvider annotation to the bean defines the bean as a JAX-WS web service. JAX-WS web services can optionally use a service endpoint interface. In addition to annotating the bean and the optional service endpoint interface, assemble all the artifacts that the web service requires, and deploy the resulting application into the application server environment to complete the process of enabling the bean as a web service. Although the use of a WSDL file is considered a best practice, we are not required to package a WSDL file with the JAX-WS web services.

Considerations when using JavaBeans

Considerations when using enterprise beans

  • The enterprise bean must be a stateless or singleton session bean.

  • Enterprise beans exposed as JAX-WS web services must be packaged in EJB 3.0 or higher modules.
  • JAX-WS applications containing enterprise beans must be deployed with the endptEnabler command.
  • JAX-WS web services using enterprise beans are supported over an HTTP or Java Message Service (JMS) transport.

  • Enterprise beans may use CDI. Note that constructor injection is not supported.

  • We can optionally include WSDL documents in the JAX-WS application packaging.

Starting with WAS v7.0 and later, Java EE 5 application modules (web application modules version 2.5 or above, or EJB modules version 3.0 or above) are scanned for annotations to identify JAX-WS services and clients. However, pre-Java EE 5 application modules (web application modules version 2.4 or before, or EJB modules version 2.1 or before) are not scanned for JAX-WS annotations, by default, for performance considerations. In the v6.1 Feature Pack for Web Services, the default behavior is to scan pre-Java EE 5 web application modules to identify JAX-WS services and to scan pre-Java EE 5 web application modules and EJB modules for service clients during application installation. Because the default behavior for WAS v7.0 and later is to not scan pre-Java EE 5 modules for annotations during application installation or server startup, to preserve backward compatability with the feature pack from previous releases, configure either the UseWSFEP61ScanPolicy property in the META-INF/MANIFEST.MF of a web application archive (WAR) file or EJB module or define the JVM custom property, com.ibm.websphere.webservices.UseWSFEP61ScanPolicy, on servers to request scanning during application installation and server startup. To learn more about annotations scanning, see the JAX-WS annotations information.


Tasks

  1. Set up a development environment for web services. We do not have to set up a development environment if we are using Rational Application Developer.
  2. Develop JAX-WS web services with annotations.
  3. Generate Java artifacts for JAX-WS applications.

    Use JAX-WS tooling to generate the necessary JAX-WS and JAXB artifacts needed for JAX-WS web services applications when starting from JavaBeans or enterprise beans components.

    If we are developing a service implementation bean that is invoked using the HTTP transport, then the WSDL file generated by the wsgen command-line tool during this step is optional. However, if we are developing a service implementation bean that is invoked using the SOAP over JMS transport, then the WSDL file generated by the wsgen tool during this step is required in subsequent steps, and therefore, not optional.

  4. (optional) Enable MTOM for JAX-WS web services. Use SOAP Message Transmission Optimization Mechanism to optimize the transmission of binary attachments, such as images or files along with web services requests.
  5. (optional) Enforce adherence to WSDL bindings in JAX-WS web services. Use the RespectBindingFeature to control whether a JAX-WS implementation is required to respect the contents of a wsdl:binding associated with an endpoint.
  6. (optional) Develop and configure a webservices.xml deployment descriptor for JAX-WS applications. We can optionally use the webservices.xml deployment descriptor to augment or override application metadata specified in annotations within the JAX-WS web services.
  7. Complete the implementation of our web services application.

  8. (Optional) Customize URL patterns in the web.xml file. When JavaBeans are exposed as JAX-WS endpoints, we can optionally customize the URL patterns within the web.xml deployment descriptor contained in the web application archive (WAR) file.
  9. Assemble the artifacts for our web service.

    Use assembly tools provided with the application server to assemble your Java-based web services modules.

    If we have assembled an EAR file containing enterprise beans modules that include web services, use the endptEnabler command-line tool or an assembly tool before deployment to produce a web services endpoint WAR file. This tool is also used to specify whether the web services are exposed using SOAP over Java Message Service (JMS) or SOAP over HTTP.

  10. Deploy the EAR file into the application server. We can now deploy the EAR file configured and enabled for JAX-WS web services onto the application server.
  11. Test the web service to make sure that the service works with the application server.

We have developed a JAX-WS application.


Related:

  • JAX-WS
  • Web services
  • Enforcing adherence to WSDL bindings in JAX-WS web services
  • Assembling web services applications
  • Deploy web services applications onto application servers
  • Testing web services-enabled clients
  • Use HTTP to transport web services
  • Use SOAP over JMS to transport web services
  • Example: Installing a web services sample with the console
  • Implement web services applications from existing WSDL files with JAX-WS
  • Artifacts used to develop web services
  • JAX-WS annotations
  • Web services specifications and APIs
  • Contexts and Dependency Injection (CDI)
  • JAX-WS API documentation
  • JAX-WS API User's Guide documentation