walkthrough

Web Service Client

Now lets look at the consumer of the Web Service, on our case the junit testcase WebServiceTest.java

  • We already saw the consumers created dynamically using cxf in the Spring configuration, we are just going to use the injected clients directly in the testcase.

Web Service Implementation

Now that the Web Service interfaces are defined (HelloWorld.java,FileManagement.java), let's look at their implementation details.

Receiving the binary content using DataHandler

The File.java is a simple bean that has 2 properties a string and a DataHandler, the DataHandler is used to receive the file contents sent from the consumer of the web service.

Java Code

Lets walk through the java code now, here we basically define the interfaces for our web services and add the implementation for the same as well

  • The HelloWorld.java interface has a one method that takes in a string parameter. Notice the annotations (@WebService to define a web service and @WebParam to define a parameter)

Spring configuration

Walk through the code

Now that the application is running, let's walk through the code.

  • The web application is wired using the web.xml

Html page to call the REST service

index.html

  • The calling html page is a simple page with 2 inputs and a submit button

Number Service

NumberService.java

  • Most of the configuration is done via annotations itself. The code just does the business logic (i.e to add 2 numbers)
  • Path("/number/") annotation specifies the relative URI path that this class will serve is /number/

Spring configuration

config.xml

  • The spring configuration is a simple one line to read all the configuration settings through annotations
  • RestApp - spring configuration file

Walk through the code

Now that the application is running, let's walk through the code.

web.xml

Who's online

There are currently 0 users and 5 guests online.

Who's new

  • Saravana Peruma...

Syndicate content