code

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

Consume the web service

  • Once the application server starts, lets run a test-case to consume the webservice mvn --define skip.tests=false -Dtest=WebServiceTest test
  • PS D:\works\hello-web-service> mvn --define skip.tests=false -Dtest=WebServiceTest test   

Launch the application

  • After the code is built launch the application by running mvn jetty:run
  • PS D:\works\hello-web-service> mvn jetty:run                                              
    [INFO] Scanning for projects...

Build the code

  • Now that the code is checked out, let's build it
  • From command line go into the hello-web-service folder and run the Maven build command - mvn clean install
  • PS D:\works> cd .\hello-web-service                                                       

Checkout the code

  • Using any gitclient checkout the source code from git://github.com/perusworld/hello-web-service.git
  • I am checking out using the command line - git clone git://github.com/perusworld/hello-web-service.git
  • PS D:\works> git clone git://github.com/perusworld/hello-web-service.git                  

Who's online

There are currently 0 users and 3 guests online.

Who's new

  • Saravana Peruma...

Syndicate content