Creating Web services using Apache CXF (Part 4): Testing

To test this we can follow the same client program which is given in the CXF site.

Just create a simple Java class and execute it.

   1: package com.your.company.service.client;
   2:  
   3: import java.util.List;
   4:  
   5: import org.apache.cxf.interceptor.LoggingInInterceptor;
   6: import org.apache.cxf.interceptor.LoggingOutInterceptor;
   7: import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
   8:  
   9: import com.your.company.service.Product;
  10: import com.your.company.service.ProductService;
  11:  
  12: public final class Client {
  13:  
  14:     private Client() {
  15:     }
  16:  
  17:     public static void main(String args[]) throws Exception {
  18:  
  19:         JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
  20:  
  21:         factory.getInInterceptors().add(new LoggingInInterceptor());
  22:         factory.getOutInterceptors().add(new LoggingOutInterceptor());
  23:         factory.setServiceClass(ProductService.class);
  24:         factory.setAddress("http://localhost:8080/CXFExample/productservice");
  25:         ProductService client = (ProductService) factory.create();
  26:  
  27:         List<Product> products = client.getProducts();
  28:         if (products != null && products.size() > 0)
  29:             System.out.println("Product Name : "
  30:                     + products.get(0).getItemName() + ", Price: "
  31:                     + products.get(0).getPrice());
  32:         System.exit(0);
  33:  
  34:     }
  35:  
  36: }

Other related posts:

1. Creating Web services using Apache CXF (Part 1) : The Basics.

2. Creating Web services using Apache CXF (Part 2) : Development.

3. Creating Web services using Apache CXF (Part 3) : Configuration.

4. Creating Web services using Apache CXF (Part 4): Testing.

17 Responses to “Creating Web services using Apache CXF (Part 4): Testing”


  1. 1 Subroto June 16, 2009 at 8:48 am

    You should add this code to Client.java:

    factory.getServiceFactory().setDataBinding(new AegisDatabinding());
    

    before factory.create(), because the server is using Aegis data binding.

  2. 3 Taras Matyashovsky June 24, 2009 at 2:31 pm

    Thanks for the great post.

    One question appeared – is there any opportunity to unite few services (in some way) in order to have one wsdl file generated?
    For instance, You have service1 and service2 as 2 separate interfaces and as a result have one wsdl for both of them?

    Best,
    Taras

  3. 5 VK August 22, 2009 at 9:41 pm

    Thanks Lijin ,

    That was a nice article.
    I have doubt that if the client is a C# application and trying to consume the same web service then it will it cause an issue ?

    Thanks in Advance
    VK


  1. 1 Creating “Contract First” – Web Services using CXF (Top Down Approach) Part 1: Creating XSDs. – Lijin’s Localhost Trackback on July 4, 2009 at 11:57 am
  2. 2 Creating “Contract First” – Web Services using CXF (Top Down Approach) Part 1: Creating XSDs. | Mind Diary Trackback on July 9, 2009 at 10:31 am

Leave a Reply




Disclaimer

The information on this site is for informational purposes only. The use of any Trademark or Copyrighted material is not intended to infringe Copyright. This blog is intended to be used under a policy of personal and non commercial use.

Subscribe it

Subscribe

Blog Stats

  • 356,994 hits

Twitting

Adds

Add to Technorati Favorites
Subscribe in NewsGator Online Subscribe in Bloglines
 Add to My AOL
Subscribe in FeedLoungeAdd to netvibes
Add to The Free Dictionary
Subscribe in NewsAlloyAdd to Pageflakes

Feeds

RSS Daily Bible Verse

  • Luke 2:8-11

 

June 2009
S M T W T F S
« May   Jul »
 123456
78910111213
14151617181920
21222324252627
282930