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;
 3: import java.util.List;
 5: import org.apache.cxf.interceptor.LoggingInInterceptor;
 6: import org.apache.cxf.interceptor.LoggingOutInterceptor;
 7: import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
 9: import;
 10: import;
 12: public final class Client {
 14:     private Client() {
 15:     }
 17:     public static void main(String args[]) throws Exception {
 19:         JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
 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();
 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);
 34:     }
 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.

19 thoughts on “Creating Web services using Apache CXF (Part 4): Testing

  1. Ok, looks like I answered my own question … kinda of

    for JAXB use:
    factory.getServiceFactory().setDataBinding(new JAXBDataBinding());

    and comment out parts of applicationContext.xml

    both beans under this



    This works on the server because JAXB is the CXF
    default Binding. I assume there is no default binding on the
    client side

  2. Lijin,

    Can you please explain why as per Subroto comment above you need
    factory.getServiceFactory().setDataBinding(new AegisDatabinding());

    I see that it doesn’t work with out this, in my case I get
    unexpected element “Product”.

    The reason I ask is that the documentation says you can use Aegis
    on the server and something else on the client e.g. JAXB binding.

    How can I use Jaxb on the client?


  3. 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

Leave a Reply to timr Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: