Chapter 11. Exposing Java Code as a Web Service

This chapter contains the following recipes:

  • Creating a service endpoint interface
  • Using non-exposable methods of service interface
  • Annotating the service endpoint interface with @WebService
  • Annotating the service endpoint interface with @SOAPBinding
  • Wrapping exceptions into faults
  • Defining a request wrapper for a web service
  • Defining a response wrapper for a web service
  • Defining a one or two way web service
  • Defining the direction of the parameters
  • Publishing a web service without an application server

Introduction

Real production environments still operate on many legacy applications that are written in a variety of programming languages. As the adaptation of the applications for integration presents a big work effort and costs a lot of money, a better approach is to expose the application functionality through API and web services. Other mechanisms for integration are also mentioned in this book, such as REST, JMS, EJB, and so on. This way, however, it is easier to integrate other applications with legacy application, as we can integrate different applications in a technology-neutral manner. Also, we can take advantage of other web service features such as interoperability and reusability.

As this book addresses Java and BPEL, we cover the aspects of how to expose the already existing Java code as a web service. To some extent, we already covered this in Chapter 8, Exposing Java Code as a SOAP Service. We start by defining the service interface which presents the entry point for other applications to integrate. The rest of the recipes cover usage of annotations for web service decoration. The last recipe shows you how to publish a web service without using an application server. In the early stages, such publishing might present a much better alternative as opposed to using an application server.

Throughout this chapter, we will work on the sample application we have prepared. The sample presents a simplified version of a credit card gateway for processing purchases, refunding, and voiding operations. The application consists of the following two components:

  • A credit card operations module (CreditCardGateway.java): Operators are able to perform various operations. We omit the user interface design for simplicity.
  • A backend operations module (BackEndSystem.java): Presents the core of the credit card operations.

Throughout the recipes, we will explore the ways in which to expose functionality of the sample application as a web service in order to enable credit card operations by other parties automatically without human intervention.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset